@lark.js/mvc 0.0.12 → 0.0.14
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 +11 -20
- package/dist/compiler.cjs +18 -345
- package/dist/compiler.d.cts +1 -30
- package/dist/compiler.d.ts +1 -30
- package/dist/compiler.js +17 -343
- package/dist/devtool.cjs +38 -84
- package/dist/devtool.js +38 -84
- package/dist/index.cjs +45 -145
- package/dist/index.d.cts +5 -41
- package/dist/index.d.ts +5 -41
- package/dist/index.js +45 -144
- package/dist/rspack.cjs +23 -351
- package/dist/rspack.d.cts +9 -24
- package/dist/rspack.d.ts +9 -24
- package/dist/rspack.js +23 -351
- package/dist/vite.cjs +55 -365
- package/dist/vite.d.cts +17 -8
- package/dist/vite.d.ts +17 -8
- package/dist/vite.js +52 -364
- package/dist/webpack.cjs +23 -351
- package/dist/webpack.d.cts +9 -15
- package/dist/webpack.d.ts +9 -15
- package/dist/webpack.js +23 -351
- package/package.json +7 -5
- package/src/client.d.ts +0 -89
package/dist/compiler.js
CHANGED
|
@@ -14512,7 +14512,7 @@ var require_lib = __commonJS({
|
|
|
14512
14512
|
options = Object.assign({}, options);
|
|
14513
14513
|
try {
|
|
14514
14514
|
options.sourceType = "module";
|
|
14515
|
-
const parser =
|
|
14515
|
+
const parser = getParser(options, input);
|
|
14516
14516
|
const ast = parser.parse();
|
|
14517
14517
|
if (parser.sawUnambiguousESM) {
|
|
14518
14518
|
return ast;
|
|
@@ -14520,7 +14520,7 @@ var require_lib = __commonJS({
|
|
|
14520
14520
|
if (parser.ambiguousScriptDifferentAst) {
|
|
14521
14521
|
try {
|
|
14522
14522
|
options.sourceType = "script";
|
|
14523
|
-
return
|
|
14523
|
+
return getParser(options, input).parse();
|
|
14524
14524
|
} catch (_unused) {
|
|
14525
14525
|
}
|
|
14526
14526
|
} else {
|
|
@@ -14530,17 +14530,17 @@ var require_lib = __commonJS({
|
|
|
14530
14530
|
} catch (moduleError) {
|
|
14531
14531
|
try {
|
|
14532
14532
|
options.sourceType = "script";
|
|
14533
|
-
return
|
|
14533
|
+
return getParser(options, input).parse();
|
|
14534
14534
|
} catch (_unused2) {
|
|
14535
14535
|
}
|
|
14536
14536
|
throw moduleError;
|
|
14537
14537
|
}
|
|
14538
14538
|
} else {
|
|
14539
|
-
return
|
|
14539
|
+
return getParser(options, input).parse();
|
|
14540
14540
|
}
|
|
14541
14541
|
}
|
|
14542
14542
|
function parseExpression(input, options) {
|
|
14543
|
-
const parser =
|
|
14543
|
+
const parser = getParser(options, input);
|
|
14544
14544
|
if (parser.options.strictMode) {
|
|
14545
14545
|
parser.state.strict = true;
|
|
14546
14546
|
}
|
|
@@ -14554,7 +14554,7 @@ var require_lib = __commonJS({
|
|
|
14554
14554
|
return tokenTypes2;
|
|
14555
14555
|
}
|
|
14556
14556
|
var tokTypes = generateExportedTokenTypes(tt);
|
|
14557
|
-
function
|
|
14557
|
+
function getParser(options, input) {
|
|
14558
14558
|
let cls = Parser;
|
|
14559
14559
|
const pluginsMap = /* @__PURE__ */ new Map();
|
|
14560
14560
|
if (options != null && options.plugins) {
|
|
@@ -15132,334 +15132,9 @@ function compileToVDomFunction(source, debug, file) {
|
|
|
15132
15132
|
return `($data,$viewId,$refAlt,$n,$refFn,$encUri,$encQuote)=>{${fullSource}}`;
|
|
15133
15133
|
}
|
|
15134
15134
|
|
|
15135
|
-
// src/compiler/swc/extract-global-vars.ts
|
|
15136
|
-
var parseSyncFn = null;
|
|
15137
|
-
var parseSyncLoadAttempted = false;
|
|
15138
|
-
async function getParser() {
|
|
15139
|
-
if (!parseSyncLoadAttempted) {
|
|
15140
|
-
parseSyncLoadAttempted = true;
|
|
15141
|
-
try {
|
|
15142
|
-
const swc = await import("@swc/core");
|
|
15143
|
-
parseSyncFn = swc.parseSync;
|
|
15144
|
-
} catch (err) {
|
|
15145
|
-
console.error("failed to load @swc/core", err);
|
|
15146
|
-
}
|
|
15147
|
-
}
|
|
15148
|
-
return parseSyncFn;
|
|
15149
|
-
}
|
|
15150
|
-
async function extractGlobalVars(source) {
|
|
15151
|
-
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15152
|
-
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15153
|
-
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15154
|
-
const template = restoreComments(converted, _comments);
|
|
15155
|
-
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15156
|
-
const fnParts = [];
|
|
15157
|
-
const htmlStore = {};
|
|
15158
|
-
let htmlIndex = 0;
|
|
15159
|
-
let lastIndex = 0;
|
|
15160
|
-
const htmlKey = String.fromCharCode(5);
|
|
15161
|
-
template.replace(
|
|
15162
|
-
templateCmdRegExp,
|
|
15163
|
-
(match, operate, content, offset) => {
|
|
15164
|
-
const start = operate ? 3 : 2;
|
|
15165
|
-
const htmlText = template.substring(lastIndex, offset + start);
|
|
15166
|
-
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15167
|
-
htmlStore[key] = htmlText;
|
|
15168
|
-
lastIndex = offset + match.length - 2;
|
|
15169
|
-
if (operate && content.trim()) {
|
|
15170
|
-
fnParts.push(';"' + key + '";', "[" + content + "]");
|
|
15171
|
-
} else {
|
|
15172
|
-
fnParts.push(';"' + key + '";', content || "");
|
|
15173
|
-
}
|
|
15174
|
-
return match;
|
|
15175
|
-
}
|
|
15176
|
-
);
|
|
15177
|
-
let fn = fnParts.join("");
|
|
15178
|
-
fn = `(function(){${fn}})`;
|
|
15179
|
-
const parseSync = await getParser();
|
|
15180
|
-
if (!parseSync) {
|
|
15181
|
-
return fallbackExtractVariables(source);
|
|
15182
|
-
}
|
|
15183
|
-
let ast;
|
|
15184
|
-
try {
|
|
15185
|
-
ast = parseSync(fn, {
|
|
15186
|
-
syntax: "ecmascript",
|
|
15187
|
-
target: "es2022"
|
|
15188
|
-
});
|
|
15189
|
-
} catch {
|
|
15190
|
-
return fallbackExtractVariables(source);
|
|
15191
|
-
}
|
|
15192
|
-
const globalExists = {};
|
|
15193
|
-
for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
|
|
15194
|
-
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15195
|
-
const fnNodes = [];
|
|
15196
|
-
walkSwcAst(ast, {
|
|
15197
|
-
VariableDeclarator(node) {
|
|
15198
|
-
if (node.id.type === "Identifier") {
|
|
15199
|
-
const name = node.id.value;
|
|
15200
|
-
globalExists[name] = node.init ? 3 : 2;
|
|
15201
|
-
}
|
|
15202
|
-
},
|
|
15203
|
-
FunctionDeclaration(node) {
|
|
15204
|
-
if (node.identifier) {
|
|
15205
|
-
globalExists[node.identifier.value] = 3;
|
|
15206
|
-
}
|
|
15207
|
-
fnNodes.push(node);
|
|
15208
|
-
},
|
|
15209
|
-
FunctionExpression(node) {
|
|
15210
|
-
fnNodes.push(node);
|
|
15211
|
-
},
|
|
15212
|
-
ArrowFunctionExpression(node) {
|
|
15213
|
-
fnNodes.push(node);
|
|
15214
|
-
},
|
|
15215
|
-
CallExpression(node) {
|
|
15216
|
-
if (node.callee.type === "Identifier") {
|
|
15217
|
-
globalExists[node.callee.value] = 1;
|
|
15218
|
-
}
|
|
15219
|
-
}
|
|
15220
|
-
});
|
|
15221
|
-
const functionParams = /* @__PURE__ */ Object.create(null);
|
|
15222
|
-
for (const fnNode of fnNodes) {
|
|
15223
|
-
const patterns = getParamPatterns(fnNode);
|
|
15224
|
-
for (const pat of patterns) {
|
|
15225
|
-
if (pat.type === "Identifier") {
|
|
15226
|
-
functionParams[pat.value] = 1;
|
|
15227
|
-
} else if (pat.type === "AssignmentPattern" && pat.left.type === "Identifier") {
|
|
15228
|
-
functionParams[pat.left.value] = 1;
|
|
15229
|
-
} else if (pat.type === "RestElement" && pat.argument.type === "Identifier") {
|
|
15230
|
-
functionParams[pat.argument.value] = 1;
|
|
15231
|
-
}
|
|
15232
|
-
}
|
|
15233
|
-
}
|
|
15234
|
-
walkSwcAst(ast, {
|
|
15235
|
-
Identifier(node) {
|
|
15236
|
-
const name = node.value;
|
|
15237
|
-
if (globalExists[name]) return;
|
|
15238
|
-
if (functionParams[name]) return;
|
|
15239
|
-
globalVars[name] = 1;
|
|
15240
|
-
},
|
|
15241
|
-
AssignmentExpression(node) {
|
|
15242
|
-
if (node.left.type === "Identifier") {
|
|
15243
|
-
const name = node.left.value;
|
|
15244
|
-
if (!globalExists[name] || globalExists[name] === 1) {
|
|
15245
|
-
globalExists[name] = (globalExists[name] || 0) + 1;
|
|
15246
|
-
}
|
|
15247
|
-
}
|
|
15248
|
-
}
|
|
15249
|
-
});
|
|
15250
|
-
return Object.keys(globalVars);
|
|
15251
|
-
}
|
|
15252
|
-
function getParamPatterns(fnNode) {
|
|
15253
|
-
if (fnNode.type === "ArrowFunctionExpression") {
|
|
15254
|
-
return fnNode.params;
|
|
15255
|
-
}
|
|
15256
|
-
return fnNode.params.map((p) => p.pat);
|
|
15257
|
-
}
|
|
15258
|
-
function fallbackExtractVariables(source) {
|
|
15259
|
-
const vars = /* @__PURE__ */ new Set();
|
|
15260
|
-
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15261
|
-
let m;
|
|
15262
|
-
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15263
|
-
vars.add(m[1]);
|
|
15264
|
-
}
|
|
15265
|
-
const eachRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15266
|
-
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15267
|
-
vars.add(m[1]);
|
|
15268
|
-
}
|
|
15269
|
-
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15270
|
-
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15271
|
-
vars.add(m[1]);
|
|
15272
|
-
}
|
|
15273
|
-
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
|
|
15274
|
-
}
|
|
15275
|
-
function walkSwcAst(ast, visitors) {
|
|
15276
|
-
function visit(node) {
|
|
15277
|
-
const type = node.type;
|
|
15278
|
-
if (visitors[type]) {
|
|
15279
|
-
visitors[type](node);
|
|
15280
|
-
}
|
|
15281
|
-
for (const key of Object.keys(node)) {
|
|
15282
|
-
if (key === "type" || key === "span" || key === "ctxt") continue;
|
|
15283
|
-
if (type === "MemberExpression" && key === "property") {
|
|
15284
|
-
const me = node;
|
|
15285
|
-
if (me.property.type !== "Computed") continue;
|
|
15286
|
-
}
|
|
15287
|
-
if (type === "KeyValueProperty" && key === "key") {
|
|
15288
|
-
const kv = node;
|
|
15289
|
-
if (kv.key.type !== "Computed") continue;
|
|
15290
|
-
}
|
|
15291
|
-
if (type === "MethodProperty" && key === "key") {
|
|
15292
|
-
const mp = node;
|
|
15293
|
-
if (mp.key.type !== "Computed") continue;
|
|
15294
|
-
}
|
|
15295
|
-
const child = Reflect.get(node, key);
|
|
15296
|
-
if (Array.isArray(child)) {
|
|
15297
|
-
for (const item of child) {
|
|
15298
|
-
if (isSwcNode(item)) visit(item);
|
|
15299
|
-
}
|
|
15300
|
-
} else if (isSwcNode(child)) {
|
|
15301
|
-
visit(child);
|
|
15302
|
-
}
|
|
15303
|
-
}
|
|
15304
|
-
}
|
|
15305
|
-
visit(ast);
|
|
15306
|
-
}
|
|
15307
|
-
function isSwcNode(v) {
|
|
15308
|
-
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15309
|
-
}
|
|
15310
|
-
var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
15311
|
-
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15312
|
-
//
|
|
15313
|
-
// These variables appear in the generated template function signature
|
|
15314
|
-
// or body. They must be excluded from extractGlobalVars() so that
|
|
15315
|
-
// they are not mistaken for user data variables and destructured from $data.
|
|
15316
|
-
// SPLITTER character constant (same as \x1e), used as namespace separator
|
|
15317
|
-
// for refData keys, event attribute encoding, and internal data structures.
|
|
15318
|
-
// Declared as: let $splitter='\x1e'
|
|
15319
|
-
"$splitter",
|
|
15320
|
-
// Data — the data object passed from Updater to the template function.
|
|
15321
|
-
// User variables are destructured from $data at the top of the function:
|
|
15322
|
-
// let {name, age} = $data;
|
|
15323
|
-
// This is the first parameter of the generated arrow function.
|
|
15324
|
-
"$data",
|
|
15325
|
-
// Null-safe toString: v => '' + (v == null ? '' : v)
|
|
15326
|
-
// Converts null/undefined to empty string, otherwise calls toString().
|
|
15327
|
-
// Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
|
|
15328
|
-
"$strSafe",
|
|
15329
|
-
// HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
|
|
15330
|
-
// Encodes &, <, >, ", ', ` to HTML entities (& < etc.)
|
|
15331
|
-
// Applied to all {{=escaped}} and {{:binding}} outputs.
|
|
15332
|
-
"$encHtml",
|
|
15333
|
-
// HTML entity map — internal object used by $encHtml:
|
|
15334
|
-
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15335
|
-
// Not a standalone function; referenced inside $encHtml's closure.
|
|
15336
|
-
"$entMap",
|
|
15337
|
-
// HTML entity RegExp — internal regexp used by $encHtml:
|
|
15338
|
-
// /[&<>"'`]/g
|
|
15339
|
-
"$entReg",
|
|
15340
|
-
// HTML entity replacer function — internal helper used by $encHtml:
|
|
15341
|
-
// m => '&' + $entMap[m] + ';'
|
|
15342
|
-
// Maps matched character to its entity string.
|
|
15343
|
-
"$entFn",
|
|
15344
|
-
// Output buffer — the string accumulator for rendered HTML.
|
|
15345
|
-
// All template output is appended via $out += '...'.
|
|
15346
|
-
// Declared as: let $out = ''
|
|
15347
|
-
"$out",
|
|
15348
|
-
// Reference lookup: (refData, value) => key
|
|
15349
|
-
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15350
|
-
// object reference. Used by {{@ref}} operator for passing object
|
|
15351
|
-
// references to child views via v-lark attributes.
|
|
15352
|
-
"$refFn",
|
|
15353
|
-
// URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
|
|
15354
|
-
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15355
|
-
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15356
|
-
"$encUri",
|
|
15357
|
-
// URI encode map — internal object used by $encUri:
|
|
15358
|
-
// {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
|
|
15359
|
-
"$uriMap",
|
|
15360
|
-
// URI encode replacer — internal helper used by $encUri:
|
|
15361
|
-
// m => $uriMap[m]
|
|
15362
|
-
"$uriFn",
|
|
15363
|
-
// URI encode regexp — internal regexp used by $encUri:
|
|
15364
|
-
// /[!')(*]/g
|
|
15365
|
-
"$uriReg",
|
|
15366
|
-
// Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
|
|
15367
|
-
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15368
|
-
// values (e.g. data-json='...').
|
|
15369
|
-
"$encQuote",
|
|
15370
|
-
// Quote encode regexp — internal regexp used by $encQuote:
|
|
15371
|
-
// /['"\\]/g
|
|
15372
|
-
"$qReg",
|
|
15373
|
-
// View ID — the unique identifier of the owning View instance.
|
|
15374
|
-
// Injected into @event attribute values at render time so that
|
|
15375
|
-
// EventDelegator can dispatch events to the correct View handler.
|
|
15376
|
-
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15377
|
-
"$viewId",
|
|
15378
|
-
// Debug: current expression text — stores the template expression being
|
|
15379
|
-
// evaluated, for error reporting. Only present in debug mode.
|
|
15380
|
-
// e.g. $dbgExpr='<%=user.name%>'
|
|
15381
|
-
"$dbgExpr",
|
|
15382
|
-
// Debug: original art syntax — stores the {{}} template syntax before
|
|
15383
|
-
// conversion, for error reporting. Only present in debug mode.
|
|
15384
|
-
// e.g. $dbgArt='{{=user.name}}'
|
|
15385
|
-
"$dbgArt",
|
|
15386
|
-
// Debug: source line number — tracks the current line in the template
|
|
15387
|
-
// source, for error reporting. Only present in debug mode.
|
|
15388
|
-
"$dbgLine",
|
|
15389
|
-
// RefData alias — fallback reference lookup table.
|
|
15390
|
-
// Defaults to $data when no explicit $refAlt is provided.
|
|
15391
|
-
// Ensures $refFn() does not crash when @ operator is used without refData.
|
|
15392
|
-
"$refAlt",
|
|
15393
|
-
// Temporary variable — used by the compiler for intermediate
|
|
15394
|
-
// expression results in generated code (e.g. loop variables,
|
|
15395
|
-
// conditional branches). Declared as: let $tmp
|
|
15396
|
-
"$tmp",
|
|
15397
|
-
// JS literals
|
|
15398
|
-
"undefined",
|
|
15399
|
-
"null",
|
|
15400
|
-
"true",
|
|
15401
|
-
"false",
|
|
15402
|
-
"NaN",
|
|
15403
|
-
"Infinity",
|
|
15404
|
-
// JS built-in globals
|
|
15405
|
-
"window",
|
|
15406
|
-
"self",
|
|
15407
|
-
"globalThis",
|
|
15408
|
-
"document",
|
|
15409
|
-
"console",
|
|
15410
|
-
"JSON",
|
|
15411
|
-
"Math",
|
|
15412
|
-
"Intl",
|
|
15413
|
-
"Promise",
|
|
15414
|
-
"Symbol",
|
|
15415
|
-
"Number",
|
|
15416
|
-
"String",
|
|
15417
|
-
"Boolean",
|
|
15418
|
-
"Array",
|
|
15419
|
-
"Object",
|
|
15420
|
-
"Date",
|
|
15421
|
-
"RegExp",
|
|
15422
|
-
"Error",
|
|
15423
|
-
"TypeError",
|
|
15424
|
-
"RangeError",
|
|
15425
|
-
"SyntaxError",
|
|
15426
|
-
"Map",
|
|
15427
|
-
"Set",
|
|
15428
|
-
"WeakMap",
|
|
15429
|
-
"WeakSet",
|
|
15430
|
-
"Proxy",
|
|
15431
|
-
"Reflect",
|
|
15432
|
-
"ArrayBuffer",
|
|
15433
|
-
"DataView",
|
|
15434
|
-
"Float32Array",
|
|
15435
|
-
"Float64Array",
|
|
15436
|
-
"Int8Array",
|
|
15437
|
-
"Int16Array",
|
|
15438
|
-
"Int32Array",
|
|
15439
|
-
"Uint8Array",
|
|
15440
|
-
"Uint16Array",
|
|
15441
|
-
"Uint32Array",
|
|
15442
|
-
"Uint8ClampedArray",
|
|
15443
|
-
// Functions
|
|
15444
|
-
"parseInt",
|
|
15445
|
-
"parseFloat",
|
|
15446
|
-
"isNaN",
|
|
15447
|
-
"isFinite",
|
|
15448
|
-
"encodeURIComponent",
|
|
15449
|
-
"decodeURIComponent",
|
|
15450
|
-
"encodeURI",
|
|
15451
|
-
"decodeURI",
|
|
15452
|
-
// SWC helpers
|
|
15453
|
-
"arguments",
|
|
15454
|
-
"this",
|
|
15455
|
-
"require",
|
|
15456
|
-
// Lark framework
|
|
15457
|
-
"Lark"
|
|
15458
|
-
]);
|
|
15459
|
-
|
|
15460
15135
|
// src/compiler/extract-global-vars.ts
|
|
15461
15136
|
var import_parser = __toESM(require_lib(), 1);
|
|
15462
|
-
async function
|
|
15137
|
+
async function extractGlobalVars(source) {
|
|
15463
15138
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15464
15139
|
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15465
15140
|
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
@@ -15496,10 +15171,10 @@ async function extractGlobalVars2(source) {
|
|
|
15496
15171
|
allowAwaitOutsideFunction: true
|
|
15497
15172
|
});
|
|
15498
15173
|
} catch {
|
|
15499
|
-
return
|
|
15174
|
+
return fallbackExtractVariables(source);
|
|
15500
15175
|
}
|
|
15501
15176
|
const globalExists = {};
|
|
15502
|
-
for (const name of
|
|
15177
|
+
for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
|
|
15503
15178
|
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15504
15179
|
const fnRange = [];
|
|
15505
15180
|
walkAst(ast, {
|
|
@@ -15558,22 +15233,22 @@ async function extractGlobalVars2(source) {
|
|
|
15558
15233
|
});
|
|
15559
15234
|
return Object.keys(globalVars);
|
|
15560
15235
|
}
|
|
15561
|
-
function
|
|
15236
|
+
function fallbackExtractVariables(source) {
|
|
15562
15237
|
const vars = /* @__PURE__ */ new Set();
|
|
15563
15238
|
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15564
15239
|
let m;
|
|
15565
15240
|
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15566
15241
|
vars.add(m[1]);
|
|
15567
15242
|
}
|
|
15568
|
-
const
|
|
15569
|
-
while ((m =
|
|
15243
|
+
const forOfRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15244
|
+
while ((m = forOfRegExp.exec(source)) !== null) {
|
|
15570
15245
|
vars.add(m[1]);
|
|
15571
15246
|
}
|
|
15572
15247
|
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15573
15248
|
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15574
15249
|
vars.add(m[1]);
|
|
15575
15250
|
}
|
|
15576
|
-
return Array.from(vars).filter((v) => !
|
|
15251
|
+
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
|
|
15577
15252
|
}
|
|
15578
15253
|
function walkAst(ast, visitors) {
|
|
15579
15254
|
function visit(node) {
|
|
@@ -15611,7 +15286,7 @@ function walkAst(ast, visitors) {
|
|
|
15611
15286
|
function isAstNode(v) {
|
|
15612
15287
|
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15613
15288
|
}
|
|
15614
|
-
var
|
|
15289
|
+
var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
15615
15290
|
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15616
15291
|
//
|
|
15617
15292
|
// These variables appear in the generated template function signature
|
|
@@ -15850,8 +15525,8 @@ function compileToFunction(source, debug, file) {
|
|
|
15850
15525
|
return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
|
|
15851
15526
|
}
|
|
15852
15527
|
async function compileTemplate(source, options = {}) {
|
|
15853
|
-
const { debug = false, file, virtualDom = false
|
|
15854
|
-
const globalVars = options.globalVars ?? await
|
|
15528
|
+
const { debug = false, file, virtualDom = false } = options;
|
|
15529
|
+
const globalVars = options.globalVars ?? await extractGlobalVars(source);
|
|
15855
15530
|
const { protectedSource, comments } = protectComments(source);
|
|
15856
15531
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
15857
15532
|
const viewEventProcessed = processViewEvents(converted);
|
|
@@ -15885,6 +15560,5 @@ export default function(data, viewId, refData) {
|
|
|
15885
15560
|
}
|
|
15886
15561
|
export {
|
|
15887
15562
|
compileTemplate,
|
|
15888
|
-
|
|
15889
|
-
extractGlobalVars as extractGlobalVarsSwc
|
|
15563
|
+
extractGlobalVars
|
|
15890
15564
|
};
|