olum-compiler 0.5.3 → 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/server.js +2 -0
- package/lib/attr.js +23 -22
- package/lib/events.js +27 -8
- package/lib/for.js +5 -3
- package/lib/html.js +21 -0
- package/lib/htmlParser.js +17 -22
- package/lib/if.js +5 -3
- package/lib/placeholder.js +28 -10
- package/lib/show.js +4 -2
- package/lib/tokens.js +10 -0
- package/package.json +1 -1
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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, "<-olum->"); // using <-olum-> (<-olum->) 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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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-> (<-olum->) 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
|
-
|
|
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()
|
|
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/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, "<-olum->"); // 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
|
|
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
|
-
//
|
|
25
|
-
//
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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(/&/g, "&"); // fix entity
|
|
60
54
|
content = content.replace(/=>/g, "=>"); // preserve arrow functions
|
|
61
55
|
content = content.replace(/<-olum->|&lt;-olum-&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
|
-
|
|
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") || "").
|
|
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
|
}
|
package/lib/placeholder.js
CHANGED
|
@@ -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 = "&lt;-olum-&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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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" —
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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 </> 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
|
};
|