@torpor/view 1.3.3 → 1.4.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/dist/{Effect-Bp-BIDDm.d.cts → Effect-Bi_nt6cx.d.cts} +16 -3
- package/dist/Effect-Bi_nt6cx.d.cts.map +1 -0
- package/dist/{Effect-VsIY2vPx.d.mts → Effect-Bi_nt6cx.d.mts} +16 -3
- package/dist/Effect-Bi_nt6cx.d.mts.map +1 -0
- package/dist/ListItemSpec-DFkYr2TE.d.cts +28 -0
- package/dist/ListItemSpec-DFkYr2TE.d.cts.map +1 -0
- package/dist/ListItemSpec-DFkYr2TE.d.mts +28 -0
- package/dist/ListItemSpec-DFkYr2TE.d.mts.map +1 -0
- package/dist/{AsyncOptions-BDtArmeL.d.mts → WatchOptions--xq-Gn4e.d.cts} +77 -4
- package/dist/WatchOptions--xq-Gn4e.d.cts.map +1 -0
- package/dist/{AsyncOptions-C_7mWR6F.d.cts → WatchOptions-DWF4EqB6.d.mts} +77 -4
- package/dist/WatchOptions-DWF4EqB6.d.mts.map +1 -0
- package/dist/compile.cjs +1299 -401
- package/dist/compile.d.cts +16 -12
- package/dist/compile.d.cts.map +1 -1
- package/dist/compile.d.mts +16 -12
- package/dist/compile.d.mts.map +1 -1
- package/dist/compile.mjs +1299 -401
- package/dist/compile.mjs.map +1 -1
- package/dist/dev.cjs +101 -51
- package/dist/dev.d.cts +33 -2
- package/dist/dev.d.cts.map +1 -1
- package/dist/dev.d.mts +33 -2
- package/dist/dev.d.mts.map +1 -1
- package/dist/dev.mjs +51 -2
- package/dist/dev.mjs.map +1 -1
- package/dist/{fromWebSocket-ERhd9KZR.mjs → fromWebSocket-B22DIys7.mjs} +11 -2
- package/dist/fromWebSocket-B22DIys7.mjs.map +1 -0
- package/dist/{fromWebSocket-Cdoghvmh.cjs → fromWebSocket-C56rkQpZ.cjs} +15 -0
- package/dist/index.cjs +605 -266
- package/dist/index.d.cts +36 -129
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +36 -129
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +593 -255
- package/dist/index.mjs.map +1 -1
- package/dist/runtime.iife.js +1 -1
- package/dist/ssr.cjs +122 -22
- package/dist/ssr.d.cts +46 -12
- package/dist/ssr.d.cts.map +1 -1
- package/dist/ssr.d.mts +46 -12
- package/dist/ssr.d.mts.map +1 -1
- package/dist/ssr.mjs +121 -23
- package/dist/ssr.mjs.map +1 -1
- package/dist/titleWarning-BMjLAXpn.mjs +72 -0
- package/dist/titleWarning-BMjLAXpn.mjs.map +1 -0
- package/dist/titleWarning-DXp4fK7q.cjs +87 -0
- package/package.json +2 -1
- package/dist/AsyncOptions-BDtArmeL.d.mts.map +0 -1
- package/dist/AsyncOptions-C_7mWR6F.d.cts.map +0 -1
- package/dist/Cleanup-D0wvGW5d.d.cts +0 -9
- package/dist/Cleanup-D0wvGW5d.d.cts.map +0 -1
- package/dist/Cleanup-D0wvGW5d.d.mts +0 -9
- package/dist/Cleanup-D0wvGW5d.d.mts.map +0 -1
- package/dist/Effect-Bp-BIDDm.d.cts.map +0 -1
- package/dist/Effect-VsIY2vPx.d.mts.map +0 -1
- package/dist/devContext-BulTn3U5.cjs +0 -27
- package/dist/devContext-ZNsPyOgB.mjs +0 -24
- package/dist/devContext-ZNsPyOgB.mjs.map +0 -1
- package/dist/fromWebSocket-ERhd9KZR.mjs.map +0 -1
package/dist/compile.mjs
CHANGED
|
@@ -512,6 +512,65 @@ function hydrationBranchComment(index) {
|
|
|
512
512
|
return `<!^${index}>`;
|
|
513
513
|
}
|
|
514
514
|
//#endregion
|
|
515
|
+
//#region src/compile/utils/escapeRawText.ts
|
|
516
|
+
/**
|
|
517
|
+
* Escapes raw-text content for inclusion in a generated template literal.
|
|
518
|
+
*
|
|
519
|
+
* Whitespace that would be altered by fragment-text whitespace collapsing is
|
|
520
|
+
* escaped (`\n`, `\t`, `\x20` for runs of spaces), so raw content round-trips
|
|
521
|
+
* exactly -- including line breaks and indentation inside scripts. Backticks
|
|
522
|
+
* and `${` are escaped so the literal doesn't terminate or interpolate, and
|
|
523
|
+
* backslashes are escaped so JavaScript escapes in the source text (e.g.
|
|
524
|
+
* `"\n"` inside an inline script) aren't consumed by the template literal.
|
|
525
|
+
*/
|
|
526
|
+
function escapeRawText(text) {
|
|
527
|
+
let result = "";
|
|
528
|
+
for (let i = 0; i < text.length; i++) {
|
|
529
|
+
const char = text[i];
|
|
530
|
+
if (char === "\\") result += "\\\\";
|
|
531
|
+
else if (char === "`") result += "\\x60";
|
|
532
|
+
else if (char === " ") {
|
|
533
|
+
let end = i + 1;
|
|
534
|
+
while (text[end] === " ") end++;
|
|
535
|
+
if (end - i > 1) {
|
|
536
|
+
result += "\\x20".repeat(end - i);
|
|
537
|
+
i = end - 1;
|
|
538
|
+
} else result += " ";
|
|
539
|
+
} else if (/\s/.test(char)) result += whitespaceEscape(char);
|
|
540
|
+
else if (char === "$" && text[i + 1] === "{") result += "\\x24";
|
|
541
|
+
else result += char;
|
|
542
|
+
}
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
function whitespaceEscape(char) {
|
|
546
|
+
switch (char) {
|
|
547
|
+
case "\n": return "\\n";
|
|
548
|
+
case "\r": return "\\r";
|
|
549
|
+
case " ": return "\\t";
|
|
550
|
+
case "\f": return "\\f";
|
|
551
|
+
case "\v": return "\\v";
|
|
552
|
+
default: return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
//#endregion
|
|
556
|
+
//#region src/compile/utils/escapeTemplateText.ts
|
|
557
|
+
/**
|
|
558
|
+
* Escapes text for inclusion in a generated template literal: backslashes,
|
|
559
|
+
* backticks and `${` are all written as escapes so the text round-trips
|
|
560
|
+
* literally instead of ending the literal or starting an interpolation.
|
|
561
|
+
*/
|
|
562
|
+
function escapeTemplateText(text) {
|
|
563
|
+
let result = "";
|
|
564
|
+
for (let i = 0; i < text.length; i++) {
|
|
565
|
+
const char = text[i];
|
|
566
|
+
if (char === "\\") result += "\\\\";
|
|
567
|
+
else if (char === "`") result += "\\x60";
|
|
568
|
+
else if (char === "$" && text[i + 1] === "{") result += "\\x24";
|
|
569
|
+
else result += char;
|
|
570
|
+
}
|
|
571
|
+
return result;
|
|
572
|
+
}
|
|
573
|
+
//#endregion
|
|
515
574
|
//#region src/compile/utils/isControlNode.ts
|
|
516
575
|
function isControlNode(node) {
|
|
517
576
|
return node.type === "control";
|
|
@@ -574,16 +633,60 @@ function getSingleElementRoot(children) {
|
|
|
574
633
|
return renderingRoot;
|
|
575
634
|
}
|
|
576
635
|
//#endregion
|
|
636
|
+
//#region src/compile/utils/interpolation.ts
|
|
637
|
+
/**
|
|
638
|
+
* Finds the `}` that closes the interpolation starting at the `{` at `start`,
|
|
639
|
+
* skipping braces inside strings, template strings, comments and regex
|
|
640
|
+
* literals. Returns -1 when the interpolation is not closed.
|
|
641
|
+
*/
|
|
642
|
+
function findMatchingBrace(text, start) {
|
|
643
|
+
let level = 0;
|
|
644
|
+
for (let i = start; i < text.length; i++) {
|
|
645
|
+
const char = text[i];
|
|
646
|
+
if (char === "{") level += 1;
|
|
647
|
+
else if (char === "}") {
|
|
648
|
+
level -= 1;
|
|
649
|
+
if (level === 0) return i;
|
|
650
|
+
} else {
|
|
651
|
+
const skipped = skipStringOrComment(text, i);
|
|
652
|
+
if (skipped !== -1) i = skipped - 1;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return -1;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Whether template text contains a complete `{...}` interpolation. Braces
|
|
659
|
+
* inside the expression's strings, comments and regex literals aren't counted
|
|
660
|
+
* as delimiters.
|
|
661
|
+
*/
|
|
662
|
+
function hasInterpolation(text) {
|
|
663
|
+
for (let i = 0; i < text.length; i++) {
|
|
664
|
+
if (text[i] !== "{") continue;
|
|
665
|
+
return findMatchingBrace(text, i) !== -1;
|
|
666
|
+
}
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Whether the supplied text is exactly one `{...}` interpolation (ignoring
|
|
671
|
+
* surrounding whitespace).
|
|
672
|
+
*/
|
|
673
|
+
function isSingleInterpolation(text) {
|
|
674
|
+
const trimmed = text.trim();
|
|
675
|
+
if (!trimmed.startsWith("{")) return false;
|
|
676
|
+
return findMatchingBrace(trimmed, 0) === trimmed.length - 1;
|
|
677
|
+
}
|
|
678
|
+
//#endregion
|
|
577
679
|
//#region src/compile/utils/isReactive.ts
|
|
578
680
|
/**
|
|
579
|
-
* Checks whether the supplied
|
|
681
|
+
* Checks whether the supplied text contains a `{...}` interpolation. Braces
|
|
682
|
+
* inside the expression's strings and comments don't count as delimiters.
|
|
580
683
|
*
|
|
581
|
-
* @param text The
|
|
684
|
+
* @param text The text to check
|
|
582
685
|
*
|
|
583
|
-
* @returns True if the supplied
|
|
686
|
+
* @returns True if the supplied text is fully or partially reactive
|
|
584
687
|
*/
|
|
585
688
|
function isReactive(text) {
|
|
586
|
-
return
|
|
689
|
+
return hasInterpolation(text);
|
|
587
690
|
}
|
|
588
691
|
//#endregion
|
|
589
692
|
//#region src/compile/utils/trimQuotes.ts
|
|
@@ -653,8 +756,11 @@ function buildNodeFragmentText(node, status, fragments, currentFragment) {
|
|
|
653
756
|
break;
|
|
654
757
|
}
|
|
655
758
|
case "text": {
|
|
656
|
-
const
|
|
657
|
-
if (currentFragment)
|
|
759
|
+
const textNode = node;
|
|
760
|
+
if (currentFragment) {
|
|
761
|
+
if (textNode.raw) currentFragment.text += escapeRawText(textNode.content);
|
|
762
|
+
else currentFragment.text += isReactive(textNode.content) ? "#" : textNode.content;
|
|
763
|
+
}
|
|
658
764
|
break;
|
|
659
765
|
}
|
|
660
766
|
case "special": buildSpecialFragmentText(node, status, fragments, currentFragment);
|
|
@@ -729,9 +835,9 @@ function buildElementFragmentText(node, status, fragments, currentFragment) {
|
|
|
729
835
|
if (a.name.startsWith("data-")) return `${a.name}=""`;
|
|
730
836
|
} else if (a.name === "class" && node.scopeStyles) {
|
|
731
837
|
needsClass = false;
|
|
732
|
-
let value = a.value ? `"${trimQuotes(a.value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
|
|
838
|
+
let value = a.value ? `"${escapeTemplateText(trimQuotes(a.value))} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
|
|
733
839
|
return `${a.name}=${value}`;
|
|
734
|
-
} else return `${a.name}${a.value != null ? `=${a.value}` : ""}`;
|
|
840
|
+
} else return `${a.name}${a.value != null ? `=${escapeTemplateText(a.value)}` : ""}`;
|
|
735
841
|
}).filter(Boolean).join(" ");
|
|
736
842
|
if (attributesText) currentFragment.text += " " + attributesText;
|
|
737
843
|
if (needsClass) currentFragment.text += ` class="torp-${status.styleHash}"`;
|
|
@@ -967,7 +1073,7 @@ function containsIdentifier(value, name) {
|
|
|
967
1073
|
* effect to the loop variable's signal).
|
|
968
1074
|
*/
|
|
969
1075
|
function forVarBindings(status, source) {
|
|
970
|
-
return collectBindings(status, (forVar) => source === void 0 || containsIdentifier(source, forVar.name));
|
|
1076
|
+
return collectBindings$1(status, (forVar) => source === void 0 || containsIdentifier(source, forVar.name));
|
|
971
1077
|
}
|
|
972
1078
|
/**
|
|
973
1079
|
* Like `forVarBindings`, but binds only the loop variables named in `names`.
|
|
@@ -975,9 +1081,9 @@ function forVarBindings(status, source) {
|
|
|
975
1081
|
* the scope's directly-evaluated code reads.
|
|
976
1082
|
*/
|
|
977
1083
|
function forVarBindingsFor(status, names) {
|
|
978
|
-
return collectBindings(status, (forVar) => names.has(forVar.name));
|
|
1084
|
+
return collectBindings$1(status, (forVar) => names.has(forVar.name));
|
|
979
1085
|
}
|
|
980
|
-
function collectBindings(status, include) {
|
|
1086
|
+
function collectBindings$1(status, include) {
|
|
981
1087
|
const bound = /* @__PURE__ */ new Set();
|
|
982
1088
|
let result = "";
|
|
983
1089
|
for (let i = status.forVars.length - 1; i >= 0; i--) {
|
|
@@ -1360,7 +1466,7 @@ function declareTextFragmentVars(fragment, node, path, status, b, varPaths, last
|
|
|
1360
1466
|
if (lastType === "text" || lastType === "space") return;
|
|
1361
1467
|
let textPath = {
|
|
1362
1468
|
parent: path,
|
|
1363
|
-
type: isSpace(node.content) ? "space" : "text",
|
|
1469
|
+
type: !node.raw && isSpace(node.content) ? "space" : "text",
|
|
1364
1470
|
children: []
|
|
1365
1471
|
};
|
|
1366
1472
|
path.children.push(textPath);
|
|
@@ -1380,11 +1486,12 @@ function declareTextFragmentVars(fragment, node, path, status, b, varPaths, last
|
|
|
1380
1486
|
} else {
|
|
1381
1487
|
status.imports.add("t_txt");
|
|
1382
1488
|
if (declareVariable) b.append(`(${node.varName} = t_txt(" ")),`);
|
|
1489
|
+
else if (node.raw) b.append(`t_txt(${JSON.stringify(node.content)}),`);
|
|
1383
1490
|
else b.append(`t_txt("${node.content}"),`);
|
|
1384
1491
|
}
|
|
1385
1492
|
}
|
|
1386
1493
|
function textNodeNeedsDeclaration(node, topLevel, lastChild) {
|
|
1387
|
-
return isReactive(node.content) || topLevel && lastChild;
|
|
1494
|
+
return !node.raw && isReactive(node.content) || topLevel && lastChild;
|
|
1388
1495
|
}
|
|
1389
1496
|
function declareSpecialFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, lastChild, declare) {
|
|
1390
1497
|
if (node.tagName === "slot") declareParentAndAnchorFragmentVars(fragment, node, path, status, b, parentName, anchorName, varPaths, "slot", declare);
|
|
@@ -1883,41 +1990,185 @@ function isForBodyLeafSafe(forBodyChildren) {
|
|
|
1883
1990
|
}
|
|
1884
1991
|
//#endregion
|
|
1885
1992
|
//#region src/compile/utils/forLoopVarNames.ts
|
|
1993
|
+
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
1886
1994
|
/**
|
|
1887
1995
|
* Extracts the declared loop variable names from a `@for` statement — the
|
|
1888
|
-
*
|
|
1889
|
-
*
|
|
1890
|
-
*
|
|
1996
|
+
* header parse shared by `buildForNode` (codegen) and the write scanners
|
|
1997
|
+
* (`forVarsWrittenIn`/`forVarsReassignedIn`, which use it to detect nested
|
|
1998
|
+
* loops that shadow an outer loop's variables).
|
|
1891
1999
|
*
|
|
1892
2000
|
* Handles the C-style (`for (let i = 0; i < n; i++)`), for-of and for-in
|
|
1893
|
-
* forms,
|
|
1894
|
-
* destructuring, quotes, comments etc (same as buildForNode's note — this is
|
|
1895
|
-
* deliberately the same heuristic).
|
|
2001
|
+
* forms, including comments, strings, nested destructuring and defaults.
|
|
1896
2002
|
*/
|
|
1897
2003
|
function forLoopVarNames(statement) {
|
|
1898
|
-
const
|
|
1899
|
-
const
|
|
1900
|
-
|
|
1901
|
-
const
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
};
|
|
2004
|
+
const source = maskComments(statement);
|
|
2005
|
+
const forIndex = source.indexOf("for");
|
|
2006
|
+
if (forIndex === -1) return [];
|
|
2007
|
+
const open = source.indexOf("(", forIndex + 3);
|
|
2008
|
+
if (open === -1) return [];
|
|
2009
|
+
const close = findMatching(source, open, "(", ")");
|
|
2010
|
+
if (close === -1) return [];
|
|
2011
|
+
const header = source.slice(open + 1, close);
|
|
1907
2012
|
const names = [];
|
|
1908
|
-
const
|
|
1909
|
-
if (
|
|
1910
|
-
const
|
|
1911
|
-
for (const
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
2013
|
+
const firstSemi = findTopLevel(header, (char) => char === ";");
|
|
2014
|
+
if (firstSemi !== -1) {
|
|
2015
|
+
const declaration = stripDeclarationKeyword(header.slice(0, firstSemi));
|
|
2016
|
+
for (const declarator of splitTopLevel(declaration, ",")) {
|
|
2017
|
+
const eq = findTopLevel(declarator, (char) => char === "=");
|
|
2018
|
+
collectBindings(eq === -1 ? declarator : declarator.slice(0, eq), names);
|
|
2019
|
+
}
|
|
2020
|
+
return [...new Set(names)];
|
|
2021
|
+
}
|
|
2022
|
+
const keyword = findLoopKeyword(header);
|
|
2023
|
+
if (keyword !== -1) collectBindings(stripDeclarationKeyword(header.slice(0, keyword)), names);
|
|
2024
|
+
return [...new Set(names)];
|
|
2025
|
+
}
|
|
2026
|
+
/** Replaces comments with spaces, preserving length and string contents. */
|
|
2027
|
+
function maskComments(source) {
|
|
2028
|
+
let masked = "";
|
|
2029
|
+
for (let i = 0; i < source.length; i++) {
|
|
2030
|
+
const skipped = skipStringOrComment(source, i);
|
|
2031
|
+
if (skipped === -1) {
|
|
2032
|
+
masked += source[i];
|
|
2033
|
+
continue;
|
|
2034
|
+
}
|
|
2035
|
+
if (source[i] === "/" && (source[i + 1] === "/" || source[i + 1] === "*")) masked += source.substring(i, skipped).replaceAll(/[^\r\n]/g, " ");
|
|
2036
|
+
else masked += source.substring(i, skipped);
|
|
2037
|
+
i = skipped - 1;
|
|
1919
2038
|
}
|
|
1920
|
-
return
|
|
2039
|
+
return masked;
|
|
2040
|
+
}
|
|
2041
|
+
/** Finds the close delimiter matching the opener at `start`. */
|
|
2042
|
+
function findMatching(source, start, open, close) {
|
|
2043
|
+
let depth = 0;
|
|
2044
|
+
for (let i = start; i < source.length; i++) {
|
|
2045
|
+
const skipped = skipStringOrComment(source, i);
|
|
2046
|
+
if (skipped !== -1) {
|
|
2047
|
+
i = skipped - 1;
|
|
2048
|
+
continue;
|
|
2049
|
+
}
|
|
2050
|
+
const char = source[i];
|
|
2051
|
+
if (char === open) depth += 1;
|
|
2052
|
+
else if (char === close) {
|
|
2053
|
+
depth -= 1;
|
|
2054
|
+
if (depth === 0) return i;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
return -1;
|
|
2058
|
+
}
|
|
2059
|
+
/** Finds the first match of `predicate` outside nested delimiters and strings. */
|
|
2060
|
+
function findTopLevel(source, predicate) {
|
|
2061
|
+
let depth = 0;
|
|
2062
|
+
for (let i = 0; i < source.length; i++) {
|
|
2063
|
+
const skipped = skipStringOrComment(source, i);
|
|
2064
|
+
if (skipped !== -1) {
|
|
2065
|
+
i = skipped - 1;
|
|
2066
|
+
continue;
|
|
2067
|
+
}
|
|
2068
|
+
const char = source[i];
|
|
2069
|
+
if (char === "(" || char === "[" || char === "{") depth += 1;
|
|
2070
|
+
else if (char === ")" || char === "]" || char === "}") depth -= 1;
|
|
2071
|
+
else if (depth === 0 && predicate(char, i)) return i;
|
|
2072
|
+
}
|
|
2073
|
+
return -1;
|
|
2074
|
+
}
|
|
2075
|
+
/** Finds a top-level `of` or `in` keyword. */
|
|
2076
|
+
function findLoopKeyword(source) {
|
|
2077
|
+
let depth = 0;
|
|
2078
|
+
for (let i = 0; i < source.length; i++) {
|
|
2079
|
+
const skipped = skipStringOrComment(source, i);
|
|
2080
|
+
if (skipped !== -1) {
|
|
2081
|
+
i = skipped - 1;
|
|
2082
|
+
continue;
|
|
2083
|
+
}
|
|
2084
|
+
const char = source[i];
|
|
2085
|
+
if (char === "(" || char === "[" || char === "{") {
|
|
2086
|
+
depth += 1;
|
|
2087
|
+
continue;
|
|
2088
|
+
}
|
|
2089
|
+
if (char === ")" || char === "]" || char === "}") {
|
|
2090
|
+
depth -= 1;
|
|
2091
|
+
continue;
|
|
2092
|
+
}
|
|
2093
|
+
if (depth !== 0) continue;
|
|
2094
|
+
for (const keyword of ["of", "in"]) {
|
|
2095
|
+
if (!source.startsWith(keyword, i)) continue;
|
|
2096
|
+
const previous = source[i - 1];
|
|
2097
|
+
const next = source[i + keyword.length];
|
|
2098
|
+
if ((previous === void 0 || !isIdentifierChar(previous)) && (next === void 0 || !isIdentifierChar(next))) return i;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
return -1;
|
|
2102
|
+
}
|
|
2103
|
+
/** Splits at a separator that isn't inside strings or nested delimiters. */
|
|
2104
|
+
function splitTopLevel(source, separator) {
|
|
2105
|
+
const parts = [];
|
|
2106
|
+
let start = 0;
|
|
2107
|
+
let depth = 0;
|
|
2108
|
+
for (let i = 0; i < source.length; i++) {
|
|
2109
|
+
const skipped = skipStringOrComment(source, i);
|
|
2110
|
+
if (skipped !== -1) {
|
|
2111
|
+
i = skipped - 1;
|
|
2112
|
+
continue;
|
|
2113
|
+
}
|
|
2114
|
+
const char = source[i];
|
|
2115
|
+
if (char === "(" || char === "[" || char === "{") depth += 1;
|
|
2116
|
+
else if (char === ")" || char === "]" || char === "}") depth -= 1;
|
|
2117
|
+
else if (depth === 0 && char === separator) {
|
|
2118
|
+
parts.push(source.slice(start, i));
|
|
2119
|
+
start = i + 1;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
parts.push(source.slice(start));
|
|
2123
|
+
return parts;
|
|
2124
|
+
}
|
|
2125
|
+
function stripDeclarationKeyword(declaration) {
|
|
2126
|
+
return declaration.trim().replace(/^(?:let|var|const)\b\s*/, "");
|
|
2127
|
+
}
|
|
2128
|
+
function collectBindings(pattern, names) {
|
|
2129
|
+
pattern = pattern.trim();
|
|
2130
|
+
if (!pattern) return;
|
|
2131
|
+
const open = pattern[0];
|
|
2132
|
+
if (open === "{") {
|
|
2133
|
+
const close = findMatching(pattern, 0, "{", "}");
|
|
2134
|
+
if (close === -1) return;
|
|
2135
|
+
for (const property of splitTopLevel(pattern.slice(1, close), ",")) collectObjectBinding(property.trim(), names);
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
if (open === "[") {
|
|
2139
|
+
const close = findMatching(pattern, 0, "[", "]");
|
|
2140
|
+
if (close === -1) return;
|
|
2141
|
+
for (let element of splitTopLevel(pattern.slice(1, close), ",")) {
|
|
2142
|
+
element = element.trim();
|
|
2143
|
+
if (!element) continue;
|
|
2144
|
+
if (element.startsWith("...")) element = element.slice(3).trim();
|
|
2145
|
+
const eq = findTopLevel(element, (char) => char === "=");
|
|
2146
|
+
collectBindings(eq === -1 ? element : element.slice(0, eq), names);
|
|
2147
|
+
}
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
const eq = findTopLevel(pattern, (char) => char === "=");
|
|
2151
|
+
const name = (eq === -1 ? pattern : pattern.slice(0, eq)).trim();
|
|
2152
|
+
if (IDENTIFIER.test(name)) names.push(name);
|
|
2153
|
+
}
|
|
2154
|
+
function collectObjectBinding(property, names) {
|
|
2155
|
+
property = property.trim();
|
|
2156
|
+
if (!property) return;
|
|
2157
|
+
if (property.startsWith("...")) {
|
|
2158
|
+
collectBindings(property.slice(3).trim(), names);
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
const colon = findTopLevel(property, (char) => char === ":");
|
|
2162
|
+
const eq = findTopLevel(property, (char) => char === "=");
|
|
2163
|
+
if (colon !== -1 && (eq === -1 || colon < eq)) {
|
|
2164
|
+
collectBindings(property.slice(colon + 1).trim(), names);
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
const name = (eq === -1 ? property : property.slice(0, eq)).trim();
|
|
2168
|
+
if (IDENTIFIER.test(name)) names.push(name);
|
|
2169
|
+
}
|
|
2170
|
+
function isIdentifierChar(char) {
|
|
2171
|
+
return /[A-Za-z0-9_$]/.test(char);
|
|
1921
2172
|
}
|
|
1922
2173
|
//#endregion
|
|
1923
2174
|
//#region src/compile/utils/forVarsWrittenIn.ts
|
|
@@ -2581,6 +2832,25 @@ function buildControlNode(node, status, b) {
|
|
|
2581
2832
|
}
|
|
2582
2833
|
}
|
|
2583
2834
|
//#endregion
|
|
2835
|
+
//#region src/compile/utils/rawTextTags.ts
|
|
2836
|
+
/**
|
|
2837
|
+
* HTML raw-text elements. Their contents aren't parsed as markup (or as a
|
|
2838
|
+
* torpor template): braces, `@` and `<` are all literal, and the browser
|
|
2839
|
+
* doesn't decode character references inside them either. Rendered `<script>`
|
|
2840
|
+
* / `<style>` content is therefore emitted exactly as written.
|
|
2841
|
+
*/
|
|
2842
|
+
const RAW_TEXT_TAGS = /* @__PURE__ */ new Set([
|
|
2843
|
+
"script",
|
|
2844
|
+
"style",
|
|
2845
|
+
"xmp",
|
|
2846
|
+
"iframe",
|
|
2847
|
+
"noembed",
|
|
2848
|
+
"noframes"
|
|
2849
|
+
]);
|
|
2850
|
+
function isRawTextTag(tagName) {
|
|
2851
|
+
return RAW_TEXT_TAGS.has(tagName.toLowerCase());
|
|
2852
|
+
}
|
|
2853
|
+
//#endregion
|
|
2584
2854
|
//#region src/compile/utils/trimEnd.ts
|
|
2585
2855
|
/**
|
|
2586
2856
|
* Trims a char from the end of the supplied text
|
|
@@ -2650,7 +2920,7 @@ function buildElementNode(node, status, b, parentName) {
|
|
|
2650
2920
|
buildElementAttributes$1(node, varName, status, b);
|
|
2651
2921
|
}
|
|
2652
2922
|
const oldPreserveWhitespace = status.preserveWhitespace;
|
|
2653
|
-
status.preserveWhitespace = node.tagName === "code" || node.tagName === "pre";
|
|
2923
|
+
status.preserveWhitespace = node.tagName === "code" || node.tagName === "pre" || isRawTextTag(node.tagName);
|
|
2654
2924
|
for (let child of node.children) buildNode(child, status, b, parentName, "null");
|
|
2655
2925
|
status.preserveWhitespace = oldPreserveWhitespace;
|
|
2656
2926
|
if (svgElement) status.ns = oldns;
|
|
@@ -2688,12 +2958,28 @@ function buildTitleNode(node, status, b) {
|
|
|
2688
2958
|
else content = `\`${content.replaceAll("{", "${t_fmt(").replaceAll("}", ")}")}\``;
|
|
2689
2959
|
} else content = `"${content}"`;
|
|
2690
2960
|
status.imports.add("$run");
|
|
2691
|
-
|
|
2692
|
-
|
|
2961
|
+
if (status.options.dev === true) {
|
|
2962
|
+
status.imports.add("t_dev_title");
|
|
2963
|
+
b.append(`{
|
|
2964
|
+
const t_title_dev = t_dev_title();
|
|
2965
|
+
$run(() => {
|
|
2966
|
+
const t_old_title = document.title;
|
|
2967
|
+
document.title = ${content};
|
|
2968
|
+
t_title_dev.set(document.title);
|
|
2969
|
+
return () => {
|
|
2970
|
+
t_title_dev.unset();
|
|
2971
|
+
document.title = t_old_title;
|
|
2972
|
+
};
|
|
2973
|
+
}, "runTitle");
|
|
2974
|
+
}`);
|
|
2975
|
+
} else {
|
|
2976
|
+
b.append("$run(() => {");
|
|
2977
|
+
b.append(`
|
|
2693
2978
|
const t_old_title = document.title;
|
|
2694
2979
|
document.title = ${content};
|
|
2695
2980
|
return () => document.title = t_old_title;
|
|
2696
|
-
}
|
|
2981
|
+
});`);
|
|
2982
|
+
}
|
|
2697
2983
|
}
|
|
2698
2984
|
function buildHeadNode(node, status, b) {
|
|
2699
2985
|
status.imports.add("$run");
|
|
@@ -2794,12 +3080,14 @@ function buildBindAttribute(node, varName, name, value, status, b, combined) {
|
|
|
2794
3080
|
let eventName = bindEventName(node, name);
|
|
2795
3081
|
let defaultValue = "\"\"";
|
|
2796
3082
|
let inputValue = "e.target.value";
|
|
3083
|
+
let setJoin = "||";
|
|
2797
3084
|
if (node.tagName === "input") {
|
|
2798
3085
|
let typeAttribute = node.attributes.find((a) => a.name === "type");
|
|
2799
3086
|
if (typeAttribute && typeAttribute.value) switch (trimQuotes(typeAttribute.value)) {
|
|
2800
3087
|
case "number":
|
|
2801
|
-
defaultValue = "
|
|
2802
|
-
inputValue = "Number(e.target.value)";
|
|
3088
|
+
defaultValue = "\"\"";
|
|
3089
|
+
inputValue = "e.target.value === \"\" ? undefined : Number(e.target.value)";
|
|
3090
|
+
setJoin = "??";
|
|
2803
3091
|
break;
|
|
2804
3092
|
case "checkbox":
|
|
2805
3093
|
defaultValue = "false";
|
|
@@ -2812,7 +3100,7 @@ function buildBindAttribute(node, varName, name, value, status, b, combined) {
|
|
|
2812
3100
|
return;
|
|
2813
3101
|
}
|
|
2814
3102
|
}
|
|
2815
|
-
let set = `${value}
|
|
3103
|
+
let set = `${value} ${setJoin} ${defaultValue}`;
|
|
2816
3104
|
const propName = name.substring(1);
|
|
2817
3105
|
buildRun("setBinding", `${propName === "value" ? `${varName}.${propName} = String(${set})` : `${varName}.${propName} = ${set}`};`, status, b);
|
|
2818
3106
|
emitBindEvent(varName, eventName, `(e) => ${value} = ${inputValue}`, `${value} = ${inputValue};`, combined, status, b);
|
|
@@ -3007,6 +3295,7 @@ function buildSpecialNode(node, status, b, parentName, root = false) {
|
|
|
3007
3295
|
//#endregion
|
|
3008
3296
|
//#region src/compile/build/client/buildTextNode.ts
|
|
3009
3297
|
function buildTextNode(node, status) {
|
|
3298
|
+
if (node.raw) return;
|
|
3010
3299
|
let fragment = status.fragmentStack.at(-1)?.fragment;
|
|
3011
3300
|
if (!fragment) return;
|
|
3012
3301
|
let content = node.content || "";
|
|
@@ -3151,7 +3440,8 @@ const importsMap$1 = {
|
|
|
3151
3440
|
SlotRender: "import { type SlotRender } from \"${folder}\";",
|
|
3152
3441
|
devContext: "import { devContext } from \"${folder}/dev\";",
|
|
3153
3442
|
t_push_dev_bound: "import { t_push_dev_bound } from \"${folder}/dev\";",
|
|
3154
|
-
t_pop_dev_bound: "import { t_pop_dev_bound } from \"${folder}/dev\";"
|
|
3443
|
+
t_pop_dev_bound: "import { t_pop_dev_bound } from \"${folder}/dev\";",
|
|
3444
|
+
t_dev_title: "import { t_dev_title } from \"${folder}/dev\";"
|
|
3155
3445
|
};
|
|
3156
3446
|
function buildCode(template, map, options, errors = [], warnings = []) {
|
|
3157
3447
|
let b = new Builder(options?.mapped);
|
|
@@ -3289,10 +3579,10 @@ function buildStyles(style, styleHash) {
|
|
|
3289
3579
|
for (let block of style.children) buildStyleNode(block, b, styleHash);
|
|
3290
3580
|
return b.toString();
|
|
3291
3581
|
}
|
|
3292
|
-
function buildStyleNode(node, b, styleHash) {
|
|
3582
|
+
function buildStyleNode(node, b, styleHash, scoped = true) {
|
|
3293
3583
|
switch (node.type) {
|
|
3294
3584
|
case "block":
|
|
3295
|
-
buildBlockNode(node, b, styleHash);
|
|
3585
|
+
buildBlockNode(node, b, styleHash, scoped);
|
|
3296
3586
|
break;
|
|
3297
3587
|
case "attribute":
|
|
3298
3588
|
buildAttributeNode(node, b);
|
|
@@ -3301,55 +3591,164 @@ function buildStyleNode(node, b, styleHash) {
|
|
|
3301
3591
|
default: throw new Error(`Invalid style node type: ${node.type}`);
|
|
3302
3592
|
}
|
|
3303
3593
|
}
|
|
3304
|
-
function buildBlockNode(block, b, styleHash) {
|
|
3594
|
+
function buildBlockNode(block, b, styleHash, scoped) {
|
|
3595
|
+
const isKeyframes = block.selector.startsWith("@keyframes") || block.selector.startsWith("@-webkit-keyframes");
|
|
3305
3596
|
if (block.selector.startsWith("@")) b.append(`${block.selector} {`);
|
|
3306
3597
|
else {
|
|
3307
|
-
block.selector = block.selector.replaceAll(/\s+/g, " ");
|
|
3308
|
-
|
|
3309
|
-
let global = false;
|
|
3310
|
-
let start = 0;
|
|
3311
|
-
for (let i = 0; i <= block.selector.length; i++) if (block.selector.substring(i).startsWith(":global(")) {
|
|
3312
|
-
i += 7;
|
|
3313
|
-
start = i + 1;
|
|
3314
|
-
global = true;
|
|
3315
|
-
} else if (global && block.selector[i] === ")") {
|
|
3316
|
-
addSelector(selectors, block.selector, styleHash, start, i, global);
|
|
3317
|
-
start = i + 1;
|
|
3318
|
-
global = false;
|
|
3319
|
-
} else if ("*,>+~".includes(block.selector[i])) {
|
|
3320
|
-
addSelector(selectors, block.selector, styleHash, start, i, global);
|
|
3321
|
-
selectors.push(block.selector[i]);
|
|
3322
|
-
start = i + 1;
|
|
3323
|
-
} else if (i === block.selector.length) addSelector(selectors, block.selector, styleHash, start, i, global);
|
|
3324
|
-
else if (block.selector[i] === " ") {
|
|
3325
|
-
addSelector(selectors, block.selector, styleHash, start, i, global);
|
|
3326
|
-
start = i + 1;
|
|
3327
|
-
}
|
|
3328
|
-
b.append(`${selectors.join(" ").replaceAll(" ,", ",")} {`);
|
|
3598
|
+
block.selector = block.selector.replaceAll(/\s+/g, " ").trim();
|
|
3599
|
+
b.append(`${scoped ? scopeSelector(block.selector, styleHash) : block.selector} {`);
|
|
3329
3600
|
}
|
|
3330
|
-
for (let child of block.children) buildStyleNode(child, b, styleHash);
|
|
3601
|
+
for (let child of block.children) buildStyleNode(child, b, styleHash, scoped && !isKeyframes);
|
|
3331
3602
|
b.append(`}`);
|
|
3332
3603
|
}
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3604
|
+
/**
|
|
3605
|
+
* Appends the component scope class to each compound selector. Both brackets
|
|
3606
|
+
* (`[data-x="a b"]`) and parentheses (`:is(.a, .b)`, `:global(...)`) are
|
|
3607
|
+
* treated as opaque, so spaces/commas inside them aren't mistaken for
|
|
3608
|
+
* combinators. `:global(...)` wrappers are removed without adding the scope.
|
|
3609
|
+
*/
|
|
3610
|
+
function scopeSelector(selector, styleHash) {
|
|
3611
|
+
let result = "";
|
|
3612
|
+
let compound = "";
|
|
3613
|
+
let bracketDepth = 0;
|
|
3614
|
+
let parenDepth = 0;
|
|
3615
|
+
let quote = null;
|
|
3616
|
+
const flush = () => {
|
|
3617
|
+
if (!compound) return;
|
|
3618
|
+
result += scopeCompound(compound, styleHash);
|
|
3619
|
+
compound = "";
|
|
3620
|
+
};
|
|
3621
|
+
for (let i = 0; i < selector.length; i++) {
|
|
3622
|
+
const char = selector[i];
|
|
3623
|
+
if (quote !== null) {
|
|
3624
|
+
compound += char;
|
|
3625
|
+
if (char === "\\") compound += selector[++i] ?? "";
|
|
3626
|
+
else if (char === quote) quote = null;
|
|
3627
|
+
continue;
|
|
3628
|
+
}
|
|
3629
|
+
if (char === "\\") compound += char + (selector[++i] ?? "");
|
|
3630
|
+
else if (char === "\"" || char === "'") {
|
|
3631
|
+
quote = char;
|
|
3632
|
+
compound += char;
|
|
3633
|
+
} else if (char === "[") {
|
|
3634
|
+
bracketDepth += 1;
|
|
3635
|
+
compound += char;
|
|
3636
|
+
} else if (char === "]") {
|
|
3637
|
+
bracketDepth -= 1;
|
|
3638
|
+
compound += char;
|
|
3639
|
+
} else if (char === "(") {
|
|
3640
|
+
parenDepth += 1;
|
|
3641
|
+
compound += char;
|
|
3642
|
+
} else if (char === ")") {
|
|
3643
|
+
parenDepth -= 1;
|
|
3644
|
+
compound += char;
|
|
3645
|
+
} else if (bracketDepth === 0 && parenDepth === 0 && (char === " " || char === "," || char === ">" || char === "+" || char === "~")) {
|
|
3646
|
+
flush();
|
|
3647
|
+
result += char;
|
|
3648
|
+
} else compound += char;
|
|
3649
|
+
}
|
|
3650
|
+
flush();
|
|
3651
|
+
return result.trim();
|
|
3652
|
+
}
|
|
3653
|
+
function scopeCompound(compound, styleHash) {
|
|
3654
|
+
if (!compound.includes(":global(")) return addScope(compound, styleHash);
|
|
3655
|
+
const { text, onlyGlobal } = stripGlobal(compound);
|
|
3656
|
+
return onlyGlobal ? text : addScope(text, styleHash);
|
|
3657
|
+
}
|
|
3658
|
+
/** Removes `:global(...)` wrappers, reporting whether anything local remained. */
|
|
3659
|
+
function stripGlobal(compound) {
|
|
3660
|
+
let text = "";
|
|
3661
|
+
let hadLocal = false;
|
|
3662
|
+
let i = 0;
|
|
3663
|
+
while (i < compound.length) {
|
|
3664
|
+
if (compound.startsWith(":global(", i)) {
|
|
3665
|
+
const close = findClosingParen(compound, i + 7);
|
|
3666
|
+
if (close === -1) {
|
|
3667
|
+
text += compound.substring(i);
|
|
3668
|
+
break;
|
|
3343
3669
|
}
|
|
3344
|
-
|
|
3670
|
+
text += compound.substring(i + 8, close);
|
|
3671
|
+
i = close + 1;
|
|
3672
|
+
continue;
|
|
3673
|
+
}
|
|
3674
|
+
const char = compound[i];
|
|
3675
|
+
if (char.trim()) hadLocal = true;
|
|
3676
|
+
text += char;
|
|
3677
|
+
i += 1;
|
|
3678
|
+
}
|
|
3679
|
+
return {
|
|
3680
|
+
text,
|
|
3681
|
+
onlyGlobal: !hadLocal
|
|
3682
|
+
};
|
|
3683
|
+
}
|
|
3684
|
+
function addScope(compound, styleHash) {
|
|
3685
|
+
const colon = findFirstPseudo(compound);
|
|
3686
|
+
const scope = `.torp-${styleHash}`;
|
|
3687
|
+
return colon === -1 ? `${compound}${scope}` : `${compound.substring(0, colon)}${scope}${compound.substring(colon)}`;
|
|
3688
|
+
}
|
|
3689
|
+
/** Finds the first top-level `:` (pseudo-class/element), skipping brackets/strings. */
|
|
3690
|
+
function findFirstPseudo(compound) {
|
|
3691
|
+
let bracketDepth = 0;
|
|
3692
|
+
let parenDepth = 0;
|
|
3693
|
+
let quote = null;
|
|
3694
|
+
for (let i = 0; i < compound.length; i++) {
|
|
3695
|
+
const char = compound[i];
|
|
3696
|
+
if (quote !== null) {
|
|
3697
|
+
if (char === "\\") i += 1;
|
|
3698
|
+
else if (char === quote) quote = null;
|
|
3699
|
+
continue;
|
|
3700
|
+
}
|
|
3701
|
+
if (char === "\\") i += 1;
|
|
3702
|
+
else if (char === "\"" || char === "'") quote = char;
|
|
3703
|
+
else if (char === "[") bracketDepth += 1;
|
|
3704
|
+
else if (char === "]") bracketDepth -= 1;
|
|
3705
|
+
else if (char === "(") parenDepth += 1;
|
|
3706
|
+
else if (char === ")") parenDepth -= 1;
|
|
3707
|
+
else if (bracketDepth === 0 && parenDepth === 0 && char === ":") return i;
|
|
3708
|
+
}
|
|
3709
|
+
return -1;
|
|
3710
|
+
}
|
|
3711
|
+
function findClosingParen(source, open) {
|
|
3712
|
+
let depth = 0;
|
|
3713
|
+
let bracketDepth = 0;
|
|
3714
|
+
let quote = null;
|
|
3715
|
+
for (let i = open; i < source.length; i++) {
|
|
3716
|
+
const char = source[i];
|
|
3717
|
+
if (quote !== null) {
|
|
3718
|
+
if (char === "\\") i += 1;
|
|
3719
|
+
else if (char === quote) quote = null;
|
|
3720
|
+
continue;
|
|
3721
|
+
}
|
|
3722
|
+
if (char === "\\") i += 1;
|
|
3723
|
+
else if (char === "\"" || char === "'") quote = char;
|
|
3724
|
+
else if (char === "[") bracketDepth += 1;
|
|
3725
|
+
else if (char === "]") bracketDepth -= 1;
|
|
3726
|
+
else if (bracketDepth === 0 && char === "(") depth += 1;
|
|
3727
|
+
else if (bracketDepth === 0 && char === ")") {
|
|
3728
|
+
depth -= 1;
|
|
3729
|
+
if (depth === 0) return i;
|
|
3345
3730
|
}
|
|
3346
|
-
selectors.push(s);
|
|
3347
3731
|
}
|
|
3732
|
+
return -1;
|
|
3348
3733
|
}
|
|
3349
3734
|
function buildAttributeNode(attribute, b) {
|
|
3350
3735
|
b.append(`${attribute.name}: ${attribute.value};`);
|
|
3351
3736
|
}
|
|
3352
3737
|
//#endregion
|
|
3738
|
+
//#region src/compile/utils/containsAwaitGroup.ts
|
|
3739
|
+
/**
|
|
3740
|
+
* Whether a markup tree contains an `@await` boundary, so the component's
|
|
3741
|
+
* render must be wrapped in a flush.
|
|
3742
|
+
*/
|
|
3743
|
+
function containsAwaitGroup(node) {
|
|
3744
|
+
if (node === void 0 || node === null) return false;
|
|
3745
|
+
if (isControlNode(node) && node.operation === "@await group") return true;
|
|
3746
|
+
if (node.type !== "text" && node.type !== "comment") {
|
|
3747
|
+
for (let child of node.children) if (containsAwaitGroup(child)) return true;
|
|
3748
|
+
}
|
|
3749
|
+
return false;
|
|
3750
|
+
}
|
|
3751
|
+
//#endregion
|
|
3353
3752
|
//#region src/compile/build/server/flushOutput.ts
|
|
3354
3753
|
/**
|
|
3355
3754
|
* Appends any pending output to the generated code, targeting the body
|
|
@@ -3402,7 +3801,7 @@ function buildServerComponentNode(node, status, b) {
|
|
|
3402
3801
|
for (let slot of node.children) if (isSpecialNode(slot) && (slot.tagName === "fill" || slot.tagName === "filldef")) {
|
|
3403
3802
|
const nameAttribute = slot.attributes.find((a) => a.name === "name");
|
|
3404
3803
|
const slotName = nameAttribute?.value ? trimQuotes(nameAttribute.value) : "_";
|
|
3405
|
-
const slotParams = [slot.hasSlotProps ? "$slot: Record<PropertyKey, any>" : "_$slot?: Record<PropertyKey, any>", fillUsesContext(slot) ? "$context?: Record<PropertyKey, any>" : "_$context?: Record<PropertyKey, any>"];
|
|
3804
|
+
const slotParams = [slot.hasSlotProps ? "$slot: Record<PropertyKey, any>" : "_$slot?: Record<PropertyKey, any>", fillUsesContext(slot) || containsAwaitGroup(slot) ? "$context?: Record<PropertyKey, any>" : "_$context?: Record<PropertyKey, any>"];
|
|
3406
3805
|
b.append(`${slot.hasSlotProps ? "// @ts-ignore\n" : ""}${slotsName}["${slotName}"] = async (\n${slotParams.join(",\n")}\n) => {`);
|
|
3407
3806
|
b.append(`let t_body = "";`);
|
|
3408
3807
|
for (let child of slot.children) buildServerNode(child, status, b);
|
|
@@ -3458,7 +3857,7 @@ function buildServerAwaitNode(node, status, b) {
|
|
|
3458
3857
|
for (let branch of node.children) if (isControlNode(branch) && branch.operation === "@with") for (let child of branch.children) buildServerNode(child, status, b);
|
|
3459
3858
|
flushOutput(status, b);
|
|
3460
3859
|
b.append(`return { body: t_body, head: t_head };`);
|
|
3461
|
-
b.append(`});`);
|
|
3860
|
+
b.append(`}, $context);`);
|
|
3462
3861
|
b.append(`${status.inHead ? "t_head" : "t_body"} += ${resultName}.body;`);
|
|
3463
3862
|
b.append(`t_head += ${resultName}.head;`);
|
|
3464
3863
|
}
|
|
@@ -3640,7 +4039,7 @@ function buildServerElementNode(node, status, b) {
|
|
|
3640
4039
|
status.output += `<${tagName}${attributes}>`;
|
|
3641
4040
|
if (!voidTags.includes(tagName)) {
|
|
3642
4041
|
const oldPreserveWhitespace = status.preserveWhitespace;
|
|
3643
|
-
status.preserveWhitespace = ["pre", "code"].includes(tagName);
|
|
4042
|
+
status.preserveWhitespace = ["pre", "code"].includes(tagName) || isRawTextTag(tagName);
|
|
3644
4043
|
if (!tagName.startsWith("@")) status.elementStack.push(tagName);
|
|
3645
4044
|
for (let child of node.children) buildServerNode(child, status, b);
|
|
3646
4045
|
if (!tagName.startsWith("@")) status.elementStack.pop();
|
|
@@ -3658,16 +4057,13 @@ function buildElementAttributes(node, status) {
|
|
|
3658
4057
|
let typeAttribute = node.attributes.find((a) => a.name === "type");
|
|
3659
4058
|
if (typeAttribute && typeAttribute.value) switch (trimQuotes(typeAttribute.value)) {
|
|
3660
4059
|
case "number":
|
|
3661
|
-
defaultValue = "
|
|
4060
|
+
defaultValue = "\"\"";
|
|
3662
4061
|
break;
|
|
3663
4062
|
case "checkbox": defaultValue = "false";
|
|
3664
4063
|
}
|
|
3665
|
-
if (!defaultValue)
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
defaultValue = "\"\"";
|
|
3669
|
-
}
|
|
3670
|
-
let valueOrDefault = `(${value}) || ${defaultValue}`;
|
|
4064
|
+
if (!defaultValue) defaultValue = "\"\"";
|
|
4065
|
+
status.imports.add("t_attr");
|
|
4066
|
+
let valueOrDefault = `t_attr(${value}) || ${defaultValue}`;
|
|
3671
4067
|
const propName = name.substring(1);
|
|
3672
4068
|
attributes.push(`${propName}="\${${valueOrDefault}}"`);
|
|
3673
4069
|
} else if (name === "class") {
|
|
@@ -3690,9 +4086,9 @@ function buildElementAttributes(node, status) {
|
|
|
3690
4086
|
attributes.push(`${name}="${trimQuotes(value).replaceAll("{", "${t_attr(").replaceAll("}", ")}")}"`);
|
|
3691
4087
|
} else if (name === "class" && node.scopeStyles && !status.inHead) {
|
|
3692
4088
|
value = value ? `"${trimQuotes(value)} torp-${status.styleHash}"` : `"torp-${status.styleHash}"`;
|
|
3693
|
-
attributes.push(`${name}="${trimQuotes(value).replaceAll("\"", """)}"`);
|
|
4089
|
+
attributes.push(escapeTemplateText(`${name}="${trimQuotes(value).replaceAll("\"", """)}"`));
|
|
3694
4090
|
needsClass = false;
|
|
3695
|
-
} else if (value != null) attributes.push(`${name}="${trimQuotes(value).replaceAll("\"", """)}"`);
|
|
4091
|
+
} else if (value != null) attributes.push(escapeTemplateText(`${name}="${trimQuotes(value).replaceAll("\"", """)}"`));
|
|
3696
4092
|
else attributes.push(`${name}`);
|
|
3697
4093
|
if (needsClass) attributes.push(`class="torp-${status.styleHash}"`);
|
|
3698
4094
|
return attributes.join(" ");
|
|
@@ -3755,15 +4151,21 @@ function buildServerSpecialNode(node, status, b) {
|
|
|
3755
4151
|
//#region src/compile/build/server/buildServerTextNode.ts
|
|
3756
4152
|
function buildServerTextNode(node, status) {
|
|
3757
4153
|
let content = node.content || "";
|
|
4154
|
+
if (node.raw) {
|
|
4155
|
+
status.output += escapeRawText(content);
|
|
4156
|
+
return;
|
|
4157
|
+
}
|
|
3758
4158
|
if (!status.preserveWhitespace) content = content.replaceAll(/\s+/g, " ");
|
|
4159
|
+
const parentTag = status.elementStack[status.elementStack.length - 1];
|
|
4160
|
+
const formatter = parentTag !== void 0 && isRawTextTag(parentTag) ? "t_fmt_raw" : "t_fmt";
|
|
3759
4161
|
let level = 0;
|
|
3760
4162
|
for (let i = 0; i < content.length; i++) {
|
|
3761
4163
|
const char = content[i];
|
|
3762
4164
|
if (char === "{") {
|
|
3763
4165
|
level++;
|
|
3764
4166
|
if (level === 1) {
|
|
3765
|
-
status.imports.add(
|
|
3766
|
-
status.output += "${
|
|
4167
|
+
status.imports.add(formatter);
|
|
4168
|
+
status.output += "${" + formatter + "(";
|
|
3767
4169
|
continue;
|
|
3768
4170
|
}
|
|
3769
4171
|
} else if (char === "}") {
|
|
@@ -3826,8 +4228,10 @@ const importsMap = {
|
|
|
3826
4228
|
$peek: "import { $peek } from \"${folder}\";",
|
|
3827
4229
|
$batch: "import { $batch } from \"${folder}\";",
|
|
3828
4230
|
t_server_flush: "import { t_server_flush } from \"${folder}\";",
|
|
4231
|
+
t_render_context: "import { t_render_context } from \"${folder}\";",
|
|
3829
4232
|
t_await_server: "import { t_await_server } from \"${folder}\";",
|
|
3830
4233
|
t_fmt: "import { t_fmt } from \"${folder}\";",
|
|
4234
|
+
t_fmt_raw: "import { t_fmt_raw } from \"${folder}\";",
|
|
3831
4235
|
t_attr: "import { t_attr } from \"${folder}\";",
|
|
3832
4236
|
t_attr_if: "import { t_attr_if } from \"${folder}\";",
|
|
3833
4237
|
t_class: "import { t_class } from \"${folder}\";",
|
|
@@ -3875,121 +4279,118 @@ function buildServerTemplate(template, imports, b, options) {
|
|
|
3875
4279
|
for (let [i, chunk] of template.script.entries()) if (chunk.script === "/* @params */" && i > 0) asyncChunks.add(i - 1);
|
|
3876
4280
|
let currentIndex = 0;
|
|
3877
4281
|
let current = template.components[0];
|
|
3878
|
-
for (let [chunkIndex, chunk] of template.script.entries())
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
if (
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
b.append(`let t_head = "";`);
|
|
3894
|
-
} else if (chunk.script === "/* @render */") {
|
|
3895
|
-
if (current.markup) {
|
|
3896
|
-
const status = {
|
|
3897
|
-
imports,
|
|
3898
|
-
output: "",
|
|
3899
|
-
styleHash: current.style?.hash || "",
|
|
3900
|
-
varNames: {},
|
|
3901
|
-
preserveWhitespace: false,
|
|
3902
|
-
awaitCount: 0,
|
|
3903
|
-
elementStack: [],
|
|
3904
|
-
options
|
|
3905
|
-
};
|
|
3906
|
-
b.append("");
|
|
3907
|
-
b.append("/* User interface */");
|
|
3908
|
-
if (current.error) {
|
|
3909
|
-
b.append(`const t_try_body = t_body;`);
|
|
3910
|
-
b.append(`const t_try_head = t_head;`);
|
|
3911
|
-
b.append("try {");
|
|
4282
|
+
for (let [chunkIndex, chunk] of template.script.entries()) {
|
|
4283
|
+
const hasAwait = current !== void 0 && (containsAwaitGroup(current.markup) || containsAwaitGroup(current.error) || containsAwaitGroup(current.head));
|
|
4284
|
+
const rendersComponent = current !== void 0 && (current.markup && markupRendersComponent(current.markup) || current.error && markupRendersComponent(current.error));
|
|
4285
|
+
if (chunk.script === "/* @params */") {
|
|
4286
|
+
let params = [
|
|
4287
|
+
current.params ?? `${current.props?.length ? "$props: Record<PropertyKey, any>" : "_$props?: Record<PropertyKey, any>"}`,
|
|
4288
|
+
`${current.contextProps?.length || rendersComponent || hasAwait ? "$context" : "_$context"}?: Record<PropertyKey, any>`,
|
|
4289
|
+
`${current.slotProps?.length ? "$slots" : "_$slots"}?: Record<string, ServerSlotRender>`
|
|
4290
|
+
];
|
|
4291
|
+
b.append(params.join(",\n") + ",");
|
|
4292
|
+
} else if (chunk.script === ") /* @return_type */ {") b.append("): Promise<{ body: string; head: string }> {");
|
|
4293
|
+
else if (chunk.script === "/* @start */") {
|
|
4294
|
+
if (rendersComponent || hasAwait) {
|
|
4295
|
+
imports.add("t_render_context");
|
|
4296
|
+
b.append(`$context = t_render_context($context);`);
|
|
3912
4297
|
}
|
|
3913
|
-
|
|
3914
|
-
if (
|
|
3915
|
-
|
|
3916
|
-
|
|
4298
|
+
if (current.contextProps?.length) b.append(`$context = Object.assign({}, $context);`);
|
|
4299
|
+
if (hasAwait) {
|
|
4300
|
+
imports.add("t_server_flush");
|
|
4301
|
+
b.append(`return t_server_flush(async () => {`);
|
|
3917
4302
|
}
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
if (
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
4303
|
+
b.append(`let t_body = "";`);
|
|
4304
|
+
b.append(`let t_head = "";`);
|
|
4305
|
+
} else if (chunk.script === "/* @render */") {
|
|
4306
|
+
if (current.markup) {
|
|
4307
|
+
const status = {
|
|
4308
|
+
imports,
|
|
4309
|
+
output: "",
|
|
4310
|
+
styleHash: current.style?.hash || "",
|
|
4311
|
+
varNames: {},
|
|
4312
|
+
preserveWhitespace: false,
|
|
4313
|
+
awaitCount: 0,
|
|
4314
|
+
elementStack: [],
|
|
4315
|
+
options
|
|
4316
|
+
};
|
|
4317
|
+
b.append("");
|
|
4318
|
+
b.append("/* User interface */");
|
|
4319
|
+
if (current.error) {
|
|
4320
|
+
b.append(`const t_try_body = t_body;`);
|
|
4321
|
+
b.append(`const t_try_head = t_head;`);
|
|
4322
|
+
b.append("try {");
|
|
4323
|
+
}
|
|
4324
|
+
buildServerNode(current.markup, status, b);
|
|
4325
|
+
if (status.output) {
|
|
4326
|
+
b.append(`t_body += \`${status.output}\`;`);
|
|
4327
|
+
status.output = "";
|
|
4328
|
+
}
|
|
3939
4329
|
}
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
4330
|
+
} else if (chunk.script === "/* @error */") {
|
|
4331
|
+
if (current.markup && current.error) {
|
|
4332
|
+
const status = {
|
|
4333
|
+
imports,
|
|
4334
|
+
output: "",
|
|
4335
|
+
styleHash: current.style?.hash || "",
|
|
4336
|
+
varNames: {},
|
|
4337
|
+
preserveWhitespace: false,
|
|
4338
|
+
awaitCount: 0,
|
|
4339
|
+
elementStack: [],
|
|
4340
|
+
options
|
|
4341
|
+
};
|
|
4342
|
+
b.append(`} catch (${current.errorVar}) {`);
|
|
4343
|
+
b.append("t_body = t_try_body;");
|
|
4344
|
+
b.append("t_head = t_try_head;");
|
|
4345
|
+
b.append("/* User interface error */");
|
|
4346
|
+
buildServerNode(current.error, status, b);
|
|
4347
|
+
if (status.output) {
|
|
4348
|
+
b.append(`t_body += \`${status.output}\`;`);
|
|
4349
|
+
status.output = "";
|
|
4350
|
+
}
|
|
4351
|
+
b.append("}");
|
|
4352
|
+
}
|
|
4353
|
+
} else if (chunk.script === "/* @head */") {
|
|
4354
|
+
if (current.head) {
|
|
4355
|
+
const status = {
|
|
4356
|
+
imports,
|
|
4357
|
+
output: "",
|
|
4358
|
+
styleHash: current.style?.hash || "",
|
|
4359
|
+
varNames: {},
|
|
4360
|
+
preserveWhitespace: false,
|
|
4361
|
+
inHead: true,
|
|
4362
|
+
awaitCount: 0,
|
|
4363
|
+
elementStack: [],
|
|
4364
|
+
options
|
|
4365
|
+
};
|
|
4366
|
+
b.append("");
|
|
4367
|
+
b.append("/* Head */");
|
|
4368
|
+
buildServerNode(current.head, status, b);
|
|
4369
|
+
flushOutput(status, b);
|
|
4370
|
+
}
|
|
4371
|
+
} else if (chunk.script === "/* @style */") {
|
|
4372
|
+
if (current.style) {
|
|
4373
|
+
b.append("");
|
|
4374
|
+
b.append("/* Style */");
|
|
4375
|
+
const styles = buildStyles(current.style, current.style.hash).replaceAll("\"", "\\\"").replaceAll(/\s+/g, " ");
|
|
4376
|
+
b.append(`t_head += "<style id='${current.style.hash}'>${styles}</style>";\n`);
|
|
4377
|
+
}
|
|
4378
|
+
} else if (chunk.script === "/* @end */") {
|
|
4379
|
+
b.append(`return { body: t_body, head: t_head };`);
|
|
4380
|
+
if (hasAwait) b.append(`});`);
|
|
4381
|
+
currentIndex += 1;
|
|
4382
|
+
current = template.components[currentIndex];
|
|
4383
|
+
} else if (asyncChunks.has(chunkIndex)) b.append(chunk.script.replace(/(?<!async\s)function\s+([A-Za-z_$][\w$]*)((?:<(?:[^<>]|<[^<>]*>)*>)?)\s*\($/, "async function $1$2("));
|
|
4384
|
+
else b.append(chunk.script);
|
|
3984
4385
|
}
|
|
3985
|
-
return false;
|
|
3986
4386
|
}
|
|
3987
4387
|
//#endregion
|
|
3988
4388
|
//#region src/compile/utils/trimWhitespace.ts
|
|
3989
4389
|
/**
|
|
3990
4390
|
* Tag names whose contents should keep all whitespace untouched, matching
|
|
3991
4391
|
* native HTML rendering of `pre`/`textarea` and the existing build-time
|
|
3992
|
-
* `preserveWhitespace` behavior for `code`.
|
|
4392
|
+
* `preserveWhitespace` behavior for `code`. Raw-text elements (including
|
|
4393
|
+
* inline `<script>` / `<style>`) keep their contents exactly as written.
|
|
3993
4394
|
*/
|
|
3994
4395
|
const PRESERVE_TAGS = /* @__PURE__ */ new Set([
|
|
3995
4396
|
"pre",
|
|
@@ -4042,7 +4443,7 @@ function trimChildren(children, preserveAll, parentTag) {
|
|
|
4042
4443
|
const grandChildren = getChildren(child);
|
|
4043
4444
|
if (grandChildren) {
|
|
4044
4445
|
const childTag = getTagName(child);
|
|
4045
|
-
trimChildren(grandChildren, preserveAll || PRESERVE_TAGS.has(childTag ?? ""), childTag);
|
|
4446
|
+
trimChildren(grandChildren, preserveAll || PRESERVE_TAGS.has(childTag ?? "") || isRawTextTag(childTag ?? ""), childTag);
|
|
4046
4447
|
}
|
|
4047
4448
|
}
|
|
4048
4449
|
if (preserveAll) return;
|
|
@@ -4981,7 +5382,7 @@ function serializeElement(node, context) {
|
|
|
4981
5382
|
context.report(`Special elements ("<${node.tagName}>") aren't supported in restricted mode yet.`, node.span.start, node.span.end);
|
|
4982
5383
|
return;
|
|
4983
5384
|
}
|
|
4984
|
-
const childContext = node.tagName === "pre" || node.tagName === "code" ? {
|
|
5385
|
+
const childContext = node.tagName === "pre" || node.tagName === "code" || isRawTextTag(node.tagName) ? {
|
|
4985
5386
|
...context,
|
|
4986
5387
|
preserveWhitespace: true
|
|
4987
5388
|
} : context;
|
|
@@ -5311,35 +5712,573 @@ function isSpaceNode(node) {
|
|
|
5311
5712
|
return isTextNode(node) && isSpace(node.content);
|
|
5312
5713
|
}
|
|
5313
5714
|
//#endregion
|
|
5314
|
-
//#region src/compile/
|
|
5715
|
+
//#region src/compile/utils/nativeTags.ts
|
|
5315
5716
|
/**
|
|
5316
|
-
*
|
|
5317
|
-
*
|
|
5318
|
-
*
|
|
5319
|
-
*
|
|
5320
|
-
* @param status The parse status
|
|
5321
|
-
* @param advance (Optional) If true, advances the parse position past the
|
|
5322
|
-
* checked string (defaults to true)
|
|
5323
|
-
*
|
|
5324
|
-
* @returns True if the supplied string was found at the current parse position
|
|
5717
|
+
* Native HTML and SVG tag names, used to tell elements apart from components.
|
|
5718
|
+
* A tag that is neither imported nor a component declared in the same file is
|
|
5719
|
+
* an element when it appears here, or when it contains a dash (an HTML custom
|
|
5720
|
+
* element). Anything else capitalized is reported as an unknown component.
|
|
5325
5721
|
*/
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5722
|
+
const htmlTags = [
|
|
5723
|
+
"a",
|
|
5724
|
+
"abbr",
|
|
5725
|
+
"address",
|
|
5726
|
+
"area",
|
|
5727
|
+
"article",
|
|
5728
|
+
"aside",
|
|
5729
|
+
"audio",
|
|
5730
|
+
"b",
|
|
5731
|
+
"base",
|
|
5732
|
+
"bdi",
|
|
5733
|
+
"bdo",
|
|
5734
|
+
"blockquote",
|
|
5735
|
+
"body",
|
|
5736
|
+
"br",
|
|
5737
|
+
"button",
|
|
5738
|
+
"canvas",
|
|
5739
|
+
"caption",
|
|
5740
|
+
"cite",
|
|
5741
|
+
"code",
|
|
5742
|
+
"col",
|
|
5743
|
+
"colgroup",
|
|
5744
|
+
"data",
|
|
5745
|
+
"datalist",
|
|
5746
|
+
"dd",
|
|
5747
|
+
"del",
|
|
5748
|
+
"details",
|
|
5749
|
+
"dfn",
|
|
5750
|
+
"dialog",
|
|
5751
|
+
"div",
|
|
5752
|
+
"dl",
|
|
5753
|
+
"dt",
|
|
5754
|
+
"em",
|
|
5755
|
+
"embed",
|
|
5756
|
+
"fieldset",
|
|
5757
|
+
"figcaption",
|
|
5758
|
+
"figure",
|
|
5759
|
+
"footer",
|
|
5760
|
+
"form",
|
|
5761
|
+
"h1",
|
|
5762
|
+
"h2",
|
|
5763
|
+
"h3",
|
|
5764
|
+
"h4",
|
|
5765
|
+
"h5",
|
|
5766
|
+
"h6",
|
|
5767
|
+
"head",
|
|
5768
|
+
"header",
|
|
5769
|
+
"hgroup",
|
|
5770
|
+
"hr",
|
|
5771
|
+
"html",
|
|
5772
|
+
"i",
|
|
5773
|
+
"iframe",
|
|
5774
|
+
"img",
|
|
5775
|
+
"input",
|
|
5776
|
+
"ins",
|
|
5777
|
+
"kbd",
|
|
5778
|
+
"label",
|
|
5779
|
+
"legend",
|
|
5780
|
+
"li",
|
|
5781
|
+
"link",
|
|
5782
|
+
"main",
|
|
5783
|
+
"map",
|
|
5784
|
+
"mark",
|
|
5785
|
+
"menu",
|
|
5786
|
+
"meta",
|
|
5787
|
+
"meter",
|
|
5788
|
+
"nav",
|
|
5789
|
+
"noscript",
|
|
5790
|
+
"object",
|
|
5791
|
+
"ol",
|
|
5792
|
+
"optgroup",
|
|
5793
|
+
"option",
|
|
5794
|
+
"output",
|
|
5795
|
+
"p",
|
|
5796
|
+
"picture",
|
|
5797
|
+
"pre",
|
|
5798
|
+
"progress",
|
|
5799
|
+
"q",
|
|
5800
|
+
"rp",
|
|
5801
|
+
"rt",
|
|
5802
|
+
"ruby",
|
|
5803
|
+
"s",
|
|
5804
|
+
"samp",
|
|
5805
|
+
"script",
|
|
5806
|
+
"search",
|
|
5807
|
+
"section",
|
|
5808
|
+
"select",
|
|
5809
|
+
"slot",
|
|
5810
|
+
"small",
|
|
5811
|
+
"source",
|
|
5812
|
+
"span",
|
|
5813
|
+
"strong",
|
|
5814
|
+
"style",
|
|
5815
|
+
"sub",
|
|
5816
|
+
"summary",
|
|
5817
|
+
"sup",
|
|
5818
|
+
"table",
|
|
5819
|
+
"tbody",
|
|
5820
|
+
"td",
|
|
5821
|
+
"template",
|
|
5822
|
+
"textarea",
|
|
5823
|
+
"tfoot",
|
|
5824
|
+
"th",
|
|
5825
|
+
"thead",
|
|
5826
|
+
"time",
|
|
5827
|
+
"title",
|
|
5828
|
+
"tr",
|
|
5829
|
+
"track",
|
|
5830
|
+
"u",
|
|
5831
|
+
"ul",
|
|
5832
|
+
"var",
|
|
5833
|
+
"video",
|
|
5834
|
+
"wbr"
|
|
5835
|
+
];
|
|
5836
|
+
const svgTags = [
|
|
5837
|
+
"a",
|
|
5838
|
+
"animate",
|
|
5839
|
+
"animateMotion",
|
|
5840
|
+
"animateTransform",
|
|
5841
|
+
"circle",
|
|
5842
|
+
"clipPath",
|
|
5843
|
+
"defs",
|
|
5844
|
+
"desc",
|
|
5845
|
+
"discard",
|
|
5846
|
+
"ellipse",
|
|
5847
|
+
"feBlend",
|
|
5848
|
+
"feColorMatrix",
|
|
5849
|
+
"feComponentTransfer",
|
|
5850
|
+
"feComposite",
|
|
5851
|
+
"feConvolveMatrix",
|
|
5852
|
+
"feDiffuseLighting",
|
|
5853
|
+
"feDisplacementMap",
|
|
5854
|
+
"feDistantLight",
|
|
5855
|
+
"feDropShadow",
|
|
5856
|
+
"feFlood",
|
|
5857
|
+
"feFuncA",
|
|
5858
|
+
"feFuncB",
|
|
5859
|
+
"feFuncG",
|
|
5860
|
+
"feFuncR",
|
|
5861
|
+
"feGaussianBlur",
|
|
5862
|
+
"feImage",
|
|
5863
|
+
"feMerge",
|
|
5864
|
+
"feMergeNode",
|
|
5865
|
+
"feMorphology",
|
|
5866
|
+
"feOffset",
|
|
5867
|
+
"fePointLight",
|
|
5868
|
+
"feSpecularLighting",
|
|
5869
|
+
"feSpotLight",
|
|
5870
|
+
"feTile",
|
|
5871
|
+
"feTurbulence",
|
|
5872
|
+
"filter",
|
|
5873
|
+
"foreignObject",
|
|
5874
|
+
"g",
|
|
5875
|
+
"image",
|
|
5876
|
+
"line",
|
|
5877
|
+
"linearGradient",
|
|
5878
|
+
"marker",
|
|
5879
|
+
"mask",
|
|
5880
|
+
"metadata",
|
|
5881
|
+
"mpath",
|
|
5882
|
+
"path",
|
|
5883
|
+
"pattern",
|
|
5884
|
+
"polygon",
|
|
5885
|
+
"polyline",
|
|
5886
|
+
"radialGradient",
|
|
5887
|
+
"rect",
|
|
5888
|
+
"script",
|
|
5889
|
+
"set",
|
|
5890
|
+
"stop",
|
|
5891
|
+
"style",
|
|
5892
|
+
"svg",
|
|
5893
|
+
"switch",
|
|
5894
|
+
"symbol",
|
|
5895
|
+
"text",
|
|
5896
|
+
"textPath",
|
|
5897
|
+
"title",
|
|
5898
|
+
"tspan",
|
|
5899
|
+
"use",
|
|
5900
|
+
"view"
|
|
5901
|
+
];
|
|
5902
|
+
const nativeTags = /* @__PURE__ */ new Set([...htmlTags, ...svgTags]);
|
|
5903
|
+
//#endregion
|
|
5904
|
+
//#region src/compile/parse/utils/usesSlot.ts
|
|
5905
|
+
const slotRegex = /\$slot\b/;
|
|
5906
|
+
/**
|
|
5907
|
+
* Checks whether the $slot variable is read in the nodes' own scope
|
|
5908
|
+
*
|
|
5909
|
+
* Note that the children of a component node are excluded, because they are
|
|
5910
|
+
* passed to the component as fills, which get their own $slot parameter.
|
|
5911
|
+
* The component's attributes do belong to this scope.
|
|
5912
|
+
*
|
|
5913
|
+
* @param nodes The nodes to check
|
|
5914
|
+
*
|
|
5915
|
+
* @returns True if a $slot variable is read in the nodes' own scope
|
|
5916
|
+
*/
|
|
5917
|
+
function usesSlot(nodes) {
|
|
5918
|
+
for (let node of nodes) if (node.type === "text") {
|
|
5919
|
+
const text = node;
|
|
5920
|
+
if (slotRegex.test(text.content)) return true;
|
|
5921
|
+
} else if (node.type === "control") {
|
|
5922
|
+
const control = node;
|
|
5923
|
+
if (slotRegex.test(control.statement)) return true;
|
|
5924
|
+
if (usesSlot(control.children)) return true;
|
|
5925
|
+
} else if (node.type === "element" || node.type === "special" || node.type === "component") {
|
|
5926
|
+
const element = node;
|
|
5927
|
+
for (let attribute of element.attributes) {
|
|
5928
|
+
if (slotRegex.test(attribute.name)) return true;
|
|
5929
|
+
if (attribute.value && slotRegex.test(attribute.value)) return true;
|
|
5930
|
+
}
|
|
5931
|
+
if (element.type !== "component" && usesSlot(element.children)) return true;
|
|
5932
|
+
}
|
|
5933
|
+
return false;
|
|
5934
|
+
}
|
|
5935
|
+
//#endregion
|
|
5936
|
+
//#region src/compile/parse/slottifyChildNodes.ts
|
|
5937
|
+
/**
|
|
5938
|
+
* Moves any child nodes that aren't already in a <fill> node into a default
|
|
5939
|
+
* <fill> node
|
|
5940
|
+
*/
|
|
5941
|
+
function slottifyChildNodes(node) {
|
|
5942
|
+
let nonFillNodes = [];
|
|
5943
|
+
for (let child of node.children) if (isFillNode(child)) {
|
|
5944
|
+
if (nonFillNodes.find((n) => !isSpaceNode(n)) === void 0) nonFillNodes = [];
|
|
5945
|
+
else break;
|
|
5946
|
+
} else nonFillNodes.push(child);
|
|
5947
|
+
if (nonFillNodes.find((n) => !isSpaceNode(n)) === void 0) nonFillNodes = [];
|
|
5948
|
+
if (nonFillNodes.length) {
|
|
5949
|
+
let defaultFillNode = node.children.find((n) => isFillNode(n) && !n.attributes.find((a) => a.name === "name"));
|
|
5950
|
+
if (!defaultFillNode) {
|
|
5951
|
+
defaultFillNode = {
|
|
5952
|
+
type: "special",
|
|
5953
|
+
tagName: "filldef",
|
|
5954
|
+
attributes: [],
|
|
5955
|
+
children: nonFillNodes,
|
|
5956
|
+
span: {
|
|
5957
|
+
start: 0,
|
|
5958
|
+
end: 0
|
|
5959
|
+
},
|
|
5960
|
+
hasSlotProps: usesSlot(nonFillNodes)
|
|
5961
|
+
};
|
|
5962
|
+
node.children.unshift(defaultFillNode);
|
|
5963
|
+
}
|
|
5964
|
+
node.children = node.children.filter((c) => isFillNode(c) || !nonFillNodes.includes(c));
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
function isFillNode(n) {
|
|
5968
|
+
return isSpecialNode(n) && (n.tagName === "fill" || n.tagName === "filldef");
|
|
5969
|
+
}
|
|
5970
|
+
//#endregion
|
|
5971
|
+
//#region src/compile/parse/utils/addError.ts
|
|
5972
|
+
/**
|
|
5973
|
+
* Adds an error to the parse status
|
|
5974
|
+
*
|
|
5975
|
+
* @param status The parse status
|
|
5976
|
+
* @param message The error message to add
|
|
5977
|
+
* @param start (Optional) The start position of the error (defaults to the
|
|
5978
|
+
* current parse position)
|
|
5979
|
+
*/
|
|
5980
|
+
function addError(status, message, start = status.i, end = status.i) {
|
|
5981
|
+
let startLine = 0;
|
|
5982
|
+
let lastLineStart = 0;
|
|
5983
|
+
let i = 0;
|
|
5984
|
+
for (; i < start; i++) if (status.source[i] === "\n") {
|
|
5985
|
+
startLine += 1;
|
|
5986
|
+
lastLineStart = i + 1;
|
|
5987
|
+
}
|
|
5988
|
+
let startChar = start - lastLineStart;
|
|
5989
|
+
let endLine = startLine;
|
|
5990
|
+
for (; i < end; i++) if (status.source[i] === "\n") {
|
|
5991
|
+
endLine += 1;
|
|
5992
|
+
lastLineStart = i + 1;
|
|
5993
|
+
}
|
|
5994
|
+
let endChar = end - lastLineStart;
|
|
5995
|
+
status.errors.push({
|
|
5996
|
+
message,
|
|
5997
|
+
startIndex: start,
|
|
5998
|
+
startLine,
|
|
5999
|
+
startChar,
|
|
6000
|
+
endIndex: end,
|
|
6001
|
+
endLine,
|
|
6002
|
+
endChar
|
|
6003
|
+
});
|
|
6004
|
+
}
|
|
6005
|
+
//#endregion
|
|
6006
|
+
//#region src/compile/parse/classifyComponents.ts
|
|
6007
|
+
/**
|
|
6008
|
+
* Classifies parsed tags as components or native elements once the whole file
|
|
6009
|
+
* has been parsed (so forward-declared local components are known).
|
|
6010
|
+
*
|
|
6011
|
+
* A tag is a component when its name is imported or is a component declared in
|
|
6012
|
+
* this file. Native and custom elements (`<div>`, `<my-widget>`,
|
|
6013
|
+
* `<linearGradient>`) stay elements. Any other capitalized tag is reported as
|
|
6014
|
+
* unknown instead of silently becoming a component call, unless the caller
|
|
6015
|
+
* opts into assuming external components (`allowUnknownComponents`).
|
|
6016
|
+
*/
|
|
6017
|
+
function classifyComponents(status, importedNames, options) {
|
|
6018
|
+
const localNames = new Set(status.components.map((component) => component.name).filter((name) => !!name));
|
|
6019
|
+
for (const component of status.components) {
|
|
6020
|
+
if (component.markup) classifyNode(component.markup, status, importedNames, localNames, options);
|
|
6021
|
+
if (component.error) classifyNode(component.error, status, importedNames, localNames, options);
|
|
6022
|
+
if (component.head) classifyNode(component.head, status, importedNames, localNames, options);
|
|
6023
|
+
}
|
|
6024
|
+
}
|
|
6025
|
+
function classifyNode(node, status, importedNames, localNames, options) {
|
|
6026
|
+
if (isParentNode(node)) for (const child of node.children) classifyNode(child, status, importedNames, localNames, options);
|
|
6027
|
+
if (!isElementNode(node)) return;
|
|
6028
|
+
const tagName = node.tagName;
|
|
6029
|
+
if (importedNames.has(tagName) || localNames.has(tagName)) {
|
|
6030
|
+
node.type = "component";
|
|
6031
|
+
slottifyChildNodes(node);
|
|
6032
|
+
} else if (!nativeTags.has(tagName) && !tagName.includes("-") && /^[A-Z]/.test(tagName)) {
|
|
6033
|
+
if (options?.allowUnknownComponents) {
|
|
6034
|
+
node.type = "component";
|
|
6035
|
+
slottifyChildNodes(node);
|
|
6036
|
+
} else addError(status, `Unknown component or element: ${tagName}. Import it or define it in this file.`, node.span.start, node.span.end);
|
|
6037
|
+
}
|
|
6038
|
+
}
|
|
6039
|
+
//#endregion
|
|
6040
|
+
//#region src/compile/parse/collectImportNames.ts
|
|
6041
|
+
/**
|
|
6042
|
+
* Collects the local binding names introduced by top-level import statements.
|
|
6043
|
+
* Used to tell component tags apart from native elements without touching the
|
|
6044
|
+
* filesystem or relying on a tag-name convention.
|
|
6045
|
+
*
|
|
6046
|
+
* This is a focused import scanner, not a general JS parser: it handles the
|
|
6047
|
+
* import forms (`default`, `* as`, named/aliased, side-effect), comments and
|
|
6048
|
+
* multiline clauses. Type-only imports are ignored (they don't introduce a
|
|
6049
|
+
* value that can be rendered as a tag).
|
|
6050
|
+
*/
|
|
6051
|
+
function collectImportNames(source) {
|
|
6052
|
+
const names = /* @__PURE__ */ new Set();
|
|
6053
|
+
let depth = 0;
|
|
6054
|
+
let i = 0;
|
|
6055
|
+
while (i < source.length) {
|
|
6056
|
+
const skipped = skipStringOrComment(source, i);
|
|
6057
|
+
if (skipped !== -1) {
|
|
6058
|
+
i = skipped;
|
|
6059
|
+
continue;
|
|
6060
|
+
}
|
|
6061
|
+
const char = source[i];
|
|
6062
|
+
if (char === "{") {
|
|
6063
|
+
depth += 1;
|
|
6064
|
+
i += 1;
|
|
6065
|
+
continue;
|
|
6066
|
+
}
|
|
6067
|
+
if (char === "}") {
|
|
6068
|
+
depth -= 1;
|
|
6069
|
+
i += 1;
|
|
6070
|
+
continue;
|
|
6071
|
+
}
|
|
6072
|
+
if (depth === 0 && char === "i" && startsWordAt(source, i, "import") && source[i - 1] !== ".") {
|
|
6073
|
+
const end = parseImport(source, i + 6, names);
|
|
6074
|
+
if (end !== -1) {
|
|
6075
|
+
i = end;
|
|
6076
|
+
continue;
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
i += 1;
|
|
6080
|
+
}
|
|
6081
|
+
return names;
|
|
6082
|
+
}
|
|
6083
|
+
/** Parses one import statement, adding its value bindings. Returns the end index. */
|
|
6084
|
+
function parseImport(source, start, names) {
|
|
6085
|
+
let i = skipSpaceAndComments(source, start);
|
|
6086
|
+
if (i >= source.length) return -1;
|
|
6087
|
+
if (source[i] === "." || source[i] === "(") return -1;
|
|
6088
|
+
if (source[i] === "\"" || source[i] === "'") return skipStringAndStatementEnd(source, i);
|
|
6089
|
+
let typeOnly = false;
|
|
6090
|
+
if (startsWordAt(source, i, "type")) {
|
|
6091
|
+
const afterType = skipSpaceAndComments(source, i + 4);
|
|
6092
|
+
const next = source[afterType];
|
|
6093
|
+
if (next === "{" || next === "*" || isIdentifierStart(next)) {
|
|
6094
|
+
if (next === "{" || next === "*" || isTypeOnlyDefault(source, afterType)) {
|
|
6095
|
+
typeOnly = true;
|
|
6096
|
+
i = afterType;
|
|
6097
|
+
}
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
while (i < source.length) {
|
|
6101
|
+
i = skipSpaceAndComments(source, i);
|
|
6102
|
+
if (i >= source.length) return -1;
|
|
6103
|
+
if (startsWordAt(source, i, "from")) {
|
|
6104
|
+
i = skipStringAndStatementEnd(source, skipSpaceAndComments(source, i + 4));
|
|
6105
|
+
return i;
|
|
6106
|
+
}
|
|
6107
|
+
const char = source[i];
|
|
6108
|
+
if (char === "{") {
|
|
6109
|
+
i += 1;
|
|
6110
|
+
while (i < source.length) {
|
|
6111
|
+
i = skipSpaceAndComments(source, i);
|
|
6112
|
+
if (source[i] === "}") {
|
|
6113
|
+
i += 1;
|
|
6114
|
+
break;
|
|
6115
|
+
}
|
|
6116
|
+
const specifier = parseSpecifier(source, i);
|
|
6117
|
+
if (!specifier) {
|
|
6118
|
+
i += 1;
|
|
6119
|
+
continue;
|
|
6120
|
+
}
|
|
6121
|
+
i = specifier.end;
|
|
6122
|
+
if (!typeOnly && specifier.name) names.add(specifier.name);
|
|
6123
|
+
}
|
|
6124
|
+
continue;
|
|
6125
|
+
}
|
|
6126
|
+
if (char === "*") {
|
|
6127
|
+
i = skipSpaceAndComments(source, i + 1);
|
|
6128
|
+
if (startsWordAt(source, i, "as")) {
|
|
6129
|
+
i = skipSpaceAndComments(source, i + 2);
|
|
6130
|
+
const identifier = readIdentifier(source, i);
|
|
6131
|
+
if (identifier) {
|
|
6132
|
+
if (!typeOnly) names.add(identifier.name);
|
|
6133
|
+
i = identifier.end;
|
|
6134
|
+
}
|
|
6135
|
+
}
|
|
6136
|
+
continue;
|
|
6137
|
+
}
|
|
6138
|
+
if (char === ",") {
|
|
6139
|
+
i += 1;
|
|
6140
|
+
continue;
|
|
6141
|
+
}
|
|
6142
|
+
if (isIdentifierStart(char)) {
|
|
6143
|
+
const identifier = readIdentifier(source, i);
|
|
6144
|
+
if (identifier) {
|
|
6145
|
+
if (!typeOnly) names.add(identifier.name);
|
|
6146
|
+
i = identifier.end;
|
|
6147
|
+
continue;
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
i += 1;
|
|
6151
|
+
}
|
|
6152
|
+
return -1;
|
|
6153
|
+
}
|
|
6154
|
+
function parseSpecifier(source, start) {
|
|
6155
|
+
let i = skipSpaceAndComments(source, start);
|
|
6156
|
+
if (i >= source.length) return void 0;
|
|
6157
|
+
let typeOnly = false;
|
|
6158
|
+
if (startsWordAt(source, i, "type")) {
|
|
6159
|
+
const afterType = skipSpaceAndComments(source, i + 4);
|
|
6160
|
+
const next = source[afterType];
|
|
6161
|
+
if (next && next !== "," && next !== "}" && !startsWordAt(source, afterType, "as")) {
|
|
6162
|
+
typeOnly = true;
|
|
6163
|
+
i = afterType;
|
|
6164
|
+
}
|
|
6165
|
+
}
|
|
6166
|
+
let name;
|
|
6167
|
+
if (source[i] === "\"" || source[i] === "'") {
|
|
6168
|
+
const end = skipStringOrComment(source, i);
|
|
6169
|
+
i = end === -1 ? i + 1 : end;
|
|
6170
|
+
} else {
|
|
6171
|
+
const identifier = readIdentifier(source, i);
|
|
6172
|
+
if (!identifier) return void 0;
|
|
6173
|
+
name = identifier.name;
|
|
6174
|
+
i = identifier.end;
|
|
6175
|
+
}
|
|
6176
|
+
i = skipSpaceAndComments(source, i);
|
|
6177
|
+
if (startsWordAt(source, i, "as")) {
|
|
6178
|
+
i = skipSpaceAndComments(source, i + 2);
|
|
6179
|
+
if (source[i] === "\"" || source[i] === "'") {
|
|
6180
|
+
const end = skipStringOrComment(source, i);
|
|
6181
|
+
i = end === -1 ? i + 1 : end;
|
|
6182
|
+
name = void 0;
|
|
6183
|
+
} else {
|
|
6184
|
+
const alias = readIdentifier(source, i);
|
|
6185
|
+
if (alias) {
|
|
6186
|
+
name = alias.name;
|
|
6187
|
+
i = alias.end;
|
|
6188
|
+
}
|
|
6189
|
+
}
|
|
6190
|
+
}
|
|
6191
|
+
i = skipSpaceAndComments(source, i);
|
|
6192
|
+
if (source[i] === ",") i += 1;
|
|
6193
|
+
return {
|
|
6194
|
+
name: typeOnly ? void 0 : name,
|
|
6195
|
+
end: i
|
|
6196
|
+
};
|
|
6197
|
+
}
|
|
6198
|
+
function isTypeOnlyDefault(source, start) {
|
|
6199
|
+
const identifier = readIdentifier(source, start);
|
|
6200
|
+
if (!identifier) return false;
|
|
6201
|
+
return startsWordAt(source, skipSpaceAndComments(source, identifier.end), "from");
|
|
6202
|
+
}
|
|
6203
|
+
function skipStringAndStatementEnd(source, start) {
|
|
6204
|
+
let i = start;
|
|
6205
|
+
if (source[i] === "\"" || source[i] === "'") {
|
|
6206
|
+
const end = skipStringOrComment(source, i);
|
|
6207
|
+
i = end === -1 ? i + 1 : end;
|
|
6208
|
+
}
|
|
6209
|
+
i = skipSpaceAndComments(source, i);
|
|
6210
|
+
if (source[i] === ";") i += 1;
|
|
6211
|
+
return i;
|
|
6212
|
+
}
|
|
6213
|
+
function skipSpaceAndComments(source, start) {
|
|
6214
|
+
let i = start;
|
|
6215
|
+
while (i < source.length) {
|
|
6216
|
+
if (/\s/.test(source[i])) {
|
|
6217
|
+
i += 1;
|
|
6218
|
+
continue;
|
|
6219
|
+
}
|
|
6220
|
+
if (source[i] === "/" && (source[i + 1] === "/" || source[i + 1] === "*")) {
|
|
6221
|
+
const skipped = skipStringOrComment(source, i);
|
|
6222
|
+
if (skipped !== -1) {
|
|
6223
|
+
i = skipped;
|
|
6224
|
+
continue;
|
|
6225
|
+
}
|
|
6226
|
+
}
|
|
6227
|
+
break;
|
|
6228
|
+
}
|
|
6229
|
+
return i;
|
|
6230
|
+
}
|
|
6231
|
+
function readIdentifier(source, start) {
|
|
6232
|
+
if (!isIdentifierStart(source[start])) return void 0;
|
|
6233
|
+
let end = start + 1;
|
|
6234
|
+
while (end < source.length && isIdentifierPart(source[end])) end += 1;
|
|
6235
|
+
return {
|
|
6236
|
+
name: source.substring(start, end),
|
|
6237
|
+
end
|
|
6238
|
+
};
|
|
6239
|
+
}
|
|
6240
|
+
function isIdentifierStart(char) {
|
|
6241
|
+
return char !== void 0 && /[A-Za-z_$]/.test(char);
|
|
6242
|
+
}
|
|
6243
|
+
function isIdentifierPart(char) {
|
|
6244
|
+
return /[A-Za-z0-9_$]/.test(char);
|
|
6245
|
+
}
|
|
6246
|
+
function startsWordAt(source, start, word) {
|
|
6247
|
+
if (!source.startsWith(word, start)) return false;
|
|
6248
|
+
const previous = source[start - 1];
|
|
6249
|
+
const next = source[start + word.length];
|
|
6250
|
+
return (previous === void 0 || !isIdentifierPart(previous)) && (next === void 0 || !isIdentifierPart(next));
|
|
6251
|
+
}
|
|
6252
|
+
//#endregion
|
|
6253
|
+
//#region src/compile/parse/utils/accept.ts
|
|
6254
|
+
/**
|
|
6255
|
+
* Checks whether the source at the current parse position matches the supplied
|
|
6256
|
+
* string
|
|
6257
|
+
*
|
|
6258
|
+
* @param value The string to check
|
|
6259
|
+
* @param status The parse status
|
|
6260
|
+
* @param advance (Optional) If true, advances the parse position past the
|
|
6261
|
+
* checked string (defaults to true)
|
|
6262
|
+
*
|
|
6263
|
+
* @returns True if the supplied string was found at the current parse position
|
|
6264
|
+
*/
|
|
6265
|
+
function accept(value, status, advance = true) {
|
|
6266
|
+
if (status.source.substring(status.i, status.i + value.length) == value) {
|
|
6267
|
+
status.i += advance ? value.length : 0;
|
|
6268
|
+
return true;
|
|
6269
|
+
}
|
|
6270
|
+
return false;
|
|
6271
|
+
}
|
|
6272
|
+
//#endregion
|
|
6273
|
+
//#region src/compile/parse/parseInlineScript.ts
|
|
6274
|
+
function parseInlineScript(status) {
|
|
6275
|
+
const start = status.i;
|
|
6276
|
+
let braceCount = 0;
|
|
6277
|
+
while (status.i < status.source.length) {
|
|
6278
|
+
const skipped = skipStringOrComment(status.source, status.i);
|
|
6279
|
+
if (skipped !== -1) {
|
|
6280
|
+
status.i = skipped;
|
|
6281
|
+
continue;
|
|
5343
6282
|
}
|
|
5344
6283
|
if (accept("{", status)) braceCount += 1;
|
|
5345
6284
|
else if (accept("}", status)) {
|
|
@@ -5400,79 +6339,36 @@ function addSpaceElement(parent, status) {
|
|
|
5400
6339
|
//#endregion
|
|
5401
6340
|
//#region src/compile/utils/isFullyReactive.ts
|
|
5402
6341
|
/**
|
|
5403
|
-
* Checks whether the supplied
|
|
6342
|
+
* Checks whether the supplied text is exactly one `{...}` interpolation,
|
|
6343
|
+
* ignoring surrounding whitespace. Braces inside the expression's strings and
|
|
6344
|
+
* comments don't count as delimiters.
|
|
5404
6345
|
*
|
|
5405
|
-
* @param text The
|
|
6346
|
+
* @param text The text to check
|
|
5406
6347
|
*
|
|
5407
|
-
* @returns True if the supplied
|
|
6348
|
+
* @returns True if the supplied text is fully reactive
|
|
5408
6349
|
*/
|
|
5409
6350
|
function isFullyReactive(text) {
|
|
5410
|
-
return
|
|
5411
|
-
}
|
|
5412
|
-
//#endregion
|
|
5413
|
-
//#region src/compile/parse/utils/addError.ts
|
|
5414
|
-
/**
|
|
5415
|
-
* Adds an error to the parse status
|
|
5416
|
-
*
|
|
5417
|
-
* @param status The parse status
|
|
5418
|
-
* @param message The error message to add
|
|
5419
|
-
* @param start (Optional) The start position of the error (defaults to the
|
|
5420
|
-
* current parse position)
|
|
5421
|
-
*/
|
|
5422
|
-
function addError(status, message, start = status.i, end = status.i) {
|
|
5423
|
-
let startLine = 0;
|
|
5424
|
-
let lastLineStart = 0;
|
|
5425
|
-
let i = 0;
|
|
5426
|
-
for (; i < start; i++) if (status.source[i] === "\n") {
|
|
5427
|
-
startLine += 1;
|
|
5428
|
-
lastLineStart = i + 1;
|
|
5429
|
-
}
|
|
5430
|
-
let startChar = start - lastLineStart;
|
|
5431
|
-
let endLine = startLine;
|
|
5432
|
-
for (; i < end; i++) if (status.source[i] === "\n") {
|
|
5433
|
-
endLine += 1;
|
|
5434
|
-
lastLineStart = i + 1;
|
|
5435
|
-
}
|
|
5436
|
-
let endChar = end - lastLineStart;
|
|
5437
|
-
status.errors.push({
|
|
5438
|
-
message,
|
|
5439
|
-
startIndex: start,
|
|
5440
|
-
startLine,
|
|
5441
|
-
startChar,
|
|
5442
|
-
endIndex: end,
|
|
5443
|
-
endLine,
|
|
5444
|
-
endChar
|
|
5445
|
-
});
|
|
5446
|
-
}
|
|
5447
|
-
//#endregion
|
|
5448
|
-
//#region src/compile/parse/utils/isAlphaNumericChar.ts
|
|
5449
|
-
/**
|
|
5450
|
-
* Checks whether the supplied character is a alpha-numeric
|
|
5451
|
-
*
|
|
5452
|
-
* @param text The string to check
|
|
5453
|
-
* @param index The index of the character in the string
|
|
5454
|
-
*
|
|
5455
|
-
* @returns True if the supplied character is alpha-numeric
|
|
5456
|
-
*/
|
|
5457
|
-
function isAlphaNumericChar(text, index) {
|
|
5458
|
-
let code = text.charCodeAt(index);
|
|
5459
|
-
return code > 47 && code < 58 || code > 64 && code < 91 || code > 96 && code < 123;
|
|
6351
|
+
return isSingleInterpolation(text);
|
|
5460
6352
|
}
|
|
5461
6353
|
//#endregion
|
|
5462
|
-
//#region src/compile/parse/utils/
|
|
6354
|
+
//#region src/compile/parse/utils/consumeTagName.ts
|
|
5463
6355
|
/**
|
|
5464
|
-
* Consumes
|
|
5465
|
-
*
|
|
6356
|
+
* Consumes a tag name, allowing letters, digits and dashes (custom elements
|
|
6357
|
+
* such as `<my-widget>`), and advances the current parse position to before
|
|
6358
|
+
* the next non-name character.
|
|
5466
6359
|
*
|
|
5467
6360
|
* @param status The parse status
|
|
5468
6361
|
*
|
|
5469
|
-
* @returns The
|
|
5470
|
-
*
|
|
6362
|
+
* @returns The tag name from the current parse position to the next non-name
|
|
6363
|
+
* character
|
|
5471
6364
|
*/
|
|
5472
|
-
function
|
|
6365
|
+
function consumeTagName(status) {
|
|
5473
6366
|
const start = status.i;
|
|
5474
|
-
for (status.i; status.i < status.source.length; status.i++)
|
|
5475
|
-
|
|
6367
|
+
for (status.i; status.i < status.source.length; status.i++) {
|
|
6368
|
+
const char = status.source[status.i];
|
|
6369
|
+
if (!/[A-Za-z0-9-]/.test(char)) return status.source.substring(start, status.i);
|
|
6370
|
+
}
|
|
6371
|
+
return status.source.substring(start, status.i);
|
|
5476
6372
|
}
|
|
5477
6373
|
//#endregion
|
|
5478
6374
|
//#region src/compile/parse/utils/consumeUntil.ts
|
|
@@ -5499,7 +6395,7 @@ function parseTag(status) {
|
|
|
5499
6395
|
consumeSpace(status);
|
|
5500
6396
|
let tagStart = status.i + 1;
|
|
5501
6397
|
let snailed = accept("@", status);
|
|
5502
|
-
let tagName =
|
|
6398
|
+
let tagName = consumeTagName(status);
|
|
5503
6399
|
let tagEnd = status.i;
|
|
5504
6400
|
if (snailed) tagName = "@" + tagName;
|
|
5505
6401
|
if (closeTag) tagName = "/" + tagName;
|
|
@@ -5554,14 +6450,20 @@ function parseAttribute(status) {
|
|
|
5554
6450
|
if (accept("=", status)) {
|
|
5555
6451
|
consumeSpace(status);
|
|
5556
6452
|
valueStart = status.i;
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
value =
|
|
5563
|
-
|
|
5564
|
-
|
|
6453
|
+
if (status.source[valueStart] === "`") {
|
|
6454
|
+
value = parseTemplateLiteral(status);
|
|
6455
|
+
valueEnd = status.i;
|
|
6456
|
+
reactive = fullyReactive = true;
|
|
6457
|
+
} else {
|
|
6458
|
+
value = parseAttributeValue(status);
|
|
6459
|
+
valueEnd = status.i;
|
|
6460
|
+
fullyReactive = isFullyReactive(value);
|
|
6461
|
+
reactive = fullyReactive;
|
|
6462
|
+
if (fullyReactive) {
|
|
6463
|
+
value = value.substring(1, value.length - 1);
|
|
6464
|
+
valueStart++;
|
|
6465
|
+
valueEnd--;
|
|
6466
|
+
}
|
|
5565
6467
|
}
|
|
5566
6468
|
} else if (name.startsWith("{") && name.endsWith("}")) {
|
|
5567
6469
|
value = name.substring(1, name.length - 1);
|
|
@@ -5584,6 +6486,18 @@ function parseAttribute(status) {
|
|
|
5584
6486
|
}
|
|
5585
6487
|
};
|
|
5586
6488
|
}
|
|
6489
|
+
/**
|
|
6490
|
+
* Consumes a backtick-delimited JavaScript template literal, reusing the
|
|
6491
|
+
* script scanner so `${...}` interpolations and nested strings/templates are
|
|
6492
|
+
* skipped correctly.
|
|
6493
|
+
*/
|
|
6494
|
+
function parseTemplateLiteral(status) {
|
|
6495
|
+
const start = status.i;
|
|
6496
|
+
const end = skipStringOrComment(status.source, start);
|
|
6497
|
+
status.i = end === -1 ? start + 1 : end;
|
|
6498
|
+
if (status.source[status.i - 1] !== "`") addError(status, "Unclosed template literal in attribute", start, status.i);
|
|
6499
|
+
return status.source.substring(start, status.i);
|
|
6500
|
+
}
|
|
5587
6501
|
function parseAttributeValue(status) {
|
|
5588
6502
|
if (accept("\"", status)) {
|
|
5589
6503
|
const value = consumeUntil("\"", status);
|
|
@@ -5664,73 +6578,6 @@ function parseText(status, element) {
|
|
|
5664
6578
|
} else status.i += 1;
|
|
5665
6579
|
}
|
|
5666
6580
|
//#endregion
|
|
5667
|
-
//#region src/compile/parse/utils/usesSlot.ts
|
|
5668
|
-
const slotRegex = /\$slot\b/;
|
|
5669
|
-
/**
|
|
5670
|
-
* Checks whether the $slot variable is read in the nodes' own scope
|
|
5671
|
-
*
|
|
5672
|
-
* Note that the children of a component node are excluded, because they are
|
|
5673
|
-
* passed to the component as fills, which get their own $slot parameter.
|
|
5674
|
-
* The component's attributes do belong to this scope.
|
|
5675
|
-
*
|
|
5676
|
-
* @param nodes The nodes to check
|
|
5677
|
-
*
|
|
5678
|
-
* @returns True if a $slot variable is read in the nodes' own scope
|
|
5679
|
-
*/
|
|
5680
|
-
function usesSlot(nodes) {
|
|
5681
|
-
for (let node of nodes) if (node.type === "text") {
|
|
5682
|
-
const text = node;
|
|
5683
|
-
if (slotRegex.test(text.content)) return true;
|
|
5684
|
-
} else if (node.type === "control") {
|
|
5685
|
-
const control = node;
|
|
5686
|
-
if (slotRegex.test(control.statement)) return true;
|
|
5687
|
-
if (usesSlot(control.children)) return true;
|
|
5688
|
-
} else if (node.type === "element" || node.type === "special" || node.type === "component") {
|
|
5689
|
-
const element = node;
|
|
5690
|
-
for (let attribute of element.attributes) {
|
|
5691
|
-
if (slotRegex.test(attribute.name)) return true;
|
|
5692
|
-
if (attribute.value && slotRegex.test(attribute.value)) return true;
|
|
5693
|
-
}
|
|
5694
|
-
if (element.type !== "component" && usesSlot(element.children)) return true;
|
|
5695
|
-
}
|
|
5696
|
-
return false;
|
|
5697
|
-
}
|
|
5698
|
-
//#endregion
|
|
5699
|
-
//#region src/compile/parse/slottifyChildNodes.ts
|
|
5700
|
-
/**
|
|
5701
|
-
* Moves any child nodes that aren't already in a <fill> node into a default
|
|
5702
|
-
* <fill> node
|
|
5703
|
-
*/
|
|
5704
|
-
function slottifyChildNodes(node) {
|
|
5705
|
-
let nonFillNodes = [];
|
|
5706
|
-
for (let child of node.children) if (isFillNode(child)) {
|
|
5707
|
-
if (nonFillNodes.find((n) => !isSpaceNode(n)) === void 0) nonFillNodes = [];
|
|
5708
|
-
else break;
|
|
5709
|
-
} else nonFillNodes.push(child);
|
|
5710
|
-
if (nonFillNodes.find((n) => !isSpaceNode(n)) === void 0) nonFillNodes = [];
|
|
5711
|
-
if (nonFillNodes.length) {
|
|
5712
|
-
let defaultFillNode = node.children.find((n) => isFillNode(n) && !n.attributes.find((a) => a.name === "name"));
|
|
5713
|
-
if (!defaultFillNode) {
|
|
5714
|
-
defaultFillNode = {
|
|
5715
|
-
type: "special",
|
|
5716
|
-
tagName: "filldef",
|
|
5717
|
-
attributes: [],
|
|
5718
|
-
children: nonFillNodes,
|
|
5719
|
-
span: {
|
|
5720
|
-
start: 0,
|
|
5721
|
-
end: 0
|
|
5722
|
-
},
|
|
5723
|
-
hasSlotProps: usesSlot(nonFillNodes)
|
|
5724
|
-
};
|
|
5725
|
-
node.children.unshift(defaultFillNode);
|
|
5726
|
-
}
|
|
5727
|
-
node.children = node.children.filter((c) => isFillNode(c) || !nonFillNodes.includes(c));
|
|
5728
|
-
}
|
|
5729
|
-
}
|
|
5730
|
-
function isFillNode(n) {
|
|
5731
|
-
return isSpecialNode(n) && (n.tagName === "fill" || n.tagName === "filldef");
|
|
5732
|
-
}
|
|
5733
|
-
//#endregion
|
|
5734
6581
|
//#region src/compile/parse/parseElement.ts
|
|
5735
6582
|
function parseElement(status) {
|
|
5736
6583
|
const current = status.components.at(-1);
|
|
@@ -5744,6 +6591,7 @@ function parseElement(status) {
|
|
|
5744
6591
|
if (voidTags.includes(element.tagName)) checkVoidElement(status, element);
|
|
5745
6592
|
if (!element.selfClosed && !voidTags.includes(element.tagName)) {
|
|
5746
6593
|
status.stack.push(element);
|
|
6594
|
+
if (isRawTextTag(element.tagName)) parseRawText(status, element);
|
|
5747
6595
|
while (status.i < status.source.length) {
|
|
5748
6596
|
addSpaceElement(element, status);
|
|
5749
6597
|
if (accept("}", status, false)) break;
|
|
@@ -5784,10 +6632,6 @@ function parseElement(status) {
|
|
|
5784
6632
|
}
|
|
5785
6633
|
status.stack.pop();
|
|
5786
6634
|
}
|
|
5787
|
-
if (/[A-Z]/.test(element.tagName[0])) {
|
|
5788
|
-
element.type = "component";
|
|
5789
|
-
slottifyChildNodes(element);
|
|
5790
|
-
}
|
|
5791
6635
|
if (isSpecialNode(element)) {
|
|
5792
6636
|
if (element.tagName === "slot") {
|
|
5793
6637
|
slottifyChildNodes(element);
|
|
@@ -5825,6 +6669,32 @@ function parseElement(status) {
|
|
|
5825
6669
|
if (!element.closed && !voidTags.includes(element.tagName)) addError(status, `Unclosed non-void element: ${element.tagName}`, start, start + element.tagName.length + 1);
|
|
5826
6670
|
return element;
|
|
5827
6671
|
}
|
|
6672
|
+
/**
|
|
6673
|
+
* Consumes a raw-text element's content as a single literal text node. The
|
|
6674
|
+
* content ends at the first matching close tag (which the caller's child loop
|
|
6675
|
+
* then handles), or at the end of the source when the element is unclosed.
|
|
6676
|
+
*/
|
|
6677
|
+
function parseRawText(status, element) {
|
|
6678
|
+
const start = status.i;
|
|
6679
|
+
const end = findRawTextEnd(status.source, element.tagName, start);
|
|
6680
|
+
if (end > start) {
|
|
6681
|
+
const text = {
|
|
6682
|
+
type: "text",
|
|
6683
|
+
content: status.source.substring(start, end),
|
|
6684
|
+
start,
|
|
6685
|
+
spans: [],
|
|
6686
|
+
raw: true
|
|
6687
|
+
};
|
|
6688
|
+
element.children.push(text);
|
|
6689
|
+
}
|
|
6690
|
+
status.i = end;
|
|
6691
|
+
}
|
|
6692
|
+
function findRawTextEnd(source, tagName, start) {
|
|
6693
|
+
const pattern = new RegExp(`</${tagName}(?=[\\s/>])`, "gi");
|
|
6694
|
+
pattern.lastIndex = start;
|
|
6695
|
+
const match = pattern.exec(source);
|
|
6696
|
+
return match ? match.index : source.length;
|
|
6697
|
+
}
|
|
5828
6698
|
function checkVoidElement(status, element) {
|
|
5829
6699
|
let i = status.i;
|
|
5830
6700
|
consumeSpace(status);
|
|
@@ -5844,7 +6714,7 @@ function checkCloseTag(status, element) {
|
|
|
5844
6714
|
accept("</", status);
|
|
5845
6715
|
consumeSpace(status);
|
|
5846
6716
|
let snailed = accept("@", status);
|
|
5847
|
-
let closingTagName =
|
|
6717
|
+
let closingTagName = consumeTagName(status);
|
|
5848
6718
|
if (snailed) closingTagName = "@" + closingTagName;
|
|
5849
6719
|
consumeSpace(status);
|
|
5850
6720
|
accept(">", status);
|
|
@@ -5954,6 +6824,8 @@ function parseControlOpen(status) {
|
|
|
5954
6824
|
};
|
|
5955
6825
|
}
|
|
5956
6826
|
function parseControlStatement(start, operation, status) {
|
|
6827
|
+
const standalone = standaloneOperations.includes(operation);
|
|
6828
|
+
const braceStartsBody = !standalone || operation === "@function" || operation === "@async function";
|
|
5957
6829
|
let parenCount = 0;
|
|
5958
6830
|
while (status.i < status.source.length) {
|
|
5959
6831
|
const skipped = skipStringOrComment(status.source, status.i);
|
|
@@ -5963,11 +6835,11 @@ function parseControlStatement(start, operation, status) {
|
|
|
5963
6835
|
}
|
|
5964
6836
|
if (accept("(", status)) parenCount += 1;
|
|
5965
6837
|
else if (accept(")", status)) parenCount -= 1;
|
|
5966
|
-
else if (accept("{", status) || accept("\n", status) &&
|
|
6838
|
+
else if (accept("{", status) && braceStartsBody || accept("\n", status) && standalone) {
|
|
5967
6839
|
if (parenCount === 0) return trimStart(status.source.substring(start, status.i - 1).trim(), "@");
|
|
5968
6840
|
} else status.i += 1;
|
|
5969
6841
|
}
|
|
5970
|
-
return "";
|
|
6842
|
+
return trimStart(status.source.substring(start, status.i).trim(), "@");
|
|
5971
6843
|
}
|
|
5972
6844
|
/**
|
|
5973
6845
|
* Groups the control node into the correct parent e.g. if/else into an if group
|
|
@@ -6220,7 +7092,6 @@ function parseStyles(source, status) {
|
|
|
6220
7092
|
marker: 0,
|
|
6221
7093
|
level: 0,
|
|
6222
7094
|
braces: [],
|
|
6223
|
-
imports: [],
|
|
6224
7095
|
script: [],
|
|
6225
7096
|
components: [],
|
|
6226
7097
|
stack: [],
|
|
@@ -6299,37 +7170,64 @@ function parseStyleAttribute(status) {
|
|
|
6299
7170
|
}
|
|
6300
7171
|
//#endregion
|
|
6301
7172
|
//#region src/compile/parse/scopeStyles.ts
|
|
7173
|
+
/**
|
|
7174
|
+
* Marks every element in a component that has scoped styles with the
|
|
7175
|
+
* component's scope class. This is intentionally not selector-based: deciding
|
|
7176
|
+
* which elements a CSS selector can match requires parsing selectors, and
|
|
7177
|
+
* pseudo-classes, attribute selectors and `@media` rules make compile-time
|
|
7178
|
+
* matching unreliable. Marking every element lets `buildStyles` append the
|
|
7179
|
+
* scope class to selectors without needing to understand their shape.
|
|
7180
|
+
*/
|
|
6302
7181
|
function scopeStyles(status) {
|
|
6303
|
-
let
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
scopeStylesOnNode(component.
|
|
7182
|
+
for (let component of status.components) {
|
|
7183
|
+
if (!component.style) continue;
|
|
7184
|
+
if (component.markup) scopeStylesOnNode(component.markup);
|
|
7185
|
+
if (component.error) scopeStylesOnNode(component.error);
|
|
6307
7186
|
}
|
|
6308
7187
|
}
|
|
6309
|
-
function scopeStylesOnNode(node
|
|
6310
|
-
if (isElementNode(node) || isComponentNode(node)
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
7188
|
+
function scopeStylesOnNode(node) {
|
|
7189
|
+
if (isElementNode(node) || isComponentNode(node) || isSpecialNode(node) && (node.tagName === "@element" || node.tagName === "@component")) node.scopeStyles = true;
|
|
7190
|
+
if (isParentNode(node)) for (let child of node.children) scopeStylesOnNode(child);
|
|
7191
|
+
}
|
|
7192
|
+
//#endregion
|
|
7193
|
+
//#region src/compile/parse/utils/isAlphaNumericChar.ts
|
|
7194
|
+
/**
|
|
7195
|
+
* Checks whether the supplied character is a alpha-numeric
|
|
7196
|
+
*
|
|
7197
|
+
* @param text The string to check
|
|
7198
|
+
* @param index The index of the character in the string
|
|
7199
|
+
*
|
|
7200
|
+
* @returns True if the supplied character is alpha-numeric
|
|
7201
|
+
*/
|
|
7202
|
+
function isAlphaNumericChar(text, index) {
|
|
7203
|
+
let code = text.charCodeAt(index);
|
|
7204
|
+
return code > 47 && code < 58 || code > 64 && code < 91 || code > 96 && code < 123;
|
|
6319
7205
|
}
|
|
6320
|
-
|
|
6321
|
-
|
|
7206
|
+
//#endregion
|
|
7207
|
+
//#region src/compile/parse/utils/consumeAlphaNumeric.ts
|
|
7208
|
+
/**
|
|
7209
|
+
* Consumes alpha-numeric characters and advances the current parse position to
|
|
7210
|
+
* before the next non-alpha character
|
|
7211
|
+
*
|
|
7212
|
+
* @param status The parse status
|
|
7213
|
+
*
|
|
7214
|
+
* @returns The string of alpha-numeric characters from the current parse position
|
|
7215
|
+
* to the next non-alpha character
|
|
7216
|
+
*/
|
|
7217
|
+
function consumeAlphaNumeric(status) {
|
|
7218
|
+
const start = status.i;
|
|
7219
|
+
for (status.i; status.i < status.source.length; status.i++) if (!isAlphaNumericChar(status.source, status.i)) return status.source.substring(start, status.i);
|
|
7220
|
+
return "";
|
|
6322
7221
|
}
|
|
6323
7222
|
//#endregion
|
|
6324
7223
|
//#region src/compile/parse/parseCode.ts
|
|
6325
|
-
function parseCode(source) {
|
|
7224
|
+
function parseCode(source, options) {
|
|
6326
7225
|
const status = {
|
|
6327
7226
|
source,
|
|
6328
7227
|
i: 0,
|
|
6329
7228
|
marker: 0,
|
|
6330
7229
|
level: 0,
|
|
6331
7230
|
braces: [],
|
|
6332
|
-
imports: [],
|
|
6333
7231
|
script: [],
|
|
6334
7232
|
components: [],
|
|
6335
7233
|
stack: [],
|
|
@@ -6385,6 +7283,7 @@ function parseCode(source) {
|
|
|
6385
7283
|
end: source.length
|
|
6386
7284
|
}
|
|
6387
7285
|
});
|
|
7286
|
+
classifyComponents(status, collectImportNames(source), options);
|
|
6388
7287
|
scopeStyles(status);
|
|
6389
7288
|
const ok = !status.errors.length;
|
|
6390
7289
|
if (!ok) status.errors = status.errors.sort((a, b) => a.startIndex - b.startIndex);
|
|
@@ -6392,7 +7291,6 @@ function parseCode(source) {
|
|
|
6392
7291
|
ok,
|
|
6393
7292
|
errors: status.errors,
|
|
6394
7293
|
template: ok ? {
|
|
6395
|
-
imports: status.imports,
|
|
6396
7294
|
script: status.script,
|
|
6397
7295
|
components: status.components
|
|
6398
7296
|
} : void 0
|
|
@@ -6488,7 +7386,6 @@ function parseComponentStart(status) {
|
|
|
6488
7386
|
marker: 0,
|
|
6489
7387
|
level: 0,
|
|
6490
7388
|
braces: [],
|
|
6491
|
-
imports: [],
|
|
6492
7389
|
script: [],
|
|
6493
7390
|
components: [],
|
|
6494
7391
|
stack: [],
|
|
@@ -6749,12 +7646,13 @@ function consumeScriptComments(status) {
|
|
|
6749
7646
|
* Parses source code into a component template
|
|
6750
7647
|
*
|
|
6751
7648
|
* @param source The source code
|
|
7649
|
+
* @param options Optional parse behaviour
|
|
6752
7650
|
*
|
|
6753
7651
|
* @returns A result indicating whether parsing was ok, and if so, containing
|
|
6754
7652
|
* the component template's parts such as script, markup and styles
|
|
6755
7653
|
*/
|
|
6756
|
-
function parse(source) {
|
|
6757
|
-
return parseCode(source);
|
|
7654
|
+
function parse(source, options) {
|
|
7655
|
+
return parseCode(source, options);
|
|
6758
7656
|
}
|
|
6759
7657
|
//#endregion
|
|
6760
7658
|
//#region src/compile/parse/bindDataTemplate.ts
|