@lark.js/mvc 0.0.10 → 0.0.11
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/README.md +10 -10
- package/dist/chunk-RIV4NK3K.js +108 -0
- package/dist/compiler.cjs +654 -114
- package/dist/compiler.d.cts +35 -35
- package/dist/compiler.d.ts +35 -35
- package/dist/compiler.js +651 -114
- package/dist/devtool.cjs +3421 -0
- package/dist/devtool.d.cts +83 -0
- package/dist/devtool.d.ts +83 -0
- package/dist/devtool.js +3333 -0
- package/dist/index.cjs +754 -147
- package/dist/index.d.cts +88 -85
- package/dist/index.d.ts +88 -85
- package/dist/index.js +751 -143
- package/dist/rspack.cjs +15978 -0
- package/dist/rspack.d.cts +122 -0
- package/dist/rspack.d.ts +122 -0
- package/dist/{chunk-SIQF4YLC.js → rspack.js} +765 -149
- package/dist/runtime.cjs +7 -7
- package/dist/runtime.d.cts +4 -4
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +10 -54
- package/dist/vite.cjs +709 -151
- package/dist/vite.d.cts +3 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +15917 -10
- package/dist/webpack.cjs +756 -159
- package/dist/webpack.d.cts +60 -4
- package/dist/webpack.d.ts +60 -4
- package/dist/webpack.js +15962 -14
- package/package.json +25 -2
package/dist/compiler.cjs
CHANGED
|
@@ -14518,7 +14518,7 @@ var require_lib = __commonJS({
|
|
|
14518
14518
|
options = Object.assign({}, options);
|
|
14519
14519
|
try {
|
|
14520
14520
|
options.sourceType = "module";
|
|
14521
|
-
const parser =
|
|
14521
|
+
const parser = getParser2(options, input);
|
|
14522
14522
|
const ast = parser.parse();
|
|
14523
14523
|
if (parser.sawUnambiguousESM) {
|
|
14524
14524
|
return ast;
|
|
@@ -14526,7 +14526,7 @@ var require_lib = __commonJS({
|
|
|
14526
14526
|
if (parser.ambiguousScriptDifferentAst) {
|
|
14527
14527
|
try {
|
|
14528
14528
|
options.sourceType = "script";
|
|
14529
|
-
return
|
|
14529
|
+
return getParser2(options, input).parse();
|
|
14530
14530
|
} catch (_unused) {
|
|
14531
14531
|
}
|
|
14532
14532
|
} else {
|
|
@@ -14536,17 +14536,17 @@ var require_lib = __commonJS({
|
|
|
14536
14536
|
} catch (moduleError) {
|
|
14537
14537
|
try {
|
|
14538
14538
|
options.sourceType = "script";
|
|
14539
|
-
return
|
|
14539
|
+
return getParser2(options, input).parse();
|
|
14540
14540
|
} catch (_unused2) {
|
|
14541
14541
|
}
|
|
14542
14542
|
throw moduleError;
|
|
14543
14543
|
}
|
|
14544
14544
|
} else {
|
|
14545
|
-
return
|
|
14545
|
+
return getParser2(options, input).parse();
|
|
14546
14546
|
}
|
|
14547
14547
|
}
|
|
14548
14548
|
function parseExpression(input, options) {
|
|
14549
|
-
const parser =
|
|
14549
|
+
const parser = getParser2(options, input);
|
|
14550
14550
|
if (parser.options.strictMode) {
|
|
14551
14551
|
parser.state.strict = true;
|
|
14552
14552
|
}
|
|
@@ -14560,7 +14560,7 @@ var require_lib = __commonJS({
|
|
|
14560
14560
|
return tokenTypes2;
|
|
14561
14561
|
}
|
|
14562
14562
|
var tokTypes = generateExportedTokenTypes(tt);
|
|
14563
|
-
function
|
|
14563
|
+
function getParser2(options, input) {
|
|
14564
14564
|
let cls = Parser;
|
|
14565
14565
|
const pluginsMap = /* @__PURE__ */ new Map();
|
|
14566
14566
|
if (options != null && options.plugins) {
|
|
@@ -14609,10 +14609,12 @@ var require_lib = __commonJS({
|
|
|
14609
14609
|
var compiler_exports = {};
|
|
14610
14610
|
__export(compiler_exports, {
|
|
14611
14611
|
compileTemplate: () => compileTemplate,
|
|
14612
|
-
extractGlobalVars: () =>
|
|
14612
|
+
extractGlobalVars: () => extractGlobalVars2,
|
|
14613
|
+
extractGlobalVarsSwc: () => extractGlobalVars
|
|
14613
14614
|
});
|
|
14614
14615
|
module.exports = __toCommonJS(compiler_exports);
|
|
14615
|
-
|
|
14616
|
+
|
|
14617
|
+
// src/compiler/template-syntax.ts
|
|
14616
14618
|
var SPLITTER = String.fromCharCode(30);
|
|
14617
14619
|
var VIEW_ID_PLACEHOLDER = String.fromCharCode(31);
|
|
14618
14620
|
function jsObjectToUrlParams(paramsStr) {
|
|
@@ -14733,7 +14735,7 @@ function convertArtSyntax(source, debug) {
|
|
|
14733
14735
|
}
|
|
14734
14736
|
if (blockStack.length > 0) {
|
|
14735
14737
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
14736
|
-
throw new Error(`
|
|
14738
|
+
throw new Error(`Unclosed block(s): ${unclosed}`);
|
|
14737
14739
|
}
|
|
14738
14740
|
return result.join("");
|
|
14739
14741
|
}
|
|
@@ -14832,7 +14834,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14832
14834
|
const object = tokens[0];
|
|
14833
14835
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14834
14836
|
throw new Error(
|
|
14835
|
-
`
|
|
14837
|
+
`Bad forOf syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forOf list as item [index]}}`
|
|
14836
14838
|
);
|
|
14837
14839
|
}
|
|
14838
14840
|
const restTokens = tokens.slice(2);
|
|
@@ -14859,7 +14861,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14859
14861
|
const object = tokens[0];
|
|
14860
14862
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14861
14863
|
throw new Error(
|
|
14862
|
-
`
|
|
14864
|
+
`Bad forIn syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forIn obj as val [key]}}`
|
|
14863
14865
|
);
|
|
14864
14866
|
}
|
|
14865
14867
|
const restTokens2 = tokens.slice(2);
|
|
@@ -14885,13 +14887,11 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14885
14887
|
const expectedCtrl = keyword.substring(1);
|
|
14886
14888
|
const last = blockStack.pop();
|
|
14887
14889
|
if (!last) {
|
|
14888
|
-
throw new Error(
|
|
14889
|
-
`[@lark.js/mvc error] unexpected {{${code}}}: no matching open block`
|
|
14890
|
-
);
|
|
14890
|
+
throw new Error(`Unexpected {{${code}}}: no matching open block`);
|
|
14891
14891
|
}
|
|
14892
14892
|
if (last.ctrl !== expectedCtrl) {
|
|
14893
14893
|
throw new Error(
|
|
14894
|
-
`
|
|
14894
|
+
`Unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14895
14895
|
);
|
|
14896
14896
|
}
|
|
14897
14897
|
return `${debugPrefix}<%}%>`;
|
|
@@ -14952,112 +14952,529 @@ function parseAsExpr(expr) {
|
|
|
14952
14952
|
bad: false
|
|
14953
14953
|
};
|
|
14954
14954
|
}
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14955
|
+
|
|
14956
|
+
// src/compiler/compile-to-vdom-function.ts
|
|
14957
|
+
var import_htmlparser2 = require("htmlparser2");
|
|
14958
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
14959
|
+
"area",
|
|
14960
|
+
"base",
|
|
14961
|
+
"br",
|
|
14962
|
+
"col",
|
|
14963
|
+
"embed",
|
|
14964
|
+
"hr",
|
|
14965
|
+
"img",
|
|
14966
|
+
"input",
|
|
14967
|
+
"link",
|
|
14968
|
+
"meta",
|
|
14969
|
+
"param",
|
|
14970
|
+
"source",
|
|
14971
|
+
"track",
|
|
14972
|
+
"wbr"
|
|
14973
|
+
]);
|
|
14974
|
+
function vdomEscapeStr(s) {
|
|
14975
|
+
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\x1e/g, "\\x1e");
|
|
14976
|
+
}
|
|
14977
|
+
function vdomResolveAttrValue(rawValue, exprStore) {
|
|
14978
|
+
const hasPlaceholders = rawValue.includes("\0");
|
|
14979
|
+
const hasViewId = rawValue.includes("");
|
|
14980
|
+
if (!hasPlaceholders && !hasViewId) {
|
|
14981
|
+
return `'${vdomEscapeStr(rawValue)}'`;
|
|
14982
|
+
}
|
|
14983
|
+
const segments = [];
|
|
14984
|
+
let remaining = rawValue;
|
|
14985
|
+
while (remaining.length > 0) {
|
|
14986
|
+
const phIdx = remaining.indexOf("\0");
|
|
14987
|
+
const viIdx = remaining.indexOf("");
|
|
14988
|
+
let nextSpecial = -1;
|
|
14989
|
+
let specialType = null;
|
|
14990
|
+
if (phIdx >= 0 && (viIdx < 0 || phIdx <= viIdx)) {
|
|
14991
|
+
nextSpecial = phIdx;
|
|
14992
|
+
specialType = "ph";
|
|
14993
|
+
} else if (viIdx >= 0) {
|
|
14994
|
+
nextSpecial = viIdx;
|
|
14995
|
+
specialType = "vi";
|
|
14996
|
+
}
|
|
14997
|
+
if (nextSpecial === -1) {
|
|
14998
|
+
if (remaining) segments.push(`'${vdomEscapeStr(remaining)}'`);
|
|
14999
|
+
break;
|
|
15000
|
+
}
|
|
15001
|
+
if (nextSpecial > 0) {
|
|
15002
|
+
segments.push(`'${vdomEscapeStr(remaining.substring(0, nextSpecial))}'`);
|
|
15003
|
+
}
|
|
15004
|
+
if (specialType === "vi") {
|
|
15005
|
+
segments.push("$viewId");
|
|
15006
|
+
remaining = remaining.substring(nextSpecial + 1);
|
|
15007
|
+
} else {
|
|
15008
|
+
const closeIdx = remaining.indexOf("\0", nextSpecial + 1);
|
|
15009
|
+
if (closeIdx === -1) {
|
|
15010
|
+
segments.push(`'${vdomEscapeStr(remaining.substring(nextSpecial))}'`);
|
|
15011
|
+
break;
|
|
14981
15012
|
}
|
|
14982
|
-
|
|
14983
|
-
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
content = `$strSafe(${content})`;
|
|
14990
|
-
}
|
|
14991
|
-
funcSource += `'+($dbgExpr='<%${operate + expr}%>',${content})+'`;
|
|
14992
|
-
} else if (content) {
|
|
14993
|
-
if (line > -1) {
|
|
14994
|
-
funcSource += `';$dbgLine=${line};$dbgArt='${art}';`;
|
|
14995
|
-
content = "";
|
|
15013
|
+
const idx = parseInt(remaining.substring(nextSpecial + 1, closeIdx));
|
|
15014
|
+
const expr = exprStore[idx];
|
|
15015
|
+
if (expr.op === "=" || expr.op === ":") {
|
|
15016
|
+
segments.push(`$n(${expr.content})`);
|
|
15017
|
+
} else if (expr.op === "!") {
|
|
15018
|
+
if (expr.content.startsWith("$encUri(") && expr.content.endsWith(")")) {
|
|
15019
|
+
segments.push(expr.content);
|
|
14996
15020
|
} else {
|
|
14997
|
-
|
|
14998
|
-
}
|
|
14999
|
-
if (funcSource.endsWith(`+'';`)) {
|
|
15000
|
-
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15001
|
-
}
|
|
15002
|
-
if (expr) {
|
|
15003
|
-
funcSource += `$dbgExpr='<%${expr}%>';`;
|
|
15021
|
+
segments.push(`$n(${expr.content})`);
|
|
15004
15022
|
}
|
|
15005
|
-
|
|
15023
|
+
} else if (expr.op === "@") {
|
|
15024
|
+
segments.push(`$refFn($refAlt,${expr.content})`);
|
|
15025
|
+
} else {
|
|
15026
|
+
segments.push(`$n(${expr.content})`);
|
|
15006
15027
|
}
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15028
|
+
remaining = remaining.substring(closeIdx + 1);
|
|
15029
|
+
}
|
|
15030
|
+
}
|
|
15031
|
+
if (segments.length === 0) return "''";
|
|
15032
|
+
if (segments.length === 1) return segments[0];
|
|
15033
|
+
return segments.join("+");
|
|
15034
|
+
}
|
|
15035
|
+
function vdomBuildPropsFromAttribs(attribs, exprStore) {
|
|
15036
|
+
if (!attribs) return "null";
|
|
15037
|
+
const keys = Object.keys(attribs);
|
|
15038
|
+
if (keys.length === 0) return "null";
|
|
15039
|
+
const entries = [];
|
|
15040
|
+
for (const name of keys) {
|
|
15041
|
+
const value = attribs[name];
|
|
15042
|
+
const valueExpr = vdomResolveAttrValue(value, exprStore);
|
|
15043
|
+
entries.push(`'${vdomEscapeStr(name)}':${valueExpr}`);
|
|
15044
|
+
}
|
|
15045
|
+
return `{${entries.join(",")}}`;
|
|
15046
|
+
}
|
|
15047
|
+
function compileToVDomFunction(source, debug, file) {
|
|
15048
|
+
const lines = [];
|
|
15049
|
+
let varCounter = 0;
|
|
15050
|
+
let propsCounter = 0;
|
|
15051
|
+
const exprStore = [];
|
|
15052
|
+
const protectedSource = source.replace(
|
|
15053
|
+
/<%([@=!:])?([\s\S]*?)%>/g,
|
|
15054
|
+
(_, op, content) => {
|
|
15055
|
+
const idx = exprStore.length;
|
|
15056
|
+
exprStore.push({ op: op || "", content: (content || "").trim() });
|
|
15057
|
+
return `\0${idx}\0`;
|
|
15058
|
+
}
|
|
15059
|
+
);
|
|
15060
|
+
const doc = (0, import_htmlparser2.parseDocument)(protectedSource, {
|
|
15061
|
+
recognizeSelfClosing: true,
|
|
15062
|
+
lowerCaseTags: false,
|
|
15063
|
+
lowerCaseAttributeNames: false,
|
|
15064
|
+
decodeEntities: false
|
|
15065
|
+
});
|
|
15066
|
+
const rootVar = `$v${varCounter++}`;
|
|
15067
|
+
lines.push(`let ${rootVar}=[]`);
|
|
15068
|
+
const maxVars = 30;
|
|
15069
|
+
const varDecls = [];
|
|
15070
|
+
for (let i = 1; i < maxVars; i++) {
|
|
15071
|
+
varDecls.push(`$v${i}`);
|
|
15072
|
+
}
|
|
15073
|
+
lines.push(`let ${varDecls.join(",")}`);
|
|
15074
|
+
function allocVar() {
|
|
15075
|
+
if (varCounter >= maxVars) return `$v${maxVars - 1}`;
|
|
15076
|
+
return `$v${varCounter++}`;
|
|
15077
|
+
}
|
|
15078
|
+
function emitNode(node, parentVar) {
|
|
15079
|
+
const type = node.type;
|
|
15080
|
+
if (type === "text") {
|
|
15081
|
+
emitText(node.data || "", parentVar);
|
|
15082
|
+
} else if (type === "tag" || type === "script" || type === "style") {
|
|
15083
|
+
emitElement(node, parentVar);
|
|
15084
|
+
}
|
|
15085
|
+
}
|
|
15086
|
+
function emitText(text, parentVar) {
|
|
15087
|
+
const parts = text.split(/\x00(\d+)\x00/);
|
|
15088
|
+
for (let i = 0; i < parts.length; i++) {
|
|
15089
|
+
if (i % 2 === 0) {
|
|
15090
|
+
const trimmed = parts[i];
|
|
15091
|
+
if (trimmed.trim()) {
|
|
15092
|
+
lines.push(`${parentVar}.push($c(0,'${vdomEscapeStr(trimmed)}'))`);
|
|
15022
15093
|
}
|
|
15023
|
-
|
|
15094
|
+
} else {
|
|
15095
|
+
const idx = parseInt(parts[i]);
|
|
15096
|
+
const expr = exprStore[idx];
|
|
15097
|
+
emitExpr(expr, parentVar);
|
|
15024
15098
|
}
|
|
15025
15099
|
}
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
|
|
15100
|
+
}
|
|
15101
|
+
function emitExpr(expr, parentVar) {
|
|
15102
|
+
if (expr.op === "=" || expr.op === ":") {
|
|
15103
|
+
lines.push(`${parentVar}.push($c(0,$n(${expr.content})))`);
|
|
15104
|
+
} else if (expr.op === "!") {
|
|
15105
|
+
if (expr.content.startsWith("$encUri(") && expr.content.endsWith(")")) {
|
|
15106
|
+
lines.push(`${parentVar}.push($c(0,${expr.content}))`);
|
|
15107
|
+
} else {
|
|
15108
|
+
lines.push(`${parentVar}.push($c(0,$n(${expr.content})))`);
|
|
15109
|
+
}
|
|
15110
|
+
} else if (expr.op === "@") {
|
|
15111
|
+
lines.push(`${parentVar}.push($c(0,$refFn($refAlt,${expr.content})))`);
|
|
15112
|
+
} else if (expr.content) {
|
|
15113
|
+
lines.push(expr.content);
|
|
15114
|
+
}
|
|
15115
|
+
}
|
|
15116
|
+
function emitElement(node, parentVar) {
|
|
15117
|
+
const tagName = node.name || "";
|
|
15118
|
+
const children = node.children || [];
|
|
15119
|
+
const childVar = allocVar();
|
|
15120
|
+
const propsKey = `__p${propsCounter++}`;
|
|
15121
|
+
const props = vdomBuildPropsFromAttribs(node.attribs, exprStore);
|
|
15122
|
+
lines.push(`let ${propsKey}=${props}`);
|
|
15123
|
+
lines.push(`${childVar}=[]`);
|
|
15124
|
+
for (const child of children) {
|
|
15125
|
+
emitNode(child, childVar);
|
|
15126
|
+
}
|
|
15127
|
+
const isVoid = VOID_ELEMENTS.has(tagName) && children.length === 0;
|
|
15128
|
+
const childrenArg = isVoid ? "1" : childVar;
|
|
15129
|
+
lines.push(
|
|
15130
|
+
`${parentVar}.push($c('${tagName}',${propsKey},${childrenArg}))`
|
|
15131
|
+
);
|
|
15132
|
+
}
|
|
15133
|
+
for (const child of doc.children) {
|
|
15134
|
+
emitNode(child, rootVar);
|
|
15135
|
+
}
|
|
15136
|
+
lines.push(`return $c($viewId,0,${rootVar})`);
|
|
15137
|
+
const body = lines.join(";");
|
|
15138
|
+
let funcBody = body;
|
|
15031
15139
|
if (debug) {
|
|
15032
15140
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15033
|
-
|
|
15141
|
+
funcBody = `let $dbgExpr,$dbgArt,$dbgLine;try{${body}}catch(ex){let msg='render view error:'+(ex.message||ex);msg+='${filePart}';throw msg;}`;
|
|
15034
15142
|
}
|
|
15035
15143
|
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15036
|
-
|
|
15037
|
-
void hasAtRule;
|
|
15144
|
+
funcBody = funcBody.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15038
15145
|
const refFallback = "if(!$refAlt)$refAlt=$data;";
|
|
15039
|
-
const fullSource = `${refFallback}let $splitter='\\x1e'
|
|
15040
|
-
return `($data,$viewId,$refAlt,$
|
|
15146
|
+
const fullSource = `${refFallback}let $splitter='\\x1e'{{VARS}};${funcBody}`;
|
|
15147
|
+
return `($data,$viewId,$refAlt,$n,$refFn,$encUri,$encQuote)=>{${fullSource}}`;
|
|
15041
15148
|
}
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15149
|
+
|
|
15150
|
+
// src/compiler/swc/extract-global-vars.ts
|
|
15151
|
+
var parseSyncFn = null;
|
|
15152
|
+
var parseSyncLoadAttempted = false;
|
|
15153
|
+
async function getParser() {
|
|
15154
|
+
if (!parseSyncLoadAttempted) {
|
|
15155
|
+
parseSyncLoadAttempted = true;
|
|
15156
|
+
try {
|
|
15157
|
+
const swc = await import("@swc/core");
|
|
15158
|
+
parseSyncFn = swc.parseSync;
|
|
15159
|
+
} catch (err) {
|
|
15160
|
+
console.error("failed to load @swc/core", err);
|
|
15161
|
+
}
|
|
15162
|
+
}
|
|
15163
|
+
return parseSyncFn;
|
|
15164
|
+
}
|
|
15165
|
+
async function extractGlobalVars(source) {
|
|
15166
|
+
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15167
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15168
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15169
|
+
const template = restoreComments(converted, _comments);
|
|
15170
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15171
|
+
const fnParts = [];
|
|
15172
|
+
const htmlStore = {};
|
|
15173
|
+
let htmlIndex = 0;
|
|
15174
|
+
let lastIndex = 0;
|
|
15175
|
+
const htmlKey = String.fromCharCode(5);
|
|
15176
|
+
template.replace(
|
|
15177
|
+
templateCmdRegExp,
|
|
15178
|
+
(match, operate, content, offset) => {
|
|
15179
|
+
const start = operate ? 3 : 2;
|
|
15180
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
15181
|
+
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15182
|
+
htmlStore[key] = htmlText;
|
|
15183
|
+
lastIndex = offset + match.length - 2;
|
|
15184
|
+
if (operate && content.trim()) {
|
|
15185
|
+
fnParts.push(';"' + key + '";', "[" + content + "]");
|
|
15186
|
+
} else {
|
|
15187
|
+
fnParts.push(';"' + key + '";', content || "");
|
|
15188
|
+
}
|
|
15189
|
+
return match;
|
|
15190
|
+
}
|
|
15057
15191
|
);
|
|
15058
|
-
|
|
15192
|
+
let fn = fnParts.join("");
|
|
15193
|
+
fn = `(function(){${fn}})`;
|
|
15194
|
+
const parseSync = await getParser();
|
|
15195
|
+
if (!parseSync) {
|
|
15196
|
+
return fallbackExtractVariables(source);
|
|
15197
|
+
}
|
|
15198
|
+
let ast;
|
|
15199
|
+
try {
|
|
15200
|
+
ast = parseSync(fn, {
|
|
15201
|
+
syntax: "ecmascript",
|
|
15202
|
+
target: "es2022"
|
|
15203
|
+
});
|
|
15204
|
+
} catch {
|
|
15205
|
+
return fallbackExtractVariables(source);
|
|
15206
|
+
}
|
|
15207
|
+
const globalExists = {};
|
|
15208
|
+
for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
|
|
15209
|
+
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15210
|
+
const fnNodes = [];
|
|
15211
|
+
walkSwcAst(ast, {
|
|
15212
|
+
VariableDeclarator(node) {
|
|
15213
|
+
if (node.id.type === "Identifier") {
|
|
15214
|
+
const name = node.id.value;
|
|
15215
|
+
globalExists[name] = node.init ? 3 : 2;
|
|
15216
|
+
}
|
|
15217
|
+
},
|
|
15218
|
+
FunctionDeclaration(node) {
|
|
15219
|
+
if (node.identifier) {
|
|
15220
|
+
globalExists[node.identifier.value] = 3;
|
|
15221
|
+
}
|
|
15222
|
+
fnNodes.push(node);
|
|
15223
|
+
},
|
|
15224
|
+
FunctionExpression(node) {
|
|
15225
|
+
fnNodes.push(node);
|
|
15226
|
+
},
|
|
15227
|
+
ArrowFunctionExpression(node) {
|
|
15228
|
+
fnNodes.push(node);
|
|
15229
|
+
},
|
|
15230
|
+
CallExpression(node) {
|
|
15231
|
+
if (node.callee.type === "Identifier") {
|
|
15232
|
+
globalExists[node.callee.value] = 1;
|
|
15233
|
+
}
|
|
15234
|
+
}
|
|
15235
|
+
});
|
|
15236
|
+
const functionParams = /* @__PURE__ */ Object.create(null);
|
|
15237
|
+
for (const fnNode of fnNodes) {
|
|
15238
|
+
const patterns = getParamPatterns(fnNode);
|
|
15239
|
+
for (const pat of patterns) {
|
|
15240
|
+
if (pat.type === "Identifier") {
|
|
15241
|
+
functionParams[pat.value] = 1;
|
|
15242
|
+
} else if (pat.type === "AssignmentPattern" && pat.left.type === "Identifier") {
|
|
15243
|
+
functionParams[pat.left.value] = 1;
|
|
15244
|
+
} else if (pat.type === "RestElement" && pat.argument.type === "Identifier") {
|
|
15245
|
+
functionParams[pat.argument.value] = 1;
|
|
15246
|
+
}
|
|
15247
|
+
}
|
|
15248
|
+
}
|
|
15249
|
+
walkSwcAst(ast, {
|
|
15250
|
+
Identifier(node) {
|
|
15251
|
+
const name = node.value;
|
|
15252
|
+
if (globalExists[name]) return;
|
|
15253
|
+
if (functionParams[name]) return;
|
|
15254
|
+
globalVars[name] = 1;
|
|
15255
|
+
},
|
|
15256
|
+
AssignmentExpression(node) {
|
|
15257
|
+
if (node.left.type === "Identifier") {
|
|
15258
|
+
const name = node.left.value;
|
|
15259
|
+
if (!globalExists[name] || globalExists[name] === 1) {
|
|
15260
|
+
globalExists[name] = (globalExists[name] || 0) + 1;
|
|
15261
|
+
}
|
|
15262
|
+
}
|
|
15263
|
+
}
|
|
15264
|
+
});
|
|
15265
|
+
return Object.keys(globalVars);
|
|
15266
|
+
}
|
|
15267
|
+
function getParamPatterns(fnNode) {
|
|
15268
|
+
if (fnNode.type === "ArrowFunctionExpression") {
|
|
15269
|
+
return fnNode.params;
|
|
15270
|
+
}
|
|
15271
|
+
return fnNode.params.map((p) => p.pat);
|
|
15272
|
+
}
|
|
15273
|
+
function fallbackExtractVariables(source) {
|
|
15274
|
+
const vars = /* @__PURE__ */ new Set();
|
|
15275
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15276
|
+
let m;
|
|
15277
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15278
|
+
vars.add(m[1]);
|
|
15279
|
+
}
|
|
15280
|
+
const eachRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15281
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15282
|
+
vars.add(m[1]);
|
|
15283
|
+
}
|
|
15284
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15285
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15286
|
+
vars.add(m[1]);
|
|
15287
|
+
}
|
|
15288
|
+
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
|
|
15059
15289
|
}
|
|
15060
|
-
function
|
|
15290
|
+
function walkSwcAst(ast, visitors) {
|
|
15291
|
+
function visit(node) {
|
|
15292
|
+
const type = node.type;
|
|
15293
|
+
if (visitors[type]) {
|
|
15294
|
+
visitors[type](node);
|
|
15295
|
+
}
|
|
15296
|
+
for (const key of Object.keys(node)) {
|
|
15297
|
+
if (key === "type" || key === "span" || key === "ctxt") continue;
|
|
15298
|
+
if (type === "MemberExpression" && key === "property") {
|
|
15299
|
+
const me = node;
|
|
15300
|
+
if (me.property.type !== "Computed") continue;
|
|
15301
|
+
}
|
|
15302
|
+
if (type === "KeyValueProperty" && key === "key") {
|
|
15303
|
+
const kv = node;
|
|
15304
|
+
if (kv.key.type !== "Computed") continue;
|
|
15305
|
+
}
|
|
15306
|
+
if (type === "MethodProperty" && key === "key") {
|
|
15307
|
+
const mp = node;
|
|
15308
|
+
if (mp.key.type !== "Computed") continue;
|
|
15309
|
+
}
|
|
15310
|
+
const child = Reflect.get(node, key);
|
|
15311
|
+
if (Array.isArray(child)) {
|
|
15312
|
+
for (const item of child) {
|
|
15313
|
+
if (isSwcNode(item)) visit(item);
|
|
15314
|
+
}
|
|
15315
|
+
} else if (isSwcNode(child)) {
|
|
15316
|
+
visit(child);
|
|
15317
|
+
}
|
|
15318
|
+
}
|
|
15319
|
+
}
|
|
15320
|
+
visit(ast);
|
|
15321
|
+
}
|
|
15322
|
+
function isSwcNode(v) {
|
|
15323
|
+
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15324
|
+
}
|
|
15325
|
+
var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
15326
|
+
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15327
|
+
//
|
|
15328
|
+
// These variables appear in the generated template function signature
|
|
15329
|
+
// or body. They must be excluded from extractGlobalVars() so that
|
|
15330
|
+
// they are not mistaken for user data variables and destructured from $data.
|
|
15331
|
+
// SPLITTER character constant (same as \x1e), used as namespace separator
|
|
15332
|
+
// for refData keys, event attribute encoding, and internal data structures.
|
|
15333
|
+
// Declared as: let $splitter='\x1e'
|
|
15334
|
+
"$splitter",
|
|
15335
|
+
// Data — the data object passed from Updater to the template function.
|
|
15336
|
+
// User variables are destructured from $data at the top of the function:
|
|
15337
|
+
// let {name, age} = $data;
|
|
15338
|
+
// This is the first parameter of the generated arrow function.
|
|
15339
|
+
"$data",
|
|
15340
|
+
// Null-safe toString: v => '' + (v == null ? '' : v)
|
|
15341
|
+
// Converts null/undefined to empty string, otherwise calls toString().
|
|
15342
|
+
// Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
|
|
15343
|
+
"$strSafe",
|
|
15344
|
+
// HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
|
|
15345
|
+
// Encodes &, <, >, ", ', ` to HTML entities (& < etc.)
|
|
15346
|
+
// Applied to all {{=escaped}} and {{:binding}} outputs.
|
|
15347
|
+
"$encHtml",
|
|
15348
|
+
// HTML entity map — internal object used by $encHtml:
|
|
15349
|
+
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15350
|
+
// Not a standalone function; referenced inside $encHtml's closure.
|
|
15351
|
+
"$entMap",
|
|
15352
|
+
// HTML entity RegExp — internal regexp used by $encHtml:
|
|
15353
|
+
// /[&<>"'`]/g
|
|
15354
|
+
"$entReg",
|
|
15355
|
+
// HTML entity replacer function — internal helper used by $encHtml:
|
|
15356
|
+
// m => '&' + $entMap[m] + ';'
|
|
15357
|
+
// Maps matched character to its entity string.
|
|
15358
|
+
"$entFn",
|
|
15359
|
+
// Output buffer — the string accumulator for rendered HTML.
|
|
15360
|
+
// All template output is appended via $out += '...'.
|
|
15361
|
+
// Declared as: let $out = ''
|
|
15362
|
+
"$out",
|
|
15363
|
+
// Reference lookup: (refData, value) => key
|
|
15364
|
+
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15365
|
+
// object reference. Used by {{@ref}} operator for passing object
|
|
15366
|
+
// references to child views via v-lark attributes.
|
|
15367
|
+
"$refFn",
|
|
15368
|
+
// URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
|
|
15369
|
+
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15370
|
+
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15371
|
+
"$encUri",
|
|
15372
|
+
// URI encode map — internal object used by $encUri:
|
|
15373
|
+
// {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
|
|
15374
|
+
"$uriMap",
|
|
15375
|
+
// URI encode replacer — internal helper used by $encUri:
|
|
15376
|
+
// m => $uriMap[m]
|
|
15377
|
+
"$uriFn",
|
|
15378
|
+
// URI encode regexp — internal regexp used by $encUri:
|
|
15379
|
+
// /[!')(*]/g
|
|
15380
|
+
"$uriReg",
|
|
15381
|
+
// Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
|
|
15382
|
+
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15383
|
+
// values (e.g. data-json='...').
|
|
15384
|
+
"$encQuote",
|
|
15385
|
+
// Quote encode regexp — internal regexp used by $encQuote:
|
|
15386
|
+
// /['"\\]/g
|
|
15387
|
+
"$qReg",
|
|
15388
|
+
// View ID — the unique identifier of the owning View instance.
|
|
15389
|
+
// Injected into @event attribute values at render time so that
|
|
15390
|
+
// EventDelegator can dispatch events to the correct View handler.
|
|
15391
|
+
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15392
|
+
"$viewId",
|
|
15393
|
+
// Debug: current expression text — stores the template expression being
|
|
15394
|
+
// evaluated, for error reporting. Only present in debug mode.
|
|
15395
|
+
// e.g. $dbgExpr='<%=user.name%>'
|
|
15396
|
+
"$dbgExpr",
|
|
15397
|
+
// Debug: original art syntax — stores the {{}} template syntax before
|
|
15398
|
+
// conversion, for error reporting. Only present in debug mode.
|
|
15399
|
+
// e.g. $dbgArt='{{=user.name}}'
|
|
15400
|
+
"$dbgArt",
|
|
15401
|
+
// Debug: source line number — tracks the current line in the template
|
|
15402
|
+
// source, for error reporting. Only present in debug mode.
|
|
15403
|
+
"$dbgLine",
|
|
15404
|
+
// RefData alias — fallback reference lookup table.
|
|
15405
|
+
// Defaults to $data when no explicit $refAlt is provided.
|
|
15406
|
+
// Ensures $refFn() does not crash when @ operator is used without refData.
|
|
15407
|
+
"$refAlt",
|
|
15408
|
+
// Temporary variable — used by the compiler for intermediate
|
|
15409
|
+
// expression results in generated code (e.g. loop variables,
|
|
15410
|
+
// conditional branches). Declared as: let $tmp
|
|
15411
|
+
"$tmp",
|
|
15412
|
+
// JS literals
|
|
15413
|
+
"undefined",
|
|
15414
|
+
"null",
|
|
15415
|
+
"true",
|
|
15416
|
+
"false",
|
|
15417
|
+
"NaN",
|
|
15418
|
+
"Infinity",
|
|
15419
|
+
// JS built-in globals
|
|
15420
|
+
"window",
|
|
15421
|
+
"self",
|
|
15422
|
+
"globalThis",
|
|
15423
|
+
"document",
|
|
15424
|
+
"console",
|
|
15425
|
+
"JSON",
|
|
15426
|
+
"Math",
|
|
15427
|
+
"Intl",
|
|
15428
|
+
"Promise",
|
|
15429
|
+
"Symbol",
|
|
15430
|
+
"Number",
|
|
15431
|
+
"String",
|
|
15432
|
+
"Boolean",
|
|
15433
|
+
"Array",
|
|
15434
|
+
"Object",
|
|
15435
|
+
"Date",
|
|
15436
|
+
"RegExp",
|
|
15437
|
+
"Error",
|
|
15438
|
+
"TypeError",
|
|
15439
|
+
"RangeError",
|
|
15440
|
+
"SyntaxError",
|
|
15441
|
+
"Map",
|
|
15442
|
+
"Set",
|
|
15443
|
+
"WeakMap",
|
|
15444
|
+
"WeakSet",
|
|
15445
|
+
"Proxy",
|
|
15446
|
+
"Reflect",
|
|
15447
|
+
"ArrayBuffer",
|
|
15448
|
+
"DataView",
|
|
15449
|
+
"Float32Array",
|
|
15450
|
+
"Float64Array",
|
|
15451
|
+
"Int8Array",
|
|
15452
|
+
"Int16Array",
|
|
15453
|
+
"Int32Array",
|
|
15454
|
+
"Uint8Array",
|
|
15455
|
+
"Uint16Array",
|
|
15456
|
+
"Uint32Array",
|
|
15457
|
+
"Uint8ClampedArray",
|
|
15458
|
+
// Functions
|
|
15459
|
+
"parseInt",
|
|
15460
|
+
"parseFloat",
|
|
15461
|
+
"isNaN",
|
|
15462
|
+
"isFinite",
|
|
15463
|
+
"encodeURIComponent",
|
|
15464
|
+
"decodeURIComponent",
|
|
15465
|
+
"encodeURI",
|
|
15466
|
+
"decodeURI",
|
|
15467
|
+
// SWC helpers
|
|
15468
|
+
"arguments",
|
|
15469
|
+
"this",
|
|
15470
|
+
"require",
|
|
15471
|
+
// Lark framework
|
|
15472
|
+
"Lark"
|
|
15473
|
+
]);
|
|
15474
|
+
|
|
15475
|
+
// src/compiler/extract-global-vars.ts
|
|
15476
|
+
var import_parser = __toESM(require_lib(), 1);
|
|
15477
|
+
async function extractGlobalVars2(source) {
|
|
15061
15478
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15062
15479
|
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15063
15480
|
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
@@ -15094,10 +15511,10 @@ function extractGlobalVars(source) {
|
|
|
15094
15511
|
allowAwaitOutsideFunction: true
|
|
15095
15512
|
});
|
|
15096
15513
|
} catch {
|
|
15097
|
-
return
|
|
15514
|
+
return fallbackExtractVariables2(source);
|
|
15098
15515
|
}
|
|
15099
15516
|
const globalExists = {};
|
|
15100
|
-
for (const name of
|
|
15517
|
+
for (const name of BUILTIN_GLOBALS2) globalExists[name] = 1;
|
|
15101
15518
|
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15102
15519
|
const fnRange = [];
|
|
15103
15520
|
walkAst(ast, {
|
|
@@ -15156,7 +15573,7 @@ function extractGlobalVars(source) {
|
|
|
15156
15573
|
});
|
|
15157
15574
|
return Object.keys(globalVars);
|
|
15158
15575
|
}
|
|
15159
|
-
function
|
|
15576
|
+
function fallbackExtractVariables2(source) {
|
|
15160
15577
|
const vars = /* @__PURE__ */ new Set();
|
|
15161
15578
|
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15162
15579
|
let m;
|
|
@@ -15171,7 +15588,7 @@ function fallbackExtractVariables(source) {
|
|
|
15171
15588
|
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15172
15589
|
vars.add(m[1]);
|
|
15173
15590
|
}
|
|
15174
|
-
return Array.from(vars).filter((v) => !
|
|
15591
|
+
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS2.has(v));
|
|
15175
15592
|
}
|
|
15176
15593
|
function walkAst(ast, visitors) {
|
|
15177
15594
|
function visit(node) {
|
|
@@ -15179,7 +15596,6 @@ function walkAst(ast, visitors) {
|
|
|
15179
15596
|
if (visitors[type]) {
|
|
15180
15597
|
visitors[type](node);
|
|
15181
15598
|
}
|
|
15182
|
-
const bag = node;
|
|
15183
15599
|
for (const key of Object.keys(node)) {
|
|
15184
15600
|
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range")
|
|
15185
15601
|
continue;
|
|
@@ -15195,7 +15611,7 @@ function walkAst(ast, visitors) {
|
|
|
15195
15611
|
const om = node;
|
|
15196
15612
|
if (!om.computed) continue;
|
|
15197
15613
|
}
|
|
15198
|
-
const child =
|
|
15614
|
+
const child = Reflect.get(node, key);
|
|
15199
15615
|
if (Array.isArray(child)) {
|
|
15200
15616
|
for (const item of child) {
|
|
15201
15617
|
if (isAstNode(item)) visit(item);
|
|
@@ -15210,7 +15626,7 @@ function walkAst(ast, visitors) {
|
|
|
15210
15626
|
function isAstNode(v) {
|
|
15211
15627
|
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15212
15628
|
}
|
|
15213
|
-
var
|
|
15629
|
+
var BUILTIN_GLOBALS2 = /* @__PURE__ */ new Set([
|
|
15214
15630
|
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15215
15631
|
//
|
|
15216
15632
|
// These variables appear in the generated template function signature
|
|
@@ -15359,8 +15775,132 @@ var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
|
15359
15775
|
// Lark framework
|
|
15360
15776
|
"Lark"
|
|
15361
15777
|
]);
|
|
15778
|
+
|
|
15779
|
+
// src/compiler/compile-template.ts
|
|
15780
|
+
function compileToFunction(source, debug, file) {
|
|
15781
|
+
const matcher = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15782
|
+
let index = 0;
|
|
15783
|
+
let funcSource = `$out+='`;
|
|
15784
|
+
let hasAtRule = false;
|
|
15785
|
+
const escapeSlashRegExp = /\\|'/g;
|
|
15786
|
+
const escapeBreakReturnRegExp = /\r|\n/g;
|
|
15787
|
+
source.replace(matcher, (match, operate, content, offset) => {
|
|
15788
|
+
funcSource += source.substring(index, offset).replace(escapeSlashRegExp, "\\$&").replace(escapeBreakReturnRegExp, "\\n");
|
|
15789
|
+
index = offset + match.length;
|
|
15790
|
+
if (debug) {
|
|
15791
|
+
let expr = source.substring(
|
|
15792
|
+
index - match.length + 2 + (operate ? 1 : 0),
|
|
15793
|
+
index - 2
|
|
15794
|
+
);
|
|
15795
|
+
const x11 = String.fromCharCode(17);
|
|
15796
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
15797
|
+
const artM = expr.match(artRegExp);
|
|
15798
|
+
let art = "";
|
|
15799
|
+
let line = -1;
|
|
15800
|
+
if (artM) {
|
|
15801
|
+
expr = expr.replace(artRegExp, "");
|
|
15802
|
+
art = artM[2];
|
|
15803
|
+
line = parseInt(artM[1], 10);
|
|
15804
|
+
} else {
|
|
15805
|
+
expr = expr.replace(escapeSlashRegExp, "\\$&").replace(escapeBreakReturnRegExp, "\\n");
|
|
15806
|
+
}
|
|
15807
|
+
if (operate === "@") {
|
|
15808
|
+
hasAtRule = true;
|
|
15809
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',$refFn($refAlt,${content}))+'`;
|
|
15810
|
+
} else if (operate === "=" || operate === ":") {
|
|
15811
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',$encHtml(${content}))+'`;
|
|
15812
|
+
} else if (operate === "!") {
|
|
15813
|
+
if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
|
|
15814
|
+
content = `$strSafe(${content})`;
|
|
15815
|
+
}
|
|
15816
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',${content})+'`;
|
|
15817
|
+
} else if (content) {
|
|
15818
|
+
if (line > -1) {
|
|
15819
|
+
funcSource += `';$dbgLine=${line};$dbgArt='${art}';`;
|
|
15820
|
+
content = "";
|
|
15821
|
+
} else {
|
|
15822
|
+
funcSource += `';`;
|
|
15823
|
+
}
|
|
15824
|
+
if (funcSource.endsWith(`+'';`)) {
|
|
15825
|
+
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15826
|
+
}
|
|
15827
|
+
if (expr) {
|
|
15828
|
+
funcSource += `$dbgExpr='<%${expr}%>';`;
|
|
15829
|
+
}
|
|
15830
|
+
funcSource += content + `;$out+='`;
|
|
15831
|
+
}
|
|
15832
|
+
} else {
|
|
15833
|
+
if (operate === "@") {
|
|
15834
|
+
hasAtRule = true;
|
|
15835
|
+
funcSource += `'+$refFn($refAlt,${content})+'`;
|
|
15836
|
+
} else if (operate === "=" || operate === ":") {
|
|
15837
|
+
funcSource += `'+$encHtml(${content})+'`;
|
|
15838
|
+
} else if (operate === "!") {
|
|
15839
|
+
if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
|
|
15840
|
+
content = `$strSafe(${content})`;
|
|
15841
|
+
}
|
|
15842
|
+
funcSource += `'+${content}+'`;
|
|
15843
|
+
} else if (content) {
|
|
15844
|
+
funcSource += `';`;
|
|
15845
|
+
if (funcSource.endsWith(`+'';`)) {
|
|
15846
|
+
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15847
|
+
}
|
|
15848
|
+
funcSource += `${content};$out+='`;
|
|
15849
|
+
}
|
|
15850
|
+
}
|
|
15851
|
+
return match;
|
|
15852
|
+
});
|
|
15853
|
+
funcSource += `';`;
|
|
15854
|
+
funcSource = funcSource.replace(/\$out\+='';/g, "");
|
|
15855
|
+
funcSource = funcSource.replace(/\$out\+=''\+/g, "$out+=");
|
|
15856
|
+
if (debug) {
|
|
15857
|
+
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15858
|
+
funcSource = `let $dbgExpr,$dbgArt,$dbgLine;try{${funcSource}}catch(ex){let msg='render view error:'+(ex.message||ex);if($dbgArt)msg+='\\r\\n\\tsrc art:{{'+$dbgArt+'}}\\r\\n\\tat line:'+$dbgLine;msg+='\\r\\n\\t'+($dbgArt?'translate to:':'expr:');msg+=$dbgExpr+'${filePart}';throw msg;}`;
|
|
15859
|
+
}
|
|
15860
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15861
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15862
|
+
void hasAtRule;
|
|
15863
|
+
const refFallback = "if(!$refAlt)$refAlt=$data;";
|
|
15864
|
+
const fullSource = `${refFallback}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
|
|
15865
|
+
return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
|
|
15866
|
+
}
|
|
15867
|
+
async function compileTemplate(source, options = {}) {
|
|
15868
|
+
const { debug = false, file, virtualDom = false, useSwc = false } = options;
|
|
15869
|
+
const globalVars = options.globalVars ?? await (useSwc ? extractGlobalVars(source) : extractGlobalVars2(source));
|
|
15870
|
+
const { protectedSource, comments } = protectComments(source);
|
|
15871
|
+
const converted = convertArtSyntax(protectedSource, debug);
|
|
15872
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
15873
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
15874
|
+
const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
|
|
15875
|
+
if (virtualDom) {
|
|
15876
|
+
const funcBody2 = compileToVDomFunction(finalSource, debug, file);
|
|
15877
|
+
const funcWithVars2 = funcBody2.replace("{{VARS}}", () => varDeclarations);
|
|
15878
|
+
return `import { vdomCreate as __larkC } from "@lark.js/mvc";
|
|
15879
|
+
import { strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
|
|
15880
|
+
export default function(data, viewId, refData) {
|
|
15881
|
+
let $data = data || {},
|
|
15882
|
+
$viewId = viewId || '',
|
|
15883
|
+
$c = __larkC,
|
|
15884
|
+
$n = __larkStrSafe;
|
|
15885
|
+
return (${funcWithVars2})($data, $viewId, refData,
|
|
15886
|
+
$n, __larkRefFn, __larkEncUri, __larkEncQuote
|
|
15887
|
+
);
|
|
15888
|
+
}`;
|
|
15889
|
+
}
|
|
15890
|
+
const funcBody = compileToFunction(finalSource, debug, file);
|
|
15891
|
+
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
15892
|
+
return `import { encHtml as __larkEncHtml, strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
|
|
15893
|
+
export default function(data, viewId, refData) {
|
|
15894
|
+
let $data = data || {},
|
|
15895
|
+
$viewId = viewId || '';
|
|
15896
|
+
return (${funcWithVars})($data, $viewId, refData,
|
|
15897
|
+
__larkEncHtml, __larkStrSafe, __larkEncUri, __larkRefFn, __larkEncQuote
|
|
15898
|
+
);
|
|
15899
|
+
}`;
|
|
15900
|
+
}
|
|
15362
15901
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15363
15902
|
0 && (module.exports = {
|
|
15364
15903
|
compileTemplate,
|
|
15365
|
-
extractGlobalVars
|
|
15904
|
+
extractGlobalVars,
|
|
15905
|
+
extractGlobalVarsSwc
|
|
15366
15906
|
});
|