@wevu/compiler 6.6.4 → 6.6.6
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/dist/index.d.mts +16 -0
- package/dist/index.mjs +170 -46
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -192,6 +192,20 @@ interface ScopedSlotComponentAsset {
|
|
|
192
192
|
classStyleWxs?: boolean;
|
|
193
193
|
inlineExpressions?: InlineExpressionAsset[];
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* 内联表达式资源描述。
|
|
197
|
+
*/
|
|
198
|
+
interface InlineExpressionIndexBindingAsset {
|
|
199
|
+
key: string;
|
|
200
|
+
binding: string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 内联表达式作用域恢复器描述。
|
|
204
|
+
*/
|
|
205
|
+
interface InlineExpressionScopeResolverAsset {
|
|
206
|
+
key: string;
|
|
207
|
+
expression: string;
|
|
208
|
+
}
|
|
195
209
|
/**
|
|
196
210
|
* 内联表达式资源描述。
|
|
197
211
|
*/
|
|
@@ -199,6 +213,8 @@ interface InlineExpressionAsset {
|
|
|
199
213
|
id: string;
|
|
200
214
|
expression: string;
|
|
201
215
|
scopeKeys: string[];
|
|
216
|
+
indexBindings?: InlineExpressionIndexBindingAsset[];
|
|
217
|
+
scopeResolvers?: InlineExpressionScopeResolverAsset[];
|
|
202
218
|
}
|
|
203
219
|
/**
|
|
204
220
|
* 模板编译结果。
|
package/dist/index.mjs
CHANGED
|
@@ -2576,7 +2576,21 @@ function buildInlineMapExpression(inlineExpressions) {
|
|
|
2576
2576
|
t.identifier("scope"),
|
|
2577
2577
|
t.identifier("$event")
|
|
2578
2578
|
], exprAst);
|
|
2579
|
-
const
|
|
2579
|
+
const entryObjProps = [t.objectProperty(t.identifier("keys"), keysExpr), t.objectProperty(t.identifier("fn"), fnExpr)];
|
|
2580
|
+
if (entry.indexBindings?.length) {
|
|
2581
|
+
const indexKeysExpr = t.arrayExpression(entry.indexBindings.map((binding) => t.stringLiteral(binding.key)));
|
|
2582
|
+
entryObjProps.push(t.objectProperty(t.identifier("indexKeys"), indexKeysExpr));
|
|
2583
|
+
}
|
|
2584
|
+
if (entry.scopeResolvers?.length) {
|
|
2585
|
+
const resolverMap = new Map(entry.scopeResolvers.map((item) => [item.key, item.expression]));
|
|
2586
|
+
const resolverExpr = t.arrayExpression(entry.scopeKeys.map((key) => {
|
|
2587
|
+
const source = resolverMap.get(key);
|
|
2588
|
+
if (!source) return t.identifier("undefined");
|
|
2589
|
+
return parseBabelExpression(source) ?? t.identifier("undefined");
|
|
2590
|
+
}));
|
|
2591
|
+
entryObjProps.push(t.objectProperty(t.identifier("scopeResolvers"), resolverExpr));
|
|
2592
|
+
}
|
|
2593
|
+
const entryObj = t.objectExpression(entryObjProps);
|
|
2580
2594
|
return t.objectProperty(t.stringLiteral(entry.id), entryObj);
|
|
2581
2595
|
});
|
|
2582
2596
|
return t.objectExpression(entries);
|
|
@@ -4397,6 +4411,7 @@ const INLINE_GLOBALS = new Set([
|
|
|
4397
4411
|
"require",
|
|
4398
4412
|
"arguments",
|
|
4399
4413
|
"__weapp_vite",
|
|
4414
|
+
"__wevuUnref",
|
|
4400
4415
|
"globalThis",
|
|
4401
4416
|
"setTimeout",
|
|
4402
4417
|
"clearTimeout",
|
|
@@ -4413,8 +4428,10 @@ const INLINE_GLOBALS = new Set([
|
|
|
4413
4428
|
"ctx",
|
|
4414
4429
|
"scope"
|
|
4415
4430
|
]);
|
|
4431
|
+
const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
4432
|
+
const SIMPLE_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
|
|
4416
4433
|
function createMemberAccess$1(target, prop) {
|
|
4417
|
-
if (
|
|
4434
|
+
if (IDENTIFIER_RE.test(prop)) return t.memberExpression(t.identifier(target), t.identifier(prop));
|
|
4418
4435
|
return t.memberExpression(t.identifier(target), t.stringLiteral(prop), true);
|
|
4419
4436
|
}
|
|
4420
4437
|
function resolveSlotPropBinding(slotProps, name) {
|
|
@@ -4423,29 +4440,16 @@ function resolveSlotPropBinding(slotProps, name) {
|
|
|
4423
4440
|
if (!prop) return "__wvSlotPropsData";
|
|
4424
4441
|
return generateExpression(createMemberAccess$1("__wvSlotPropsData", prop));
|
|
4425
4442
|
}
|
|
4426
|
-
function
|
|
4427
|
-
const parsed = parseBabelExpressionFile(exp);
|
|
4428
|
-
if (!parsed) return null;
|
|
4429
|
-
const { ast, expression } = parsed;
|
|
4430
|
-
const locals = collectScopedSlotLocals(context);
|
|
4431
|
-
const slotProps = collectSlotPropMapping(context);
|
|
4432
|
-
for (const name of Object.keys(slotProps)) locals.add(name);
|
|
4433
|
-
const usedLocals = [];
|
|
4434
|
-
const usedLocalSet = /* @__PURE__ */ new Set();
|
|
4435
|
-
const markLocal = (name) => {
|
|
4436
|
-
if (usedLocalSet.has(name)) return;
|
|
4437
|
-
usedLocalSet.add(name);
|
|
4438
|
-
usedLocals.push(name);
|
|
4439
|
-
};
|
|
4443
|
+
function rewriteExpressionAst(ast, locals, options) {
|
|
4440
4444
|
traverse(ast, {
|
|
4441
4445
|
Identifier(path) {
|
|
4442
4446
|
if (!path.isReferencedIdentifier()) return;
|
|
4443
4447
|
const name = path.node.name;
|
|
4444
4448
|
if (name === "$event") return;
|
|
4445
4449
|
if (name === "ctx" || name === "scope") return;
|
|
4446
|
-
if (path.scope.
|
|
4450
|
+
if (path.scope.getBinding(name)) return;
|
|
4447
4451
|
if (locals.has(name)) {
|
|
4448
|
-
markLocal(name);
|
|
4452
|
+
options?.markLocal?.(name);
|
|
4449
4453
|
path.replaceWith(createMemberAccess$1("scope", name));
|
|
4450
4454
|
return;
|
|
4451
4455
|
}
|
|
@@ -4456,19 +4460,85 @@ function registerInlineExpression(exp, context) {
|
|
|
4456
4460
|
path.replaceWith(t.identifier("ctx"));
|
|
4457
4461
|
}
|
|
4458
4462
|
});
|
|
4459
|
-
|
|
4463
|
+
}
|
|
4464
|
+
function buildInlineIndexBindings(context) {
|
|
4465
|
+
if (!context.forStack.length) return [];
|
|
4466
|
+
return context.forStack.map((forInfo, level) => ({
|
|
4467
|
+
key: `__wv_i${level}`,
|
|
4468
|
+
binding: forInfo.index?.trim() || "index"
|
|
4469
|
+
}));
|
|
4470
|
+
}
|
|
4471
|
+
function buildForItemResolverExpression(targetKey, context, slotProps, indexBindings) {
|
|
4472
|
+
let targetLevel = -1;
|
|
4473
|
+
for (let level = context.forStack.length - 1; level >= 0; level -= 1) if (context.forStack[level]?.item === targetKey) {
|
|
4474
|
+
targetLevel = level;
|
|
4475
|
+
break;
|
|
4476
|
+
}
|
|
4477
|
+
if (targetLevel < 0) return null;
|
|
4478
|
+
const listExp = context.forStack[targetLevel]?.listExp?.trim() ?? "";
|
|
4479
|
+
const indexBinding = indexBindings[targetLevel];
|
|
4480
|
+
if (!listExp || !indexBinding || !SIMPLE_PATH_RE.test(listExp)) return null;
|
|
4481
|
+
const root = listExp.split(".")[0];
|
|
4482
|
+
const localRoots = new Set(Object.keys(slotProps));
|
|
4483
|
+
for (let level = 0; level <= targetLevel; level += 1) {
|
|
4484
|
+
const item = context.forStack[level]?.item?.trim();
|
|
4485
|
+
const index = context.forStack[level]?.index?.trim();
|
|
4486
|
+
if (item) localRoots.add(item);
|
|
4487
|
+
if (index) localRoots.add(index);
|
|
4488
|
+
localRoots.add("index");
|
|
4489
|
+
}
|
|
4490
|
+
if (localRoots.has(root)) return null;
|
|
4491
|
+
return `({type:'for-item',path:${JSON.stringify(listExp)},indexKey:${JSON.stringify(indexBinding.key)}})`;
|
|
4492
|
+
}
|
|
4493
|
+
function buildScopeResolvers(usedLocals, context, slotProps, indexBindings) {
|
|
4494
|
+
const resolvers = [];
|
|
4495
|
+
for (const key of usedLocals) {
|
|
4496
|
+
const expression = buildForItemResolverExpression(key, context, slotProps, indexBindings);
|
|
4497
|
+
if (!expression) continue;
|
|
4498
|
+
resolvers.push({
|
|
4499
|
+
key,
|
|
4500
|
+
expression
|
|
4501
|
+
});
|
|
4502
|
+
}
|
|
4503
|
+
return resolvers;
|
|
4504
|
+
}
|
|
4505
|
+
function registerInlineExpression(exp, context) {
|
|
4506
|
+
const parsed = parseBabelExpressionFile(exp);
|
|
4507
|
+
if (!parsed) return null;
|
|
4508
|
+
const { ast } = parsed;
|
|
4509
|
+
const locals = collectScopedSlotLocals(context);
|
|
4510
|
+
const slotProps = collectSlotPropMapping(context);
|
|
4511
|
+
for (const name of Object.keys(slotProps)) locals.add(name);
|
|
4512
|
+
const usedLocals = [];
|
|
4513
|
+
const usedLocalSet = /* @__PURE__ */ new Set();
|
|
4514
|
+
const markLocal = (name) => {
|
|
4515
|
+
if (usedLocalSet.has(name)) return;
|
|
4516
|
+
usedLocalSet.add(name);
|
|
4517
|
+
usedLocals.push(name);
|
|
4518
|
+
};
|
|
4519
|
+
rewriteExpressionAst(ast, locals, { markLocal });
|
|
4520
|
+
const updatedStmt = ast.program.body[0];
|
|
4521
|
+
const updatedExpressionNode = updatedStmt && "expression" in updatedStmt ? updatedStmt.expression : null;
|
|
4522
|
+
const updatedExpression = updatedExpressionNode ? generateExpression(updatedExpressionNode) : exp;
|
|
4460
4523
|
const scopeBindings = usedLocals.map((name) => {
|
|
4461
4524
|
return resolveSlotPropBinding(slotProps, name) ?? name;
|
|
4462
4525
|
});
|
|
4526
|
+
const indexBindings = buildInlineIndexBindings(context);
|
|
4527
|
+
const scopeResolvers = buildScopeResolvers(usedLocals, context, slotProps, indexBindings);
|
|
4463
4528
|
const asset = {
|
|
4464
4529
|
id: `__wv_inline_${context.inlineExpressionSeed++}`,
|
|
4465
4530
|
expression: updatedExpression,
|
|
4466
4531
|
scopeKeys: usedLocals
|
|
4467
4532
|
};
|
|
4533
|
+
if (scopeResolvers.length) {
|
|
4534
|
+
asset.indexBindings = indexBindings;
|
|
4535
|
+
asset.scopeResolvers = scopeResolvers;
|
|
4536
|
+
}
|
|
4468
4537
|
context.inlineExpressions.push(asset);
|
|
4469
4538
|
return {
|
|
4470
4539
|
id: asset.id,
|
|
4471
|
-
scopeBindings
|
|
4540
|
+
scopeBindings,
|
|
4541
|
+
indexBindings: scopeResolvers.length ? indexBindings.map((binding) => binding.binding) : []
|
|
4472
4542
|
};
|
|
4473
4543
|
}
|
|
4474
4544
|
|
|
@@ -4574,6 +4644,50 @@ function normalizeJsExpressionWithContext(exp, context, options) {
|
|
|
4574
4644
|
return (stmt && "expression" in stmt ? stmt.expression : null) || null;
|
|
4575
4645
|
}
|
|
4576
4646
|
|
|
4647
|
+
//#endregion
|
|
4648
|
+
//#region src/plugins/vue/compiler/template/expression/runtimeBinding.ts
|
|
4649
|
+
function buildForIndexAccess$1(context) {
|
|
4650
|
+
if (!context.forStack.length) return "";
|
|
4651
|
+
return context.forStack.map((info) => `[${info.index ?? "index"}]`).join("");
|
|
4652
|
+
}
|
|
4653
|
+
/**
|
|
4654
|
+
* 检测表达式是否包含小程序模板不稳定的调用语义。
|
|
4655
|
+
*/
|
|
4656
|
+
function shouldFallbackToRuntimeBinding(exp) {
|
|
4657
|
+
const trimmed = exp.trim();
|
|
4658
|
+
if (!trimmed) return false;
|
|
4659
|
+
const parsed = parseBabelExpressionFile(normalizeWxmlExpression(trimmed));
|
|
4660
|
+
if (!parsed) return false;
|
|
4661
|
+
let shouldFallback = false;
|
|
4662
|
+
traverse(parsed.ast, {
|
|
4663
|
+
CallExpression(path) {
|
|
4664
|
+
shouldFallback = true;
|
|
4665
|
+
path.stop();
|
|
4666
|
+
},
|
|
4667
|
+
OptionalCallExpression(path) {
|
|
4668
|
+
shouldFallback = true;
|
|
4669
|
+
path.stop();
|
|
4670
|
+
}
|
|
4671
|
+
});
|
|
4672
|
+
return shouldFallback;
|
|
4673
|
+
}
|
|
4674
|
+
/**
|
|
4675
|
+
* 将复杂表达式注册为 JS 运行时计算绑定,返回可用于模板 mustache 的绑定引用。
|
|
4676
|
+
*/
|
|
4677
|
+
function registerRuntimeBindingExpression(exp, context, options) {
|
|
4678
|
+
const expAst = normalizeJsExpressionWithContext(exp, context, options);
|
|
4679
|
+
if (!expAst) return null;
|
|
4680
|
+
const binding = {
|
|
4681
|
+
name: `__wv_bind_${context.classStyleBindings.filter((item) => item.type === "bind").length}`,
|
|
4682
|
+
type: "bind",
|
|
4683
|
+
exp,
|
|
4684
|
+
expAst,
|
|
4685
|
+
forStack: context.forStack.map((info) => ({ ...info }))
|
|
4686
|
+
};
|
|
4687
|
+
context.classStyleBindings.push(binding);
|
|
4688
|
+
return `${binding.name}${buildForIndexAccess$1(context)}`;
|
|
4689
|
+
}
|
|
4690
|
+
|
|
4577
4691
|
//#endregion
|
|
4578
4692
|
//#region src/plugins/vue/compiler/template/mustache.ts
|
|
4579
4693
|
function renderMustache(expression, context) {
|
|
@@ -4588,7 +4702,7 @@ function toWxmlStringLiteral(value) {
|
|
|
4588
4702
|
function cloneForStack(context) {
|
|
4589
4703
|
return context.forStack.map((info) => ({ ...info }));
|
|
4590
4704
|
}
|
|
4591
|
-
function buildForIndexAccess
|
|
4705
|
+
function buildForIndexAccess(context) {
|
|
4592
4706
|
if (!context.forStack.length) return "";
|
|
4593
4707
|
return context.forStack.map((info) => `[${info.index ?? "index"}]`).join("");
|
|
4594
4708
|
}
|
|
@@ -4660,7 +4774,7 @@ function renderClassAttribute(staticClass, dynamicClassExp, context) {
|
|
|
4660
4774
|
const expAst = mergeJsExpressionParts(jsParts);
|
|
4661
4775
|
const binding = createClassStyleBinding(context, "class", generateExpressionCode(expAst), expAst);
|
|
4662
4776
|
context.classStyleBindings.push(binding);
|
|
4663
|
-
const indexAccess = buildForIndexAccess
|
|
4777
|
+
const indexAccess = buildForIndexAccess(context);
|
|
4664
4778
|
return `class="${renderMustache(`${binding.name}${indexAccess}`, context)}"`;
|
|
4665
4779
|
}
|
|
4666
4780
|
function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
|
|
@@ -4694,7 +4808,7 @@ function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
|
|
|
4694
4808
|
const expAst = mergeJsExpressionParts(jsParts);
|
|
4695
4809
|
const binding = createClassStyleBinding(context, "style", generateExpressionCode(expAst), expAst);
|
|
4696
4810
|
context.classStyleBindings.push(binding);
|
|
4697
|
-
const indexAccess = buildForIndexAccess
|
|
4811
|
+
const indexAccess = buildForIndexAccess(context);
|
|
4698
4812
|
return `style="${renderMustache(`${binding.name}${indexAccess}`, context)}"`;
|
|
4699
4813
|
}
|
|
4700
4814
|
function transformAttribute(node, _context) {
|
|
@@ -4715,23 +4829,10 @@ function isTopLevelObjectLiteral(exp) {
|
|
|
4715
4829
|
if (!parsed) return false;
|
|
4716
4830
|
return unwrapTsExpression(parsed).type === "ObjectExpression";
|
|
4717
4831
|
}
|
|
4718
|
-
function buildForIndexAccess(context) {
|
|
4719
|
-
if (!context.forStack.length) return "";
|
|
4720
|
-
return context.forStack.map((info) => `[${info.index ?? "index"}]`).join("");
|
|
4721
|
-
}
|
|
4722
4832
|
function createBindRuntimeAttr(argValue, rawExpValue, context) {
|
|
4723
|
-
const
|
|
4724
|
-
if (!
|
|
4725
|
-
|
|
4726
|
-
name: `__wv_bind_${context.classStyleBindings.filter((item) => item.type === "bind").length}`,
|
|
4727
|
-
type: "bind",
|
|
4728
|
-
exp: rawExpValue,
|
|
4729
|
-
expAst,
|
|
4730
|
-
forStack: context.forStack.map((info) => ({ ...info }))
|
|
4731
|
-
};
|
|
4732
|
-
context.classStyleBindings.push(binding);
|
|
4733
|
-
const indexAccess = buildForIndexAccess(context);
|
|
4734
|
-
return `${argValue}="${renderMustache(`${binding.name}${indexAccess}`, context)}"`;
|
|
4833
|
+
const bindingRef = registerRuntimeBindingExpression(rawExpValue, context, { hint: `:${argValue} 绑定` });
|
|
4834
|
+
if (!bindingRef) return null;
|
|
4835
|
+
return `${argValue}="${renderMustache(bindingRef, context)}"`;
|
|
4735
4836
|
}
|
|
4736
4837
|
function createInlineObjectLiteralAttr(argValue, rawExpValue, context) {
|
|
4737
4838
|
const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context).trim();
|
|
@@ -4776,6 +4877,10 @@ function transformBindDirective(node, context, forInfo) {
|
|
|
4776
4877
|
if (context.objectLiteralBindMode === "inline") return createInlineObjectLiteralAttr(argValue, rawExpValue, context);
|
|
4777
4878
|
return createBindRuntimeAttr(argValue, rawExpValue, context);
|
|
4778
4879
|
}
|
|
4880
|
+
if (shouldFallbackToRuntimeBinding(rawExpValue)) {
|
|
4881
|
+
const runtimeAttr = createBindRuntimeAttr(argValue, rawExpValue, context);
|
|
4882
|
+
if (runtimeAttr) return runtimeAttr;
|
|
4883
|
+
}
|
|
4779
4884
|
return `${argValue}="${renderMustache(normalizeWxmlExpressionWithContext(rawExpValue, context), context)}"`;
|
|
4780
4885
|
}
|
|
4781
4886
|
|
|
@@ -4856,6 +4961,11 @@ function buildInlineScopeAttrs(scopeBindings, context) {
|
|
|
4856
4961
|
return `data-wv-s${index}="${renderMustache(binding.replace(/"/g, """), context)}"`;
|
|
4857
4962
|
});
|
|
4858
4963
|
}
|
|
4964
|
+
function buildInlineIndexAttrs(indexBindings, context) {
|
|
4965
|
+
return indexBindings.map((binding, index) => {
|
|
4966
|
+
return `data-wv-i${index}="${renderMustache(binding.replace(/"/g, """), context)}"`;
|
|
4967
|
+
});
|
|
4968
|
+
}
|
|
4859
4969
|
function resolveEventPrefix(modifiers) {
|
|
4860
4970
|
const hasCatch = modifiers.some((modifier) => modifier.content === "catch");
|
|
4861
4971
|
const hasStop = modifiers.some((modifier) => modifier.content === "stop");
|
|
@@ -4881,9 +4991,11 @@ function transformOnDirective(node, context) {
|
|
|
4881
4991
|
if (context.rewriteScopedSlot) {
|
|
4882
4992
|
if (inlineExpression) {
|
|
4883
4993
|
const scopeAttrs = buildInlineScopeAttrs(inlineExpression.scopeBindings, context);
|
|
4994
|
+
const indexAttrs = buildInlineIndexAttrs(inlineExpression.indexBindings, context);
|
|
4884
4995
|
return [
|
|
4885
4996
|
`data-wv-inline-id="${inlineExpression.id}"`,
|
|
4886
4997
|
...scopeAttrs,
|
|
4998
|
+
...indexAttrs,
|
|
4887
4999
|
`${bindAttr}="__weapp_vite_owner"`
|
|
4888
5000
|
].filter(Boolean).join(" ");
|
|
4889
5001
|
}
|
|
@@ -4896,9 +5008,11 @@ function transformOnDirective(node, context) {
|
|
|
4896
5008
|
const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context);
|
|
4897
5009
|
if (inlineExpression) {
|
|
4898
5010
|
const scopeAttrs = buildInlineScopeAttrs(inlineExpression.scopeBindings, context);
|
|
5011
|
+
const indexAttrs = buildInlineIndexAttrs(inlineExpression.indexBindings, context);
|
|
4899
5012
|
return [
|
|
4900
5013
|
`data-wv-inline-id="${inlineExpression.id}"`,
|
|
4901
5014
|
...scopeAttrs,
|
|
5015
|
+
...indexAttrs,
|
|
4902
5016
|
`${bindAttr}="__weapp_vite_inline"`
|
|
4903
5017
|
].filter(Boolean).join(" ");
|
|
4904
5018
|
}
|
|
@@ -4995,7 +5109,8 @@ function collectElementAttributes(node, context, options) {
|
|
|
4995
5109
|
continue;
|
|
4996
5110
|
}
|
|
4997
5111
|
if (prop.name === "text" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
4998
|
-
|
|
5112
|
+
const rawExp = prop.exp.content;
|
|
5113
|
+
vTextExp = (shouldFallbackToRuntimeBinding(rawExp) ? registerRuntimeBindingExpression(rawExp, context, { hint: "v-text" }) : null) ?? normalizeWxmlExpressionWithContext(rawExp, context);
|
|
4999
5114
|
continue;
|
|
5000
5115
|
}
|
|
5001
5116
|
const dir = transformDirective(prop, context, node, options?.forInfo);
|
|
@@ -5415,6 +5530,9 @@ function transformNormalElement(node, context, transformNode) {
|
|
|
5415
5530
|
|
|
5416
5531
|
//#endregion
|
|
5417
5532
|
//#region src/plugins/vue/compiler/template/elements/tag-structural.ts
|
|
5533
|
+
function resolveConditionExpression$1(rawExpValue, context, hint) {
|
|
5534
|
+
return (shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context);
|
|
5535
|
+
}
|
|
5418
5536
|
function transformIfElement(node, context, transformNode) {
|
|
5419
5537
|
const renderTemplateMustache = (exp) => renderMustache(exp, context);
|
|
5420
5538
|
const ifDirective = node.props.find((prop) => prop.type === NodeTypes.DIRECTIVE && (prop.name === "if" || prop.name === "else-if" || prop.name === "else"));
|
|
@@ -5431,10 +5549,10 @@ function transformIfElement(node, context, transformNode) {
|
|
|
5431
5549
|
const content = slotDirective || templateSlotChildren.length > 0 ? transformComponentWithSlots(elementWithoutIf, context, transformNode) : transformNormalElement(elementWithoutIf, context, transformNode);
|
|
5432
5550
|
const dir = ifDirective;
|
|
5433
5551
|
if (dir.name === "if" && dir.exp) {
|
|
5434
|
-
const expValue =
|
|
5552
|
+
const expValue = resolveConditionExpression$1(dir.exp.type === NodeTypes.SIMPLE_EXPRESSION ? dir.exp.content : "", context, "v-if");
|
|
5435
5553
|
return context.platform.wrapIf(expValue, content, renderTemplateMustache);
|
|
5436
5554
|
} else if (dir.name === "else-if" && dir.exp) {
|
|
5437
|
-
const expValue =
|
|
5555
|
+
const expValue = resolveConditionExpression$1(dir.exp.type === NodeTypes.SIMPLE_EXPRESSION ? dir.exp.content : "", context, "v-else-if");
|
|
5438
5556
|
return context.platform.wrapElseIf(expValue, content, renderTemplateMustache);
|
|
5439
5557
|
} else if (dir.name === "else") return context.platform.wrapElse(content);
|
|
5440
5558
|
return content;
|
|
@@ -5445,7 +5563,7 @@ function transformForElement(node, context, transformNode) {
|
|
|
5445
5563
|
if (!forDirective || !forDirective.exp) return transformNormalElement(node, context, transformNode);
|
|
5446
5564
|
const forInfo = parseForExpression(forDirective.exp.type === NodeTypes.SIMPLE_EXPRESSION ? forDirective.exp.content : "");
|
|
5447
5565
|
if (context.classStyleRuntime === "js" && !forInfo.index) forInfo.index = `__wv_index_${context.forIndexSeed++}`;
|
|
5448
|
-
const listExp = forInfo.listExp ?
|
|
5566
|
+
const listExp = forInfo.listExp ? resolveConditionExpression$1(forInfo.listExp, context, "v-for 列表") : void 0;
|
|
5449
5567
|
const listExpAst = forInfo.listExp ? normalizeJsExpressionWithContext(forInfo.listExp, context, { hint: "v-for 列表" }) : void 0;
|
|
5450
5568
|
const scopedForInfo = listExp ? {
|
|
5451
5569
|
...forInfo,
|
|
@@ -5488,6 +5606,9 @@ function transformForElement(node, context, transformNode) {
|
|
|
5488
5606
|
|
|
5489
5607
|
//#endregion
|
|
5490
5608
|
//#region src/plugins/vue/compiler/template/elements/tag-builtin.ts
|
|
5609
|
+
function resolveConditionExpression(rawExpValue, context, hint) {
|
|
5610
|
+
return (shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context);
|
|
5611
|
+
}
|
|
5491
5612
|
function transformTransitionElement(node, context, transformNode) {
|
|
5492
5613
|
context.warnings.push("<transition> 组件:过渡效果需要动画库或运行时支持,仅渲染子节点。");
|
|
5493
5614
|
const children = node.children.map((child) => transformNode(child, context)).join("");
|
|
@@ -5533,11 +5654,11 @@ function transformTemplateElement(node, context, transformNode) {
|
|
|
5533
5654
|
props: base
|
|
5534
5655
|
};
|
|
5535
5656
|
if (dir.name === "if" && dir.exp) {
|
|
5536
|
-
const expValue =
|
|
5657
|
+
const expValue = resolveConditionExpression(dir.exp.type === NodeTypes.SIMPLE_EXPRESSION ? dir.exp.content : "", context, "template v-if");
|
|
5537
5658
|
return context.platform.wrapIf(expValue, children, renderTemplateMustache);
|
|
5538
5659
|
}
|
|
5539
5660
|
if (dir.name === "else-if" && dir.exp) {
|
|
5540
|
-
const expValue =
|
|
5661
|
+
const expValue = resolveConditionExpression(dir.exp.type === NodeTypes.SIMPLE_EXPRESSION ? dir.exp.content : "", context, "template v-else-if");
|
|
5541
5662
|
return context.platform.wrapElseIf(expValue, children, renderTemplateMustache);
|
|
5542
5663
|
}
|
|
5543
5664
|
if (dir.name === "else") return context.platform.wrapElse(children);
|
|
@@ -5579,7 +5700,10 @@ function transformText(node, _context) {
|
|
|
5579
5700
|
}
|
|
5580
5701
|
function transformInterpolation(node, context) {
|
|
5581
5702
|
const { content } = node;
|
|
5582
|
-
if (content.type === NodeTypes.SIMPLE_EXPRESSION)
|
|
5703
|
+
if (content.type === NodeTypes.SIMPLE_EXPRESSION) {
|
|
5704
|
+
const rawExpValue = content.content;
|
|
5705
|
+
return renderMustache((shouldFallbackToRuntimeBinding(rawExpValue) ? registerRuntimeBindingExpression(rawExpValue, context, { hint: "插值表达式" }) : null) ?? normalizeWxmlExpressionWithContext(rawExpValue, context), context);
|
|
5706
|
+
}
|
|
5583
5707
|
/* istanbul ignore next */
|
|
5584
5708
|
return renderMustache("", context);
|
|
5585
5709
|
}
|