Skip to content

Commit f7f4c39

Browse files
committed
Prepare for CDN delivery
1 parent 7656bf0 commit f7f4c39

21 files changed

+7559
-7647
lines changed

easycoder/easycoder-min.js

Lines changed: 218 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easycoder/easycoder.js

Lines changed: 7285 additions & 3305 deletions
Large diffs are not rendered by default.

easycoder/easycoder.zip

23.2 KB
Binary file not shown.

js/easycoder/Compile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ const EasyCoder_Compiler = {
315315
this.tokens = tokens;
316316
this.index = 0;
317317
this.program = [];
318+
this.program.script = 0;
318319
this.program.symbols = {};
319320
this.symbols = this.program.symbols;
320321
this.warnings = [];

js/easycoder/Core.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -870,46 +870,6 @@ const EasyCoder_Core = {
870870
}
871871
},
872872

873-
Load: {
874-
875-
compile: compiler => {
876-
const lino = compiler.getLino();
877-
const type = compiler.nextToken();
878-
switch (type) {
879-
case `plugin`:
880-
const name = compiler.getNextValue();
881-
compiler.addCommand({
882-
domain: `core`,
883-
keyword: `load`,
884-
lino,
885-
name
886-
});
887-
return true;
888-
}
889-
return false;
890-
},
891-
892-
run: program => {
893-
const command = program[program.pc];
894-
const name = program.getValue(command.name);
895-
switch (command.keyword) {
896-
case `load`:
897-
if (program.checkPlugin(name)) {
898-
return command.pc + 1;
899-
}
900-
EasyCoder_Plugins.getLocalPlugin(
901-
program.getPluginsPath,
902-
name,
903-
program.getPlugin,
904-
program.addLocalPlugin,
905-
function () {
906-
program.run(command.pc + 1);
907-
});
908-
return 0;
909-
}
910-
}
911-
},
912-
913873
Module: {
914874

915875
compile: compiler => {
@@ -2184,8 +2144,6 @@ const EasyCoder_Core = {
21842144
return EasyCoder_Core.Import;
21852145
case `index`:
21862146
return EasyCoder_Core.Index;
2187-
case `load`:
2188-
return EasyCoder_Core.Load;
21892147
case `module`:
21902148
return EasyCoder_Core.Module;
21912149
case `multiply`:

js/easycoder/Main.js

Lines changed: 15 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const EasyCoder = {
33
name: `EasyCoder_Main`,
44

55
domain: {
6-
core: EasyCoder_Core
6+
core: EasyCoder_Core,
7+
browser: EasyCoder_Browser,
8+
json: EasyCoder_Json,
9+
rest: EasyCoder_Rest
710
},
811

912
elementId: 0,
@@ -144,22 +147,26 @@ const EasyCoder = {
144147
},
145148

146149
require: function(type, src, cb) {
150+
let prefix = ``;
151+
if (src[0] == `/`) {
152+
prefix = window.location + `/`;
153+
}
147154
const element = document.createElement(type === `css` ? `link` : `script`);
148155
switch (type) {
149156
case `css`:
150157
element.type = `text/css`;
151-
element.href = src;
158+
element.href = `${prefix}${src}`;
152159
element.rel = `stylesheet`;
153160
break;
154161
case `js`:
155162
element.type = `text/javascript`;
156-
element.src = src;
163+
element.src = `${prefix}${src}`;
157164
break;
158165
default:
159166
return;
160167
}
161168
element.onload = function () {
162-
console.log(`${Date.now() - EasyCoder.timestamp} ms: Library ${src} loaded`);
169+
console.log(`${Date.now() - EasyCoder.timestamp} ms: Library ${prefix}${src} loaded`);
163170
cb();
164171
};
165172
document.head.appendChild(element);
@@ -239,10 +246,6 @@ const EasyCoder = {
239246
program.require = this.require;
240247
program.isUndefined = this.isUndefined;
241248
program.isJsonString = this.isJsonString;
242-
program.checkPlugin = this.checkPlugin;
243-
program.getPlugin = this.getPlugin;
244-
program.addLocalPlugin = this.addLocalPlugin;
245-
program.getPluginsPath = this.getPluginsPath;
246249
program.getSymbolRecord = this.getSymbolRecord;
247250
program.verifySymbol = this.verifySymbol;
248251
program.runtimeError = this.runtimeError;
@@ -325,9 +328,9 @@ const EasyCoder = {
325328
const source = this.tokeniseFile(file);
326329
try {
327330
program = this.compileScript(source, imports, module, parent);
328-
this.scriptIndex++;
329331
if (!program.script) {
330-
program.script = this.scriptIndex;
332+
program.script = EasyCoder.scriptIndex;
333+
EasyCoder.scriptIndex++;
331334
}
332335
const finishCompile = Date.now();
333336
console.log(`${finishCompile - this.timestamp} ms: ` +
@@ -359,7 +362,8 @@ const EasyCoder = {
359362
}
360363
},
361364

362-
tokenise: function(source) {
365+
start: function(source) {
366+
EasyCoder.scriptIndex = 0;
363367
const script = source.split(`\n`);
364368
if (!this.tokenising) {
365369
try {
@@ -370,104 +374,4 @@ const EasyCoder = {
370374
this.tokenising = true;
371375
}
372376
},
373-
374-
setPluginCount: function(count) {
375-
EasyCoder.plugins = [];
376-
EasyCoder.pluginCount = count;
377-
},
378-
379-
checkPlugin: function(name) {
380-
return EasyCoder.domain[name];
381-
},
382-
383-
getPlugin: function(name, src, onload) {
384-
if (EasyCoder.domain[name]) {
385-
onload();
386-
return;
387-
}
388-
const script = document.createElement(`script`);
389-
script.type = `text/javascript`;
390-
let location = document.scripts[0].src;
391-
location = location.substring(0, location.indexOf(`/easycoder.js`));
392-
// script.src = `${location}/${src}?ver=${EasyCoder.version}`;
393-
script.src = `${src}?ver=${EasyCoder.version}`;
394-
script.onload = function () {
395-
console.log(`${Date.now() - EasyCoder.timestamp} ms: Plugin ${src} loaded`);
396-
onload();
397-
};
398-
document.head.appendChild(script);
399-
},
400-
401-
addGlobalPlugin: function(name, handler) {
402-
// alert(`Add plugin ${name}`);
403-
EasyCoder.plugins.push({
404-
name,
405-
handler
406-
});
407-
if (EasyCoder.plugins.length === EasyCoder.pluginCount) {
408-
EasyCoder.plugins.forEach(function (plugin) {
409-
EasyCoder.domain[plugin.name] = plugin.handler;
410-
});
411-
EasyCoder.tokenise(EasyCoder.source);
412-
}
413-
},
414-
415-
addLocalPlugin: function(name, handler, callback) {
416-
EasyCoder.domain[name] = handler;
417-
callback();
418-
},
419-
420-
getPluginsPath: function() {
421-
return EasyCoder.pluginsPath;
422-
},
423-
424-
loadPluginJs: function(path) {
425-
console.log(`${Date.now() - this.timestamp} ms: Load ${path}/easycoder/plugins.js`);
426-
const script = document.createElement(`script`);
427-
script.src = `${window.location.origin}${path}/easycoder/plugins.js?ver=${this.version}`;
428-
script.type = `text/javascript`;
429-
script.onload = () => {
430-
EasyCoder_Plugins.getGlobalPlugins(
431-
this.timestamp,
432-
path,
433-
this.setPluginCount,
434-
this.getPlugin,
435-
this.addGlobalPlugin
436-
);
437-
};
438-
script.onerror = () => {
439-
if (path) {
440-
this.loadPluginJs(path.slice(0, path.lastIndexOf(`/`)));
441-
} else {
442-
this.reportError({
443-
message: `Can't load plugins.js`
444-
}, this.program, this.source);
445-
}
446-
};
447-
document.head.appendChild(script);
448-
this.pluginsPath = path;
449-
},
450-
451-
start: function(source) {
452-
this.source = source;
453-
this.scriptIndex = 0;
454-
let pathname = window.location.pathname;
455-
if (pathname.endsWith(`/`)) {
456-
pathname = pathname.slice(0, -1);
457-
} else {
458-
pathname = ``;
459-
}
460-
if (typeof EasyCoder_Plugins === `undefined`) {
461-
this.loadPluginJs(pathname);
462-
} else {
463-
this.pluginsPath = pathname;
464-
EasyCoder_Plugins.getGlobalPlugins(
465-
this.timestamp,
466-
pathname,
467-
this.setPluginCount,
468-
this.getPlugin,
469-
this.addGlobalPlugin
470-
);
471-
}
472-
}
473377
};

js/plugins/anagrams.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ const EasyCoder_Anagrams = {
4040

4141
compile: () => {}
4242
}
43-
};
43+
};
44+
45+
// eslint-disable-next-line no-unused-vars
46+
EasyCoder.domain.anagrams = EasyCoder_Anagrams;

js/plugins/aws.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,7 @@ const EasyCoder_AWS = {
228228

229229
test: () => {}
230230
}
231-
};
231+
};
232+
233+
// eslint-disable-next-line no-unused-vars
234+
EasyCoder.domain.aws = EasyCoder_AWS;

0 commit comments

Comments
 (0)