@cilix/lightjs 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core.js +43 -22
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -385,8 +385,6 @@ module.exports = (config, fs, path) => {
|
|
|
385
385
|
return c == '\n' || c == '\r'
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
// amazing
|
|
389
|
-
// https://stackoverflow.com/a/32567789
|
|
390
388
|
function is_letter (c) {
|
|
391
389
|
return c.toLowerCase() != c.toUpperCase();
|
|
392
390
|
}
|
|
@@ -706,8 +704,9 @@ module.exports = (config, fs, path) => {
|
|
|
706
704
|
return false;
|
|
707
705
|
}
|
|
708
706
|
|
|
709
|
-
function peek(t) {
|
|
710
|
-
|
|
707
|
+
function peek(t, forward) {
|
|
708
|
+
const tk = forward ? tokens[cursor + forward] : tok;
|
|
709
|
+
if (tk.type === t) {
|
|
711
710
|
return true;
|
|
712
711
|
}
|
|
713
712
|
return false;
|
|
@@ -993,12 +992,32 @@ module.exports = (config, fs, path) => {
|
|
|
993
992
|
};
|
|
994
993
|
}
|
|
995
994
|
|
|
995
|
+
function isEventHandler(ident) {
|
|
996
|
+
const c = ident[2];
|
|
997
|
+
return ident.indexOf('on') === 0 && c.length === 1 && c === c.toUpperCase() && c !== c.toLowerCase();
|
|
998
|
+
}
|
|
999
|
+
|
|
996
1000
|
function parse_attributes() {
|
|
997
1001
|
let attr = {};
|
|
998
1002
|
let events = [];
|
|
999
1003
|
while (true) {
|
|
1000
1004
|
let key = tok.data;
|
|
1001
|
-
if (
|
|
1005
|
+
if (peek("on") || (peek('ident') && isEventHandler(tok.data))) {
|
|
1006
|
+
includeRuntime = true;
|
|
1007
|
+
let handler;
|
|
1008
|
+
let evt;
|
|
1009
|
+
if (accept('on')) {
|
|
1010
|
+
expect(":");
|
|
1011
|
+
evt = tok.data;
|
|
1012
|
+
} else {
|
|
1013
|
+
evt = tok.data.replace('on', '').toLowerCase();
|
|
1014
|
+
}
|
|
1015
|
+
expect("ident");
|
|
1016
|
+
expect("=");
|
|
1017
|
+
handler = parse_strict_string();
|
|
1018
|
+
let nosync = accept('nosync');
|
|
1019
|
+
events.push({ type: evt, handler: handler, sync: !nosync });
|
|
1020
|
+
} else if (accept("ident") || accept("as")) {
|
|
1002
1021
|
// allow ':' in attribute names
|
|
1003
1022
|
while (accept(':')) {
|
|
1004
1023
|
if (key === 'bind') {
|
|
@@ -1020,16 +1039,6 @@ module.exports = (config, fs, path) => {
|
|
|
1020
1039
|
} else {
|
|
1021
1040
|
attr[key] = { type: "bool", data: true };
|
|
1022
1041
|
}
|
|
1023
|
-
} else if (accept("on")) {
|
|
1024
|
-
includeRuntime = true;
|
|
1025
|
-
expect(":");
|
|
1026
|
-
let handler;
|
|
1027
|
-
let evt = tok.data;
|
|
1028
|
-
expect("ident");
|
|
1029
|
-
expect("=");
|
|
1030
|
-
handler = parse_strict_string();
|
|
1031
|
-
let nosync = accept('nosync');
|
|
1032
|
-
events.push({ type: evt, handler: handler, sync: !nosync });
|
|
1033
1042
|
} else {
|
|
1034
1043
|
break;
|
|
1035
1044
|
}
|
|
@@ -1177,6 +1186,10 @@ module.exports = (config, fs, path) => {
|
|
|
1177
1186
|
parent = current;
|
|
1178
1187
|
}
|
|
1179
1188
|
|
|
1189
|
+
function isAssignment() {
|
|
1190
|
+
return peek('let') || (peek('ident') && peek(':', 1));
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1180
1193
|
function parse_tag_list() {
|
|
1181
1194
|
if (accept("if")) {
|
|
1182
1195
|
parse_if_statement();
|
|
@@ -1211,6 +1224,9 @@ module.exports = (config, fs, path) => {
|
|
|
1211
1224
|
} else if (accept("when")) {
|
|
1212
1225
|
parse_when_statement();
|
|
1213
1226
|
parse_tag_list();
|
|
1227
|
+
} else if (parse_state.in_tag && isAssignment()) {
|
|
1228
|
+
parse_assignment();
|
|
1229
|
+
parse_tag_list();
|
|
1214
1230
|
} else if (peek("ident")) {
|
|
1215
1231
|
parse_tag();
|
|
1216
1232
|
parse_tag_list();
|
|
@@ -1222,9 +1238,6 @@ module.exports = (config, fs, path) => {
|
|
|
1222
1238
|
ast_node('yield', { pos: tok.pos, file: tok.file });
|
|
1223
1239
|
next();
|
|
1224
1240
|
parse_tag_list();
|
|
1225
|
-
} else if (parse_state.in_tag && (peek('global') || peek('const') || peek('let'))) {
|
|
1226
|
-
parse_assignment();
|
|
1227
|
-
parse_tag_list();
|
|
1228
1241
|
} else if (parse_state.in_tag && peek('js_context')) {
|
|
1229
1242
|
includeRuntime = true;
|
|
1230
1243
|
parent.js = tok.data;
|
|
@@ -1293,10 +1306,18 @@ module.exports = (config, fs, path) => {
|
|
|
1293
1306
|
|
|
1294
1307
|
function parse_assignment () {
|
|
1295
1308
|
const global = tok.data === 'global';
|
|
1296
|
-
|
|
1309
|
+
if (peek('global') || peek('let')) {
|
|
1310
|
+
next();
|
|
1311
|
+
}
|
|
1297
1312
|
let dst = { data: tok.data, pos: tok.pos, file: tok.file };
|
|
1298
1313
|
expect('ident');
|
|
1299
|
-
accept("=")
|
|
1314
|
+
if (!accept("=") && !accept(':')) {
|
|
1315
|
+
throw_error({
|
|
1316
|
+
msg: 'expected assignment',
|
|
1317
|
+
pos: tok.pos,
|
|
1318
|
+
file: tok.file
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1300
1321
|
let val = parse_rhs();
|
|
1301
1322
|
ast_node('set', {
|
|
1302
1323
|
global,
|
|
@@ -1358,12 +1379,12 @@ module.exports = (config, fs, path) => {
|
|
|
1358
1379
|
pos: pos,
|
|
1359
1380
|
file: file
|
|
1360
1381
|
});
|
|
1382
|
+
} else if (isAssignment() || peek('global')) {
|
|
1383
|
+
parse_assignment();
|
|
1361
1384
|
} else if (tok.type === "ident") {
|
|
1362
1385
|
parse_tag_list();
|
|
1363
1386
|
} else if (peek("tag")) {
|
|
1364
1387
|
parse_custom_tag();
|
|
1365
|
-
} else if (peek('const') || peek('let') || peek('global')) {
|
|
1366
|
-
parse_assignment();
|
|
1367
1388
|
} else if (peek('js_context')) {
|
|
1368
1389
|
includeRuntime = true;
|
|
1369
1390
|
ast_node('js', { js: tok.data, pos: tok.pos, file: tok.file });
|