@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 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
- this.emit(`const ${v} = createTextNode(${JSON.stringify(node.content)})`);
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
+ "&lt;": "<",
644
+ "&gt;": ">",
645
+ "&quot;": '"',
646
+ "&#39;": "'",
647
+ "&apos;": "'",
648
+ "&nbsp;": "\xA0",
649
+ "&mdash;": "\u2014",
650
+ "&ndash;": "\u2013",
651
+ "&lsquo;": "\u2018",
652
+ "&rsquo;": "\u2019",
653
+ "&ldquo;": "\u201C",
654
+ "&rdquo;": "\u201D",
655
+ "&bull;": "\u2022",
656
+ "&hellip;": "\u2026",
657
+ "&copy;": "\xA9",
658
+ "&reg;": "\xAE",
659
+ "&trade;": "\u2122",
660
+ "&rarr;": "\u2192",
661
+ "&larr;": "\u2190",
662
+ "&uarr;": "\u2191",
663
+ "&darr;": "\u2193",
664
+ "&times;": "\xD7",
665
+ "&divide;": "\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
- * export default function render(_ctx) { ... }
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
- * export default function render(_ctx) { ... }
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
- this.emit(`const ${v} = createTextNode(${JSON.stringify(node.content)})`);
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
+ "&amp;": "&",
611
+ "&lt;": "<",
612
+ "&gt;": ">",
613
+ "&quot;": '"',
614
+ "&#39;": "'",
615
+ "&apos;": "'",
616
+ "&nbsp;": "\xA0",
617
+ "&mdash;": "\u2014",
618
+ "&ndash;": "\u2013",
619
+ "&lsquo;": "\u2018",
620
+ "&rsquo;": "\u2019",
621
+ "&ldquo;": "\u201C",
622
+ "&rdquo;": "\u201D",
623
+ "&bull;": "\u2022",
624
+ "&hellip;": "\u2026",
625
+ "&copy;": "\xA9",
626
+ "&reg;": "\xAE",
627
+ "&trade;": "\u2122",
628
+ "&rarr;": "\u2192",
629
+ "&larr;": "\u2190",
630
+ "&uarr;": "\u2191",
631
+ "&darr;": "\u2193",
632
+ "&times;": "\xD7",
633
+ "&divide;": "\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.2",
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.2"
42
+ "@matthesketh/utopia-core": "0.0.4"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "tsup src/index.ts --format esm,cjs --dts",