@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/vite.cjs
CHANGED
|
@@ -33,9 +33,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
));
|
|
34
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
35
|
|
|
36
|
-
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.
|
|
36
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.43_@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
37
|
var init_cjs_shims = __esm({
|
|
38
|
-
"../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.
|
|
38
|
+
"../../node_modules/.pnpm/tsup@8.5.1_@swc+core@1.15.43_@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
39
|
"use strict";
|
|
40
40
|
}
|
|
41
41
|
});
|
|
@@ -14529,7 +14529,7 @@ var require_lib = __commonJS({
|
|
|
14529
14529
|
options = Object.assign({}, options);
|
|
14530
14530
|
try {
|
|
14531
14531
|
options.sourceType = "module";
|
|
14532
|
-
const parser =
|
|
14532
|
+
const parser = getParser(options, input);
|
|
14533
14533
|
const ast = parser.parse();
|
|
14534
14534
|
if (parser.sawUnambiguousESM) {
|
|
14535
14535
|
return ast;
|
|
@@ -14537,7 +14537,7 @@ var require_lib = __commonJS({
|
|
|
14537
14537
|
if (parser.ambiguousScriptDifferentAst) {
|
|
14538
14538
|
try {
|
|
14539
14539
|
options.sourceType = "script";
|
|
14540
|
-
return
|
|
14540
|
+
return getParser(options, input).parse();
|
|
14541
14541
|
} catch (_unused) {
|
|
14542
14542
|
}
|
|
14543
14543
|
} else {
|
|
@@ -14547,17 +14547,17 @@ var require_lib = __commonJS({
|
|
|
14547
14547
|
} catch (moduleError) {
|
|
14548
14548
|
try {
|
|
14549
14549
|
options.sourceType = "script";
|
|
14550
|
-
return
|
|
14550
|
+
return getParser(options, input).parse();
|
|
14551
14551
|
} catch (_unused2) {
|
|
14552
14552
|
}
|
|
14553
14553
|
throw moduleError;
|
|
14554
14554
|
}
|
|
14555
14555
|
} else {
|
|
14556
|
-
return
|
|
14556
|
+
return getParser(options, input).parse();
|
|
14557
14557
|
}
|
|
14558
14558
|
}
|
|
14559
14559
|
function parseExpression(input, options) {
|
|
14560
|
-
const parser =
|
|
14560
|
+
const parser = getParser(options, input);
|
|
14561
14561
|
if (parser.options.strictMode) {
|
|
14562
14562
|
parser.state.strict = true;
|
|
14563
14563
|
}
|
|
@@ -14571,7 +14571,7 @@ var require_lib = __commonJS({
|
|
|
14571
14571
|
return tokenTypes2;
|
|
14572
14572
|
}
|
|
14573
14573
|
var tokTypes = generateExportedTokenTypes(tt);
|
|
14574
|
-
function
|
|
14574
|
+
function getParser(options, input) {
|
|
14575
14575
|
let cls = Parser;
|
|
14576
14576
|
const pluginsMap = /* @__PURE__ */ new Map();
|
|
14577
14577
|
if (options != null && options.plugins) {
|
|
@@ -14621,12 +14621,14 @@ var vite_exports = {};
|
|
|
14621
14621
|
__export(vite_exports, {
|
|
14622
14622
|
default: () => vite_default,
|
|
14623
14623
|
larkMvcPlugin: () => larkMvcPlugin,
|
|
14624
|
-
|
|
14624
|
+
larkMvcPlugin7: () => larkMvcPlugin7,
|
|
14625
|
+
larkMvcPluginLegacy: () => larkMvcPluginLegacy,
|
|
14626
|
+
larkMvcPluginLegacy7: () => larkMvcPluginLegacy7
|
|
14625
14627
|
});
|
|
14626
14628
|
module.exports = __toCommonJS(vite_exports);
|
|
14627
14629
|
init_cjs_shims();
|
|
14628
|
-
var import_path =
|
|
14629
|
-
var import_fs =
|
|
14630
|
+
var import_path = require("path");
|
|
14631
|
+
var import_fs = require("fs");
|
|
14630
14632
|
|
|
14631
14633
|
// src/compiler.ts
|
|
14632
14634
|
init_cjs_shims();
|
|
@@ -15169,336 +15171,10 @@ function compileToVDomFunction(source, debug, file) {
|
|
|
15169
15171
|
return `($data,$viewId,$refAlt,$n,$refFn,$encUri,$encQuote)=>{${fullSource}}`;
|
|
15170
15172
|
}
|
|
15171
15173
|
|
|
15172
|
-
// src/compiler/swc/extract-global-vars.ts
|
|
15173
|
-
init_cjs_shims();
|
|
15174
|
-
var parseSyncFn = null;
|
|
15175
|
-
var parseSyncLoadAttempted = false;
|
|
15176
|
-
async function getParser() {
|
|
15177
|
-
if (!parseSyncLoadAttempted) {
|
|
15178
|
-
parseSyncLoadAttempted = true;
|
|
15179
|
-
try {
|
|
15180
|
-
const swc = await import("@swc/core");
|
|
15181
|
-
parseSyncFn = swc.parseSync;
|
|
15182
|
-
} catch (err) {
|
|
15183
|
-
console.error("failed to load @swc/core", err);
|
|
15184
|
-
}
|
|
15185
|
-
}
|
|
15186
|
-
return parseSyncFn;
|
|
15187
|
-
}
|
|
15188
|
-
async function extractGlobalVars(source) {
|
|
15189
|
-
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15190
|
-
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15191
|
-
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
15192
|
-
const template = restoreComments(converted, _comments);
|
|
15193
|
-
const templateCmdRegExp = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
15194
|
-
const fnParts = [];
|
|
15195
|
-
const htmlStore = {};
|
|
15196
|
-
let htmlIndex = 0;
|
|
15197
|
-
let lastIndex = 0;
|
|
15198
|
-
const htmlKey = String.fromCharCode(5);
|
|
15199
|
-
template.replace(
|
|
15200
|
-
templateCmdRegExp,
|
|
15201
|
-
(match, operate, content, offset) => {
|
|
15202
|
-
const start = operate ? 3 : 2;
|
|
15203
|
-
const htmlText = template.substring(lastIndex, offset + start);
|
|
15204
|
-
const key = htmlKey + htmlIndex++ + htmlKey;
|
|
15205
|
-
htmlStore[key] = htmlText;
|
|
15206
|
-
lastIndex = offset + match.length - 2;
|
|
15207
|
-
if (operate && content.trim()) {
|
|
15208
|
-
fnParts.push(';"' + key + '";', "[" + content + "]");
|
|
15209
|
-
} else {
|
|
15210
|
-
fnParts.push(';"' + key + '";', content || "");
|
|
15211
|
-
}
|
|
15212
|
-
return match;
|
|
15213
|
-
}
|
|
15214
|
-
);
|
|
15215
|
-
let fn = fnParts.join("");
|
|
15216
|
-
fn = `(function(){${fn}})`;
|
|
15217
|
-
const parseSync = await getParser();
|
|
15218
|
-
if (!parseSync) {
|
|
15219
|
-
return fallbackExtractVariables(source);
|
|
15220
|
-
}
|
|
15221
|
-
let ast;
|
|
15222
|
-
try {
|
|
15223
|
-
ast = parseSync(fn, {
|
|
15224
|
-
syntax: "ecmascript",
|
|
15225
|
-
target: "es2022"
|
|
15226
|
-
});
|
|
15227
|
-
} catch {
|
|
15228
|
-
return fallbackExtractVariables(source);
|
|
15229
|
-
}
|
|
15230
|
-
const globalExists = {};
|
|
15231
|
-
for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
|
|
15232
|
-
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15233
|
-
const fnNodes = [];
|
|
15234
|
-
walkSwcAst(ast, {
|
|
15235
|
-
VariableDeclarator(node) {
|
|
15236
|
-
if (node.id.type === "Identifier") {
|
|
15237
|
-
const name = node.id.value;
|
|
15238
|
-
globalExists[name] = node.init ? 3 : 2;
|
|
15239
|
-
}
|
|
15240
|
-
},
|
|
15241
|
-
FunctionDeclaration(node) {
|
|
15242
|
-
if (node.identifier) {
|
|
15243
|
-
globalExists[node.identifier.value] = 3;
|
|
15244
|
-
}
|
|
15245
|
-
fnNodes.push(node);
|
|
15246
|
-
},
|
|
15247
|
-
FunctionExpression(node) {
|
|
15248
|
-
fnNodes.push(node);
|
|
15249
|
-
},
|
|
15250
|
-
ArrowFunctionExpression(node) {
|
|
15251
|
-
fnNodes.push(node);
|
|
15252
|
-
},
|
|
15253
|
-
CallExpression(node) {
|
|
15254
|
-
if (node.callee.type === "Identifier") {
|
|
15255
|
-
globalExists[node.callee.value] = 1;
|
|
15256
|
-
}
|
|
15257
|
-
}
|
|
15258
|
-
});
|
|
15259
|
-
const functionParams = /* @__PURE__ */ Object.create(null);
|
|
15260
|
-
for (const fnNode of fnNodes) {
|
|
15261
|
-
const patterns = getParamPatterns(fnNode);
|
|
15262
|
-
for (const pat of patterns) {
|
|
15263
|
-
if (pat.type === "Identifier") {
|
|
15264
|
-
functionParams[pat.value] = 1;
|
|
15265
|
-
} else if (pat.type === "AssignmentPattern" && pat.left.type === "Identifier") {
|
|
15266
|
-
functionParams[pat.left.value] = 1;
|
|
15267
|
-
} else if (pat.type === "RestElement" && pat.argument.type === "Identifier") {
|
|
15268
|
-
functionParams[pat.argument.value] = 1;
|
|
15269
|
-
}
|
|
15270
|
-
}
|
|
15271
|
-
}
|
|
15272
|
-
walkSwcAst(ast, {
|
|
15273
|
-
Identifier(node) {
|
|
15274
|
-
const name = node.value;
|
|
15275
|
-
if (globalExists[name]) return;
|
|
15276
|
-
if (functionParams[name]) return;
|
|
15277
|
-
globalVars[name] = 1;
|
|
15278
|
-
},
|
|
15279
|
-
AssignmentExpression(node) {
|
|
15280
|
-
if (node.left.type === "Identifier") {
|
|
15281
|
-
const name = node.left.value;
|
|
15282
|
-
if (!globalExists[name] || globalExists[name] === 1) {
|
|
15283
|
-
globalExists[name] = (globalExists[name] || 0) + 1;
|
|
15284
|
-
}
|
|
15285
|
-
}
|
|
15286
|
-
}
|
|
15287
|
-
});
|
|
15288
|
-
return Object.keys(globalVars);
|
|
15289
|
-
}
|
|
15290
|
-
function getParamPatterns(fnNode) {
|
|
15291
|
-
if (fnNode.type === "ArrowFunctionExpression") {
|
|
15292
|
-
return fnNode.params;
|
|
15293
|
-
}
|
|
15294
|
-
return fnNode.params.map((p) => p.pat);
|
|
15295
|
-
}
|
|
15296
|
-
function fallbackExtractVariables(source) {
|
|
15297
|
-
const vars = /* @__PURE__ */ new Set();
|
|
15298
|
-
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15299
|
-
let m;
|
|
15300
|
-
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15301
|
-
vars.add(m[1]);
|
|
15302
|
-
}
|
|
15303
|
-
const eachRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15304
|
-
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15305
|
-
vars.add(m[1]);
|
|
15306
|
-
}
|
|
15307
|
-
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15308
|
-
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15309
|
-
vars.add(m[1]);
|
|
15310
|
-
}
|
|
15311
|
-
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
|
|
15312
|
-
}
|
|
15313
|
-
function walkSwcAst(ast, visitors) {
|
|
15314
|
-
function visit(node) {
|
|
15315
|
-
const type = node.type;
|
|
15316
|
-
if (visitors[type]) {
|
|
15317
|
-
visitors[type](node);
|
|
15318
|
-
}
|
|
15319
|
-
for (const key of Object.keys(node)) {
|
|
15320
|
-
if (key === "type" || key === "span" || key === "ctxt") continue;
|
|
15321
|
-
if (type === "MemberExpression" && key === "property") {
|
|
15322
|
-
const me = node;
|
|
15323
|
-
if (me.property.type !== "Computed") continue;
|
|
15324
|
-
}
|
|
15325
|
-
if (type === "KeyValueProperty" && key === "key") {
|
|
15326
|
-
const kv = node;
|
|
15327
|
-
if (kv.key.type !== "Computed") continue;
|
|
15328
|
-
}
|
|
15329
|
-
if (type === "MethodProperty" && key === "key") {
|
|
15330
|
-
const mp = node;
|
|
15331
|
-
if (mp.key.type !== "Computed") continue;
|
|
15332
|
-
}
|
|
15333
|
-
const child = Reflect.get(node, key);
|
|
15334
|
-
if (Array.isArray(child)) {
|
|
15335
|
-
for (const item of child) {
|
|
15336
|
-
if (isSwcNode(item)) visit(item);
|
|
15337
|
-
}
|
|
15338
|
-
} else if (isSwcNode(child)) {
|
|
15339
|
-
visit(child);
|
|
15340
|
-
}
|
|
15341
|
-
}
|
|
15342
|
-
}
|
|
15343
|
-
visit(ast);
|
|
15344
|
-
}
|
|
15345
|
-
function isSwcNode(v) {
|
|
15346
|
-
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15347
|
-
}
|
|
15348
|
-
var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
15349
|
-
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15350
|
-
//
|
|
15351
|
-
// These variables appear in the generated template function signature
|
|
15352
|
-
// or body. They must be excluded from extractGlobalVars() so that
|
|
15353
|
-
// they are not mistaken for user data variables and destructured from $data.
|
|
15354
|
-
// SPLITTER character constant (same as \x1e), used as namespace separator
|
|
15355
|
-
// for refData keys, event attribute encoding, and internal data structures.
|
|
15356
|
-
// Declared as: let $splitter='\x1e'
|
|
15357
|
-
"$splitter",
|
|
15358
|
-
// Data — the data object passed from Updater to the template function.
|
|
15359
|
-
// User variables are destructured from $data at the top of the function:
|
|
15360
|
-
// let {name, age} = $data;
|
|
15361
|
-
// This is the first parameter of the generated arrow function.
|
|
15362
|
-
"$data",
|
|
15363
|
-
// Null-safe toString: v => '' + (v == null ? '' : v)
|
|
15364
|
-
// Converts null/undefined to empty string, otherwise calls toString().
|
|
15365
|
-
// Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
|
|
15366
|
-
"$strSafe",
|
|
15367
|
-
// HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
|
|
15368
|
-
// Encodes &, <, >, ", ', ` to HTML entities (& < etc.)
|
|
15369
|
-
// Applied to all {{=escaped}} and {{:binding}} outputs.
|
|
15370
|
-
"$encHtml",
|
|
15371
|
-
// HTML entity map — internal object used by $encHtml:
|
|
15372
|
-
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15373
|
-
// Not a standalone function; referenced inside $encHtml's closure.
|
|
15374
|
-
"$entMap",
|
|
15375
|
-
// HTML entity RegExp — internal regexp used by $encHtml:
|
|
15376
|
-
// /[&<>"'`]/g
|
|
15377
|
-
"$entReg",
|
|
15378
|
-
// HTML entity replacer function — internal helper used by $encHtml:
|
|
15379
|
-
// m => '&' + $entMap[m] + ';'
|
|
15380
|
-
// Maps matched character to its entity string.
|
|
15381
|
-
"$entFn",
|
|
15382
|
-
// Output buffer — the string accumulator for rendered HTML.
|
|
15383
|
-
// All template output is appended via $out += '...'.
|
|
15384
|
-
// Declared as: let $out = ''
|
|
15385
|
-
"$out",
|
|
15386
|
-
// Reference lookup: (refData, value) => key
|
|
15387
|
-
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15388
|
-
// object reference. Used by {{@ref}} operator for passing object
|
|
15389
|
-
// references to child views via v-lark attributes.
|
|
15390
|
-
"$refFn",
|
|
15391
|
-
// URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
|
|
15392
|
-
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15393
|
-
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15394
|
-
"$encUri",
|
|
15395
|
-
// URI encode map — internal object used by $encUri:
|
|
15396
|
-
// {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
|
|
15397
|
-
"$uriMap",
|
|
15398
|
-
// URI encode replacer — internal helper used by $encUri:
|
|
15399
|
-
// m => $uriMap[m]
|
|
15400
|
-
"$uriFn",
|
|
15401
|
-
// URI encode regexp — internal regexp used by $encUri:
|
|
15402
|
-
// /[!')(*]/g
|
|
15403
|
-
"$uriReg",
|
|
15404
|
-
// Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
|
|
15405
|
-
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15406
|
-
// values (e.g. data-json='...').
|
|
15407
|
-
"$encQuote",
|
|
15408
|
-
// Quote encode regexp — internal regexp used by $encQuote:
|
|
15409
|
-
// /['"\\]/g
|
|
15410
|
-
"$qReg",
|
|
15411
|
-
// View ID — the unique identifier of the owning View instance.
|
|
15412
|
-
// Injected into @event attribute values at render time so that
|
|
15413
|
-
// EventDelegator can dispatch events to the correct View handler.
|
|
15414
|
-
// The \x1f placeholder in compiled output is replaced with '+$viewId+'.
|
|
15415
|
-
"$viewId",
|
|
15416
|
-
// Debug: current expression text — stores the template expression being
|
|
15417
|
-
// evaluated, for error reporting. Only present in debug mode.
|
|
15418
|
-
// e.g. $dbgExpr='<%=user.name%>'
|
|
15419
|
-
"$dbgExpr",
|
|
15420
|
-
// Debug: original art syntax — stores the {{}} template syntax before
|
|
15421
|
-
// conversion, for error reporting. Only present in debug mode.
|
|
15422
|
-
// e.g. $dbgArt='{{=user.name}}'
|
|
15423
|
-
"$dbgArt",
|
|
15424
|
-
// Debug: source line number — tracks the current line in the template
|
|
15425
|
-
// source, for error reporting. Only present in debug mode.
|
|
15426
|
-
"$dbgLine",
|
|
15427
|
-
// RefData alias — fallback reference lookup table.
|
|
15428
|
-
// Defaults to $data when no explicit $refAlt is provided.
|
|
15429
|
-
// Ensures $refFn() does not crash when @ operator is used without refData.
|
|
15430
|
-
"$refAlt",
|
|
15431
|
-
// Temporary variable — used by the compiler for intermediate
|
|
15432
|
-
// expression results in generated code (e.g. loop variables,
|
|
15433
|
-
// conditional branches). Declared as: let $tmp
|
|
15434
|
-
"$tmp",
|
|
15435
|
-
// JS literals
|
|
15436
|
-
"undefined",
|
|
15437
|
-
"null",
|
|
15438
|
-
"true",
|
|
15439
|
-
"false",
|
|
15440
|
-
"NaN",
|
|
15441
|
-
"Infinity",
|
|
15442
|
-
// JS built-in globals
|
|
15443
|
-
"window",
|
|
15444
|
-
"self",
|
|
15445
|
-
"globalThis",
|
|
15446
|
-
"document",
|
|
15447
|
-
"console",
|
|
15448
|
-
"JSON",
|
|
15449
|
-
"Math",
|
|
15450
|
-
"Intl",
|
|
15451
|
-
"Promise",
|
|
15452
|
-
"Symbol",
|
|
15453
|
-
"Number",
|
|
15454
|
-
"String",
|
|
15455
|
-
"Boolean",
|
|
15456
|
-
"Array",
|
|
15457
|
-
"Object",
|
|
15458
|
-
"Date",
|
|
15459
|
-
"RegExp",
|
|
15460
|
-
"Error",
|
|
15461
|
-
"TypeError",
|
|
15462
|
-
"RangeError",
|
|
15463
|
-
"SyntaxError",
|
|
15464
|
-
"Map",
|
|
15465
|
-
"Set",
|
|
15466
|
-
"WeakMap",
|
|
15467
|
-
"WeakSet",
|
|
15468
|
-
"Proxy",
|
|
15469
|
-
"Reflect",
|
|
15470
|
-
"ArrayBuffer",
|
|
15471
|
-
"DataView",
|
|
15472
|
-
"Float32Array",
|
|
15473
|
-
"Float64Array",
|
|
15474
|
-
"Int8Array",
|
|
15475
|
-
"Int16Array",
|
|
15476
|
-
"Int32Array",
|
|
15477
|
-
"Uint8Array",
|
|
15478
|
-
"Uint16Array",
|
|
15479
|
-
"Uint32Array",
|
|
15480
|
-
"Uint8ClampedArray",
|
|
15481
|
-
// Functions
|
|
15482
|
-
"parseInt",
|
|
15483
|
-
"parseFloat",
|
|
15484
|
-
"isNaN",
|
|
15485
|
-
"isFinite",
|
|
15486
|
-
"encodeURIComponent",
|
|
15487
|
-
"decodeURIComponent",
|
|
15488
|
-
"encodeURI",
|
|
15489
|
-
"decodeURI",
|
|
15490
|
-
// SWC helpers
|
|
15491
|
-
"arguments",
|
|
15492
|
-
"this",
|
|
15493
|
-
"require",
|
|
15494
|
-
// Lark framework
|
|
15495
|
-
"Lark"
|
|
15496
|
-
]);
|
|
15497
|
-
|
|
15498
15174
|
// src/compiler/extract-global-vars.ts
|
|
15499
15175
|
init_cjs_shims();
|
|
15500
15176
|
var import_parser = __toESM(require_lib(), 1);
|
|
15501
|
-
async function
|
|
15177
|
+
async function extractGlobalVars(source) {
|
|
15502
15178
|
const { protectedSource, comments: _comments } = protectComments(source);
|
|
15503
15179
|
const viewEventProcessed = processViewEvents(protectedSource);
|
|
15504
15180
|
const converted = convertArtSyntax(viewEventProcessed, false);
|
|
@@ -15535,10 +15211,10 @@ async function extractGlobalVars2(source) {
|
|
|
15535
15211
|
allowAwaitOutsideFunction: true
|
|
15536
15212
|
});
|
|
15537
15213
|
} catch {
|
|
15538
|
-
return
|
|
15214
|
+
return fallbackExtractVariables(source);
|
|
15539
15215
|
}
|
|
15540
15216
|
const globalExists = {};
|
|
15541
|
-
for (const name of
|
|
15217
|
+
for (const name of BUILTIN_GLOBALS) globalExists[name] = 1;
|
|
15542
15218
|
const globalVars = /* @__PURE__ */ Object.create(null);
|
|
15543
15219
|
const fnRange = [];
|
|
15544
15220
|
walkAst(ast, {
|
|
@@ -15597,22 +15273,22 @@ async function extractGlobalVars2(source) {
|
|
|
15597
15273
|
});
|
|
15598
15274
|
return Object.keys(globalVars);
|
|
15599
15275
|
}
|
|
15600
|
-
function
|
|
15276
|
+
function fallbackExtractVariables(source) {
|
|
15601
15277
|
const vars = /* @__PURE__ */ new Set();
|
|
15602
15278
|
const outputRegExp = /\{\{[:=!@]\s*([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15603
15279
|
let m;
|
|
15604
15280
|
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15605
15281
|
vars.add(m[1]);
|
|
15606
15282
|
}
|
|
15607
|
-
const
|
|
15608
|
-
while ((m =
|
|
15283
|
+
const forOfRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15284
|
+
while ((m = forOfRegExp.exec(source)) !== null) {
|
|
15609
15285
|
vars.add(m[1]);
|
|
15610
15286
|
}
|
|
15611
15287
|
const ifRegExp = /\{\{(?:else\s+)?if\s+([a-zA-Z_$][\w$]*)[^}]*\}\}/g;
|
|
15612
15288
|
while ((m = ifRegExp.exec(source)) !== null) {
|
|
15613
15289
|
vars.add(m[1]);
|
|
15614
15290
|
}
|
|
15615
|
-
return Array.from(vars).filter((v) => !
|
|
15291
|
+
return Array.from(vars).filter((v) => !BUILTIN_GLOBALS.has(v));
|
|
15616
15292
|
}
|
|
15617
15293
|
function walkAst(ast, visitors) {
|
|
15618
15294
|
function visit(node) {
|
|
@@ -15650,7 +15326,7 @@ function walkAst(ast, visitors) {
|
|
|
15650
15326
|
function isAstNode(v) {
|
|
15651
15327
|
return !!v && typeof v === "object" && typeof v.type === "string";
|
|
15652
15328
|
}
|
|
15653
|
-
var
|
|
15329
|
+
var BUILTIN_GLOBALS = /* @__PURE__ */ new Set([
|
|
15654
15330
|
// ─── Template runtime helpers (injected by compileToFunction) ───────
|
|
15655
15331
|
//
|
|
15656
15332
|
// These variables appear in the generated template function signature
|
|
@@ -15889,8 +15565,8 @@ function compileToFunction(source, debug, file) {
|
|
|
15889
15565
|
return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
|
|
15890
15566
|
}
|
|
15891
15567
|
async function compileTemplate(source, options = {}) {
|
|
15892
|
-
const { debug = false, file, virtualDom = false
|
|
15893
|
-
const globalVars = options.globalVars ?? await
|
|
15568
|
+
const { debug = false, file, virtualDom = false } = options;
|
|
15569
|
+
const globalVars = options.globalVars ?? await extractGlobalVars(source);
|
|
15894
15570
|
const { protectedSource, comments } = protectComments(source);
|
|
15895
15571
|
const converted = convertArtSyntax(protectedSource, debug);
|
|
15896
15572
|
const viewEventProcessed = processViewEvents(converted);
|
|
@@ -15926,7 +15602,7 @@ export default function(data, viewId, refData) {
|
|
|
15926
15602
|
// src/vite.ts
|
|
15927
15603
|
var LARK_TEMPLATE_SUFFIX = "?lark-template";
|
|
15928
15604
|
function larkMvcPlugin(options = {}) {
|
|
15929
|
-
const { debug = false, virtualDom = false
|
|
15605
|
+
const { debug = false, virtualDom = false } = options;
|
|
15930
15606
|
let root = __dirname;
|
|
15931
15607
|
return {
|
|
15932
15608
|
name: "lark-template",
|
|
@@ -15938,10 +15614,13 @@ function larkMvcPlugin(options = {}) {
|
|
|
15938
15614
|
const sourcePath = source.split("?")[0];
|
|
15939
15615
|
if (sourcePath.endsWith(".html") && importer) {
|
|
15940
15616
|
const importerPath = importer.split("?")[0];
|
|
15941
|
-
let resolved = import_path.
|
|
15942
|
-
if (
|
|
15943
|
-
|
|
15944
|
-
|
|
15617
|
+
let resolved = (0, import_path.resolve)((0, import_path.dirname)(importerPath), sourcePath);
|
|
15618
|
+
if (resolved.startsWith("/@fs")) {
|
|
15619
|
+
resolved = resolved.slice("/@fs".length);
|
|
15620
|
+
}
|
|
15621
|
+
if (!(0, import_path.isAbsolute)(resolved) || !(0, import_fs.existsSync)(resolved)) {
|
|
15622
|
+
const rootResolved = (0, import_path.join)(root, resolved);
|
|
15623
|
+
if ((0, import_fs.existsSync)(rootResolved)) {
|
|
15945
15624
|
resolved = rootResolved;
|
|
15946
15625
|
}
|
|
15947
15626
|
}
|
|
@@ -15954,16 +15633,19 @@ function larkMvcPlugin(options = {}) {
|
|
|
15954
15633
|
const query = qIdx >= 0 ? id.slice(qIdx + 1) : "";
|
|
15955
15634
|
if (query.split("&").includes("lark-template")) {
|
|
15956
15635
|
let filePath = qIdx >= 0 ? id.slice(0, qIdx) : id;
|
|
15957
|
-
if (
|
|
15958
|
-
|
|
15959
|
-
|
|
15636
|
+
if (filePath.startsWith("/@fs")) {
|
|
15637
|
+
filePath = filePath.slice(4);
|
|
15638
|
+
}
|
|
15639
|
+
if (!(0, import_path.isAbsolute)(filePath) || !(0, import_fs.existsSync)(filePath)) {
|
|
15640
|
+
const rootResolved = (0, import_path.join)(root, filePath);
|
|
15641
|
+
if ((0, import_fs.existsSync)(rootResolved)) {
|
|
15960
15642
|
filePath = rootResolved;
|
|
15961
15643
|
}
|
|
15962
15644
|
}
|
|
15963
|
-
if (!import_fs.
|
|
15964
|
-
const raw = import_fs.
|
|
15965
|
-
const globalVars = await
|
|
15966
|
-
return compileTemplate(raw, { debug, globalVars, virtualDom
|
|
15645
|
+
if (!(0, import_fs.existsSync)(filePath)) return void 0;
|
|
15646
|
+
const raw = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
15647
|
+
const globalVars = await extractGlobalVars(raw);
|
|
15648
|
+
return compileTemplate(raw, { debug, globalVars, virtualDom });
|
|
15967
15649
|
}
|
|
15968
15650
|
return void 0;
|
|
15969
15651
|
}
|
|
@@ -15971,29 +15653,37 @@ function larkMvcPlugin(options = {}) {
|
|
|
15971
15653
|
}
|
|
15972
15654
|
var vite_default = larkMvcPlugin;
|
|
15973
15655
|
function larkMvcPluginLegacy(options = {}) {
|
|
15974
|
-
const { debug = false, virtualDom = false
|
|
15656
|
+
const { debug = false, virtualDom = false } = options;
|
|
15975
15657
|
return {
|
|
15976
15658
|
name: "lark-template",
|
|
15977
15659
|
enforce: "pre",
|
|
15978
15660
|
resolveId(source, importer) {
|
|
15979
15661
|
if (source.endsWith(".html") && importer) {
|
|
15980
|
-
return import_path.
|
|
15662
|
+
return (0, import_path.resolve)((0, import_path.dirname)(importer), source) + LARK_TEMPLATE_SUFFIX;
|
|
15981
15663
|
}
|
|
15982
15664
|
return void 0;
|
|
15983
15665
|
},
|
|
15984
15666
|
async load(id) {
|
|
15985
15667
|
if (id.endsWith(LARK_TEMPLATE_SUFFIX)) {
|
|
15986
15668
|
const filePath = id.slice(0, -LARK_TEMPLATE_SUFFIX.length);
|
|
15987
|
-
const raw = import_fs.
|
|
15988
|
-
const globalVars = await
|
|
15989
|
-
return compileTemplate(raw, { debug, globalVars, virtualDom
|
|
15669
|
+
const raw = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
15670
|
+
const globalVars = await extractGlobalVars(raw);
|
|
15671
|
+
return compileTemplate(raw, { debug, globalVars, virtualDom });
|
|
15990
15672
|
}
|
|
15991
15673
|
return void 0;
|
|
15992
15674
|
}
|
|
15993
15675
|
};
|
|
15994
15676
|
}
|
|
15677
|
+
function larkMvcPlugin7(options = {}) {
|
|
15678
|
+
return larkMvcPlugin(options);
|
|
15679
|
+
}
|
|
15680
|
+
function larkMvcPluginLegacy7(options = {}) {
|
|
15681
|
+
return larkMvcPluginLegacy(options);
|
|
15682
|
+
}
|
|
15995
15683
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15996
15684
|
0 && (module.exports = {
|
|
15997
15685
|
larkMvcPlugin,
|
|
15998
|
-
|
|
15686
|
+
larkMvcPlugin7,
|
|
15687
|
+
larkMvcPluginLegacy,
|
|
15688
|
+
larkMvcPluginLegacy7
|
|
15999
15689
|
});
|
package/dist/vite.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { Plugin as Plugin$1 } from 'vite7';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @lark.js/mvc Vite Plugin for Template Compilation
|
|
@@ -24,24 +25,32 @@ import { Plugin } from 'vite';
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
|
|
28
|
+
interface LarkMvcVitePluginOptions {
|
|
29
|
+
/** Enable debug mode with line tracking (default: false) */
|
|
30
|
+
debug?: boolean;
|
|
31
|
+
/** Enable virtual DOM output (default: false) */
|
|
32
|
+
virtualDom?: boolean;
|
|
33
|
+
}
|
|
27
34
|
/**
|
|
28
35
|
* Create a Vite plugin that compiles .html template files.
|
|
29
36
|
*
|
|
30
37
|
* @param options - Plugin options
|
|
31
|
-
* @param options.debug - Enable debug mode with line tracking (default: false)
|
|
32
38
|
* @param options.virtualDom - Generate VDOM output instead of HTML string (default: false)
|
|
33
39
|
* @returns Vite plugin instance
|
|
34
40
|
*/
|
|
35
|
-
declare function larkMvcPlugin(options?:
|
|
36
|
-
debug?: boolean;
|
|
37
|
-
virtualDom?: boolean;
|
|
38
|
-
useSwc?: boolean;
|
|
39
|
-
}): Plugin;
|
|
41
|
+
declare function larkMvcPlugin(options?: LarkMvcVitePluginOptions): Plugin;
|
|
40
42
|
|
|
41
43
|
declare function larkMvcPluginLegacy(options?: {
|
|
42
44
|
debug?: boolean;
|
|
43
45
|
virtualDom?: boolean;
|
|
44
|
-
useSwc?: boolean;
|
|
45
46
|
}): Plugin;
|
|
47
|
+
declare function larkMvcPlugin7(options?: {
|
|
48
|
+
debug?: boolean;
|
|
49
|
+
virtualDom?: boolean;
|
|
50
|
+
}): Plugin$1;
|
|
51
|
+
declare function larkMvcPluginLegacy7(options?: {
|
|
52
|
+
debug?: boolean;
|
|
53
|
+
virtualDom?: boolean;
|
|
54
|
+
}): Plugin$1;
|
|
46
55
|
|
|
47
|
-
export { larkMvcPlugin as default, larkMvcPlugin, larkMvcPluginLegacy };
|
|
56
|
+
export { type LarkMvcVitePluginOptions, larkMvcPlugin as default, larkMvcPlugin, larkMvcPlugin7, larkMvcPluginLegacy, larkMvcPluginLegacy7 };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { Plugin as Plugin$1 } from 'vite7';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @lark.js/mvc Vite Plugin for Template Compilation
|
|
@@ -24,24 +25,32 @@ import { Plugin } from 'vite';
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
|
|
28
|
+
interface LarkMvcVitePluginOptions {
|
|
29
|
+
/** Enable debug mode with line tracking (default: false) */
|
|
30
|
+
debug?: boolean;
|
|
31
|
+
/** Enable virtual DOM output (default: false) */
|
|
32
|
+
virtualDom?: boolean;
|
|
33
|
+
}
|
|
27
34
|
/**
|
|
28
35
|
* Create a Vite plugin that compiles .html template files.
|
|
29
36
|
*
|
|
30
37
|
* @param options - Plugin options
|
|
31
|
-
* @param options.debug - Enable debug mode with line tracking (default: false)
|
|
32
38
|
* @param options.virtualDom - Generate VDOM output instead of HTML string (default: false)
|
|
33
39
|
* @returns Vite plugin instance
|
|
34
40
|
*/
|
|
35
|
-
declare function larkMvcPlugin(options?:
|
|
36
|
-
debug?: boolean;
|
|
37
|
-
virtualDom?: boolean;
|
|
38
|
-
useSwc?: boolean;
|
|
39
|
-
}): Plugin;
|
|
41
|
+
declare function larkMvcPlugin(options?: LarkMvcVitePluginOptions): Plugin;
|
|
40
42
|
|
|
41
43
|
declare function larkMvcPluginLegacy(options?: {
|
|
42
44
|
debug?: boolean;
|
|
43
45
|
virtualDom?: boolean;
|
|
44
|
-
useSwc?: boolean;
|
|
45
46
|
}): Plugin;
|
|
47
|
+
declare function larkMvcPlugin7(options?: {
|
|
48
|
+
debug?: boolean;
|
|
49
|
+
virtualDom?: boolean;
|
|
50
|
+
}): Plugin$1;
|
|
51
|
+
declare function larkMvcPluginLegacy7(options?: {
|
|
52
|
+
debug?: boolean;
|
|
53
|
+
virtualDom?: boolean;
|
|
54
|
+
}): Plugin$1;
|
|
46
55
|
|
|
47
|
-
export { larkMvcPlugin as default, larkMvcPlugin, larkMvcPluginLegacy };
|
|
56
|
+
export { type LarkMvcVitePluginOptions, larkMvcPlugin as default, larkMvcPlugin, larkMvcPlugin7, larkMvcPluginLegacy, larkMvcPluginLegacy7 };
|