@cilix/lightjs 0.0.15 → 0.0.16
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 +81 -11
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -288,6 +288,47 @@ module.exports = (config, fs, path) => {
|
|
|
288
288
|
'wbr'
|
|
289
289
|
];
|
|
290
290
|
|
|
291
|
+
const bindHelpers = {
|
|
292
|
+
input: {
|
|
293
|
+
number: {
|
|
294
|
+
prop: "valueAsNumber",
|
|
295
|
+
event: "input"
|
|
296
|
+
},
|
|
297
|
+
range: {
|
|
298
|
+
prop: "valueAsNumber",
|
|
299
|
+
event: "input"
|
|
300
|
+
},
|
|
301
|
+
checkbox: {
|
|
302
|
+
prop: "checked",
|
|
303
|
+
event: "change"
|
|
304
|
+
},
|
|
305
|
+
radio: {
|
|
306
|
+
prop: "checked",
|
|
307
|
+
event: "change"
|
|
308
|
+
},
|
|
309
|
+
default: {
|
|
310
|
+
prop: "value",
|
|
311
|
+
event: "input"
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
textarea: {
|
|
315
|
+
default: {
|
|
316
|
+
prop: "value",
|
|
317
|
+
event: "input"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
select: {
|
|
321
|
+
multiple: {
|
|
322
|
+
prop: "selectedOptions[]",
|
|
323
|
+
event: "change"
|
|
324
|
+
},
|
|
325
|
+
default: {
|
|
326
|
+
prop: "value",
|
|
327
|
+
event: "change"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
291
332
|
const getPathInfo = (p, base) => {
|
|
292
333
|
const full = base ? path.resolve(base, p) : path.resolve(p);
|
|
293
334
|
const parent = path.dirname(full);
|
|
@@ -333,8 +374,8 @@ module.exports = (config, fs, path) => {
|
|
|
333
374
|
|
|
334
375
|
const tokenize = (prog, file, offset) => {
|
|
335
376
|
let cursor = 0, end_pos = prog.length - 1;
|
|
336
|
-
|
|
337
|
-
|
|
377
|
+
const tokens = [{ type: "file_begin", data: file, pos: 0, file: file }];
|
|
378
|
+
const keywords = [
|
|
338
379
|
"tag",
|
|
339
380
|
"each",
|
|
340
381
|
"if",
|
|
@@ -354,7 +395,7 @@ module.exports = (config, fs, path) => {
|
|
|
354
395
|
"catch"
|
|
355
396
|
];
|
|
356
397
|
|
|
357
|
-
|
|
398
|
+
const symbols = [
|
|
358
399
|
".",
|
|
359
400
|
"#",
|
|
360
401
|
"=",
|
|
@@ -1031,11 +1072,11 @@ module.exports = (config, fs, path) => {
|
|
|
1031
1072
|
let nosync = accept('nosync');
|
|
1032
1073
|
events.push({ type: evt, handler: handler, sync: !nosync });
|
|
1033
1074
|
} else if (accept("ident") || accept("as")) {
|
|
1034
|
-
|
|
1075
|
+
if (key === 'bind') {
|
|
1076
|
+
includeRuntime = true;
|
|
1077
|
+
}
|
|
1078
|
+
// allow ':' in attribute names ...for now
|
|
1035
1079
|
while (accept(':')) {
|
|
1036
|
-
if (key === 'bind') {
|
|
1037
|
-
includeRuntime = true;
|
|
1038
|
-
}
|
|
1039
1080
|
key += ':'
|
|
1040
1081
|
key += tok.data;
|
|
1041
1082
|
expect("ident");
|
|
@@ -1556,7 +1597,19 @@ module.exports = (config, fs, path) => {
|
|
|
1556
1597
|
if (a === 'innerHTML') innerText = val;
|
|
1557
1598
|
if (val !== false || a === 'innerHTML') {
|
|
1558
1599
|
emit(' ');
|
|
1559
|
-
|
|
1600
|
+
if (a === 'bind') {
|
|
1601
|
+
const bindInfo = bindHelpers[node.data.name];
|
|
1602
|
+
if (bindInfo) {
|
|
1603
|
+
let type = 'default';
|
|
1604
|
+
if (attr.type && attr.type.data[0]) {
|
|
1605
|
+
type = attr.type.data[0].data;
|
|
1606
|
+
}
|
|
1607
|
+
const details = bindInfo[type];
|
|
1608
|
+
emit(details.prop);
|
|
1609
|
+
}
|
|
1610
|
+
} else {
|
|
1611
|
+
emit(a.replace('bind:', ''));
|
|
1612
|
+
}
|
|
1560
1613
|
emit('="');
|
|
1561
1614
|
if (t === 'array') {
|
|
1562
1615
|
val = val.map((c) => {
|
|
@@ -2485,8 +2538,20 @@ module.exports = (config, fs, path) => {
|
|
|
2485
2538
|
emit(', {');
|
|
2486
2539
|
}
|
|
2487
2540
|
for (let a in attr) {
|
|
2488
|
-
|
|
2489
|
-
|
|
2541
|
+
if (a === 'bind') {
|
|
2542
|
+
const bindInfo = bindHelpers[node.data.name];
|
|
2543
|
+
if (bindInfo) {
|
|
2544
|
+
let type = 'default';
|
|
2545
|
+
if (attr.type && attr.type.data[0]) {
|
|
2546
|
+
type = attr.type.data[0].data;
|
|
2547
|
+
}
|
|
2548
|
+
const details = bindInfo[type];
|
|
2549
|
+
evts.push({ type: details.event, bindHandler: { lhs: attr[a], rhs: details.prop }, sync: true });
|
|
2550
|
+
const val = attr[a];
|
|
2551
|
+
a = details.prop;
|
|
2552
|
+
attr[a] = val;
|
|
2553
|
+
}
|
|
2554
|
+
} else if (a === 'bind:value') {
|
|
2490
2555
|
evts.push({ type: 'input', handler: `${attr[a].data} = $e.target.value;`, sync: true });
|
|
2491
2556
|
attr.value = { type: 'ident', data: attr[a].data };
|
|
2492
2557
|
a = 'value';
|
|
@@ -2502,7 +2567,12 @@ module.exports = (config, fs, path) => {
|
|
|
2502
2567
|
emit('"');
|
|
2503
2568
|
emit(e.type);
|
|
2504
2569
|
emit('": function($e) {');
|
|
2505
|
-
|
|
2570
|
+
if (e.bindHandler) {
|
|
2571
|
+
walk(e.bindHandler.lhs);
|
|
2572
|
+
emit(` = $e.target.${e.bindHandler.rhs}`);
|
|
2573
|
+
} else {
|
|
2574
|
+
emit(e.handler);
|
|
2575
|
+
}
|
|
2506
2576
|
emit(`;${e.sync ? ' $sync();' : ''} }, `);
|
|
2507
2577
|
}
|
|
2508
2578
|
emit('}');
|