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