@wevu/compiler 6.16.37 → 6.16.41
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 +6 -0
- package/dist/index.mjs +190 -22
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -309,6 +309,7 @@ interface ForParseResult {
|
|
|
309
309
|
*/
|
|
310
310
|
interface TemplateCompileOptions {
|
|
311
311
|
platform?: MiniProgramPlatform;
|
|
312
|
+
isPage?: boolean;
|
|
312
313
|
/**
|
|
313
314
|
* Vue `<script setup>` props 解构重命名映射,key 为模板中使用的本地别名,value 为原始 prop 名。
|
|
314
315
|
*/
|
|
@@ -332,6 +333,7 @@ interface TemplateCompileOptions {
|
|
|
332
333
|
functionPropNames?: Iterable<FunctionPropNameMatcher>;
|
|
333
334
|
wevuComponentTags?: Iterable<string>;
|
|
334
335
|
componentNameMap?: Record<string, string>;
|
|
336
|
+
miniProgramComponentTags?: Iterable<string>;
|
|
335
337
|
}
|
|
336
338
|
/**
|
|
337
339
|
* 作用域插槽编译模式。
|
|
@@ -799,6 +801,10 @@ interface TransformScriptOptions {
|
|
|
799
801
|
* 以避免小程序属性校验对复杂表达式/代理值产生误报。
|
|
800
802
|
*/
|
|
801
803
|
relaxStructuredTypeOnlyProps?: boolean;
|
|
804
|
+
/**
|
|
805
|
+
* 当前组件模板包含 scoped slot outlet,需要接收 scoped slot 桥接属性。
|
|
806
|
+
*/
|
|
807
|
+
scopedSlotHostProperties?: boolean;
|
|
802
808
|
}
|
|
803
809
|
//#endregion
|
|
804
810
|
//#region src/plugins/vue/transform/transformScript/index.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -582,7 +582,8 @@ const __weapp_defineThemeJson = (config) => (__weapp_json_macro_values.push(conf
|
|
|
582
582
|
try {
|
|
583
583
|
const { mod, dependencies } = await bundleRequire({
|
|
584
584
|
filepath: tempFile,
|
|
585
|
-
cwd: dir
|
|
585
|
+
cwd: dir,
|
|
586
|
+
tsconfig: false
|
|
586
587
|
});
|
|
587
588
|
const resolved = mod?.default ?? mod;
|
|
588
589
|
const values = Array.isArray(resolved) ? resolved : [resolved];
|
|
@@ -3193,6 +3194,32 @@ function injectFunctionPropPaths(componentOptionsObject, paths) {
|
|
|
3193
3194
|
componentOptionsObject.properties.push(t.objectProperty(t.identifier(WEVU_FUNCTION_PROP_PATHS_KEY), t.arrayExpression(uniquePaths.map((path) => t.stringLiteral(path)))));
|
|
3194
3195
|
return true;
|
|
3195
3196
|
}
|
|
3197
|
+
function createScopedSlotHostPropertyDefinition(typeName, value) {
|
|
3198
|
+
return t.objectExpression([t.objectProperty(t.identifier("type"), typeName === "String" ? t.identifier("String") : t.nullLiteral()), t.objectProperty(t.identifier("value"), value === null ? t.nullLiteral() : t.stringLiteral(value))]);
|
|
3199
|
+
}
|
|
3200
|
+
function createScopedSlotHostProperties() {
|
|
3201
|
+
return [
|
|
3202
|
+
t.objectProperty(t.identifier(WEVU_SLOT_NAMES_PROP), createScopedSlotHostPropertyDefinition("null", null)),
|
|
3203
|
+
t.objectProperty(t.identifier(WEVU_SLOT_OWNER_ID_PROP), createScopedSlotHostPropertyDefinition("String", "")),
|
|
3204
|
+
t.objectProperty(t.identifier(WEVU_SLOT_SCOPE_KEY), createScopedSlotHostPropertyDefinition("null", null))
|
|
3205
|
+
];
|
|
3206
|
+
}
|
|
3207
|
+
function injectScopedSlotHostProperties(componentOptionsObject) {
|
|
3208
|
+
const propertiesProp = getObjectPropertyByKey$1(componentOptionsObject, "properties");
|
|
3209
|
+
if (!propertiesProp) {
|
|
3210
|
+
componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier("properties"), t.objectExpression(createScopedSlotHostProperties())));
|
|
3211
|
+
return true;
|
|
3212
|
+
}
|
|
3213
|
+
if (!t.isObjectExpression(propertiesProp.value)) return false;
|
|
3214
|
+
let changed = false;
|
|
3215
|
+
for (const prop of createScopedSlotHostProperties().reverse()) {
|
|
3216
|
+
const key = t.isIdentifier(prop.key) ? prop.key.name : void 0;
|
|
3217
|
+
if (!key || getObjectPropertyByKey$1(propertiesProp.value, key)) continue;
|
|
3218
|
+
propertiesProp.value.properties.unshift(prop);
|
|
3219
|
+
changed = true;
|
|
3220
|
+
}
|
|
3221
|
+
return changed;
|
|
3222
|
+
}
|
|
3196
3223
|
function unwrapTypeLikeExpression(node) {
|
|
3197
3224
|
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression(node.expression);
|
|
3198
3225
|
if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression(node.expression);
|
|
@@ -3299,6 +3326,7 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
|
|
|
3299
3326
|
}) || transformed;
|
|
3300
3327
|
if (componentOptionsObject) transformed = injectSetupInitialData(componentOptionsObject) || transformed;
|
|
3301
3328
|
if (componentOptionsObject && options?.relaxStructuredTypeOnlyProps) transformed = relaxStructuredTypeOnlyProps(componentOptionsObject) || transformed;
|
|
3329
|
+
if (componentOptionsObject && options?.scopedSlotHostProperties) transformed = injectScopedSlotHostProperties(componentOptionsObject) || transformed;
|
|
3302
3330
|
if (componentOptionsObject) {
|
|
3303
3331
|
transformed = injectPropsAliases(componentOptionsObject, options?.propsAliases) || transformed;
|
|
3304
3332
|
transformed = injectPropsDerivedKeys(componentOptionsObject, options?.propsDerivedKeys) || transformed;
|
|
@@ -6487,6 +6515,30 @@ function isTopLevelObjectLiteral(exp) {
|
|
|
6487
6515
|
if (!parsed) return false;
|
|
6488
6516
|
return unwrapTsExpression(parsed).type === "ObjectExpression";
|
|
6489
6517
|
}
|
|
6518
|
+
function isStaticLiteralNode(node) {
|
|
6519
|
+
const normalized = unwrapTsExpression(node);
|
|
6520
|
+
if (normalized.type === "StringLiteral" || normalized.type === "NumericLiteral" || normalized.type === "BooleanLiteral" || normalized.type === "NullLiteral") return true;
|
|
6521
|
+
if (normalized.type === "UnaryExpression") return (normalized.operator === "-" || normalized.operator === "+") && normalized.argument.type === "NumericLiteral";
|
|
6522
|
+
if (normalized.type === "ArrayExpression") {
|
|
6523
|
+
for (const element of normalized.elements) if (!element || element.type === "SpreadElement" || !isStaticLiteralNode(element)) return false;
|
|
6524
|
+
return true;
|
|
6525
|
+
}
|
|
6526
|
+
if (normalized.type === "ObjectExpression") {
|
|
6527
|
+
for (const property of normalized.properties) {
|
|
6528
|
+
if (property.type !== "ObjectProperty" || property.computed) return false;
|
|
6529
|
+
const value = property.value;
|
|
6530
|
+
if (!t.isExpression(value) || !isStaticLiteralNode(value)) return false;
|
|
6531
|
+
}
|
|
6532
|
+
return true;
|
|
6533
|
+
}
|
|
6534
|
+
return false;
|
|
6535
|
+
}
|
|
6536
|
+
function isStaticObjectLiteral(exp) {
|
|
6537
|
+
const parsed = parseBabelExpression(exp);
|
|
6538
|
+
if (!parsed) return false;
|
|
6539
|
+
const normalized = unwrapTsExpression(parsed);
|
|
6540
|
+
return normalized.type === "ObjectExpression" && isStaticLiteralNode(normalized);
|
|
6541
|
+
}
|
|
6490
6542
|
function createBindRuntimeAttr(argValue, rawExpValue, context) {
|
|
6491
6543
|
const bindingRef = registerRuntimeBindingExpression(rawExpValue, context, { hint: `:${argValue} 绑定` });
|
|
6492
6544
|
if (!bindingRef) return null;
|
|
@@ -6594,7 +6646,7 @@ function transformBindDirective(node, context, forInfo, options) {
|
|
|
6594
6646
|
return context.platform.keyAttr(expValue);
|
|
6595
6647
|
}
|
|
6596
6648
|
if (isTopLevelObjectLiteral(rawExpValue)) {
|
|
6597
|
-
if (context.objectLiteralBindMode === "inline") return createInlineObjectLiteralAttr(argValue, rawExpValue, context);
|
|
6649
|
+
if (context.objectLiteralBindMode === "inline" || isStaticObjectLiteral(rawExpValue)) return createInlineObjectLiteralAttr(argValue, rawExpValue, context);
|
|
6598
6650
|
return createBindRuntimeAttr(argValue, rawExpValue, context);
|
|
6599
6651
|
}
|
|
6600
6652
|
if (shouldFallbackToRuntimeBinding(rawExpValue)) {
|
|
@@ -6737,6 +6789,9 @@ function transformModelDirective(node, context, elementNode, options) {
|
|
|
6737
6789
|
//#region src/plugins/vue/compiler/template/directives/on.ts
|
|
6738
6790
|
const SIMPLE_IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
6739
6791
|
const isSimpleHandler = (value) => SIMPLE_IDENTIFIER_RE.test(value);
|
|
6792
|
+
function isScriptSetupHandlerBinding(value, context) {
|
|
6793
|
+
return isSimpleHandler(value) && Boolean(context.scriptSetupBindings?.[value]);
|
|
6794
|
+
}
|
|
6740
6795
|
function shouldUseDetailPayload(options) {
|
|
6741
6796
|
return options?.isComponent === true;
|
|
6742
6797
|
}
|
|
@@ -6769,7 +6824,7 @@ function transformOnDirective(node, context, options) {
|
|
|
6769
6824
|
if (!exp) return null;
|
|
6770
6825
|
const rawExpValue = exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content.trim() : "";
|
|
6771
6826
|
const useDetailPayload = shouldUseDetailPayload(options);
|
|
6772
|
-
const inlineSource = useDetailPayload && isSimpleHandler(rawExpValue) ? `${rawExpValue}($event)` : rawExpValue;
|
|
6827
|
+
const inlineSource = (useDetailPayload || isScriptSetupHandlerBinding(rawExpValue, context)) && isSimpleHandler(rawExpValue) ? `${rawExpValue}($event)` : rawExpValue;
|
|
6773
6828
|
const isInlineExpression = inlineSource && !isSimpleHandler(inlineSource);
|
|
6774
6829
|
const inlineExpression = isInlineExpression ? registerInlineExpression(inlineSource, context) : null;
|
|
6775
6830
|
const mappedEvent = options?.isComponent === true ? argValue : context.platform.mapEventName(argValue);
|
|
@@ -7164,6 +7219,7 @@ function createScopedSlotComponent(context, slotKey, props, children, transformN
|
|
|
7164
7219
|
...context,
|
|
7165
7220
|
scopedSlotComponents: context.scopedSlotComponents,
|
|
7166
7221
|
componentGenerics: {},
|
|
7222
|
+
miniProgramComponentTags: context.miniProgramComponentTags,
|
|
7167
7223
|
scopeStack: [],
|
|
7168
7224
|
slotPropStack: [],
|
|
7169
7225
|
rewriteScopedSlot: true,
|
|
@@ -7384,7 +7440,7 @@ function transformSlotElement(node, context, transformNode) {
|
|
|
7384
7440
|
if (!slotPropsExp && slotPresentExp) slotTag = `${context.platform.wrapIf(slotPresentExp, slotTag, (exp) => renderMustache(exp, context))}${context.platform.wrapElse(fallbackContent)}`;
|
|
7385
7441
|
else if (!slotPropsExp) slotTag = `<slot${slotAttrString}>${fallbackContent}</slot>`;
|
|
7386
7442
|
}
|
|
7387
|
-
if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default"
|
|
7443
|
+
if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default" || !context.isPage)) return slotTag;
|
|
7388
7444
|
const hasScopeBindings = Boolean(slotPropsExp);
|
|
7389
7445
|
const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
|
|
7390
7446
|
context.componentGenerics[genericKey] = true;
|
|
@@ -7428,14 +7484,45 @@ function hasDirectComponentSlotChild(children, context) {
|
|
|
7428
7484
|
function isWevuComponentTag(node, context) {
|
|
7429
7485
|
return context.wevuComponentTags ? context.wevuComponentTags.has(node.tag) : /^[A-Z]/.test(node.tag);
|
|
7430
7486
|
}
|
|
7431
|
-
function
|
|
7487
|
+
function hasDirectWevuComponentSlotChild(children, context) {
|
|
7488
|
+
return children.some((child) => {
|
|
7489
|
+
if (child.type !== NodeTypes.ELEMENT) return false;
|
|
7490
|
+
const element = child;
|
|
7491
|
+
if (element.tag === "template" || isBuiltinTag(resolveTemplateTagName(element.tag, context))) return false;
|
|
7492
|
+
return isWevuComponentTag(element, context);
|
|
7493
|
+
});
|
|
7494
|
+
}
|
|
7495
|
+
function hasMiniProgramComponentSlotDescendant(children, context) {
|
|
7496
|
+
const componentTags = context.miniProgramComponentTags;
|
|
7497
|
+
if (!componentTags?.size) return false;
|
|
7498
|
+
return children.some((child) => {
|
|
7499
|
+
if (child.type !== NodeTypes.ELEMENT) return false;
|
|
7500
|
+
const element = child;
|
|
7501
|
+
if (componentTags.has(element.tag)) return true;
|
|
7502
|
+
return hasMiniProgramComponentSlotDescendant(element.children, context);
|
|
7503
|
+
});
|
|
7504
|
+
}
|
|
7505
|
+
function hasNativeComponentSlotDescendant(children, context) {
|
|
7506
|
+
return children.some((child) => {
|
|
7507
|
+
if (child.type !== NodeTypes.ELEMENT) return false;
|
|
7508
|
+
const element = child;
|
|
7509
|
+
if (!isBuiltinTag(resolveTemplateTagName(element.tag, context)) && element.tag.includes("-") && !isWevuComponentTag(element, context)) return true;
|
|
7510
|
+
return hasNativeComponentSlotDescendant(element.children, context);
|
|
7511
|
+
});
|
|
7512
|
+
}
|
|
7513
|
+
function shouldAugmentPlainSlot(decl, context, ownerNode, hasScopedSlotPropsSibling) {
|
|
7432
7514
|
if (context.scopedSlotsRequireProps) return false;
|
|
7433
7515
|
if (context.rewriteScopedSlot && !isWevuComponentTag(ownerNode, context)) return false;
|
|
7434
|
-
if (context.rewriteScopedSlot
|
|
7435
|
-
|
|
7436
|
-
|
|
7516
|
+
if (context.rewriteScopedSlot) {
|
|
7517
|
+
if (context.scopedSlotsCompiler === "augmented" && !decl.implicitDefault) return true;
|
|
7518
|
+
return context.scopedSlotsCompiler === "augmented" ? hasMiniProgramComponentSlotDescendant(decl.children, context) : hasScopedSlotPropsSibling && hasDirectComponentSlotChild(decl.children, context);
|
|
7519
|
+
}
|
|
7520
|
+
if (context.scopedSlotsCompiler === "augmented") {
|
|
7521
|
+
if (!decl.implicitDefault) return true;
|
|
7522
|
+
return hasMiniProgramComponentSlotDescendant(decl.children, context) || !isWevuComponentTag(ownerNode, context) && hasNativeComponentSlotDescendant(decl.children, context);
|
|
7523
|
+
}
|
|
7437
7524
|
if (!isWevuComponentTag(ownerNode, context)) return false;
|
|
7438
|
-
return
|
|
7525
|
+
return hasScopedSlotPropsSibling || hasDirectWevuComponentSlotChild(decl.children, context);
|
|
7439
7526
|
}
|
|
7440
7527
|
function resolveTemplateSlotCondition(node, context) {
|
|
7441
7528
|
const directive = node.props.find((prop) => prop.type === NodeTypes.DIRECTIVE && (prop.name === "if" || prop.name === "else-if" || prop.name === "else") && (prop.name === "else" || prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION));
|
|
@@ -7447,7 +7534,12 @@ function resolveTemplateSlotCondition(node, context) {
|
|
|
7447
7534
|
condition: rawExp ? normalizeWxmlExpressionWithContext(rawExp, context) : void 0
|
|
7448
7535
|
};
|
|
7449
7536
|
}
|
|
7450
|
-
function
|
|
7537
|
+
function resolveInlineStaticSlotName(name) {
|
|
7538
|
+
if (!name.startsWith("'") || !name.endsWith("'")) return null;
|
|
7539
|
+
const normalizedName = name.slice(1, -1);
|
|
7540
|
+
return /^[A-Z_$][\w$]*$/i.test(normalizedName) ? normalizedName : null;
|
|
7541
|
+
}
|
|
7542
|
+
function pushSlotNamesAttr(attrs, slotNames, context, options) {
|
|
7451
7543
|
if (!slotNames.length) return;
|
|
7452
7544
|
const seen = /* @__PURE__ */ new Set();
|
|
7453
7545
|
const entries = /* @__PURE__ */ new Map();
|
|
@@ -7468,9 +7560,20 @@ function pushSlotNamesAttr(attrs, slotNames, context) {
|
|
|
7468
7560
|
entries.set(item.name, entry);
|
|
7469
7561
|
}
|
|
7470
7562
|
const properties = [];
|
|
7563
|
+
const inlineProperties = [];
|
|
7564
|
+
let canInlineStatic = !options?.forInfo;
|
|
7471
7565
|
for (const [name, entry] of entries) {
|
|
7472
7566
|
const value = entry.conditions.length ? entry.conditions.map((condition) => `(${condition})`).join("||") : "true";
|
|
7567
|
+
const inlineName = resolveInlineStaticSlotName(name);
|
|
7568
|
+
if (value !== "true" || !inlineName) canInlineStatic = false;
|
|
7473
7569
|
properties.push(`[${name}]:${value}`);
|
|
7570
|
+
inlineProperties.push(`${inlineName}:${value}`);
|
|
7571
|
+
}
|
|
7572
|
+
if (canInlineStatic) {
|
|
7573
|
+
const inlineSlots = `{${inlineProperties.join(",")}}`;
|
|
7574
|
+
const mustache = context.mustacheInterpolation === "spaced" ? renderMustache(inlineSlots, context) : `{{ ${inlineSlots} }}`;
|
|
7575
|
+
attrs.push(`${WEVU_SLOT_NAMES_ATTR}="${mustache}"`);
|
|
7576
|
+
return;
|
|
7474
7577
|
}
|
|
7475
7578
|
const slotNamesRef = registerRuntimeBindingExpression(`{${properties.join(",")}}`, context, { hint: "vue-slots 元数据" });
|
|
7476
7579
|
if (slotNamesRef) attrs.push(`${WEVU_SLOT_NAMES_ATTR}="${renderMustache(slotNamesRef, context)}"`);
|
|
@@ -7619,7 +7722,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
7619
7722
|
});
|
|
7620
7723
|
let children = node.children.map((child) => transformNode(child, context)).join("");
|
|
7621
7724
|
if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
|
|
7622
|
-
if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context);
|
|
7725
|
+
if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context, { forInfo: options?.forInfo });
|
|
7623
7726
|
const mergedAttrs = [...extraAttrs, ...attrs];
|
|
7624
7727
|
const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
|
|
7625
7728
|
const { tag } = node;
|
|
@@ -7627,7 +7730,8 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
7627
7730
|
}
|
|
7628
7731
|
const scopedSlotDeclarations = [];
|
|
7629
7732
|
const plainSlotDeclarations = [];
|
|
7630
|
-
|
|
7733
|
+
const hasScopedSlotProps = slotDeclarations.some((decl) => Object.keys(decl.props).length > 0);
|
|
7734
|
+
for (const decl of slotDeclarations) if (Object.keys(decl.props).length > 0 || shouldAugmentPlainSlot(decl, context, node, hasScopedSlotProps)) scopedSlotDeclarations.push(decl);
|
|
7631
7735
|
else plainSlotDeclarations.push(decl);
|
|
7632
7736
|
const slotNames = [];
|
|
7633
7737
|
const slotGenericAttrs = [];
|
|
@@ -7655,7 +7759,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
7655
7759
|
...attrs,
|
|
7656
7760
|
...slotGenericAttrs
|
|
7657
7761
|
];
|
|
7658
|
-
pushSlotNamesAttr(mergedAttrs, slotNames, context);
|
|
7762
|
+
pushSlotNamesAttr(mergedAttrs, slotNames, context, { forInfo: options?.forInfo });
|
|
7659
7763
|
if (scopedSlotDeclarations.length) {
|
|
7660
7764
|
const scopePropsExp = buildScopePropsExpression(context);
|
|
7661
7765
|
if (scopePropsExp) mergedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(scopePropsExp, context)}"`);
|
|
@@ -7721,7 +7825,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
|
|
|
7721
7825
|
});
|
|
7722
7826
|
let children = node.children.map((child) => transformNode(child, context)).join("");
|
|
7723
7827
|
if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
|
|
7724
|
-
if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context);
|
|
7828
|
+
if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context, { forInfo: options?.forInfo });
|
|
7725
7829
|
const mergedAttrs = [...extraAttrs, ...attrs];
|
|
7726
7830
|
const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
|
|
7727
7831
|
const { tag } = node;
|
|
@@ -7742,7 +7846,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
|
|
|
7742
7846
|
if (shouldExposePlainSlotPresence(node) || isWevuComponentTag(node, context)) pushSlotNamesAttr(mergedAttrs, slotDeclarations.map((decl) => ({
|
|
7743
7847
|
name: stringifySlotName(decl.name, context),
|
|
7744
7848
|
condition: decl.condition
|
|
7745
|
-
})), context);
|
|
7849
|
+
})), context, { forInfo: options?.forInfo });
|
|
7746
7850
|
const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
|
|
7747
7851
|
const { tag } = node;
|
|
7748
7852
|
return renderedSlots ? `<${tag}${attrString}>${renderedSlots}</${tag}>` : `<${tag}${attrString} />`;
|
|
@@ -8043,6 +8147,11 @@ const HTML_VOID_TAGS = new Set([
|
|
|
8043
8147
|
"track",
|
|
8044
8148
|
"wbr"
|
|
8045
8149
|
]);
|
|
8150
|
+
function resolveTemplateIsPage(filename, options) {
|
|
8151
|
+
if (options?.isPage !== true) return false;
|
|
8152
|
+
const normalized = filename.replace(/\\/g, "/");
|
|
8153
|
+
return !/(?:^|\/)(?:components|layouts|custom-tab-bar)\//.test(normalized);
|
|
8154
|
+
}
|
|
8046
8155
|
function resolveSlotFallbackWrapperComponent(strategy) {
|
|
8047
8156
|
if (strategy !== "virtual-host") return;
|
|
8048
8157
|
return {
|
|
@@ -8091,6 +8200,7 @@ function compileVueTemplateToWxml(template, filename, options) {
|
|
|
8091
8200
|
filename,
|
|
8092
8201
|
warnings,
|
|
8093
8202
|
platform: options?.platform ?? getMiniProgramTemplatePlatform(),
|
|
8203
|
+
isPage: resolveTemplateIsPage(filename, options),
|
|
8094
8204
|
propsAliases: options?.propsAliases,
|
|
8095
8205
|
propsDerivedKeys: options?.propsDerivedKeys,
|
|
8096
8206
|
scriptSetupBindings: options?.scriptSetupBindings,
|
|
@@ -8126,7 +8236,8 @@ function compileVueTemplateToWxml(template, filename, options) {
|
|
|
8126
8236
|
inlineExpressionSeed: 0,
|
|
8127
8237
|
functionPropPaths: /* @__PURE__ */ new Set(),
|
|
8128
8238
|
functionPropNames: Array.from(options?.functionPropNames ?? []),
|
|
8129
|
-
wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0
|
|
8239
|
+
wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0,
|
|
8240
|
+
miniProgramComponentTags: options?.miniProgramComponentTags ? new Set(options.miniProgramComponentTags) : void 0
|
|
8130
8241
|
};
|
|
8131
8242
|
let wxml = ast.children.map((child) => transformNode(child, context)).join("");
|
|
8132
8243
|
if (context.classStyleWxs) wxml = `${buildClassStyleWxsTag(context.classStyleWxsExtension || "wxs", context.classStyleWxsSrc)}\n${wxml}`;
|
|
@@ -8198,6 +8309,32 @@ function extractStaticDefineOptionsName(scriptSetupContent) {
|
|
|
8198
8309
|
} });
|
|
8199
8310
|
return componentName;
|
|
8200
8311
|
}
|
|
8312
|
+
function extractStaticDefineComponentJsonIsComponent(scriptSetupContent) {
|
|
8313
|
+
let ast;
|
|
8314
|
+
try {
|
|
8315
|
+
ast = parse$3(scriptSetupContent, BABEL_TS_MODULE_PARSER_OPTIONS);
|
|
8316
|
+
} catch {
|
|
8317
|
+
return false;
|
|
8318
|
+
}
|
|
8319
|
+
let isComponent = false;
|
|
8320
|
+
traverse(ast, { CallExpression(path) {
|
|
8321
|
+
if (isComponent) return;
|
|
8322
|
+
const callee = path.node.callee;
|
|
8323
|
+
if (!t.isIdentifier(callee, { name: "defineComponentJson" })) return;
|
|
8324
|
+
const arg = path.node.arguments[0];
|
|
8325
|
+
if (!t.isObjectExpression(arg)) return;
|
|
8326
|
+
for (const property of arg.properties) {
|
|
8327
|
+
if (!t.isObjectProperty(property)) continue;
|
|
8328
|
+
const key = property.key;
|
|
8329
|
+
if ((t.isIdentifier(key) ? key.name === "component" : t.isStringLiteral(key) ? key.value === "component" : false) && t.isBooleanLiteral(property.value) && property.value.value) {
|
|
8330
|
+
isComponent = true;
|
|
8331
|
+
path.stop();
|
|
8332
|
+
return;
|
|
8333
|
+
}
|
|
8334
|
+
}
|
|
8335
|
+
} });
|
|
8336
|
+
return isComponent;
|
|
8337
|
+
}
|
|
8201
8338
|
async function resolveVueSfcComponentName(resolvedId, warn) {
|
|
8202
8339
|
if (!resolvedId?.endsWith(".vue")) return;
|
|
8203
8340
|
try {
|
|
@@ -8210,11 +8347,28 @@ async function resolveVueSfcComponentName(resolvedId, warn) {
|
|
|
8210
8347
|
return;
|
|
8211
8348
|
}
|
|
8212
8349
|
}
|
|
8350
|
+
async function resolveVueSfcIsMiniProgramComponent(resolvedId, warn) {
|
|
8351
|
+
if (!resolvedId?.endsWith(".vue")) return false;
|
|
8352
|
+
try {
|
|
8353
|
+
const { descriptor, errors } = parse(await readFile$1(resolvedId, "utf8"), { filename: resolvedId });
|
|
8354
|
+
if (errors.length > 0 || !descriptor.scriptSetup?.content) return false;
|
|
8355
|
+
return extractStaticDefineComponentJsonIsComponent(descriptor.scriptSetup.content);
|
|
8356
|
+
} catch (error) {
|
|
8357
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
8358
|
+
warn?.(`[Vue 编译] 解析 ${resolvedId} 的 defineComponentJson.component 失败:${message}`);
|
|
8359
|
+
return false;
|
|
8360
|
+
}
|
|
8361
|
+
}
|
|
8213
8362
|
function registerComponentName(result, tag, componentName) {
|
|
8214
8363
|
if (!componentName) return;
|
|
8215
8364
|
result.componentNameMap[tag] = componentName;
|
|
8216
8365
|
result.componentNameMap[pascalToKebab(tag)] = componentName;
|
|
8217
8366
|
}
|
|
8367
|
+
function registerMiniProgramComponentTag(result, tag, isComponent) {
|
|
8368
|
+
if (!isComponent) return;
|
|
8369
|
+
result.miniProgramComponentTags.add(tag);
|
|
8370
|
+
result.miniProgramComponentTags.add(pascalToKebab(tag));
|
|
8371
|
+
}
|
|
8218
8372
|
function collectTemplateComponentNames(template, filename, warn) {
|
|
8219
8373
|
const warnHandler = resolveWarnHandler(warn);
|
|
8220
8374
|
const tags = collectVueTemplateTags(template, {
|
|
@@ -8286,6 +8440,7 @@ async function collectScriptSetupUsingComponents(options) {
|
|
|
8286
8440
|
result.wevuComponentTags.add(pascalToKebab(localName));
|
|
8287
8441
|
}
|
|
8288
8442
|
registerComponentName(result, localName, await resolveVueSfcComponentName(resolved?.resolvedId, autoUsingComponents?.warn ?? compileOptions?.warn));
|
|
8443
|
+
registerMiniProgramComponentTag(result, localName, await resolveVueSfcIsMiniProgramComponent(resolved?.resolvedId, autoUsingComponents?.warn ?? compileOptions?.warn));
|
|
8289
8444
|
}
|
|
8290
8445
|
} catch (error) {
|
|
8291
8446
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -8316,7 +8471,12 @@ async function collectAutoImportWevuComponents(options) {
|
|
|
8316
8471
|
}
|
|
8317
8472
|
const componentName = await resolveVueSfcComponentName(resolved.resolvedId, autoImportTags.warn ?? warn);
|
|
8318
8473
|
registerComponentName(result, tag, componentName);
|
|
8319
|
-
|
|
8474
|
+
const isMiniProgramComponent = await resolveVueSfcIsMiniProgramComponent(resolved.resolvedId, autoImportTags.warn ?? warn);
|
|
8475
|
+
registerMiniProgramComponentTag(result, tag, isMiniProgramComponent);
|
|
8476
|
+
if (resolved.name) {
|
|
8477
|
+
registerComponentName(result, resolved.name, componentName);
|
|
8478
|
+
registerMiniProgramComponentTag(result, resolved.name, isMiniProgramComponent);
|
|
8479
|
+
}
|
|
8320
8480
|
}
|
|
8321
8481
|
}
|
|
8322
8482
|
async function collectComponentSourceInfo(options) {
|
|
@@ -8324,6 +8484,7 @@ async function collectComponentSourceInfo(options) {
|
|
|
8324
8484
|
autoUsingComponentsMap: {},
|
|
8325
8485
|
autoComponentMeta: {},
|
|
8326
8486
|
wevuComponentTags: /* @__PURE__ */ new Set(),
|
|
8487
|
+
miniProgramComponentTags: /* @__PURE__ */ new Set(),
|
|
8327
8488
|
componentNameMap: {}
|
|
8328
8489
|
};
|
|
8329
8490
|
await collectScriptSetupUsingComponents({
|
|
@@ -8384,7 +8545,8 @@ async function evaluateJsLikeConfig(source, filename, lang) {
|
|
|
8384
8545
|
try {
|
|
8385
8546
|
const { mod } = await bundleRequire({
|
|
8386
8547
|
filepath: tempFile,
|
|
8387
|
-
cwd: dir
|
|
8548
|
+
cwd: dir,
|
|
8549
|
+
tsconfig: false
|
|
8388
8550
|
});
|
|
8389
8551
|
let resolved = mod?.default ?? mod;
|
|
8390
8552
|
if (typeof resolved === "function") resolved = resolved();
|
|
@@ -8748,7 +8910,8 @@ export const __weapp_define_options = __weapp_define_options_values
|
|
|
8748
8910
|
try {
|
|
8749
8911
|
const { mod, dependencies } = await bundleRequire({
|
|
8750
8912
|
filepath: tempFile,
|
|
8751
|
-
cwd: dir
|
|
8913
|
+
cwd: dir,
|
|
8914
|
+
tsconfig: false
|
|
8752
8915
|
});
|
|
8753
8916
|
const exported = mod?.__weapp_define_options ?? mod;
|
|
8754
8917
|
return {
|
|
@@ -9243,7 +9406,8 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
|
|
|
9243
9406
|
functionPropPaths: templateCompiled?.functionPropPaths,
|
|
9244
9407
|
propsAliases,
|
|
9245
9408
|
propsDerivedKeys,
|
|
9246
|
-
relaxStructuredTypeOnlyProps
|
|
9409
|
+
relaxStructuredTypeOnlyProps,
|
|
9410
|
+
scopedSlotHostProperties: Boolean(templateCompiled?.componentGenerics && Object.keys(templateCompiled.componentGenerics).length > 0)
|
|
9247
9411
|
});
|
|
9248
9412
|
return {
|
|
9249
9413
|
script: transformed.code,
|
|
@@ -9336,12 +9500,14 @@ async function compileVueFile(source, filename, options) {
|
|
|
9336
9500
|
const propsDerivedKeys = scriptCompiled ? resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCompiled.content) : void 0;
|
|
9337
9501
|
const baseTemplateOptions = parsed.isAppFile ? {
|
|
9338
9502
|
...options?.template,
|
|
9503
|
+
isPage: options?.isPage,
|
|
9339
9504
|
propsAliases,
|
|
9340
9505
|
propsDerivedKeys,
|
|
9341
9506
|
scriptSetupBindings: scriptCompiled?.bindings,
|
|
9342
9507
|
scopedSlotsRequireProps: true
|
|
9343
9508
|
} : {
|
|
9344
9509
|
...options?.template,
|
|
9510
|
+
isPage: options?.isPage,
|
|
9345
9511
|
propsAliases,
|
|
9346
9512
|
propsDerivedKeys,
|
|
9347
9513
|
scriptSetupBindings: scriptCompiled?.bindings
|
|
@@ -9349,11 +9515,13 @@ async function compileVueFile(source, filename, options) {
|
|
|
9349
9515
|
const templateOptions = componentSourceInfo.wevuComponentTags.size ? {
|
|
9350
9516
|
...baseTemplateOptions,
|
|
9351
9517
|
wevuComponentTags: componentSourceInfo.wevuComponentTags,
|
|
9352
|
-
componentNameMap: componentSourceInfo.componentNameMap
|
|
9518
|
+
componentNameMap: componentSourceInfo.componentNameMap,
|
|
9519
|
+
miniProgramComponentTags: componentSourceInfo.miniProgramComponentTags
|
|
9353
9520
|
} : {
|
|
9354
9521
|
...baseTemplateOptions,
|
|
9355
9522
|
wevuComponentTags: [],
|
|
9356
|
-
componentNameMap: componentSourceInfo.componentNameMap
|
|
9523
|
+
componentNameMap: componentSourceInfo.componentNameMap,
|
|
9524
|
+
miniProgramComponentTags: componentSourceInfo.miniProgramComponentTags
|
|
9357
9525
|
};
|
|
9358
9526
|
const templateCompiled = compileTemplatePhase(parsed.descriptor, filename, templateOptions, result);
|
|
9359
9527
|
const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo, scriptCompiled);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.16.
|
|
4
|
+
"version": "6.16.41",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue": "^3.5.35",
|
|
53
53
|
"@weapp-core/constants": "0.1.12",
|
|
54
54
|
"@weapp-core/shared": "3.0.4",
|
|
55
|
-
"@weapp-vite/ast": "6.16.
|
|
55
|
+
"@weapp-vite/ast": "6.16.41",
|
|
56
56
|
"rolldown-require": "2.0.18"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|