@lark.js/mvc 0.0.9 → 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 -32
- package/dist/chunk-RIV4NK3K.js +108 -0
- package/dist/compiler.cjs +733 -193
- package/dist/compiler.d.cts +35 -35
- package/dist/compiler.d.ts +35 -35
- package/dist/compiler.js +730 -193
- 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 +811 -319
- package/dist/index.d.cts +247 -491
- package/dist/index.d.ts +247 -491
- package/dist/index.js +808 -280
- package/dist/rspack.cjs +15978 -0
- package/dist/rspack.d.cts +122 -0
- package/dist/rspack.d.ts +122 -0
- package/dist/{chunk-3HSA7OHB.js → rspack.js} +809 -193
- package/dist/runtime.cjs +35 -10
- package/dist/runtime.d.cts +22 -13
- package/dist/runtime.d.ts +22 -13
- package/dist/runtime.js +13 -34
- package/dist/vite.cjs +753 -195
- package/dist/vite.d.cts +3 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +15917 -10
- package/dist/webpack.cjs +798 -201
- 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
|
@@ -4,6 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
7
10
|
var __commonJS = (cb, mod) => function __require() {
|
|
8
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
12
|
};
|
|
@@ -24,10 +27,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
27
|
mod
|
|
25
28
|
));
|
|
26
29
|
|
|
30
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.41_@swc+helpers@0.5.23__jiti@2.7.0_postcss@8.5.15_tsx@4.22.4_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/esm_shims.js
|
|
31
|
+
import path from "path";
|
|
32
|
+
import { fileURLToPath } from "url";
|
|
33
|
+
var getFilename, __filename;
|
|
34
|
+
var init_esm_shims = __esm({
|
|
35
|
+
"../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.41_@swc+helpers@0.5.23__jiti@2.7.0_postcss@8.5.15_tsx@4.22.4_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/esm_shims.js"() {
|
|
36
|
+
"use strict";
|
|
37
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
38
|
+
__filename = /* @__PURE__ */ getFilename();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
27
42
|
// ../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
|
|
28
43
|
var require_lib = __commonJS({
|
|
29
44
|
"../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports) {
|
|
30
45
|
"use strict";
|
|
46
|
+
init_esm_shims();
|
|
31
47
|
Object.defineProperty(exports, "__esModule", {
|
|
32
48
|
value: true
|
|
33
49
|
});
|
|
@@ -14512,7 +14528,7 @@ var require_lib = __commonJS({
|
|
|
14512
14528
|
options = Object.assign({}, options);
|
|
14513
14529
|
try {
|
|
14514
14530
|
options.sourceType = "module";
|
|
14515
|
-
const parser =
|
|
14531
|
+
const parser = getParser2(options, input);
|
|
14516
14532
|
const ast = parser.parse();
|
|
14517
14533
|
if (parser.sawUnambiguousESM) {
|
|
14518
14534
|
return ast;
|
|
@@ -14520,7 +14536,7 @@ var require_lib = __commonJS({
|
|
|
14520
14536
|
if (parser.ambiguousScriptDifferentAst) {
|
|
14521
14537
|
try {
|
|
14522
14538
|
options.sourceType = "script";
|
|
14523
|
-
return
|
|
14539
|
+
return getParser2(options, input).parse();
|
|
14524
14540
|
} catch (_unused) {
|
|
14525
14541
|
}
|
|
14526
14542
|
} else {
|
|
@@ -14530,17 +14546,17 @@ var require_lib = __commonJS({
|
|
|
14530
14546
|
} catch (moduleError) {
|
|
14531
14547
|
try {
|
|
14532
14548
|
options.sourceType = "script";
|
|
14533
|
-
return
|
|
14549
|
+
return getParser2(options, input).parse();
|
|
14534
14550
|
} catch (_unused2) {
|
|
14535
14551
|
}
|
|
14536
14552
|
throw moduleError;
|
|
14537
14553
|
}
|
|
14538
14554
|
} else {
|
|
14539
|
-
return
|
|
14555
|
+
return getParser2(options, input).parse();
|
|
14540
14556
|
}
|
|
14541
14557
|
}
|
|
14542
14558
|
function parseExpression(input, options) {
|
|
14543
|
-
const parser =
|
|
14559
|
+
const parser = getParser2(options, input);
|
|
14544
14560
|
if (parser.options.strictMode) {
|
|
14545
14561
|
parser.state.strict = true;
|
|
14546
14562
|
}
|
|
@@ -14554,7 +14570,7 @@ var require_lib = __commonJS({
|
|
|
14554
14570
|
return tokenTypes2;
|
|
14555
14571
|
}
|
|
14556
14572
|
var tokTypes = generateExportedTokenTypes(tt);
|
|
14557
|
-
function
|
|
14573
|
+
function getParser2(options, input) {
|
|
14558
14574
|
let cls = Parser;
|
|
14559
14575
|
const pluginsMap = /* @__PURE__ */ new Map();
|
|
14560
14576
|
if (options != null && options.plugins) {
|
|
@@ -14599,8 +14615,17 @@ var require_lib = __commonJS({
|
|
|
14599
14615
|
}
|
|
14600
14616
|
});
|
|
14601
14617
|
|
|
14618
|
+
// src/rspack.ts
|
|
14619
|
+
init_esm_shims();
|
|
14620
|
+
|
|
14602
14621
|
// src/compiler.ts
|
|
14603
|
-
|
|
14622
|
+
init_esm_shims();
|
|
14623
|
+
|
|
14624
|
+
// src/compiler/compile-template.ts
|
|
14625
|
+
init_esm_shims();
|
|
14626
|
+
|
|
14627
|
+
// src/compiler/template-syntax.ts
|
|
14628
|
+
init_esm_shims();
|
|
14604
14629
|
var SPLITTER = String.fromCharCode(30);
|
|
14605
14630
|
var VIEW_ID_PLACEHOLDER = String.fromCharCode(31);
|
|
14606
14631
|
function jsObjectToUrlParams(paramsStr) {
|
|
@@ -14721,7 +14746,7 @@ function convertArtSyntax(source, debug) {
|
|
|
14721
14746
|
}
|
|
14722
14747
|
if (blockStack.length > 0) {
|
|
14723
14748
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
14724
|
-
throw new Error(`
|
|
14749
|
+
throw new Error(`Unclosed block(s): ${unclosed}`);
|
|
14725
14750
|
}
|
|
14726
14751
|
return result.join("");
|
|
14727
14752
|
}
|
|
@@ -14820,7 +14845,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14820
14845
|
const object = tokens[0];
|
|
14821
14846
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14822
14847
|
throw new Error(
|
|
14823
|
-
`
|
|
14848
|
+
`Bad forOf syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forOf list as item [index]}}`
|
|
14824
14849
|
);
|
|
14825
14850
|
}
|
|
14826
14851
|
const restTokens = tokens.slice(2);
|
|
@@ -14847,7 +14872,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14847
14872
|
const object = tokens[0];
|
|
14848
14873
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14849
14874
|
throw new Error(
|
|
14850
|
-
`
|
|
14875
|
+
`Bad forIn syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forIn obj as val [key]}}`
|
|
14851
14876
|
);
|
|
14852
14877
|
}
|
|
14853
14878
|
const restTokens2 = tokens.slice(2);
|
|
@@ -14873,13 +14898,11 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14873
14898
|
const expectedCtrl = keyword.substring(1);
|
|
14874
14899
|
const last = blockStack.pop();
|
|
14875
14900
|
if (!last) {
|
|
14876
|
-
throw new Error(
|
|
14877
|
-
`[@lark.js/mvc error] unexpected {{${code}}}: no matching open block`
|
|
14878
|
-
);
|
|
14901
|
+
throw new Error(`Unexpected {{${code}}}: no matching open block`);
|
|
14879
14902
|
}
|
|
14880
14903
|
if (last.ctrl !== expectedCtrl) {
|
|
14881
14904
|
throw new Error(
|
|
14882
|
-
`
|
|
14905
|
+
`Unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14883
14906
|
);
|
|
14884
14907
|
}
|
|
14885
14908
|
return `${debugPrefix}<%}%>`;
|
|
@@ -14940,112 +14963,532 @@ function parseAsExpr(expr) {
|
|
|
14940
14963
|
bad: false
|
|
14941
14964
|
};
|
|
14942
14965
|
}
|
|
14943
|
-
|
|
14944
|
-
|
|
14945
|
-
|
|
14946
|
-
|
|
14947
|
-
|
|
14948
|
-
|
|
14949
|
-
|
|
14950
|
-
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
|
|
14954
|
-
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14966
|
+
|
|
14967
|
+
// src/compiler/compile-to-vdom-function.ts
|
|
14968
|
+
init_esm_shims();
|
|
14969
|
+
import { parseDocument } from "htmlparser2";
|
|
14970
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
14971
|
+
"area",
|
|
14972
|
+
"base",
|
|
14973
|
+
"br",
|
|
14974
|
+
"col",
|
|
14975
|
+
"embed",
|
|
14976
|
+
"hr",
|
|
14977
|
+
"img",
|
|
14978
|
+
"input",
|
|
14979
|
+
"link",
|
|
14980
|
+
"meta",
|
|
14981
|
+
"param",
|
|
14982
|
+
"source",
|
|
14983
|
+
"track",
|
|
14984
|
+
"wbr"
|
|
14985
|
+
]);
|
|
14986
|
+
function vdomEscapeStr(s) {
|
|
14987
|
+
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\x1e/g, "\\x1e");
|
|
14988
|
+
}
|
|
14989
|
+
function vdomResolveAttrValue(rawValue, exprStore) {
|
|
14990
|
+
const hasPlaceholders = rawValue.includes("\0");
|
|
14991
|
+
const hasViewId = rawValue.includes("");
|
|
14992
|
+
if (!hasPlaceholders && !hasViewId) {
|
|
14993
|
+
return `'${vdomEscapeStr(rawValue)}'`;
|
|
14994
|
+
}
|
|
14995
|
+
const segments = [];
|
|
14996
|
+
let remaining = rawValue;
|
|
14997
|
+
while (remaining.length > 0) {
|
|
14998
|
+
const phIdx = remaining.indexOf("\0");
|
|
14999
|
+
const viIdx = remaining.indexOf("");
|
|
15000
|
+
let nextSpecial = -1;
|
|
15001
|
+
let specialType = null;
|
|
15002
|
+
if (phIdx >= 0 && (viIdx < 0 || phIdx <= viIdx)) {
|
|
15003
|
+
nextSpecial = phIdx;
|
|
15004
|
+
specialType = "ph";
|
|
15005
|
+
} else if (viIdx >= 0) {
|
|
15006
|
+
nextSpecial = viIdx;
|
|
15007
|
+
specialType = "vi";
|
|
15008
|
+
}
|
|
15009
|
+
if (nextSpecial === -1) {
|
|
15010
|
+
if (remaining) segments.push(`'${vdomEscapeStr(remaining)}'`);
|
|
15011
|
+
break;
|
|
15012
|
+
}
|
|
15013
|
+
if (nextSpecial > 0) {
|
|
15014
|
+
segments.push(`'${vdomEscapeStr(remaining.substring(0, nextSpecial))}'`);
|
|
15015
|
+
}
|
|
15016
|
+
if (specialType === "vi") {
|
|
15017
|
+
segments.push("$viewId");
|
|
15018
|
+
remaining = remaining.substring(nextSpecial + 1);
|
|
15019
|
+
} else {
|
|
15020
|
+
const closeIdx = remaining.indexOf("\0", nextSpecial + 1);
|
|
15021
|
+
if (closeIdx === -1) {
|
|
15022
|
+
segments.push(`'${vdomEscapeStr(remaining.substring(nextSpecial))}'`);
|
|
15023
|
+
break;
|
|
14969
15024
|
}
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
content = `$strSafe(${content})`;
|
|
14978
|
-
}
|
|
14979
|
-
funcSource += `'+($dbgExpr='<%${operate + expr}%>',${content})+'`;
|
|
14980
|
-
} else if (content) {
|
|
14981
|
-
if (line > -1) {
|
|
14982
|
-
funcSource += `';$dbgLine=${line};$dbgArt='${art}';`;
|
|
14983
|
-
content = "";
|
|
15025
|
+
const idx = parseInt(remaining.substring(nextSpecial + 1, closeIdx));
|
|
15026
|
+
const expr = exprStore[idx];
|
|
15027
|
+
if (expr.op === "=" || expr.op === ":") {
|
|
15028
|
+
segments.push(`$n(${expr.content})`);
|
|
15029
|
+
} else if (expr.op === "!") {
|
|
15030
|
+
if (expr.content.startsWith("$encUri(") && expr.content.endsWith(")")) {
|
|
15031
|
+
segments.push(expr.content);
|
|
14984
15032
|
} else {
|
|
14985
|
-
|
|
14986
|
-
}
|
|
14987
|
-
if (funcSource.endsWith(`+'';`)) {
|
|
14988
|
-
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15033
|
+
segments.push(`$n(${expr.content})`);
|
|
14989
15034
|
}
|
|
14990
|
-
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
15035
|
+
} else if (expr.op === "@") {
|
|
15036
|
+
segments.push(`$refFn($refAlt,${expr.content})`);
|
|
15037
|
+
} else {
|
|
15038
|
+
segments.push(`$n(${expr.content})`);
|
|
14994
15039
|
}
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15040
|
+
remaining = remaining.substring(closeIdx + 1);
|
|
15041
|
+
}
|
|
15042
|
+
}
|
|
15043
|
+
if (segments.length === 0) return "''";
|
|
15044
|
+
if (segments.length === 1) return segments[0];
|
|
15045
|
+
return segments.join("+");
|
|
15046
|
+
}
|
|
15047
|
+
function vdomBuildPropsFromAttribs(attribs, exprStore) {
|
|
15048
|
+
if (!attribs) return "null";
|
|
15049
|
+
const keys = Object.keys(attribs);
|
|
15050
|
+
if (keys.length === 0) return "null";
|
|
15051
|
+
const entries = [];
|
|
15052
|
+
for (const name of keys) {
|
|
15053
|
+
const value = attribs[name];
|
|
15054
|
+
const valueExpr = vdomResolveAttrValue(value, exprStore);
|
|
15055
|
+
entries.push(`'${vdomEscapeStr(name)}':${valueExpr}`);
|
|
15056
|
+
}
|
|
15057
|
+
return `{${entries.join(",")}}`;
|
|
15058
|
+
}
|
|
15059
|
+
function compileToVDomFunction(source, debug, file) {
|
|
15060
|
+
const lines = [];
|
|
15061
|
+
let varCounter = 0;
|
|
15062
|
+
let propsCounter = 0;
|
|
15063
|
+
const exprStore = [];
|
|
15064
|
+
const protectedSource = source.replace(
|
|
15065
|
+
/<%([@=!:])?([\s\S]*?)%>/g,
|
|
15066
|
+
(_, op, content) => {
|
|
15067
|
+
const idx = exprStore.length;
|
|
15068
|
+
exprStore.push({ op: op || "", content: (content || "").trim() });
|
|
15069
|
+
return `\0${idx}\0`;
|
|
15070
|
+
}
|
|
15071
|
+
);
|
|
15072
|
+
const doc = parseDocument(protectedSource, {
|
|
15073
|
+
recognizeSelfClosing: true,
|
|
15074
|
+
lowerCaseTags: false,
|
|
15075
|
+
lowerCaseAttributeNames: false,
|
|
15076
|
+
decodeEntities: false
|
|
15077
|
+
});
|
|
15078
|
+
const rootVar = `$v${varCounter++}`;
|
|
15079
|
+
lines.push(`let ${rootVar}=[]`);
|
|
15080
|
+
const maxVars = 30;
|
|
15081
|
+
const varDecls = [];
|
|
15082
|
+
for (let i = 1; i < maxVars; i++) {
|
|
15083
|
+
varDecls.push(`$v${i}`);
|
|
15084
|
+
}
|
|
15085
|
+
lines.push(`let ${varDecls.join(",")}`);
|
|
15086
|
+
function allocVar() {
|
|
15087
|
+
if (varCounter >= maxVars) return `$v${maxVars - 1}`;
|
|
15088
|
+
return `$v${varCounter++}`;
|
|
15089
|
+
}
|
|
15090
|
+
function emitNode(node, parentVar) {
|
|
15091
|
+
const type = node.type;
|
|
15092
|
+
if (type === "text") {
|
|
15093
|
+
emitText(node.data || "", parentVar);
|
|
15094
|
+
} else if (type === "tag" || type === "script" || type === "style") {
|
|
15095
|
+
emitElement(node, parentVar);
|
|
15096
|
+
}
|
|
15097
|
+
}
|
|
15098
|
+
function emitText(text, parentVar) {
|
|
15099
|
+
const parts = text.split(/\x00(\d+)\x00/);
|
|
15100
|
+
for (let i = 0; i < parts.length; i++) {
|
|
15101
|
+
if (i % 2 === 0) {
|
|
15102
|
+
const trimmed = parts[i];
|
|
15103
|
+
if (trimmed.trim()) {
|
|
15104
|
+
lines.push(`${parentVar}.push($c(0,'${vdomEscapeStr(trimmed)}'))`);
|
|
15010
15105
|
}
|
|
15011
|
-
|
|
15106
|
+
} else {
|
|
15107
|
+
const idx = parseInt(parts[i]);
|
|
15108
|
+
const expr = exprStore[idx];
|
|
15109
|
+
emitExpr(expr, parentVar);
|
|
15012
15110
|
}
|
|
15013
15111
|
}
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15112
|
+
}
|
|
15113
|
+
function emitExpr(expr, parentVar) {
|
|
15114
|
+
if (expr.op === "=" || expr.op === ":") {
|
|
15115
|
+
lines.push(`${parentVar}.push($c(0,$n(${expr.content})))`);
|
|
15116
|
+
} else if (expr.op === "!") {
|
|
15117
|
+
if (expr.content.startsWith("$encUri(") && expr.content.endsWith(")")) {
|
|
15118
|
+
lines.push(`${parentVar}.push($c(0,${expr.content}))`);
|
|
15119
|
+
} else {
|
|
15120
|
+
lines.push(`${parentVar}.push($c(0,$n(${expr.content})))`);
|
|
15121
|
+
}
|
|
15122
|
+
} else if (expr.op === "@") {
|
|
15123
|
+
lines.push(`${parentVar}.push($c(0,$refFn($refAlt,${expr.content})))`);
|
|
15124
|
+
} else if (expr.content) {
|
|
15125
|
+
lines.push(expr.content);
|
|
15126
|
+
}
|
|
15127
|
+
}
|
|
15128
|
+
function emitElement(node, parentVar) {
|
|
15129
|
+
const tagName = node.name || "";
|
|
15130
|
+
const children = node.children || [];
|
|
15131
|
+
const childVar = allocVar();
|
|
15132
|
+
const propsKey = `__p${propsCounter++}`;
|
|
15133
|
+
const props = vdomBuildPropsFromAttribs(node.attribs, exprStore);
|
|
15134
|
+
lines.push(`let ${propsKey}=${props}`);
|
|
15135
|
+
lines.push(`${childVar}=[]`);
|
|
15136
|
+
for (const child of children) {
|
|
15137
|
+
emitNode(child, childVar);
|
|
15138
|
+
}
|
|
15139
|
+
const isVoid = VOID_ELEMENTS.has(tagName) && children.length === 0;
|
|
15140
|
+
const childrenArg = isVoid ? "1" : childVar;
|
|
15141
|
+
lines.push(
|
|
15142
|
+
`${parentVar}.push($c('${tagName}',${propsKey},${childrenArg}))`
|
|
15143
|
+
);
|
|
15144
|
+
}
|
|
15145
|
+
for (const child of doc.children) {
|
|
15146
|
+
emitNode(child, rootVar);
|
|
15147
|
+
}
|
|
15148
|
+
lines.push(`return $c($viewId,0,${rootVar})`);
|
|
15149
|
+
const body = lines.join(";");
|
|
15150
|
+
let funcBody = body;
|
|
15019
15151
|
if (debug) {
|
|
15020
15152
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15021
|
-
|
|
15153
|
+
funcBody = `let $dbgExpr,$dbgArt,$dbgLine;try{${body}}catch(ex){let msg='render view error:'+(ex.message||ex);msg+='${filePart}';throw msg;}`;
|
|
15022
15154
|
}
|
|
15023
15155
|
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15024
|
-
|
|
15025
|
-
void hasAtRule;
|
|
15156
|
+
funcBody = funcBody.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15026
15157
|
const refFallback = "if(!$refAlt)$refAlt=$data;";
|
|
15027
|
-
const fullSource = `${refFallback}let $splitter='\\x1e'
|
|
15028
|
-
return `($data,$viewId,$refAlt,$
|
|
15158
|
+
const fullSource = `${refFallback}let $splitter='\\x1e'{{VARS}};${funcBody}`;
|
|
15159
|
+
return `($data,$viewId,$refAlt,$n,$refFn,$encUri,$encQuote)=>{${fullSource}}`;
|
|
15029
15160
|
}
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15161
|
+
|
|
15162
|
+
// src/compiler/swc/extract-global-vars.ts
|
|
15163
|
+
init_esm_shims();
|
|
15164
|
+
var parseSyncFn = null;
|
|
15165
|
+
var parseSyncLoadAttempted = false;
|
|
15166
|
+
async function getParser() {
|
|
15167
|
+
if (!parseSyncLoadAttempted) {
|
|
15168
|
+
parseSyncLoadAttempted = true;
|
|
15169
|
+
try {
|
|
15170
|
+
const swc = await import("@swc/core");
|
|
15171
|
+
parseSyncFn = swc.parseSync;
|
|
15172
|
+
} catch (err) {
|
|
15173
|
+
console.error("failed to load @swc/core", err);
|
|
15174
|
+
}
|
|
15175
|
+
}
|
|
15176
|
+
return parseSyncFn;
|
|
15177
|
+
}
|
|
15178
|
+
async function extractGlobalVars(source) {
|
|
15179
|
+
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15180
|
+
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15181
|
+
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15182
|
+
const template = restoreComments(converted, _comments);
|
|
15183
|
+
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15184
|
+
const fnParts = [];
|
|
15185
|
+
const htmlStore = {};
|
|
15186
|
+
let htmlIndex = 0;
|
|
15187
|
+
let lastIndex = 0;
|
|
15188
|
+
const htmlKey = String.fromCharCode(5);
|
|
15189
|
+
template.replace(
|
|
15190
|
+
templateCmdRegExp,
|
|
15191
|
+
(match, operate, content, offset) => {
|
|
15192
|
+
const start = operate ? 3 : 2;
|
|
15193
|
+
const htmlText = template.substring(lastIndex, offset + start);
|
|
15194
|
+
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15195
|
+
htmlStore[key] = htmlText;
|
|
15196
|
+
lastIndex = offset + match.length - 2;
|
|
15197
|
+
if (operate && content.trim()) {
|
|
15198
|
+
fnParts.push(';"' + key + '";', "[" + content + "]");
|
|
15199
|
+
} else {
|
|
15200
|
+
fnParts.push(';"' + key + '";', content || "");
|
|
15201
|
+
}
|
|
15202
|
+
return match;
|
|
15203
|
+
}
|
|
15045
15204
|
);
|
|
15046
|
-
|
|
15205
|
+
let fn = fnParts.join("");
|
|
15206
|
+
fn = `(function(){${fn}})`;
|
|
15207
|
+
const parseSync = await getParser();
|
|
15208
|
+
if (!parseSync) {
|
|
15209
|
+
return fallbackExtractVariables(source);
|
|
15210
|
+
}
|
|
15211
|
+
let ast;
|
|
15212
|
+
try {
|
|
15213
|
+
ast = parseSync(fn, {
|
|
15214
|
+
syntax: "ecmascript",
|
|
15215
|
+
target: "es2022"
|
|
15216
|
+
});
|
|
15217
|
+
} catch {
|
|
15218
|
+
return fallbackExtractVariables(source);
|
|
15219
|
+
}
|
|
15220
|
+
const globalExists = {};
|
|
15221
|
+
for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
|
|
15222
|
+
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15223
|
+
const fnNodes = [];
|
|
15224
|
+
walkSwcAst(ast, {
|
|
15225
|
+
VariableDeclarator(node) {
|
|
15226
|
+
if (node.id.type === "Identifier") {
|
|
15227
|
+
const name = node.id.value;
|
|
15228
|
+
globalExists[name] = node.init ? 3 : 2;
|
|
15229
|
+
}
|
|
15230
|
+
},
|
|
15231
|
+
FunctionDeclaration(node) {
|
|
15232
|
+
if (node.identifier) {
|
|
15233
|
+
globalExists[node.identifier.value] = 3;
|
|
15234
|
+
}
|
|
15235
|
+
fnNodes.push(node);
|
|
15236
|
+
},
|
|
15237
|
+
FunctionExpression(node) {
|
|
15238
|
+
fnNodes.push(node);
|
|
15239
|
+
},
|
|
15240
|
+
ArrowFunctionExpression(node) {
|
|
15241
|
+
fnNodes.push(node);
|
|
15242
|
+
},
|
|
15243
|
+
CallExpression(node) {
|
|
15244
|
+
if (node.callee.type === "Identifier") {
|
|
15245
|
+
globalExists[node.callee.value] = 1;
|
|
15246
|
+
}
|
|
15247
|
+
}
|
|
15248
|
+
});
|
|
15249
|
+
const functionParams = /* @__PURE__ */ Object.create(null);
|
|
15250
|
+
for (const fnNode of fnNodes) {
|
|
15251
|
+
const patterns = getParamPatterns(fnNode);
|
|
15252
|
+
for (const pat of patterns) {
|
|
15253
|
+
if (pat.type === "Identifier") {
|
|
15254
|
+
functionParams[pat.value] = 1;
|
|
15255
|
+
} else if (pat.type === "AssignmentPattern" && pat.left.type === "Identifier") {
|
|
15256
|
+
functionParams[pat.left.value] = 1;
|
|
15257
|
+
} else if (pat.type === "RestElement" && pat.argument.type === "Identifier") {
|
|
15258
|
+
functionParams[pat.argument.value] = 1;
|
|
15259
|
+
}
|
|
15260
|
+
}
|
|
15261
|
+
}
|
|
15262
|
+
walkSwcAst(ast, {
|
|
15263
|
+
Identifier(node) {
|
|
15264
|
+
const name = node.value;
|
|
15265
|
+
if (globalExists[name]) return;
|
|
15266
|
+
if (functionParams[name]) return;
|
|
15267
|
+
globalVars[name] = 1;
|
|
15268
|
+
},
|
|
15269
|
+
AssignmentExpression(node) {
|
|
15270
|
+
if (node.left.type === "Identifier") {
|
|
15271
|
+
const name = node.left.value;
|
|
15272
|
+
if (!globalExists[name] || globalExists[name] === 1) {
|
|
15273
|
+
globalExists[name] = (globalExists[name] || 0) + 1;
|
|
15274
|
+
}
|
|
15275
|
+
}
|
|
15276
|
+
}
|
|
15277
|
+
});
|
|
15278
|
+
return Object.keys(globalVars);
|
|
15279
|
+
}
|
|
15280
|
+
function getParamPatterns(fnNode) {
|
|
15281
|
+
if (fnNode.type === "ArrowFunctionExpression") {
|
|
15282
|
+
return fnNode.params;
|
|
15283
|
+
}
|
|
15284
|
+
return fnNode.params.map((p) => p.pat);
|
|
15047
15285
|
}
|
|
15048
|
-
function
|
|
15286
|
+
function fallbackExtractVariables(source) {
|
|
15287
|
+
const vars = /* @__PURE__ */ new Set();
|
|
15288
|
+
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15289
|
+
let m;
|
|
15290
|
+
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15291
|
+
vars.add(m[1]);
|
|
15292
|
+
}
|
|
15293
|
+
const eachRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15294
|
+
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15295
|
+
vars.add(m[1]);
|
|
15296
|
+
}
|
|
15297
|
+
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15298
|
+
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15299
|
+
vars.add(m[1]);
|
|
15300
|
+
}
|
|
15301
|
+
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
|
|
15302
|
+
}
|
|
15303
|
+
function walkSwcAst(ast, visitors) {
|
|
15304
|
+
function visit(node) {
|
|
15305
|
+
const type = node.type;
|
|
15306
|
+
if (visitors[type]) {
|
|
15307
|
+
visitors[type](node);
|
|
15308
|
+
}
|
|
15309
|
+
for (const key of Object.keys(node)) {
|
|
15310
|
+
if (key === "type" || key === "span" || key === "ctxt") continue;
|
|
15311
|
+
if (type === "MemberExpression" && key === "property") {
|
|
15312
|
+
const me = node;
|
|
15313
|
+
if (me.property.type !== "Computed") continue;
|
|
15314
|
+
}
|
|
15315
|
+
if (type === "KeyValueProperty" && key === "key") {
|
|
15316
|
+
const kv = node;
|
|
15317
|
+
if (kv.key.type !== "Computed") continue;
|
|
15318
|
+
}
|
|
15319
|
+
if (type === "MethodProperty" && key === "key") {
|
|
15320
|
+
const mp = node;
|
|
15321
|
+
if (mp.key.type !== "Computed") continue;
|
|
15322
|
+
}
|
|
15323
|
+
const child = Reflect.get(node, key);
|
|
15324
|
+
if (Array.isArray(child)) {
|
|
15325
|
+
for (const item of child) {
|
|
15326
|
+
if (isSwcNode(item)) visit(item);
|
|
15327
|
+
}
|
|
15328
|
+
} else if (isSwcNode(child)) {
|
|
15329
|
+
visit(child);
|
|
15330
|
+
}
|
|
15331
|
+
}
|
|
15332
|
+
}
|
|
15333
|
+
visit(ast);
|
|
15334
|
+
}
|
|
15335
|
+
function isSwcNode(v) {
|
|
15336
|
+
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15337
|
+
}
|
|
15338
|
+
var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
15339
|
+
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15340
|
+
//
|
|
15341
|
+
// These variables appear in the generated template function signature
|
|
15342
|
+
// or body. They must be excluded from extractGlobalVars() so that
|
|
15343
|
+
// they are not mistaken for user data variables and destructured from $data.
|
|
15344
|
+
// SPLITTER character constant (same as \x1e), used as namespace separator
|
|
15345
|
+
// for refData keys, event attribute encoding, and internal data structures.
|
|
15346
|
+
// Declared as: let $splitter='\x1e'
|
|
15347
|
+
"$splitter",
|
|
15348
|
+
// Data — the data object passed from Updater to the template function.
|
|
15349
|
+
// User variables are destructured from $data at the top of the function:
|
|
15350
|
+
// let {name, age} = $data;
|
|
15351
|
+
// This is the first parameter of the generated arrow function.
|
|
15352
|
+
"$data",
|
|
15353
|
+
// Null-safe toString: v => '' + (v == null ? '' : v)
|
|
15354
|
+
// Converts null/undefined to empty string, otherwise calls toString().
|
|
15355
|
+
// Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
|
|
15356
|
+
"$strSafe",
|
|
15357
|
+
// HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
|
|
15358
|
+
// Encodes &, <, >, ", ', ` to HTML entities (& < etc.)
|
|
15359
|
+
// Applied to all {{=escaped}} and {{:binding}} outputs.
|
|
15360
|
+
"$encHtml",
|
|
15361
|
+
// HTML entity map — internal object used by $encHtml:
|
|
15362
|
+
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15363
|
+
// Not a standalone function; referenced inside $encHtml's closure.
|
|
15364
|
+
"$entMap",
|
|
15365
|
+
// HTML entity RegExp — internal regexp used by $encHtml:
|
|
15366
|
+
// /[&<>"'`]/g
|
|
15367
|
+
"$entReg",
|
|
15368
|
+
// HTML entity replacer function — internal helper used by $encHtml:
|
|
15369
|
+
// m => '&' + $entMap[m] + ';'
|
|
15370
|
+
// Maps matched character to its entity string.
|
|
15371
|
+
"$entFn",
|
|
15372
|
+
// Output buffer — the string accumulator for rendered HTML.
|
|
15373
|
+
// All template output is appended via $out += '...'.
|
|
15374
|
+
// Declared as: let $out = ''
|
|
15375
|
+
"$out",
|
|
15376
|
+
// Reference lookup: (refData, value) => key
|
|
15377
|
+
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15378
|
+
// object reference. Used by {{@ref}} operator for passing object
|
|
15379
|
+
// references to child views via v-lark attributes.
|
|
15380
|
+
"$refFn",
|
|
15381
|
+
// URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
|
|
15382
|
+
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15383
|
+
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15384
|
+
"$encUri",
|
|
15385
|
+
// URI encode map — internal object used by $encUri:
|
|
15386
|
+
// {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
|
|
15387
|
+
"$uriMap",
|
|
15388
|
+
// URI encode replacer — internal helper used by $encUri:
|
|
15389
|
+
// m => $uriMap[m]
|
|
15390
|
+
"$uriFn",
|
|
15391
|
+
// URI encode regexp — internal regexp used by $encUri:
|
|
15392
|
+
// /[!')(*]/g
|
|
15393
|
+
"$uriReg",
|
|
15394
|
+
// Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
|
|
15395
|
+
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15396
|
+
// values (e.g. data-json='...').
|
|
15397
|
+
"$encQuote",
|
|
15398
|
+
// Quote encode regexp — internal regexp used by $encQuote:
|
|
15399
|
+
// /['"\\]/g
|
|
15400
|
+
"$qReg",
|
|
15401
|
+
// View ID — the unique identifier of the owning View instance.
|
|
15402
|
+
// Injected into @event attribute values at render time so that
|
|
15403
|
+
// EventDelegator can dispatch events to the correct View handler.
|
|
15404
|
+
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15405
|
+
"$viewId",
|
|
15406
|
+
// Debug: current expression text — stores the template expression being
|
|
15407
|
+
// evaluated, for error reporting. Only present in debug mode.
|
|
15408
|
+
// e.g. $dbgExpr='<%=user.name%>'
|
|
15409
|
+
"$dbgExpr",
|
|
15410
|
+
// Debug: original art syntax — stores the {{}} template syntax before
|
|
15411
|
+
// conversion, for error reporting. Only present in debug mode.
|
|
15412
|
+
// e.g. $dbgArt='{{=user.name}}'
|
|
15413
|
+
"$dbgArt",
|
|
15414
|
+
// Debug: source line number — tracks the current line in the template
|
|
15415
|
+
// source, for error reporting. Only present in debug mode.
|
|
15416
|
+
"$dbgLine",
|
|
15417
|
+
// RefData alias — fallback reference lookup table.
|
|
15418
|
+
// Defaults to $data when no explicit $refAlt is provided.
|
|
15419
|
+
// Ensures $refFn() does not crash when @ operator is used without refData.
|
|
15420
|
+
"$refAlt",
|
|
15421
|
+
// Temporary variable — used by the compiler for intermediate
|
|
15422
|
+
// expression results in generated code (e.g. loop variables,
|
|
15423
|
+
// conditional branches). Declared as: let $tmp
|
|
15424
|
+
"$tmp",
|
|
15425
|
+
// JS literals
|
|
15426
|
+
"undefined",
|
|
15427
|
+
"null",
|
|
15428
|
+
"true",
|
|
15429
|
+
"false",
|
|
15430
|
+
"NaN",
|
|
15431
|
+
"Infinity",
|
|
15432
|
+
// JS built-in globals
|
|
15433
|
+
"window",
|
|
15434
|
+
"self",
|
|
15435
|
+
"globalThis",
|
|
15436
|
+
"document",
|
|
15437
|
+
"console",
|
|
15438
|
+
"JSON",
|
|
15439
|
+
"Math",
|
|
15440
|
+
"Intl",
|
|
15441
|
+
"Promise",
|
|
15442
|
+
"Symbol",
|
|
15443
|
+
"Number",
|
|
15444
|
+
"String",
|
|
15445
|
+
"Boolean",
|
|
15446
|
+
"Array",
|
|
15447
|
+
"Object",
|
|
15448
|
+
"Date",
|
|
15449
|
+
"RegExp",
|
|
15450
|
+
"Error",
|
|
15451
|
+
"TypeError",
|
|
15452
|
+
"RangeError",
|
|
15453
|
+
"SyntaxError",
|
|
15454
|
+
"Map",
|
|
15455
|
+
"Set",
|
|
15456
|
+
"WeakMap",
|
|
15457
|
+
"WeakSet",
|
|
15458
|
+
"Proxy",
|
|
15459
|
+
"Reflect",
|
|
15460
|
+
"ArrayBuffer",
|
|
15461
|
+
"DataView",
|
|
15462
|
+
"Float32Array",
|
|
15463
|
+
"Float64Array",
|
|
15464
|
+
"Int8Array",
|
|
15465
|
+
"Int16Array",
|
|
15466
|
+
"Int32Array",
|
|
15467
|
+
"Uint8Array",
|
|
15468
|
+
"Uint16Array",
|
|
15469
|
+
"Uint32Array",
|
|
15470
|
+
"Uint8ClampedArray",
|
|
15471
|
+
// Functions
|
|
15472
|
+
"parseInt",
|
|
15473
|
+
"parseFloat",
|
|
15474
|
+
"isNaN",
|
|
15475
|
+
"isFinite",
|
|
15476
|
+
"encodeURIComponent",
|
|
15477
|
+
"decodeURIComponent",
|
|
15478
|
+
"encodeURI",
|
|
15479
|
+
"decodeURI",
|
|
15480
|
+
// SWC helpers
|
|
15481
|
+
"arguments",
|
|
15482
|
+
"this",
|
|
15483
|
+
"require",
|
|
15484
|
+
// Lark framework
|
|
15485
|
+
"Lark"
|
|
15486
|
+
]);
|
|
15487
|
+
|
|
15488
|
+
// src/compiler/extract-global-vars.ts
|
|
15489
|
+
init_esm_shims();
|
|
15490
|
+
var import_parser = __toESM(require_lib(), 1);
|
|
15491
|
+
async function extractGlobalVars2(source) {
|
|
15049
15492
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15050
15493
|
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15051
15494
|
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
@@ -15082,9 +15525,10 @@ function extractGlobalVars(source) {
|
|
|
15082
15525
|
allowAwaitOutsideFunction: true
|
|
15083
15526
|
});
|
|
15084
15527
|
} catch {
|
|
15085
|
-
return
|
|
15528
|
+
return fallbackExtractVariables2(source);
|
|
15086
15529
|
}
|
|
15087
|
-
const globalExists = {
|
|
15530
|
+
const globalExists = {};
|
|
15531
|
+
for (const name of BUILTIN_GLOBALS2) globalExists[name] = 1;
|
|
15088
15532
|
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15089
15533
|
const fnRange = [];
|
|
15090
15534
|
walkAst(ast, {
|
|
@@ -15143,7 +15587,7 @@ function extractGlobalVars(source) {
|
|
|
15143
15587
|
});
|
|
15144
15588
|
return Object.keys(globalVars);
|
|
15145
15589
|
}
|
|
15146
|
-
function
|
|
15590
|
+
function fallbackExtractVariables2(source) {
|
|
15147
15591
|
const vars = /* @__PURE__ */ new Set();
|
|
15148
15592
|
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15149
15593
|
let m;
|
|
@@ -15158,7 +15602,7 @@ function fallbackExtractVariables(source) {
|
|
|
15158
15602
|
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15159
15603
|
vars.add(m[1]);
|
|
15160
15604
|
}
|
|
15161
|
-
return Array.from(vars).filter((v) => !
|
|
15605
|
+
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS2.has(v));
|
|
15162
15606
|
}
|
|
15163
15607
|
function walkAst(ast, visitors) {
|
|
15164
15608
|
function visit(node) {
|
|
@@ -15166,7 +15610,6 @@ function walkAst(ast, visitors) {
|
|
|
15166
15610
|
if (visitors[type]) {
|
|
15167
15611
|
visitors[type](node);
|
|
15168
15612
|
}
|
|
15169
|
-
const bag = node;
|
|
15170
15613
|
for (const key of Object.keys(node)) {
|
|
15171
15614
|
if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range")
|
|
15172
15615
|
continue;
|
|
@@ -15182,7 +15625,7 @@ function walkAst(ast, visitors) {
|
|
|
15182
15625
|
const om = node;
|
|
15183
15626
|
if (!om.computed) continue;
|
|
15184
15627
|
}
|
|
15185
|
-
const child =
|
|
15628
|
+
const child = Reflect.get(node, key);
|
|
15186
15629
|
if (Array.isArray(child)) {
|
|
15187
15630
|
for (const item of child) {
|
|
15188
15631
|
if (isAstNode(item)) visit(item);
|
|
@@ -15197,7 +15640,7 @@ function walkAst(ast, visitors) {
|
|
|
15197
15640
|
function isAstNode(v) {
|
|
15198
15641
|
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15199
15642
|
}
|
|
15200
|
-
var
|
|
15643
|
+
var BUILTIN_GLOBALS2 = /* @__PURE__ */ new Set([
|
|
15201
15644
|
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15202
15645
|
//
|
|
15203
15646
|
// These variables appear in the generated template function signature
|
|
@@ -15206,149 +15649,322 @@ var BUILTIN_GLOBALS = {
|
|
|
15206
15649
|
// SPLITTER character constant (same as \x1e), used as namespace separator
|
|
15207
15650
|
// for refData keys, event attribute encoding, and internal data structures.
|
|
15208
15651
|
// Declared as: let $splitter='\x1e'
|
|
15209
|
-
$splitter
|
|
15652
|
+
"$splitter",
|
|
15210
15653
|
// Data — the data object passed from Updater to the template function.
|
|
15211
15654
|
// User variables are destructured from $data at the top of the function:
|
|
15212
15655
|
// let {name, age} = $data;
|
|
15213
15656
|
// This is the first parameter of the generated arrow function.
|
|
15214
|
-
$data
|
|
15657
|
+
"$data",
|
|
15215
15658
|
// Null-safe toString: v => '' + (v == null ? '' : v)
|
|
15216
15659
|
// Converts null/undefined to empty string, otherwise calls toString().
|
|
15217
15660
|
// Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
|
|
15218
|
-
$strSafe
|
|
15661
|
+
"$strSafe",
|
|
15219
15662
|
// HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
|
|
15220
15663
|
// Encodes &, <, >, ", ', ` to HTML entities (& < etc.)
|
|
15221
15664
|
// Applied to all {{=escaped}} and {{:binding}} outputs.
|
|
15222
|
-
$encHtml
|
|
15665
|
+
"$encHtml",
|
|
15223
15666
|
// HTML entity map — internal object used by $encHtml:
|
|
15224
15667
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15225
15668
|
// Not a standalone function; referenced inside $encHtml's closure.
|
|
15226
|
-
$entMap
|
|
15669
|
+
"$entMap",
|
|
15227
15670
|
// HTML entity RegExp — internal regexp used by $encHtml:
|
|
15228
15671
|
// /[&<>"'`]/g
|
|
15229
|
-
$entReg
|
|
15672
|
+
"$entReg",
|
|
15230
15673
|
// HTML entity replacer function — internal helper used by $encHtml:
|
|
15231
15674
|
// m => '&' + $entMap[m] + ';'
|
|
15232
15675
|
// Maps matched character to its entity string.
|
|
15233
|
-
$entFn
|
|
15676
|
+
"$entFn",
|
|
15234
15677
|
// Output buffer — the string accumulator for rendered HTML.
|
|
15235
15678
|
// All template output is appended via $out += '...'.
|
|
15236
15679
|
// Declared as: let $out = ''
|
|
15237
|
-
$out
|
|
15680
|
+
"$out",
|
|
15238
15681
|
// Reference lookup: (refData, value) => key
|
|
15239
15682
|
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15240
15683
|
// object reference. Used by {{@ref}} operator for passing object
|
|
15241
15684
|
// references to child views via v-lark attributes.
|
|
15242
|
-
$refFn
|
|
15685
|
+
"$refFn",
|
|
15243
15686
|
// URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
|
|
15244
15687
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15245
15688
|
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15246
|
-
$encUri
|
|
15689
|
+
"$encUri",
|
|
15247
15690
|
// URI encode map — internal object used by $encUri:
|
|
15248
15691
|
// {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
|
|
15249
|
-
$uriMap
|
|
15692
|
+
"$uriMap",
|
|
15250
15693
|
// URI encode replacer — internal helper used by $encUri:
|
|
15251
15694
|
// m => $uriMap[m]
|
|
15252
|
-
$uriFn
|
|
15695
|
+
"$uriFn",
|
|
15253
15696
|
// URI encode regexp — internal regexp used by $encUri:
|
|
15254
15697
|
// /[!')(*]/g
|
|
15255
|
-
$uriReg
|
|
15698
|
+
"$uriReg",
|
|
15256
15699
|
// Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
|
|
15257
15700
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15258
15701
|
// values (e.g. data-json='...').
|
|
15259
|
-
$encQuote
|
|
15702
|
+
"$encQuote",
|
|
15260
15703
|
// Quote encode regexp — internal regexp used by $encQuote:
|
|
15261
15704
|
// /['"\\]/g
|
|
15262
|
-
$qReg
|
|
15705
|
+
"$qReg",
|
|
15263
15706
|
// View ID — the unique identifier of the owning View instance.
|
|
15264
15707
|
// Injected into @event attribute values at render time so that
|
|
15265
15708
|
// EventDelegator can dispatch events to the correct View handler.
|
|
15266
15709
|
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15267
|
-
$viewId
|
|
15710
|
+
"$viewId",
|
|
15268
15711
|
// Debug: current expression text — stores the template expression being
|
|
15269
15712
|
// evaluated, for error reporting. Only present in debug mode.
|
|
15270
15713
|
// e.g. $dbgExpr='<%=user.name%>'
|
|
15271
|
-
$dbgExpr
|
|
15714
|
+
"$dbgExpr",
|
|
15272
15715
|
// Debug: original art syntax — stores the {{}} template syntax before
|
|
15273
15716
|
// conversion, for error reporting. Only present in debug mode.
|
|
15274
15717
|
// e.g. $dbgArt='{{=user.name}}'
|
|
15275
|
-
$dbgArt
|
|
15718
|
+
"$dbgArt",
|
|
15276
15719
|
// Debug: source line number — tracks the current line in the template
|
|
15277
15720
|
// source, for error reporting. Only present in debug mode.
|
|
15278
|
-
$dbgLine
|
|
15721
|
+
"$dbgLine",
|
|
15279
15722
|
// RefData alias — fallback reference lookup table.
|
|
15280
15723
|
// Defaults to $data when no explicit $refAlt is provided.
|
|
15281
15724
|
// Ensures $refFn() does not crash when @ operator is used without refData.
|
|
15282
|
-
$refAlt
|
|
15725
|
+
"$refAlt",
|
|
15283
15726
|
// Temporary variable — used by the compiler for intermediate
|
|
15284
15727
|
// expression results in generated code (e.g. loop variables,
|
|
15285
15728
|
// conditional branches). Declared as: let $tmp
|
|
15286
|
-
$tmp
|
|
15729
|
+
"$tmp",
|
|
15287
15730
|
// JS literals
|
|
15288
|
-
undefined
|
|
15289
|
-
null
|
|
15290
|
-
true
|
|
15291
|
-
false
|
|
15292
|
-
NaN
|
|
15293
|
-
Infinity
|
|
15731
|
+
"undefined",
|
|
15732
|
+
"null",
|
|
15733
|
+
"true",
|
|
15734
|
+
"false",
|
|
15735
|
+
"NaN",
|
|
15736
|
+
"Infinity",
|
|
15294
15737
|
// JS built-in globals
|
|
15295
|
-
window
|
|
15296
|
-
self
|
|
15297
|
-
globalThis
|
|
15298
|
-
document
|
|
15299
|
-
console
|
|
15300
|
-
JSON
|
|
15301
|
-
Math
|
|
15302
|
-
Intl
|
|
15303
|
-
Promise
|
|
15304
|
-
Symbol
|
|
15305
|
-
Number
|
|
15306
|
-
String
|
|
15307
|
-
Boolean
|
|
15308
|
-
Array
|
|
15309
|
-
Object
|
|
15310
|
-
Date
|
|
15311
|
-
RegExp
|
|
15312
|
-
Error
|
|
15313
|
-
TypeError
|
|
15314
|
-
RangeError
|
|
15315
|
-
SyntaxError
|
|
15316
|
-
Map
|
|
15317
|
-
Set
|
|
15318
|
-
WeakMap
|
|
15319
|
-
WeakSet
|
|
15320
|
-
Proxy
|
|
15321
|
-
Reflect
|
|
15322
|
-
ArrayBuffer
|
|
15323
|
-
DataView
|
|
15324
|
-
Float32Array
|
|
15325
|
-
Float64Array
|
|
15326
|
-
Int8Array
|
|
15327
|
-
Int16Array
|
|
15328
|
-
Int32Array
|
|
15329
|
-
Uint8Array
|
|
15330
|
-
Uint16Array
|
|
15331
|
-
Uint32Array
|
|
15332
|
-
Uint8ClampedArray
|
|
15738
|
+
"window",
|
|
15739
|
+
"self",
|
|
15740
|
+
"globalThis",
|
|
15741
|
+
"document",
|
|
15742
|
+
"console",
|
|
15743
|
+
"JSON",
|
|
15744
|
+
"Math",
|
|
15745
|
+
"Intl",
|
|
15746
|
+
"Promise",
|
|
15747
|
+
"Symbol",
|
|
15748
|
+
"Number",
|
|
15749
|
+
"String",
|
|
15750
|
+
"Boolean",
|
|
15751
|
+
"Array",
|
|
15752
|
+
"Object",
|
|
15753
|
+
"Date",
|
|
15754
|
+
"RegExp",
|
|
15755
|
+
"Error",
|
|
15756
|
+
"TypeError",
|
|
15757
|
+
"RangeError",
|
|
15758
|
+
"SyntaxError",
|
|
15759
|
+
"Map",
|
|
15760
|
+
"Set",
|
|
15761
|
+
"WeakMap",
|
|
15762
|
+
"WeakSet",
|
|
15763
|
+
"Proxy",
|
|
15764
|
+
"Reflect",
|
|
15765
|
+
"ArrayBuffer",
|
|
15766
|
+
"DataView",
|
|
15767
|
+
"Float32Array",
|
|
15768
|
+
"Float64Array",
|
|
15769
|
+
"Int8Array",
|
|
15770
|
+
"Int16Array",
|
|
15771
|
+
"Int32Array",
|
|
15772
|
+
"Uint8Array",
|
|
15773
|
+
"Uint16Array",
|
|
15774
|
+
"Uint32Array",
|
|
15775
|
+
"Uint8ClampedArray",
|
|
15333
15776
|
// Functions
|
|
15334
|
-
parseInt
|
|
15335
|
-
parseFloat
|
|
15336
|
-
isNaN
|
|
15337
|
-
isFinite
|
|
15338
|
-
encodeURIComponent
|
|
15339
|
-
decodeURIComponent
|
|
15340
|
-
encodeURI
|
|
15341
|
-
decodeURI
|
|
15777
|
+
"parseInt",
|
|
15778
|
+
"parseFloat",
|
|
15779
|
+
"isNaN",
|
|
15780
|
+
"isFinite",
|
|
15781
|
+
"encodeURIComponent",
|
|
15782
|
+
"decodeURIComponent",
|
|
15783
|
+
"encodeURI",
|
|
15784
|
+
"decodeURI",
|
|
15342
15785
|
// Babel helpers
|
|
15343
|
-
arguments
|
|
15344
|
-
this
|
|
15345
|
-
require
|
|
15786
|
+
"arguments",
|
|
15787
|
+
"this",
|
|
15788
|
+
"require",
|
|
15346
15789
|
// Lark framework
|
|
15347
|
-
Lark
|
|
15348
|
-
|
|
15349
|
-
|
|
15790
|
+
"Lark"
|
|
15791
|
+
]);
|
|
15792
|
+
|
|
15793
|
+
// src/compiler/compile-template.ts
|
|
15794
|
+
function compileToFunction(source, debug, file) {
|
|
15795
|
+
const matcher = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15796
|
+
let index = 0;
|
|
15797
|
+
let funcSource = `$out+='`;
|
|
15798
|
+
let hasAtRule = false;
|
|
15799
|
+
const escapeSlashRegExp = /\\|'/g;
|
|
15800
|
+
const escapeBreakReturnRegExp = /\r|\n/g;
|
|
15801
|
+
source.replace(matcher, (match, operate, content, offset) => {
|
|
15802
|
+
funcSource += source.substring(index, offset).replace(escapeSlashRegExp, "\\$&").replace(escapeBreakReturnRegExp, "\\n");
|
|
15803
|
+
index = offset + match.length;
|
|
15804
|
+
if (debug) {
|
|
15805
|
+
let expr = source.substring(
|
|
15806
|
+
index - match.length + 2 + (operate ? 1 : 0),
|
|
15807
|
+
index - 2
|
|
15808
|
+
);
|
|
15809
|
+
const x11 = String.fromCharCode(17);
|
|
15810
|
+
const artRegExp = new RegExp(`^'(\\d+)${x11}([^${x11}]+)${x11}'$`);
|
|
15811
|
+
const artM = expr.match(artRegExp);
|
|
15812
|
+
let art = "";
|
|
15813
|
+
let line = -1;
|
|
15814
|
+
if (artM) {
|
|
15815
|
+
expr = expr.replace(artRegExp, "");
|
|
15816
|
+
art = artM[2];
|
|
15817
|
+
line = parseInt(artM[1], 10);
|
|
15818
|
+
} else {
|
|
15819
|
+
expr = expr.replace(escapeSlashRegExp, "\\$&").replace(escapeBreakReturnRegExp, "\\n");
|
|
15820
|
+
}
|
|
15821
|
+
if (operate === "@") {
|
|
15822
|
+
hasAtRule = true;
|
|
15823
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',$refFn($refAlt,${content}))+'`;
|
|
15824
|
+
} else if (operate === "=" || operate === ":") {
|
|
15825
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',$encHtml(${content}))+'`;
|
|
15826
|
+
} else if (operate === "!") {
|
|
15827
|
+
if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
|
|
15828
|
+
content = `$strSafe(${content})`;
|
|
15829
|
+
}
|
|
15830
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',${content})+'`;
|
|
15831
|
+
} else if (content) {
|
|
15832
|
+
if (line > -1) {
|
|
15833
|
+
funcSource += `';$dbgLine=${line};$dbgArt='${art}';`;
|
|
15834
|
+
content = "";
|
|
15835
|
+
} else {
|
|
15836
|
+
funcSource += `';`;
|
|
15837
|
+
}
|
|
15838
|
+
if (funcSource.endsWith(`+'';`)) {
|
|
15839
|
+
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15840
|
+
}
|
|
15841
|
+
if (expr) {
|
|
15842
|
+
funcSource += `$dbgExpr='<%${expr}%>';`;
|
|
15843
|
+
}
|
|
15844
|
+
funcSource += content + `;$out+='`;
|
|
15845
|
+
}
|
|
15846
|
+
} else {
|
|
15847
|
+
if (operate === "@") {
|
|
15848
|
+
hasAtRule = true;
|
|
15849
|
+
funcSource += `'+$refFn($refAlt,${content})+'`;
|
|
15850
|
+
} else if (operate === "=" || operate === ":") {
|
|
15851
|
+
funcSource += `'+$encHtml(${content})+'`;
|
|
15852
|
+
} else if (operate === "!") {
|
|
15853
|
+
if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
|
|
15854
|
+
content = `$strSafe(${content})`;
|
|
15855
|
+
}
|
|
15856
|
+
funcSource += `'+${content}+'`;
|
|
15857
|
+
} else if (content) {
|
|
15858
|
+
funcSource += `';`;
|
|
15859
|
+
if (funcSource.endsWith(`+'';`)) {
|
|
15860
|
+
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15861
|
+
}
|
|
15862
|
+
funcSource += `${content};$out+='`;
|
|
15863
|
+
}
|
|
15864
|
+
}
|
|
15865
|
+
return match;
|
|
15866
|
+
});
|
|
15867
|
+
funcSource += `';`;
|
|
15868
|
+
funcSource = funcSource.replace(/\$out\+='';/g, "");
|
|
15869
|
+
funcSource = funcSource.replace(/\$out\+=''\+/g, "$out+=");
|
|
15870
|
+
if (debug) {
|
|
15871
|
+
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15872
|
+
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;}`;
|
|
15873
|
+
}
|
|
15874
|
+
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15875
|
+
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15876
|
+
void hasAtRule;
|
|
15877
|
+
const refFallback = "if(!$refAlt)$refAlt=$data;";
|
|
15878
|
+
const fullSource = `${refFallback}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
|
|
15879
|
+
return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
|
|
15880
|
+
}
|
|
15881
|
+
async function compileTemplate(source, options = {}) {
|
|
15882
|
+
const { debug = false, file, virtualDom = false, useSwc = false } = options;
|
|
15883
|
+
const globalVars = options.globalVars ?? await (useSwc ? extractGlobalVars(source) : extractGlobalVars2(source));
|
|
15884
|
+
const { protectedSource, comments } = protectComments(source);
|
|
15885
|
+
const converted = convertArtSyntax(protectedSource, debug);
|
|
15886
|
+
const viewEventProcessed = processViewEvents(converted);
|
|
15887
|
+
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
15888
|
+
const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
|
|
15889
|
+
if (virtualDom) {
|
|
15890
|
+
const funcBody2 = compileToVDomFunction(finalSource, debug, file);
|
|
15891
|
+
const funcWithVars2 = funcBody2.replace("{{VARS}}", () => varDeclarations);
|
|
15892
|
+
return `import { vdomCreate as __larkC } from "@lark.js/mvc";
|
|
15893
|
+
import { strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
|
|
15894
|
+
export default function(data, viewId, refData) {
|
|
15895
|
+
let $data = data || {},
|
|
15896
|
+
$viewId = viewId || '',
|
|
15897
|
+
$c = __larkC,
|
|
15898
|
+
$n = __larkStrSafe;
|
|
15899
|
+
return (${funcWithVars2})($data, $viewId, refData,
|
|
15900
|
+
$n, __larkRefFn, __larkEncUri, __larkEncQuote
|
|
15901
|
+
);
|
|
15902
|
+
}`;
|
|
15903
|
+
}
|
|
15904
|
+
const funcBody = compileToFunction(finalSource, debug, file);
|
|
15905
|
+
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
15906
|
+
return `import { encHtml as __larkEncHtml, strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
|
|
15907
|
+
export default function(data, viewId, refData) {
|
|
15908
|
+
let $data = data || {},
|
|
15909
|
+
$viewId = viewId || '';
|
|
15910
|
+
return (${funcWithVars})($data, $viewId, refData,
|
|
15911
|
+
__larkEncHtml, __larkStrSafe, __larkEncUri, __larkRefFn, __larkEncQuote
|
|
15912
|
+
);
|
|
15913
|
+
}`;
|
|
15914
|
+
}
|
|
15350
15915
|
|
|
15916
|
+
// src/rspack.ts
|
|
15917
|
+
async function larkMvcLoader(source) {
|
|
15918
|
+
try {
|
|
15919
|
+
const options = this.getOptions();
|
|
15920
|
+
const { debug = false, virtualDom = false, useSwc = false } = options;
|
|
15921
|
+
const globalVars = await extractGlobalVars2(source);
|
|
15922
|
+
return await compileTemplate(source, {
|
|
15923
|
+
debug,
|
|
15924
|
+
globalVars,
|
|
15925
|
+
virtualDom,
|
|
15926
|
+
useSwc
|
|
15927
|
+
});
|
|
15928
|
+
} catch (err) {
|
|
15929
|
+
console.error(err);
|
|
15930
|
+
return "";
|
|
15931
|
+
}
|
|
15932
|
+
}
|
|
15933
|
+
var LarkMvcPlugin = class {
|
|
15934
|
+
options;
|
|
15935
|
+
constructor(options = {}) {
|
|
15936
|
+
this.options = {
|
|
15937
|
+
debug: false,
|
|
15938
|
+
virtualDom: false,
|
|
15939
|
+
useSwc: false,
|
|
15940
|
+
test: /\.html$/,
|
|
15941
|
+
exclude: /node_modules/,
|
|
15942
|
+
...options
|
|
15943
|
+
};
|
|
15944
|
+
}
|
|
15945
|
+
/**
|
|
15946
|
+
* Rspack plugin entry point.
|
|
15947
|
+
* Called by rspack when the plugin is applied.
|
|
15948
|
+
*/
|
|
15949
|
+
apply(compiler) {
|
|
15950
|
+
const { debug, virtualDom, useSwc, test, exclude } = this.options;
|
|
15951
|
+
const loaderPath = __filename;
|
|
15952
|
+
compiler.options.module = compiler.options.module || {};
|
|
15953
|
+
compiler.options.module.rules = compiler.options.module.rules || [];
|
|
15954
|
+
compiler.options.module.rules.push({
|
|
15955
|
+
test,
|
|
15956
|
+
exclude,
|
|
15957
|
+
use: [
|
|
15958
|
+
{
|
|
15959
|
+
loader: loaderPath,
|
|
15960
|
+
options: { debug, virtualDom, useSwc }
|
|
15961
|
+
}
|
|
15962
|
+
]
|
|
15963
|
+
});
|
|
15964
|
+
}
|
|
15965
|
+
};
|
|
15351
15966
|
export {
|
|
15352
|
-
|
|
15353
|
-
|
|
15967
|
+
LarkMvcPlugin,
|
|
15968
|
+
larkMvcLoader as default,
|
|
15969
|
+
larkMvcLoader
|
|
15354
15970
|
};
|