@matthesketh/utopia-compiler 0.0.2 → 0.0.4
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/dist/index.cjs +36 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +36 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -480,7 +480,8 @@ ${fnBody}
|
|
|
480
480
|
if (!node.content) return null;
|
|
481
481
|
this.helpers.add("createTextNode");
|
|
482
482
|
const v = this.freshVar();
|
|
483
|
-
|
|
483
|
+
const decoded = decodeEntities(node.content);
|
|
484
|
+
this.emit(`const ${v} = createTextNode(${JSON.stringify(decoded)})`);
|
|
484
485
|
return v;
|
|
485
486
|
}
|
|
486
487
|
genInterpolation(node, scope) {
|
|
@@ -637,6 +638,40 @@ function isComponentTag(tag) {
|
|
|
637
638
|
function escapeStr(s) {
|
|
638
639
|
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
639
640
|
}
|
|
641
|
+
var ENTITY_MAP = {
|
|
642
|
+
"&": "&",
|
|
643
|
+
"<": "<",
|
|
644
|
+
">": ">",
|
|
645
|
+
""": '"',
|
|
646
|
+
"'": "'",
|
|
647
|
+
"'": "'",
|
|
648
|
+
" ": "\xA0",
|
|
649
|
+
"—": "\u2014",
|
|
650
|
+
"–": "\u2013",
|
|
651
|
+
"‘": "\u2018",
|
|
652
|
+
"’": "\u2019",
|
|
653
|
+
"“": "\u201C",
|
|
654
|
+
"”": "\u201D",
|
|
655
|
+
"•": "\u2022",
|
|
656
|
+
"…": "\u2026",
|
|
657
|
+
"©": "\xA9",
|
|
658
|
+
"®": "\xAE",
|
|
659
|
+
"™": "\u2122",
|
|
660
|
+
"→": "\u2192",
|
|
661
|
+
"←": "\u2190",
|
|
662
|
+
"↑": "\u2191",
|
|
663
|
+
"↓": "\u2193",
|
|
664
|
+
"×": "\xD7",
|
|
665
|
+
"÷": "\xF7"
|
|
666
|
+
};
|
|
667
|
+
function decodeEntities(text) {
|
|
668
|
+
return text.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|(\w+));/g, (match, dec, hex, named) => {
|
|
669
|
+
if (dec) return String.fromCodePoint(parseInt(dec, 10));
|
|
670
|
+
if (hex) return String.fromCodePoint(parseInt(hex, 16));
|
|
671
|
+
if (named) return ENTITY_MAP[`&${named};`] ?? match;
|
|
672
|
+
return match;
|
|
673
|
+
});
|
|
674
|
+
}
|
|
640
675
|
function generate(ast, options) {
|
|
641
676
|
const gen = new CodeGenerator(options);
|
|
642
677
|
return gen.generate(ast);
|
package/dist/index.d.cts
CHANGED
|
@@ -144,7 +144,8 @@ interface CompileResult {
|
|
|
144
144
|
*
|
|
145
145
|
* // <script> block contents (user code) inlined here
|
|
146
146
|
*
|
|
147
|
-
*
|
|
147
|
+
* function __render() { ... }
|
|
148
|
+
* export default { render: __render }
|
|
148
149
|
* ```
|
|
149
150
|
*
|
|
150
151
|
* The caller (e.g. the Vite plugin) is responsible for injecting the CSS
|
package/dist/index.d.ts
CHANGED
|
@@ -144,7 +144,8 @@ interface CompileResult {
|
|
|
144
144
|
*
|
|
145
145
|
* // <script> block contents (user code) inlined here
|
|
146
146
|
*
|
|
147
|
-
*
|
|
147
|
+
* function __render() { ... }
|
|
148
|
+
* export default { render: __render }
|
|
148
149
|
* ```
|
|
149
150
|
*
|
|
150
151
|
* The caller (e.g. the Vite plugin) is responsible for injecting the CSS
|
package/dist/index.js
CHANGED
|
@@ -448,7 +448,8 @@ ${fnBody}
|
|
|
448
448
|
if (!node.content) return null;
|
|
449
449
|
this.helpers.add("createTextNode");
|
|
450
450
|
const v = this.freshVar();
|
|
451
|
-
|
|
451
|
+
const decoded = decodeEntities(node.content);
|
|
452
|
+
this.emit(`const ${v} = createTextNode(${JSON.stringify(decoded)})`);
|
|
452
453
|
return v;
|
|
453
454
|
}
|
|
454
455
|
genInterpolation(node, scope) {
|
|
@@ -605,6 +606,40 @@ function isComponentTag(tag) {
|
|
|
605
606
|
function escapeStr(s) {
|
|
606
607
|
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
607
608
|
}
|
|
609
|
+
var ENTITY_MAP = {
|
|
610
|
+
"&": "&",
|
|
611
|
+
"<": "<",
|
|
612
|
+
">": ">",
|
|
613
|
+
""": '"',
|
|
614
|
+
"'": "'",
|
|
615
|
+
"'": "'",
|
|
616
|
+
" ": "\xA0",
|
|
617
|
+
"—": "\u2014",
|
|
618
|
+
"–": "\u2013",
|
|
619
|
+
"‘": "\u2018",
|
|
620
|
+
"’": "\u2019",
|
|
621
|
+
"“": "\u201C",
|
|
622
|
+
"”": "\u201D",
|
|
623
|
+
"•": "\u2022",
|
|
624
|
+
"…": "\u2026",
|
|
625
|
+
"©": "\xA9",
|
|
626
|
+
"®": "\xAE",
|
|
627
|
+
"™": "\u2122",
|
|
628
|
+
"→": "\u2192",
|
|
629
|
+
"←": "\u2190",
|
|
630
|
+
"↑": "\u2191",
|
|
631
|
+
"↓": "\u2193",
|
|
632
|
+
"×": "\xD7",
|
|
633
|
+
"÷": "\xF7"
|
|
634
|
+
};
|
|
635
|
+
function decodeEntities(text) {
|
|
636
|
+
return text.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|(\w+));/g, (match, dec, hex, named) => {
|
|
637
|
+
if (dec) return String.fromCodePoint(parseInt(dec, 10));
|
|
638
|
+
if (hex) return String.fromCodePoint(parseInt(hex, 16));
|
|
639
|
+
if (named) return ENTITY_MAP[`&${named};`] ?? match;
|
|
640
|
+
return match;
|
|
641
|
+
});
|
|
642
|
+
}
|
|
608
643
|
function generate(ast, options) {
|
|
609
644
|
const gen = new CodeGenerator(options);
|
|
610
645
|
return gen.generate(ast);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matthesketh/utopia-compiler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Compiler for .utopia single-file components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@matthesketh/utopia-core": "0.0.
|
|
42
|
+
"@matthesketh/utopia-core": "0.0.4"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|