olum-compiler 0.5.2 → 0.6.0

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/bin/copySrc.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // todo check changed files only to be copied, use this project https://github.com/eissapk/diff
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
- const { copy, remove } = require("../lib/helpers");
4
+ const { copy, remove, rewriteImports } = require("../lib/helpers");
5
5
 
6
6
  const entryPoint = path.resolve(__dirname, "../../../src");
7
7
  const entryPoint2 = path.resolve(__dirname, "../../../public");
package/bin/server.js CHANGED
@@ -17,11 +17,13 @@ function handleWsFile() {
17
17
  function getPath(entry, url) {
18
18
  entry = entry.endsWith("/") ? entry : entry + "/";
19
19
  url = url.startsWith("/") ? url.slice(1) : url;
20
+
20
21
  const paths = [
21
22
  path.resolve(entry, url),
22
23
  path.resolve(entry, "../", url),
23
24
  path.resolve(process.cwd(), url),
24
25
  ];
26
+
25
27
  return paths.find(fs.existsSync) || null;
26
28
  }
27
29
  // todo handle https
package/lib/attr.js CHANGED
@@ -9,29 +9,30 @@ function handleAttr(body, counter, filePath) {
9
9
  elms.forEach((item) => {
10
10
  const attrs = item.getAttributeNames();
11
11
  if (attrs.length) {
12
- // {identifier} shorthand: <img {src} /> → <img src="{src}" /> → src="${src}" in template -- inspired by svelete
13
- attrs.filter(attr => /^\{\w+\}$/.test(attr)).forEach(attr => {
14
- const attrName = attr.slice(1, -1);
15
- item.removeAttribute(attr);
16
- item.setAttribute(attrName, "{" + attrName + "}");
17
- });
12
+ // DISABLED — {identifier} shorthand (<img {src} /> → src="{src}"). Naked braces aren't allowed
13
+ // in attribute position anymore (values live in ""); write src="{src}" instead. Uncomment to re-enable.
14
+ // attrs.filter(attr => /^\{\w+\}$/.test(attr)).forEach(attr => {
15
+ // const attrName = attr.slice(1, -1);
16
+ // item.removeAttribute(attr);
17
+ // item.setAttribute(attrName, "{" + attrName + "}");
18
+ // });
18
19
 
19
- const dynamicAttrs = attrs.filter((attr) => attr.startsWith(":"));
20
- if (dynamicAttrs.length) {
21
- dynamicAttrs.forEach((attrName) => {
22
- let attrValue = item.getAttribute(attrName);
23
- if (attrValue) {
24
- attrName = attrName.trim().slice(1);
25
- attrValue = attrValue.trim();
26
- let chain = "-[[-${JSON.parse(JSON.stringify(" + attrValue + "))}-]]-";
27
- chain = chain.replace(/{/g, "&lt;-olum-&gt;"); // using <-olum-> (&lt;-olum-&gt;) as placeholder for "{"
28
- // // console.log({chain});
29
- // item.setAttribute("data-o-attr-" + attrName, chain);
30
- item.setAttribute(attrName, chain);
31
- item.removeAttribute(":"+attrName);
32
- }
33
- });
34
- }
20
+ // DISABLED — :attr dynamic binding (:src="expr"). Colon attributes are gone; regular
21
+ // attributes are literal strings with {expr} interpolation inside. Uncomment to re-enable.
22
+ // const dynamicAttrs = attrs.filter((attr) => attr.startsWith(":"));
23
+ // if (dynamicAttrs.length) {
24
+ // dynamicAttrs.forEach((attrName) => {
25
+ // let attrValue = item.getAttribute(attrName);
26
+ // if (attrValue) {
27
+ // attrName = attrName.trim().slice(1);
28
+ // attrValue = attrValue.trim();
29
+ // let chain = "-[[-${JSON.parse(JSON.stringify(" + attrValue + "))}-]]-";
30
+ // chain = chain.replace(/{/g, "&lt;-olum-&gt;"); // using <-olum-> (&lt;-olum-&gt;) as placeholder for "{"
31
+ // item.setAttribute(attrName, chain);
32
+ // item.removeAttribute(":"+attrName);
33
+ // }
34
+ // });
35
+ // }
35
36
  }
36
37
  });
37
38
  }
package/lib/events.js CHANGED
@@ -2,7 +2,16 @@ const events = require("./domEvents");
2
2
  const { getLineInfo } = require("./lineCounter");
3
3
  const path = require("path");
4
4
 
5
- function handleEvents(body, counter, filePath) {
5
+ // An event value is plain JS inside "" (like native HTML `onclick="..."`): either a method-call
6
+ // list — onclick="inc()" / onclick="inc(), dec()" — or an inline arrow/function expression —
7
+ // oninput="(e)=> state.x = e.target.value". Arrow/function values are extracted to a named
8
+ // __olumAnon_ method (collected in anonHandlers, injected into the component JS) so the call-list
9
+ // parser below can treat them uniformly as `__olumAnon_xxx($event)`.
10
+ function looksLikeFunction(str) {
11
+ return /^(?:\([^)]*\)|[\w$]+)\s*=>/.test(str) || /^function\b/.test(str);
12
+ }
13
+
14
+ function handleEvents(body, counter, filePath, anonHandlers) {
6
15
  let name = path.basename(filePath).replace(/\.html/i, "");
7
16
  name = name.slice(0, 1).toLowerCase() + name.slice(1); // make compName camel case
8
17
 
@@ -10,7 +19,15 @@ function handleEvents(body, counter, filePath) {
10
19
  elms.forEach(item => {
11
20
  events.forEach(e => {
12
21
  if (item.hasAttribute(e)) {
13
- const attrValue = item.getAttribute(e);
22
+ let attrValue = item.getAttribute(e).trim();
23
+
24
+ // inline arrow/function handler -> extract to a named method, then parse the call below
25
+ if (looksLikeFunction(attrValue)) {
26
+ const handlerName = "__olumAnon_" + Math.random().toString(36).slice(2, 9);
27
+ if (anonHandlers) anonHandlers.push(`const ${handlerName} = ${attrValue};`);
28
+ attrValue = handlerName + "($event)";
29
+ }
30
+
14
31
  let methods = attrValue.split("),");
15
32
  methods = methods.map(str => (str.replace(/\)$/, "") + ")").trim());
16
33
  let methodsNames = methods.map(str => (str.trim().split("(")[0]).trim());
@@ -33,12 +50,14 @@ function handleEvents(body, counter, filePath) {
33
50
  item.removeAttribute(e);
34
51
  // console.log(item.outerHTML);
35
52
 
36
- // todo handle direct logic inside event attribute with needing to invoke a method
37
- const mode = item.getAttribute("mode");
38
- if (mode) {
39
- item.setAttribute("data-o-event-mode", mode);
40
- item.removeAttribute("mode");
41
- }
53
+ // DISABLED — `mode` event modifiers (mode="prevent|stop|once|passive|capture|self").
54
+ // Handle it inside the arrow instead, e.g. onsubmit="(e)=> { e.preventDefault(); save() }".
55
+ // Uncomment to re-enable. (The runtime data-o-event-mode reader in app.js is now dead code.)
56
+ // const mode = item.getAttribute("mode");
57
+ // if (mode) {
58
+ // item.setAttribute("data-o-event-mode", mode);
59
+ // item.removeAttribute("mode");
60
+ // }
42
61
  // console.log(item.outerHTML + "\n----------");
43
62
  }
44
63
  });
package/lib/for.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const { getLineInfo } = require("./lineCounter");
2
2
  const { forOf, forIn } = require("./regex");
3
3
  const { isNum,id } = require("./helpers");
4
- const { RAW_OPEN, RAW_CLOSE } = require("./tokens");
4
+ const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
5
5
 
6
6
  function handleForStatement(body, counter, filePath) {
7
7
  // using <-olum-> (&lt;-olum-&gt;) as placeholder for "{" inside map method
@@ -9,7 +9,9 @@ function handleForStatement(body, counter, filePath) {
9
9
  forElms.forEach(item => {
10
10
  // console.log(item.outerHTML + "\n----------");
11
11
  if (item.hasAttribute("each")) {
12
- const condition = item.getAttribute("each").trim().replace(/^\{|\}$/g, "");
12
+ // `each` is a plain JS expression (no braces): <for each="item of state.items">
13
+ // shieldOps: protect <,> from the jsdom text round-trip (restored in htmlParser)
14
+ const condition = shieldOps(item.getAttribute("each").trim());
13
15
 
14
16
  // #3 (keyed reconciliation): if the <for> declares key={expr}, stamp every component
15
17
  // placeholder in this loop with data-o-key="{expr}". `expr` references the loop variable, so
@@ -18,7 +20,7 @@ function handleForStatement(body, counter, filePath) {
18
20
  // nested loop has already stamped its own placeholders — we skip any that are already keyed.
19
21
  const keyAttr = item.getAttribute("key");
20
22
  if (keyAttr) {
21
- const keyExpr = keyAttr.trim().replace(/^\{|\}$/g, "");
23
+ const keyExpr = keyAttr.trim();
22
24
  new Array().slice.call(item.querySelectorAll("olum")).forEach(olum => {
23
25
  if (!olum.hasAttribute("data-o-key")) olum.setAttribute("data-o-key", "{" + keyExpr + "}");
24
26
  });
package/lib/helpers.js CHANGED
@@ -486,6 +486,64 @@ function minifyJS(src) {
486
486
  return out;
487
487
  }
488
488
 
489
+ function resolvePackage(pkgName) {
490
+ const pkgJsonPath = path.join(
491
+ process.cwd(),
492
+ "node_modules",
493
+ pkgName,
494
+ "package.json"
495
+ );
496
+
497
+ if (!fs.existsSync(pkgJsonPath)) {
498
+ throw new Error(`Package "${pkgName}" not found`);
499
+ }
500
+
501
+ const pkg = JSON.parse(
502
+ fs.readFileSync(pkgJsonPath, "utf8")
503
+ );
504
+
505
+ let entry;
506
+
507
+ if (typeof pkg.exports === "string") {
508
+ entry = pkg.exports;
509
+ } else if (pkg.exports?.["."]?.import) {
510
+ entry = pkg.exports["."].import;
511
+ } else if (pkg.exports?.["."]?.default) {
512
+ entry = pkg.exports["."].default;
513
+ } else if (typeof pkg.exports?.["."] === "string") {
514
+ entry = pkg.exports["."];
515
+ } else {
516
+ entry = pkg.module || pkg.main || "index.js";
517
+ }
518
+
519
+ entry = entry.replace(/^\.?\//, "");
520
+
521
+ return `/node_modules/${pkgName}/${entry}`;
522
+ }
523
+
524
+ function rewriteImports(code) {
525
+ return code.replace(
526
+ /from\s+["']([^"']+)["']/g,
527
+ (match, specifier) => {
528
+ if (
529
+ specifier.startsWith(".") ||
530
+ specifier.startsWith("/") ||
531
+ specifier.startsWith("http:")
532
+ || specifier.startsWith("https:")
533
+ ) {
534
+ return match;
535
+ }
536
+
537
+ try {
538
+ return `from "${resolvePackage(specifier)}"`;
539
+ } catch (err) {
540
+ console.warn(err.message);
541
+ return match;
542
+ }
543
+ }
544
+ );
545
+ }
546
+
489
547
  module.exports.isNum = isNum;
490
548
  module.exports.id = id;
491
549
  module.exports.isUpper = isUpper;
@@ -507,3 +565,4 @@ module.exports.createScopeHandler = createScopeHandler;
507
565
  module.exports.getGlobalMethods = getGlobalMethods;
508
566
  module.exports.getGlobalProps = getGlobalProps;
509
567
  module.exports.minifyJS = minifyJS;
568
+ module.exports.rewriteImports = rewriteImports;
package/lib/html.js ADDED
@@ -0,0 +1,21 @@
1
+ const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
2
+
3
+ // `html="expr"` — render the expression as UNESCAPED HTML, replacing the element's content
4
+ // (like Vue's v-html / React's dangerouslySetInnerHTML). It's a "code attribute": the "" holds a
5
+ // JS expression. Output is a raw `${expr}` interpolation (NOT wrapped in olum.esc), so use it only
6
+ // on trusted/sanitized HTML. The per-value primitive olum.html(x) still exists for inline/mixed use.
7
+ //
8
+ // Runs before the control-flow handlers (which dissolve elements into template text), so an html
9
+ // element inside <for>/<if> is rewritten while it's still a real DOM node.
10
+ function handleHtml(body) {
11
+ const elms = new Array().slice.call(body.querySelectorAll("[html]"));
12
+ elms.forEach((item) => {
13
+ const expr = shieldOps((item.getAttribute("html") || "").trim()); // protect <,> from the DOM round-trip
14
+ item.removeAttribute("html");
15
+ if (!expr) return;
16
+ const encoded = expr.replace(/{/g, "&lt;-olum-&gt;"); // hide JS braces from the {expr} escape pass
17
+ item.innerHTML = RAW_OPEN + encoded + RAW_CLOSE; // raw ${expr} — replaces the element's content
18
+ });
19
+ }
20
+
21
+ module.exports = handleHtml;
package/lib/htmlParser.js CHANGED
@@ -6,40 +6,34 @@ const handleIfStatement = require("./if");
6
6
  const handleForStatement = require("./for");
7
7
  const handleShowStatement = require("./show");
8
8
  const handleEvents = require("./events");
9
- const handleStyles = require("./styles");
10
- const handleModels = require("./models");
11
- const handleAttr = require("./attr");
9
+ // const handleStyles = require("./styles");
10
+ // const handleModels = require("./models");
11
+ // const handleAttr = require("./attr");
12
12
  const handleCompPlaceholder = require("./compPlaceholder");
13
- const { RAW_OPEN, RAW_CLOSE } = require("./tokens");
13
+ const handleHtml = require("./html");
14
+ const { RAW_OPEN, RAW_CLOSE, LT, GT } = require("./tokens");
14
15
 
15
16
  function htmlparser(str, counter, filePath) {
16
17
  let content = str.replace(script, "").replace(style, "");
17
18
  content = clean(content); // clean html comments to avoid runtime errors
18
19
  content = placeholder(content, selfClosingTag, "self");
19
20
  content = placeholder(content, normalTag, "normal");
20
- // Allow unquoted each={expr} / when={expr} / key={expr} — wrap in quotes so jsdom can parse the
21
- // attribute. `key` is part of #3 (keyed <for>): <for each={t of arr} key={t.id}>.
22
- content = content.replace(/\b(each|when|key)=\{([^}]+)\}/g, '$1="{$2}"');
23
21
 
24
- // Anonymous function event handlers: on<event>={(e)=> expr} → on<event>="__olumAnon_id($event)"
25
- // The extracted function body is collected and later injected into the component JS as a named method.
22
+ // Inline arrow/function event handlers (oninput="(e)=> expr") are extracted into named
23
+ // __olumAnon_ methods inside handleEvents (collected here, injected into the component JS later).
26
24
  const anonHandlers = [];
27
- content = content.replace(/(on[a-z]+)=\{((?:[^{}]|\{[^{}]*\})*)\}/g, (match, attr, fn) => {
28
- const trimmed = fn.trim();
29
- if (/^(?:\([^)]*\)|\w+)\s*=>|^function[\s(]/.test(trimmed)) {
30
- const handlerName = "__olumAnon_" + Math.random().toString(36).slice(2, 9);
31
- anonHandlers.push(`const ${handlerName} = ${trimmed};`);
32
- return `${attr}="${handlerName}($event)"`;
33
- }
34
- return match;
35
- });
36
25
 
37
26
  // using dom parser
38
27
  const body = new jsdom.JSDOM(content).window.document.body;
39
- handleEvents(body, counter, filePath);
40
- handleStyles(body, counter, filePath);
41
- handleAttr(body, counter, filePath);
42
- handleModels(body, counter, filePath);
28
+ handleHtml(body); // html="expr" -> unescaped ${expr} content (before control-flow dissolves elements)
29
+ handleEvents(body, counter, filePath, anonHandlers);
30
+ // DISABLED — :style object binding. Colon attributes are gone; use a string style with
31
+ // {expr} interpolation instead, e.g. style="color:{state.color}". Uncomment to re-enable.
32
+ // handleStyles(body, counter, filePath);
33
+ // handleAttr(body, counter, filePath);
34
+ // DISABLED — `model` two-way binding. Bind manually instead: value="{state.x}" + an
35
+ // oninput handler that writes state.x. Uncomment to re-enable.
36
+ // handleModels(body, counter, filePath);
43
37
  handleIfStatement(body, counter, filePath);
44
38
  handleForStatement(body, counter, filePath);
45
39
  handleShowStatement(body, counter, filePath);
@@ -59,6 +53,7 @@ function htmlparser(str, counter, filePath) {
59
53
  content = content.replace(/&amp;/g, "&"); // fix entity
60
54
  content = content.replace(/=&gt;/g, "=>"); // preserve arrow functions
61
55
  content = content.replace(/&lt;-olum-&gt;|&amp;lt;-olum-&amp;gt;/g, "{"); // fix curly braces sign
56
+ content = content.split(LT).join("<").split(GT).join(">"); // restore shielded <,> in directive expressions
62
57
 
63
58
  // #2: structural (compiler-generated) interpolations produce raw HTML, so emit them as plain
64
59
  // `${...}` WITHOUT esc(). Done after the escape pass so user braces are already handled.
package/lib/if.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const { getLineInfo } = require("./lineCounter");
2
- const { RAW_OPEN, RAW_CLOSE } = require("./tokens");
2
+ const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
3
3
 
4
4
  function hasElseIfOrElse(node) {
5
5
  const nextNode = node.nextElementSibling;
@@ -14,7 +14,9 @@ function handleIfStatement(body, counter, filePath) {
14
14
  ifElms.forEach(item => {
15
15
  // console.log(item.outerHTML + "\n----------");
16
16
  if (item.hasAttribute("when")) {
17
- const condition = item.getAttribute("when").replace(/^\{|\}$/g, "");
17
+ // `when` is a plain JS expression (no braces): <if when="state.n > 0">
18
+ // shieldOps: protect <,> from the jsdom text round-trip (restored in htmlParser)
19
+ const condition = shieldOps(item.getAttribute("when").trim());
18
20
 
19
21
  // start: store if statement value in olum tag
20
22
  const olums = item.querySelectorAll("olum");
@@ -30,7 +32,7 @@ function handleIfStatement(body, counter, filePath) {
30
32
  let nodesArr = [{ content: innerContent, when: condition }];
31
33
  function recursive(item) {
32
34
  const node = hasElseIfOrElse(item);
33
- nodesArr.push({ content: node.innerHTML, when: (node.getAttribute("when") || "").replace(/^\{|\}$/g, "") });
35
+ nodesArr.push({ content: node.innerHTML, when: shieldOps((node.getAttribute("when") || "").trim()) });
34
36
  toBeRemovedArr.push(node);
35
37
  if (hasElseIfOrElse(node)) recursive(node);
36
38
  }
@@ -3,30 +3,48 @@ const { isFullArr, isUpper } = require("./helpers");
3
3
  // { must be double-encoded so it survives jsdom + htmlParser transformations
4
4
  const ESC = "&amp;lt;-olum-&amp;gt;";
5
5
 
6
+ // A string-valued prop is literal by default, with {expr} interpolation inside (like a regular
7
+ // attribute): title="Hello {state.name}". If it contains {expr}, compile it to a TEMPLATE LITERAL
8
+ // so the literal text + interpolated parts concatenate into a string. The { of each ${...} is
9
+ // ESC-encoded so htmlParser's {expr} escape pass leaves it alone (restored to { at the end).
10
+ // A plain value (no braces) stays a quoted string literal.
11
+ function literalExpr(raw) {
12
+ if (/\{[^{}]+\}/.test(raw)) {
13
+ const body = raw.replace(/`/g, "\\`").replace(/\{([^{}]+)\}/g, "${$1}"); // {x} -> ${x}
14
+ return ("`" + body + "`").replace(/\{/g, ESC);
15
+ }
16
+ return "'" + raw.replace(/'/g, "\\'") + "'";
17
+ }
18
+
6
19
  function parseProps(attrsStr) {
7
20
  const entries = [];
8
21
  const srcEntries = []; // prop-name:state-key pairs for setter write-back
9
- // six alternatives in priority order:
22
+ // six alternatives in priority order (groups kept intact for easy toggling):
10
23
  // 1. {key} 2. key="{expr}" 3. key='{expr}' 4. key={expr} 5. key="value" 6. key='value'
24
+ // NOTE: the naked-brace forms 1 ({key} shorthand) and 4 (key={expr}) are DISABLED — values must
25
+ // live inside quotes, consistent with every other attribute. Uncomment their branches to re-enable.
11
26
  const attrRegex = /\{(\w+)\}|(\w+)="\{([^}]+)\}"|(\w+)='\{([^}]+)\}'|(\w+)=\{([^}]+)\}|(\w+)="([^"]*)"|(\w+)='([^']*)'/g;
12
27
  let match;
13
28
  while ((match = attrRegex.exec(attrsStr)) !== null) {
14
29
  let propName, expr, isExpr = false;
15
- if (match[1] !== undefined) {
16
- propName = match[1]; expr = match[1]; isExpr = true; // {key} shorthand
17
- } else if (match[2] && match[3] !== undefined) {
30
+ // DISABLED — {key} shorthand. Uncomment to re-enable.
31
+ // if (match[1] !== undefined) {
32
+ // propName = match[1]; expr = match[1]; isExpr = true; // {key} shorthand
33
+ // } else
34
+ if (match[2] && match[3] !== undefined) {
18
35
  propName = match[2]; expr = match[3]; isExpr = true; // key="{expr}"
19
36
  } else if (match[4] && match[5] !== undefined) {
20
37
  propName = match[4]; expr = match[5]; isExpr = true; // key='{expr}'
21
- } else if (match[6] && match[7] !== undefined) {
22
- propName = match[6]; expr = match[7]; isExpr = true; // key={expr}
38
+ // DISABLED — key={expr} unquoted. Uncomment to re-enable.
39
+ // } else if (match[6] && match[7] !== undefined) {
40
+ // propName = match[6]; expr = match[7]; isExpr = true; // key={expr}
23
41
  } else if (match[8] && match[9] !== undefined) {
24
- // key="value" — always single-quote in JS so no " appears in the HTML attr
42
+ // key="value" — literal string, or template literal if it contains {expr} interpolation
25
43
  let v = match[9];
26
- if (v.startsWith("'") && v.endsWith("'") && v.length >= 2) v = v.slice(1, -1);
27
- propName = match[8]; expr = "'" + v.replace(/'/g, "\\'") + "'"; isExpr = false;
44
+ if (!/\{[^{}]+\}/.test(v) && v.startsWith("'") && v.endsWith("'") && v.length >= 2) v = v.slice(1, -1);
45
+ propName = match[8]; expr = literalExpr(v); isExpr = false;
28
46
  } else if (match[10] && match[11] !== undefined) {
29
- propName = match[10]; expr = "'" + match[11].replace(/'/g, "\\'") + "'"; isExpr = false;
47
+ propName = match[10]; expr = literalExpr(match[11]); isExpr = false;
30
48
  }
31
49
  if (!propName) continue;
32
50
  if (isExpr) {
package/lib/show.js CHANGED
@@ -1,12 +1,14 @@
1
1
  const { getLineInfo } = require("./lineCounter");
2
- const { RAW_OPEN, RAW_CLOSE } = require("./tokens");
2
+ const { RAW_OPEN, RAW_CLOSE, shieldOps } = require("./tokens");
3
3
 
4
4
  function handleShowStatement(body, counter, filePath) {
5
5
  const showElms = new Array().slice.call(body.querySelectorAll("show")).reverse(); // we must reverse to start with the very deep if tag which doesn't have nested if tags inside it
6
6
  showElms.forEach(item => {
7
7
  // console.log(item.outerHTML + "\n----------");
8
8
  if (item.hasAttribute("when")) {
9
- const condition = item.getAttribute("when").replace(/^\{|\}$/g, "");
9
+ // `when` is a plain JS expression (no braces): <show when="state.visible">
10
+ // shieldOps: protect <,> from the jsdom text round-trip (restored in htmlParser)
11
+ const condition = shieldOps(item.getAttribute("when").trim());
10
12
  const innerContent = item.innerHTML;
11
13
  // RAW_OPEN/RAW_CLOSE: structural interpolation (both branches return HTML); see tokens.js / #2.
12
14
  const ternaryOperator = RAW_OPEN+condition +"?`"+ innerContent + "`:`"+ "<div style=\"display:none;\">"+innerContent+"</div>`"+RAW_CLOSE;
package/lib/tokens.js CHANGED
@@ -8,7 +8,17 @@
8
8
  //
9
9
  // Plain ASCII so they survive a jsdom parse/serialize round-trip unchanged, and regex-safe so they
10
10
  // can be swapped with a simple global replace.
11
+ // LT/GT shield: a directive expression (when="a > b", each="x of f(a < b)") is spliced into the
12
+ // markup as TEXT, so jsdom serializes its < and > to &lt;/&gt; and produces broken JS. We replace
13
+ // them with these sentinels in the CONDITION string only (never in branch/display text), then
14
+ // restore them in htmlParser after the round-trip — so escaped <,> in user-visible text are untouched.
15
+ const LT = "OLUM_LT";
16
+ const GT = "OLUM_GT";
17
+
11
18
  module.exports = {
12
19
  RAW_OPEN: "OLUM_RAW_OPEN",
13
20
  RAW_CLOSE: "OLUM_RAW_CLOSE",
21
+ LT,
22
+ GT,
23
+ shieldOps: (s) => String(s).split("<").join(LT).split(">").join(GT),
14
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {