@cilix/lightjs 0.0.4 → 0.0.5
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 +28 -20
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -1447,9 +1447,11 @@ module.exports = (config) => {
|
|
|
1447
1447
|
}
|
|
1448
1448
|
emit('<');
|
|
1449
1449
|
emit(node.data.name);
|
|
1450
|
+
let innerText = null;
|
|
1450
1451
|
for (let a in attr) {
|
|
1451
1452
|
let val = evaluate(attr[a]);
|
|
1452
1453
|
const t = getType(val);
|
|
1454
|
+
if (a === 'innerHTML') innerText = val;
|
|
1453
1455
|
if (val !== false || a === 'innerHTML') {
|
|
1454
1456
|
emit(' ');
|
|
1455
1457
|
emit(a.replace('bind:', ''));
|
|
@@ -1473,11 +1475,13 @@ module.exports = (config) => {
|
|
|
1473
1475
|
emit('>');
|
|
1474
1476
|
if (void_tags.indexOf(node.data.name) === -1) {
|
|
1475
1477
|
if (node.data.name === 'html') {
|
|
1478
|
+
if (innerText) err('cannot set innerHTML of html tag');
|
|
1476
1479
|
if (found.html) err('html tag may only be used once', node.data);
|
|
1477
1480
|
found.html = true;
|
|
1478
1481
|
} else if (!found.html) {
|
|
1479
1482
|
err('html tag must be the first tag printed', node.data);
|
|
1480
1483
|
} else if (node.data.name === 'head') {
|
|
1484
|
+
if (innerText) err('cannot set innerHTML of head tag');
|
|
1481
1485
|
if (found.head) err('head tag may only be used once', node.data);
|
|
1482
1486
|
found.head = true;
|
|
1483
1487
|
} else if (node.data.name === 'body') {
|
|
@@ -1485,23 +1489,25 @@ module.exports = (config) => {
|
|
|
1485
1489
|
if (found.body) err('body tag may only be used once', node.data);
|
|
1486
1490
|
found.body = true;
|
|
1487
1491
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
emit(
|
|
1492
|
+
if (innerText) {
|
|
1493
|
+
emit(innerText);
|
|
1494
|
+
emit('</');
|
|
1495
|
+
emit(node.data.name);
|
|
1496
|
+
emit('>');
|
|
1497
|
+
} else {
|
|
1498
|
+
node.children.forEach(walk);
|
|
1499
|
+
if (node.data.name === 'head') {
|
|
1500
|
+
emit('<script>');
|
|
1501
|
+
emit(`document.addEventListener('DOMContentLoaded', function () {\n`);
|
|
1502
|
+
emit(`(function (data){${js}})(${JSON.stringify(initial_state)})`);
|
|
1503
|
+
emit('});');
|
|
1504
|
+
emit('<' + '/script>');
|
|
1499
1505
|
}
|
|
1506
|
+
emit('</');
|
|
1507
|
+
emit(node.data.name);
|
|
1508
|
+
emit('>');
|
|
1509
|
+
inScript = false;
|
|
1500
1510
|
}
|
|
1501
|
-
emit('</');
|
|
1502
|
-
emit(node.data.name);
|
|
1503
|
-
emit('>');
|
|
1504
|
-
inScript = false;
|
|
1505
1511
|
}
|
|
1506
1512
|
} break;
|
|
1507
1513
|
case 'if': {
|
|
@@ -1520,14 +1526,14 @@ module.exports = (config) => {
|
|
|
1520
1526
|
if (t === 'array' || t === 'string') {
|
|
1521
1527
|
for (let i = 0; i < val.length; i++) {
|
|
1522
1528
|
s[it[0]] = val[i];
|
|
1523
|
-
s[it[1]] = i;
|
|
1529
|
+
if (it[1]) s[it[1]] = i;
|
|
1524
1530
|
node.children.forEach(walk);
|
|
1525
1531
|
}
|
|
1526
1532
|
} else if (t === 'object') {
|
|
1527
1533
|
const keys = Object.keys(val);
|
|
1528
1534
|
for (let i = 0; i < keys.length; i++) {
|
|
1529
1535
|
s[it[0]] = keys[i];
|
|
1530
|
-
s[it[1]] = val[keys[i]];
|
|
1536
|
+
if (it[1]) s[it[1]] = val[keys[i]];
|
|
1531
1537
|
node.children.forEach(walk);
|
|
1532
1538
|
}
|
|
1533
1539
|
} else {
|
|
@@ -1804,7 +1810,7 @@ module.exports = (config) => {
|
|
|
1804
1810
|
if (t === 'object' || t === 'null' || t === 'array') {
|
|
1805
1811
|
stack.push(JSON.stringify(val));
|
|
1806
1812
|
} else {
|
|
1807
|
-
stack.push(
|
|
1813
|
+
stack.push(val.toString());
|
|
1808
1814
|
}
|
|
1809
1815
|
} break;
|
|
1810
1816
|
case 'join': {
|
|
@@ -2631,7 +2637,8 @@ module.exports = (config) => {
|
|
|
2631
2637
|
|
|
2632
2638
|
createFileList(ast);
|
|
2633
2639
|
|
|
2634
|
-
emit(`document.addEventListener('DOMContentLoaded', function () {\n`);
|
|
2640
|
+
// emit(`document.addEventListener('DOMContentLoaded', function () {\n`);
|
|
2641
|
+
emit('(function () {')
|
|
2635
2642
|
emit(`${light_runtime}`);
|
|
2636
2643
|
emit('var $sync = function () {};\n');
|
|
2637
2644
|
for (let g in globals) {
|
|
@@ -2675,7 +2682,8 @@ module.exports = (config) => {
|
|
|
2675
2682
|
});
|
|
2676
2683
|
|
|
2677
2684
|
emit('$sync();\n');
|
|
2678
|
-
emit('});\n');
|
|
2685
|
+
// emit('});\n');
|
|
2686
|
+
emit('})();\n');
|
|
2679
2687
|
|
|
2680
2688
|
return out;
|
|
2681
2689
|
};
|