@wevu/compiler 6.15.17 → 6.15.18
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 +11 -4
- package/dist/index.mjs +260 -88
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -283,6 +283,7 @@ interface TemplateCompileOptions {
|
|
|
283
283
|
mustacheInterpolation?: MustacheInterpolationMode;
|
|
284
284
|
wxsExtension?: string;
|
|
285
285
|
classStyleWxsSrc?: string;
|
|
286
|
+
wevuComponentTags?: Iterable<string>;
|
|
286
287
|
}
|
|
287
288
|
/**
|
|
288
289
|
* 作用域插槽编译模式。
|
|
@@ -384,6 +385,12 @@ declare function getMiniProgramTemplatePlatform(platform?: MpPlatform): MiniProg
|
|
|
384
385
|
declare function compileVueTemplateToWxml(template: string, filename: string, options?: TemplateCompileOptions): TemplateCompileResult;
|
|
385
386
|
//#endregion
|
|
386
387
|
//#region src/plugins/vue/transform/compileVueFile/types.d.ts
|
|
388
|
+
interface ResolvedUsingComponentInfo {
|
|
389
|
+
from?: string;
|
|
390
|
+
resolvedId?: string;
|
|
391
|
+
sourceType?: 'wevu-sfc' | 'native';
|
|
392
|
+
}
|
|
393
|
+
type ResolvedUsingComponentPath = string | ResolvedUsingComponentInfo;
|
|
387
394
|
/**
|
|
388
395
|
* Vue 单文件组件转换结果。
|
|
389
396
|
*/
|
|
@@ -415,7 +422,7 @@ interface AutoUsingComponentsOptions {
|
|
|
415
422
|
localName: string;
|
|
416
423
|
importedName?: string;
|
|
417
424
|
kind: 'default' | 'named';
|
|
418
|
-
}) => Promise<
|
|
425
|
+
}) => Promise<ResolvedUsingComponentPath | undefined>;
|
|
419
426
|
warn?: (message: string) => void;
|
|
420
427
|
}
|
|
421
428
|
/**
|
|
@@ -423,10 +430,10 @@ interface AutoUsingComponentsOptions {
|
|
|
423
430
|
*/
|
|
424
431
|
interface AutoImportTagsOptions {
|
|
425
432
|
enabled?: boolean;
|
|
426
|
-
resolveUsingComponent?: (tag: string, importerFilename: string) => Promise<{
|
|
433
|
+
resolveUsingComponent?: (tag: string, importerFilename: string) => Promise<({
|
|
427
434
|
name: string;
|
|
428
435
|
from: string;
|
|
429
|
-
} | undefined>;
|
|
436
|
+
} & ResolvedUsingComponentInfo) | undefined>;
|
|
430
437
|
warn?: (message: string) => void;
|
|
431
438
|
}
|
|
432
439
|
/**
|
|
@@ -850,4 +857,4 @@ interface CollectVueTemplateTagsOptions {
|
|
|
850
857
|
*/
|
|
851
858
|
declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
|
|
852
859
|
//#endregion
|
|
853
|
-
export { type AstEngineName, type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ScopedSlotComponentAsset, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, VUE_COMPONENT_TAG_RE, type VueTransformResult, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, type WevuDefaults, type WevuPageFeatureFlag, type WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
|
|
860
|
+
export { type AstEngineName, type AutoImportTagsOptions, type AutoUsingComponentsOptions, CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, type ClassStyleBinding, type ClassStyleRuntime, type CollectVueTemplateTagsOptions, type CompileVueFileOptions, type ForParseResult, type InlineExpressionAsset, type JsLikeLang, type JsonConfig, type JsonMergeContext, type JsonMergeStage, type JsonMergeStrategy, type MiniProgramPlatform, type ModuleResolver, type MpPlatform, RESERVED_VUE_COMPONENT_TAGS, type ReadAndParseSfcOptions, type ResolveSfcBlockSrcOptions, type ResolvedUsingComponentInfo, type ResolvedUsingComponentPath, type ScopedSlotComponentAsset, type StyleCompileOptions, type StyleCompileResult, type TemplateCompileOptions, type TemplateCompileResult, type TemplateRefBinding, type TransformResult, type TransformScriptOptions, VUE_COMPONENT_TAG_RE, type VueTransformResult, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, type WevuDefaults, type WevuPageFeatureFlag, type WevuPageHookName, WevuRuntimeApiName, alipayPlatform, buildClassStyleComputedCode, buildClassStyleWxsTag, builtinComponentsSet, clearFileCaches, collectTargetOptionsObjectsFromCode, collectVueTemplateTags, collectWevuFeaturesFromCodeReachableImports, collectWevuPageFeatureFlags, collectWevuPageFeatureFlagsFromCode, compileConfigBlocks, compileJsxFile, compileVueFile as compileSfc, compileVueFile, compileVueStyleToWxss as compileStyle, compileVueStyleToWxss, compileVueTemplateToWxml as compileTemplate, compileVueTemplateToWxml, createJsonMerger, createPageEntryMatcher, defaultMiniProgramPlatform, defaultMiniProgramTemplatePlatform, defaultPlatform, evaluateJsLikeConfig, extractJsonMacroFromScriptSetup, generateScopedId, getClassStyleWxsSource, getDefaultMiniProgramPlatform, getDefaultMiniProgramTemplatePlatform, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeatureFlagsIntoOptionsObject, injectWevuPageFeaturesInJs, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isInvalidate, isJsonLikeLang, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import os from "node:os";
|
|
|
13
13
|
import process from "node:process";
|
|
14
14
|
import { collectFeatureFlagsFromCode, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
|
|
15
15
|
import { LRUCache } from "lru-cache";
|
|
16
|
-
import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_LAYOUT_HOSTS_KEY, WEVU_LAYOUT_HOST_ID_PREFIX, WEVU_LAYOUT_HOST_REF_PREFIX, WEVU_MODEL_HANDLER, WEVU_OWNER_HANDLER, WEVU_PROPS_KEY, WEVU_SLOT_OWNER_ATTR, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_PROPS_DATA_KEY, WEVU_SLOT_PROPS_KEY, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY, WEVU_TEMPLATE_REFS_KEY } from "@weapp-core/constants";
|
|
16
|
+
import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_LAYOUT_HOSTS_KEY, WEVU_LAYOUT_HOST_ID_PREFIX, WEVU_LAYOUT_HOST_REF_PREFIX, WEVU_MODEL_HANDLER, WEVU_OWNER_HANDLER, WEVU_PROPS_KEY, WEVU_SLOT_NAMES_ATTR, WEVU_SLOT_OWNER_ATTR, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_PROPS_DATA_KEY, WEVU_SLOT_PROPS_KEY, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY, WEVU_TEMPLATE_REFS_KEY } from "@weapp-core/constants";
|
|
17
17
|
import { compileScript, parse } from "vue/compiler-sfc";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { parse as parse$1 } from "@vue/compiler-dom";
|
|
@@ -1767,6 +1767,7 @@ function injectTemplateComponentMeta(ast, templateComponentMeta) {
|
|
|
1767
1767
|
* 1. 移除从 'vue' 导入 defineComponent
|
|
1768
1768
|
* 2. 移除 __name 属性
|
|
1769
1769
|
* 3. 移除空参数的 __expose() 调用(保留 defineExpose 生成的 __expose({...}))
|
|
1770
|
+
* 4. 移除运行时未使用的 __isScriptSetup 标识
|
|
1770
1771
|
*/
|
|
1771
1772
|
function vueSfcTransformPlugin() {
|
|
1772
1773
|
return {
|
|
@@ -1794,6 +1795,10 @@ function vueSfcTransformPlugin() {
|
|
|
1794
1795
|
path.node.properties = filtered;
|
|
1795
1796
|
},
|
|
1796
1797
|
CallExpression(path) {
|
|
1798
|
+
if (t.isMemberExpression(path.node.callee) && t.isIdentifier(path.node.callee.object, { name: "Object" }) && t.isIdentifier(path.node.callee.property, { name: "defineProperty" }) && t.isIdentifier(path.node.arguments[0], { name: "__returned__" }) && t.isStringLiteral(path.node.arguments[1], { value: "__isScriptSetup" }) && path.parentPath?.isExpressionStatement()) {
|
|
1799
|
+
path.parentPath.remove();
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1797
1802
|
if (t.isIdentifier(path.node.callee, { name: "__expose" }) && path.parentPath?.isExpressionStatement() && path.node.arguments.length === 0) path.parentPath.remove();
|
|
1798
1803
|
}
|
|
1799
1804
|
}
|
|
@@ -3901,6 +3906,10 @@ function compileJsxTemplateAndCollectComponents(source, filename, options) {
|
|
|
3901
3906
|
//#region src/plugins/jsx/compileJsxFile.ts
|
|
3902
3907
|
const LEADING_DOT_RE = /^\./;
|
|
3903
3908
|
const SETUP_CALL_RE$1 = /\bsetup\s*\(/;
|
|
3909
|
+
function normalizeUsingComponentFrom(value) {
|
|
3910
|
+
if (!value) return;
|
|
3911
|
+
return typeof value === "string" ? value : value.from;
|
|
3912
|
+
}
|
|
3904
3913
|
/**
|
|
3905
3914
|
* 编译 JSX/TSX 文件,输出 wevu 脚本与 WXML 模板。
|
|
3906
3915
|
*/
|
|
@@ -3928,11 +3937,11 @@ async function compileJsxFile(source, filename, options) {
|
|
|
3928
3937
|
const autoUsingComponentsMap = {};
|
|
3929
3938
|
if (options?.autoUsingComponents?.resolveUsingComponentPath && autoComponentContext.templateTags.size > 0) for (const imported of autoComponentContext.importedComponents) {
|
|
3930
3939
|
if (!autoComponentContext.templateTags.has(imported.localName)) continue;
|
|
3931
|
-
let resolved = await options.autoUsingComponents.resolveUsingComponentPath(imported.importSource, filename, {
|
|
3940
|
+
let resolved = normalizeUsingComponentFrom(await options.autoUsingComponents.resolveUsingComponentPath(imported.importSource, filename, {
|
|
3932
3941
|
localName: imported.localName,
|
|
3933
3942
|
importedName: imported.importedName,
|
|
3934
3943
|
kind: imported.kind
|
|
3935
|
-
});
|
|
3944
|
+
}));
|
|
3936
3945
|
if (!resolved && imported.importSource.startsWith("/")) resolved = removeExtensionDeep(imported.importSource);
|
|
3937
3946
|
if (!resolved) continue;
|
|
3938
3947
|
autoUsingComponentsMap[imported.localName] = resolved;
|
|
@@ -6319,11 +6328,13 @@ function stringifySlotName(info, context) {
|
|
|
6319
6328
|
if (info.type === "static") return info.value === "default" ? "'default'" : `'${info.value}'`;
|
|
6320
6329
|
return normalizeWxmlExpressionWithContext(info.exp, context);
|
|
6321
6330
|
}
|
|
6322
|
-
function buildSlotDeclaration(name, propsExp, children, context) {
|
|
6331
|
+
function buildSlotDeclaration(name, propsExp, children, context, options) {
|
|
6323
6332
|
return {
|
|
6324
6333
|
name,
|
|
6325
6334
|
props: propsExp ? parseSlotPropsExpression(propsExp, context) : {},
|
|
6326
|
-
children
|
|
6335
|
+
children,
|
|
6336
|
+
implicitDefault: options?.implicitDefault,
|
|
6337
|
+
condition: options?.condition
|
|
6327
6338
|
};
|
|
6328
6339
|
}
|
|
6329
6340
|
function createScopedSlotComponent(context, slotKey, props, children, transformNode) {
|
|
@@ -6382,16 +6393,19 @@ function renderSlotFallback(decl, context, transformNode) {
|
|
|
6382
6393
|
const rawContent = rawRenderedChildren.map((item) => item.code).join("");
|
|
6383
6394
|
if (!rawContent) return "";
|
|
6384
6395
|
const slotAttr = renderSlotNameAttribute(decl.name, context, "slot");
|
|
6385
|
-
|
|
6386
|
-
|
|
6396
|
+
const wrapCondition = (content) => {
|
|
6397
|
+
return decl.condition ? context.platform.wrapIf(decl.condition, content, (exp) => renderMustache(exp, context)) : content;
|
|
6398
|
+
};
|
|
6399
|
+
if (!slotAttr) return wrapCondition(rawContent);
|
|
6400
|
+
if (!context.slotSingleRootNoWrapper) return wrapCondition(`<view ${slotAttr}>${rawContent}</view>`);
|
|
6387
6401
|
const renderedChildren = rawRenderedChildren.filter((item) => item.code.trim().length > 0);
|
|
6388
6402
|
if (!renderedChildren.length) return "";
|
|
6389
6403
|
const content = renderedChildren.map((item) => item.code).join("");
|
|
6390
6404
|
if (renderedChildren.length === 1) {
|
|
6391
6405
|
const projected = injectAttributeIntoOpeningTag(renderedChildren[0].code, slotAttr);
|
|
6392
|
-
if (projected) return projected;
|
|
6406
|
+
if (projected) return wrapCondition(projected);
|
|
6393
6407
|
}
|
|
6394
|
-
return `<view ${slotAttr}>${content}</view
|
|
6408
|
+
return wrapCondition(`<view ${slotAttr}>${content}</view>`);
|
|
6395
6409
|
}
|
|
6396
6410
|
function transformSlotElement(node, context, transformNode) {
|
|
6397
6411
|
if (isScopedSlotsDisabled(context)) return transformSlotElementPlain(node, context, transformNode);
|
|
@@ -6408,11 +6422,15 @@ function transformSlotElement(node, context, transformNode) {
|
|
|
6408
6422
|
if (nameAttr) slotAttrs.push(nameAttr);
|
|
6409
6423
|
const slotAttrString = slotAttrs.length ? ` ${slotAttrs.join(" ")}` : "";
|
|
6410
6424
|
const slotTag = fallbackContent ? `<slot${slotAttrString}>${fallbackContent}</slot>` : `<slot${slotAttrString} />`;
|
|
6411
|
-
if (context.scopedSlotsRequireProps
|
|
6425
|
+
if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default")) return slotTag;
|
|
6412
6426
|
const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
|
|
6413
6427
|
context.componentGenerics[genericKey] = true;
|
|
6414
6428
|
slotPropsExp = slotPropsExp ?? "[]";
|
|
6415
|
-
const scopedAttrs = [
|
|
6429
|
+
const scopedAttrs = [
|
|
6430
|
+
`${context.platform.directives.ifAttr}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`,
|
|
6431
|
+
`${WEVU_SLOT_OWNER_ATTR}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`,
|
|
6432
|
+
`${WEVU_SLOT_PROPS_ATTR}="${renderMustache(slotPropsExp, context)}"`
|
|
6433
|
+
];
|
|
6416
6434
|
if (context.slotMultipleInstance) scopedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(WEVU_SLOT_SCOPE_KEY, context)}"`);
|
|
6417
6435
|
return `${slotTag}${`<${genericKey}${scopedAttrs.length ? ` ${scopedAttrs.join(" ")}` : ""} />`}`;
|
|
6418
6436
|
}
|
|
@@ -6431,6 +6449,49 @@ function transformSlotElementPlain(node, context, transformNode) {
|
|
|
6431
6449
|
}
|
|
6432
6450
|
//#endregion
|
|
6433
6451
|
//#region src/plugins/vue/compiler/template/elements/tag-component.ts
|
|
6452
|
+
function hasLegacySlotAttribute(children) {
|
|
6453
|
+
return children.some((child) => {
|
|
6454
|
+
if (child.type !== NodeTypes.ELEMENT) return false;
|
|
6455
|
+
return child.props.some((prop) => prop.type === NodeTypes.ATTRIBUTE && prop.name === "slot");
|
|
6456
|
+
});
|
|
6457
|
+
}
|
|
6458
|
+
function isRenderableSlotChild(child) {
|
|
6459
|
+
if (child.type === NodeTypes.COMMENT) return false;
|
|
6460
|
+
if (child.type === NodeTypes.TEXT) return child.content.trim().length > 0;
|
|
6461
|
+
return true;
|
|
6462
|
+
}
|
|
6463
|
+
function hasDirectComponentSlotChild(children, context) {
|
|
6464
|
+
return children.some((child) => {
|
|
6465
|
+
if (child.type !== NodeTypes.ELEMENT) return false;
|
|
6466
|
+
if (child.tag === "component") return true;
|
|
6467
|
+
if (child.tag === "template") return false;
|
|
6468
|
+
if (isBuiltinTag(resolveTemplateTagName(child.tag, context))) return false;
|
|
6469
|
+
return /^[A-Z]/.test(child.tag);
|
|
6470
|
+
});
|
|
6471
|
+
}
|
|
6472
|
+
function resolveTemplateSlotCondition(node, context) {
|
|
6473
|
+
const ifDirective = node.props.find((prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "if" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION);
|
|
6474
|
+
const rawExp = ifDirective?.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? ifDirective.exp.content : "";
|
|
6475
|
+
return rawExp ? normalizeWxmlExpressionWithContext(rawExp, context) : void 0;
|
|
6476
|
+
}
|
|
6477
|
+
function pushSlotNamesAttr(attrs, slotNames, context) {
|
|
6478
|
+
if (!slotNames.length) return;
|
|
6479
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6480
|
+
const entries = [];
|
|
6481
|
+
for (const item of slotNames) {
|
|
6482
|
+
const dedupeKey = `${item.name}:${item.condition ?? ""}`;
|
|
6483
|
+
if (seen.has(dedupeKey)) continue;
|
|
6484
|
+
seen.add(dedupeKey);
|
|
6485
|
+
entries.push(item.condition ? `((${item.condition}) ? ${item.name} : '')` : item.name);
|
|
6486
|
+
}
|
|
6487
|
+
attrs.push(`${WEVU_SLOT_NAMES_ATTR}="${renderMustache(`[${entries.join(",")}]`, context)}"`);
|
|
6488
|
+
}
|
|
6489
|
+
function shouldExposePlainSlotPresence(node) {
|
|
6490
|
+
return node.tag === "component";
|
|
6491
|
+
}
|
|
6492
|
+
function isWevuComponentTag(node, context) {
|
|
6493
|
+
return context.wevuComponentTags ? context.wevuComponentTags.has(node.tag) : /^[A-Z]/.test(node.tag);
|
|
6494
|
+
}
|
|
6434
6495
|
function transformComponentWithSlots(node, context, transformNode, options) {
|
|
6435
6496
|
if (isScopedSlotsDisabled(context)) return transformComponentWithSlotsFallback(node, context, transformNode, options);
|
|
6436
6497
|
const extraAttrs = options?.extraAttrs ?? [];
|
|
@@ -6442,18 +6503,20 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
6442
6503
|
const templateSlot = findSlotDirective(child);
|
|
6443
6504
|
if (templateSlot) {
|
|
6444
6505
|
const slotName = resolveSlotNameFromDirective(templateSlot);
|
|
6445
|
-
slotDeclarations.push(buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context));
|
|
6506
|
+
slotDeclarations.push(buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) }));
|
|
6446
6507
|
continue;
|
|
6447
6508
|
}
|
|
6448
6509
|
}
|
|
6449
6510
|
nonTemplateChildren.push(child);
|
|
6450
6511
|
}
|
|
6512
|
+
const defaultSlotChildren = nonTemplateChildren.filter(isRenderableSlotChild);
|
|
6451
6513
|
if (slotDirective) {
|
|
6452
6514
|
if (slotDeclarations.length) context.warnings.push("组件上的 v-slot 与 <template v-slot> 不能同时使用;仅使用组件上的 v-slot。");
|
|
6453
6515
|
slotDeclarations.length = 0;
|
|
6454
6516
|
slotDeclarations.push(buildSlotDeclaration(resolveSlotNameFromDirective(slotDirective), slotDirective.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? slotDirective.exp.content : void 0, node.children, context));
|
|
6455
|
-
} else if (slotDeclarations.length &&
|
|
6456
|
-
else slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0,
|
|
6517
|
+
} else if (slotDeclarations.length && defaultSlotChildren.length) if (slotDeclarations.some((decl) => decl.name.type === "default" || decl.name.type === "static" && decl.name.value === "default")) context.warnings.push("存在显式的 v-slot:default,默认插槽内容将被忽略。");
|
|
6518
|
+
else slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true }));
|
|
6519
|
+
else if (!slotDeclarations.length && defaultSlotChildren.length && !context.scopedSlotsRequireProps && !hasLegacySlotAttribute(defaultSlotChildren)) slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true }));
|
|
6457
6520
|
if (!slotDeclarations.length) {
|
|
6458
6521
|
const { attrs, vTextExp } = collectElementAttributes(node, context, {
|
|
6459
6522
|
skipSlotDirective: true,
|
|
@@ -6462,25 +6525,30 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
6462
6525
|
});
|
|
6463
6526
|
let children = node.children.map((child) => transformNode(child, context)).join("");
|
|
6464
6527
|
if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
|
|
6528
|
+
if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context);
|
|
6465
6529
|
const attrString = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
6466
6530
|
const { tag } = node;
|
|
6467
6531
|
return children ? `<${tag}${attrString}>${children}</${tag}>` : `<${tag}${attrString} />`;
|
|
6468
6532
|
}
|
|
6469
6533
|
const scopedSlotDeclarations = [];
|
|
6470
6534
|
const plainSlotDeclarations = [];
|
|
6471
|
-
for (const decl of slotDeclarations)
|
|
6472
|
-
|
|
6473
|
-
if (!context.scopedSlotsRequireProps || hasSlotProps) scopedSlotDeclarations.push(decl);
|
|
6474
|
-
else plainSlotDeclarations.push(decl);
|
|
6475
|
-
}
|
|
6535
|
+
for (const decl of slotDeclarations) if (Object.keys(decl.props).length > 0 || !context.scopedSlotsRequireProps && decl.implicitDefault && hasDirectComponentSlotChild(decl.children, context)) scopedSlotDeclarations.push(decl);
|
|
6536
|
+
else plainSlotDeclarations.push(decl);
|
|
6476
6537
|
const slotNames = [];
|
|
6477
6538
|
const slotGenericAttrs = [];
|
|
6478
6539
|
for (const decl of scopedSlotDeclarations) {
|
|
6479
6540
|
const slotKey = resolveSlotKey(context, decl.name);
|
|
6480
6541
|
const { componentName } = createScopedSlotComponent(context, slotKey, decl.props, decl.children, transformNode);
|
|
6481
|
-
slotNames.push(
|
|
6542
|
+
slotNames.push({
|
|
6543
|
+
name: stringifySlotName(decl.name, context),
|
|
6544
|
+
condition: decl.condition
|
|
6545
|
+
});
|
|
6482
6546
|
slotGenericAttrs.push(`generic:scoped-slots-${slotKey}="${componentName}"`);
|
|
6483
6547
|
}
|
|
6548
|
+
if (shouldExposePlainSlotPresence(node) || isWevuComponentTag(node, context)) for (const decl of plainSlotDeclarations) slotNames.push({
|
|
6549
|
+
name: stringifySlotName(decl.name, context),
|
|
6550
|
+
condition: decl.condition
|
|
6551
|
+
});
|
|
6484
6552
|
const { attrs } = collectElementAttributes(node, context, {
|
|
6485
6553
|
skipSlotDirective: true,
|
|
6486
6554
|
forInfo: options?.forInfo,
|
|
@@ -6491,7 +6559,7 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
6491
6559
|
...attrs,
|
|
6492
6560
|
...slotGenericAttrs
|
|
6493
6561
|
];
|
|
6494
|
-
|
|
6562
|
+
pushSlotNamesAttr(mergedAttrs, slotNames, context);
|
|
6495
6563
|
if (scopedSlotDeclarations.length) {
|
|
6496
6564
|
const scopePropsExp = buildScopePropsExpression(context);
|
|
6497
6565
|
if (scopePropsExp) mergedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(scopePropsExp, context)}"`);
|
|
@@ -6512,18 +6580,19 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
|
|
|
6512
6580
|
const templateSlot = findSlotDirective(child);
|
|
6513
6581
|
if (templateSlot) {
|
|
6514
6582
|
const slotName = resolveSlotNameFromDirective(templateSlot);
|
|
6515
|
-
slotDeclarations.push(buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context));
|
|
6583
|
+
slotDeclarations.push(buildSlotDeclaration(slotName, templateSlot.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? templateSlot.exp.content : void 0, child.children, context, { condition: resolveTemplateSlotCondition(child, context) }));
|
|
6516
6584
|
continue;
|
|
6517
6585
|
}
|
|
6518
6586
|
}
|
|
6519
6587
|
nonTemplateChildren.push(child);
|
|
6520
6588
|
}
|
|
6589
|
+
const defaultSlotChildren = nonTemplateChildren.filter(isRenderableSlotChild);
|
|
6521
6590
|
if (slotDirective) {
|
|
6522
6591
|
if (slotDeclarations.length) context.warnings.push("组件上的 v-slot 与 <template v-slot> 不能同时使用;仅使用组件上的 v-slot。");
|
|
6523
6592
|
slotDeclarations.length = 0;
|
|
6524
6593
|
slotDeclarations.push(buildSlotDeclaration(resolveSlotNameFromDirective(slotDirective), slotDirective.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? slotDirective.exp.content : void 0, node.children, context));
|
|
6525
|
-
} else if (slotDeclarations.length &&
|
|
6526
|
-
else slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0,
|
|
6594
|
+
} else if (slotDeclarations.length && defaultSlotChildren.length) if (slotDeclarations.some((decl) => decl.name.type === "default" || decl.name.type === "static" && decl.name.value === "default")) context.warnings.push("存在显式的 v-slot:default,默认插槽内容将被忽略。");
|
|
6595
|
+
else slotDeclarations.push(buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context));
|
|
6527
6596
|
if (!slotDeclarations.length) {
|
|
6528
6597
|
const { attrs, vTextExp } = collectElementAttributes(node, context, {
|
|
6529
6598
|
skipSlotDirective: true,
|
|
@@ -6532,6 +6601,7 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
|
|
|
6532
6601
|
});
|
|
6533
6602
|
let children = node.children.map((child) => transformNode(child, context)).join("");
|
|
6534
6603
|
if (vTextExp !== void 0) children = renderMustache(vTextExp, context);
|
|
6604
|
+
if (children && defaultSlotChildren.length && !hasLegacySlotAttribute(defaultSlotChildren) && isWevuComponentTag(node, context)) pushSlotNamesAttr(attrs, [{ name: "'default'" }], context);
|
|
6535
6605
|
const attrString = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
6536
6606
|
const { tag } = node;
|
|
6537
6607
|
return children ? `<${tag}${attrString}>${children}</${tag}>` : `<${tag}${attrString} />`;
|
|
@@ -6544,6 +6614,10 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
|
|
|
6544
6614
|
isComponent: true
|
|
6545
6615
|
});
|
|
6546
6616
|
const mergedAttrs = [...extraAttrs, ...attrs];
|
|
6617
|
+
if (shouldExposePlainSlotPresence(node) || isWevuComponentTag(node, context)) pushSlotNamesAttr(mergedAttrs, slotDeclarations.map((decl) => ({
|
|
6618
|
+
name: stringifySlotName(decl.name, context),
|
|
6619
|
+
condition: decl.condition
|
|
6620
|
+
})), context);
|
|
6547
6621
|
const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
|
|
6548
6622
|
const { tag } = node;
|
|
6549
6623
|
return renderedSlots ? `<${tag}${attrString}>${renderedSlots}</${tag}>` : `<${tag}${attrString} />`;
|
|
@@ -6569,7 +6643,8 @@ function transformComponentElement(node, context, transformNode) {
|
|
|
6569
6643
|
const attrs = [];
|
|
6570
6644
|
const slotDirective = findSlotDirective(node);
|
|
6571
6645
|
const templateSlotChildren = node.children.filter((child) => child.type === NodeTypes.ELEMENT && child.tag === "template" && findSlotDirective(child));
|
|
6572
|
-
|
|
6646
|
+
const shouldUseAugmentedDefaultSlot = node.children.length > 0 && !context.scopedSlotsRequireProps;
|
|
6647
|
+
if (slotDirective || templateSlotChildren.length > 0 || shouldUseAugmentedDefaultSlot) return transformComponentWithSlots({
|
|
6573
6648
|
...node,
|
|
6574
6649
|
props: otherProps
|
|
6575
6650
|
}, context, transformNode, { extraAttrs: [`data-is="${renderMustache(componentVar, context)}"`] });
|
|
@@ -6591,7 +6666,9 @@ function transformNormalElement(node, context, transformNode) {
|
|
|
6591
6666
|
const tag = resolveTemplateTagName(node.tag, context);
|
|
6592
6667
|
const slotDirective = findSlotDirective(node);
|
|
6593
6668
|
const templateSlotChildren = node.children.filter((child) => child.type === NodeTypes.ELEMENT && child.tag === "template" && findSlotDirective(child));
|
|
6594
|
-
|
|
6669
|
+
const shouldUseAugmentedDefaultSlot = node.children.length > 0 && !context.scopedSlotsRequireProps && !isBuiltinTag(tag);
|
|
6670
|
+
const shouldUseSlotPresenceMetadata = node.children.length > 0 && (context.wevuComponentTags ? context.wevuComponentTags.has(node.tag) : /^[A-Z]/.test(node.tag));
|
|
6671
|
+
if (slotDirective || templateSlotChildren.length > 0 || shouldUseAugmentedDefaultSlot || shouldUseSlotPresenceMetadata) return transformComponentWithSlots(node, context, transformNode);
|
|
6595
6672
|
const { attrs, vTextExp } = collectElementAttributes(node, context, { resolvedTag: tag });
|
|
6596
6673
|
let children = "";
|
|
6597
6674
|
if (node.children.length > 0) children = node.children.map((child) => transformNode(child, context)).join("");
|
|
@@ -6875,7 +6952,8 @@ function compileVueTemplateToWxml(template, filename, options) {
|
|
|
6875
6952
|
layoutHosts: [],
|
|
6876
6953
|
layoutHostIndexSeed: 0,
|
|
6877
6954
|
inlineExpressions: [],
|
|
6878
|
-
inlineExpressionSeed: 0
|
|
6955
|
+
inlineExpressionSeed: 0,
|
|
6956
|
+
wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0
|
|
6879
6957
|
};
|
|
6880
6958
|
let wxml = ast.children.map((child) => transformNode(child, context)).join("");
|
|
6881
6959
|
if (context.classStyleWxs) wxml = `${buildClassStyleWxsTag(context.classStyleWxsExtension || "wxs", context.classStyleWxsSrc)}\n${wxml}`;
|
|
@@ -6903,6 +6981,141 @@ function compileVueTemplateToWxml(template, filename, options) {
|
|
|
6903
6981
|
}
|
|
6904
6982
|
}
|
|
6905
6983
|
//#endregion
|
|
6984
|
+
//#region src/plugins/vue/transform/compileVueFile/componentSources.ts
|
|
6985
|
+
function normalizeResolvedUsingComponent(result) {
|
|
6986
|
+
if (!result) return;
|
|
6987
|
+
if (typeof result === "string") return { from: result };
|
|
6988
|
+
return result;
|
|
6989
|
+
}
|
|
6990
|
+
function isWevuSfcComponent(result) {
|
|
6991
|
+
return result?.sourceType === "wevu-sfc" || Boolean(result?.resolvedId?.endsWith(".vue"));
|
|
6992
|
+
}
|
|
6993
|
+
function isVueSfcSource(source) {
|
|
6994
|
+
return source.endsWith(".vue");
|
|
6995
|
+
}
|
|
6996
|
+
function pascalToKebab(name) {
|
|
6997
|
+
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
6998
|
+
}
|
|
6999
|
+
function collectTemplateComponentNames(template, filename, warn) {
|
|
7000
|
+
const warnHandler = resolveWarnHandler(warn);
|
|
7001
|
+
const tags = collectVueTemplateTags(template, {
|
|
7002
|
+
filename,
|
|
7003
|
+
warnLabel: "自动 usingComponents",
|
|
7004
|
+
warn: (message) => warnHandler(message),
|
|
7005
|
+
shouldCollect: isAutoImportCandidateTag
|
|
7006
|
+
});
|
|
7007
|
+
for (const tag of [...tags]) if (tag.includes("-")) {
|
|
7008
|
+
const pascalName = tag.split("-").filter(Boolean).map((segment) => `${segment.charAt(0).toUpperCase()}${segment.slice(1)}`).join("");
|
|
7009
|
+
if (pascalName) tags.add(pascalName);
|
|
7010
|
+
}
|
|
7011
|
+
return tags;
|
|
7012
|
+
}
|
|
7013
|
+
async function collectScriptSetupUsingComponents(options) {
|
|
7014
|
+
const { descriptor, descriptorForCompile, filename, compileOptions, autoUsingComponents, result } = options;
|
|
7015
|
+
if (!descriptor.scriptSetup || !descriptor.template) return;
|
|
7016
|
+
const templateComponentNames = collectTemplateComponentNames(descriptor.template.content, filename, autoUsingComponents?.warn ?? compileOptions?.warn);
|
|
7017
|
+
if (!templateComponentNames.size) return;
|
|
7018
|
+
try {
|
|
7019
|
+
const setupAst = parse$3(descriptorForCompile.scriptSetup.content, BABEL_TS_MODULE_PARSER_OPTIONS);
|
|
7020
|
+
const pending = [];
|
|
7021
|
+
traverse(setupAst, { ImportDeclaration(path) {
|
|
7022
|
+
if (path.node.importKind === "type") return;
|
|
7023
|
+
if (!t.isStringLiteral(path.node.source)) return;
|
|
7024
|
+
const importSource = path.node.source.value;
|
|
7025
|
+
for (const specifier of path.node.specifiers) {
|
|
7026
|
+
if ("importKind" in specifier && specifier.importKind === "type") continue;
|
|
7027
|
+
if (!("local" in specifier) || !t.isIdentifier(specifier.local)) continue;
|
|
7028
|
+
const localName = specifier.local.name;
|
|
7029
|
+
if (!templateComponentNames.has(localName)) continue;
|
|
7030
|
+
if (t.isImportDefaultSpecifier(specifier)) pending.push({
|
|
7031
|
+
localName,
|
|
7032
|
+
importSource,
|
|
7033
|
+
importedName: "default",
|
|
7034
|
+
kind: "default"
|
|
7035
|
+
});
|
|
7036
|
+
else if (t.isImportSpecifier(specifier)) {
|
|
7037
|
+
const importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : t.isStringLiteral(specifier.imported) ? specifier.imported.value : void 0;
|
|
7038
|
+
pending.push({
|
|
7039
|
+
localName,
|
|
7040
|
+
importSource,
|
|
7041
|
+
importedName,
|
|
7042
|
+
kind: "named"
|
|
7043
|
+
});
|
|
7044
|
+
}
|
|
7045
|
+
}
|
|
7046
|
+
} });
|
|
7047
|
+
for (const { localName, importSource, importedName, kind } of pending) {
|
|
7048
|
+
let resolved = autoUsingComponents?.resolveUsingComponentPath ? normalizeResolvedUsingComponent(await autoUsingComponents.resolveUsingComponentPath(importSource, filename, {
|
|
7049
|
+
localName,
|
|
7050
|
+
importedName,
|
|
7051
|
+
kind
|
|
7052
|
+
})) : void 0;
|
|
7053
|
+
if (!resolved?.from && importSource.startsWith("/")) resolved = {
|
|
7054
|
+
from: removeExtensionDeep(importSource),
|
|
7055
|
+
resolvedId: importSource
|
|
7056
|
+
};
|
|
7057
|
+
if (resolved?.from) {
|
|
7058
|
+
result.autoUsingComponentsMap[localName] = resolved.from;
|
|
7059
|
+
result.autoComponentMeta[localName] = resolved.from;
|
|
7060
|
+
}
|
|
7061
|
+
if (isVueSfcSource(importSource) || isWevuSfcComponent(resolved)) {
|
|
7062
|
+
result.wevuComponentTags.add(localName);
|
|
7063
|
+
result.wevuComponentTags.add(pascalToKebab(localName));
|
|
7064
|
+
}
|
|
7065
|
+
}
|
|
7066
|
+
} catch (error) {
|
|
7067
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
7068
|
+
autoUsingComponents?.warn?.(`[Vue 编译] 解析 ${filename} 的 <script setup> 导入失败:${message}`);
|
|
7069
|
+
}
|
|
7070
|
+
}
|
|
7071
|
+
async function collectAutoImportWevuComponents(options) {
|
|
7072
|
+
const { descriptor, filename, autoImportTags, warn, result } = options;
|
|
7073
|
+
if (!autoImportTags || !descriptor.template) return;
|
|
7074
|
+
const warnHandler = resolveWarnHandler(autoImportTags.warn ?? warn);
|
|
7075
|
+
const tags = collectVueTemplateTags(descriptor.template.content, {
|
|
7076
|
+
filename,
|
|
7077
|
+
warnLabel: "自动导入标签",
|
|
7078
|
+
warn: (message) => warnHandler(message),
|
|
7079
|
+
shouldCollect: isAutoImportCandidateTag
|
|
7080
|
+
});
|
|
7081
|
+
for (const tag of tags) {
|
|
7082
|
+
let resolved;
|
|
7083
|
+
try {
|
|
7084
|
+
resolved = await autoImportTags.resolveUsingComponent(tag, filename);
|
|
7085
|
+
} catch {
|
|
7086
|
+
resolved = void 0;
|
|
7087
|
+
}
|
|
7088
|
+
if (!resolved?.from) continue;
|
|
7089
|
+
if (isWevuSfcComponent(resolved)) {
|
|
7090
|
+
result.wevuComponentTags.add(tag);
|
|
7091
|
+
if (resolved.name) result.wevuComponentTags.add(resolved.name);
|
|
7092
|
+
}
|
|
7093
|
+
}
|
|
7094
|
+
}
|
|
7095
|
+
async function collectComponentSourceInfo(options) {
|
|
7096
|
+
const result = {
|
|
7097
|
+
autoUsingComponentsMap: {},
|
|
7098
|
+
autoComponentMeta: {},
|
|
7099
|
+
wevuComponentTags: /* @__PURE__ */ new Set()
|
|
7100
|
+
};
|
|
7101
|
+
await collectScriptSetupUsingComponents({
|
|
7102
|
+
descriptor: options.descriptor,
|
|
7103
|
+
descriptorForCompile: options.descriptorForCompile,
|
|
7104
|
+
filename: options.filename,
|
|
7105
|
+
compileOptions: options.compileOptions,
|
|
7106
|
+
autoUsingComponents: options.autoUsingComponents,
|
|
7107
|
+
result
|
|
7108
|
+
});
|
|
7109
|
+
await collectAutoImportWevuComponents({
|
|
7110
|
+
descriptor: options.descriptor,
|
|
7111
|
+
filename: options.filename,
|
|
7112
|
+
autoImportTags: options.autoImportTags,
|
|
7113
|
+
warn: options.compileOptions?.warn,
|
|
7114
|
+
result
|
|
7115
|
+
});
|
|
7116
|
+
return result;
|
|
7117
|
+
}
|
|
7118
|
+
//#endregion
|
|
6906
7119
|
//#region src/plugins/vue/transform/config.ts
|
|
6907
7120
|
/**
|
|
6908
7121
|
* 规范化配置块语言。
|
|
@@ -7567,66 +7780,10 @@ function composeSourceMaps(transformedMap, originalMap) {
|
|
|
7567
7780
|
//#endregion
|
|
7568
7781
|
//#region src/plugins/vue/transform/compileVueFile/script.ts
|
|
7569
7782
|
const TYPE_ONLY_DEFINE_PROPS_RE = /\bdefineProps\s*</;
|
|
7570
|
-
function
|
|
7571
|
-
const
|
|
7572
|
-
|
|
7573
|
-
filename,
|
|
7574
|
-
warnLabel: "自动 usingComponents",
|
|
7575
|
-
warn: (message) => warnHandler(message),
|
|
7576
|
-
shouldCollect: (tag) => VUE_COMPONENT_TAG_RE.test(tag)
|
|
7577
|
-
});
|
|
7578
|
-
}
|
|
7579
|
-
async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, isAppFile) {
|
|
7580
|
-
const autoUsingComponentsMap = {};
|
|
7581
|
-
const autoComponentMeta = {};
|
|
7783
|
+
async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, _autoUsingComponents, templateCompiled, isAppFile, componentSourceInfo) {
|
|
7784
|
+
const autoUsingComponentsMap = { ...componentSourceInfo?.autoUsingComponentsMap ?? {} };
|
|
7785
|
+
const autoComponentMeta = { ...componentSourceInfo?.autoComponentMeta ?? {} };
|
|
7582
7786
|
const relaxStructuredTypeOnlyProps = Boolean(descriptor.scriptSetup?.content && TYPE_ONLY_DEFINE_PROPS_RE.test(descriptor.scriptSetup.content));
|
|
7583
|
-
if (autoUsingComponents && descriptor.scriptSetup && descriptor.template) {
|
|
7584
|
-
const templateComponentNames = collectTemplateComponentNames(descriptor.template.content, filename, autoUsingComponents.warn ?? options?.warn);
|
|
7585
|
-
if (templateComponentNames.size) try {
|
|
7586
|
-
const setupAst = parse$3(descriptorForCompile.scriptSetup.content, BABEL_TS_MODULE_PARSER_OPTIONS);
|
|
7587
|
-
const pending = [];
|
|
7588
|
-
traverse(setupAst, { ImportDeclaration(path) {
|
|
7589
|
-
if (path.node.importKind === "type") return;
|
|
7590
|
-
if (!t.isStringLiteral(path.node.source)) return;
|
|
7591
|
-
const importSource = path.node.source.value;
|
|
7592
|
-
for (const specifier of path.node.specifiers) {
|
|
7593
|
-
if ("importKind" in specifier && specifier.importKind === "type") continue;
|
|
7594
|
-
if (!("local" in specifier) || !t.isIdentifier(specifier.local)) continue;
|
|
7595
|
-
const localName = specifier.local.name;
|
|
7596
|
-
if (!templateComponentNames.has(localName)) continue;
|
|
7597
|
-
if (t.isImportDefaultSpecifier(specifier)) pending.push({
|
|
7598
|
-
localName,
|
|
7599
|
-
importSource,
|
|
7600
|
-
importedName: "default",
|
|
7601
|
-
kind: "default"
|
|
7602
|
-
});
|
|
7603
|
-
else if (t.isImportSpecifier(specifier)) {
|
|
7604
|
-
const importedName = t.isIdentifier(specifier.imported) ? specifier.imported.name : t.isStringLiteral(specifier.imported) ? specifier.imported.value : void 0;
|
|
7605
|
-
pending.push({
|
|
7606
|
-
localName,
|
|
7607
|
-
importSource,
|
|
7608
|
-
importedName,
|
|
7609
|
-
kind: "named"
|
|
7610
|
-
});
|
|
7611
|
-
}
|
|
7612
|
-
}
|
|
7613
|
-
} });
|
|
7614
|
-
for (const { localName, importSource, importedName, kind } of pending) {
|
|
7615
|
-
let resolved = await autoUsingComponents.resolveUsingComponentPath(importSource, filename, {
|
|
7616
|
-
localName,
|
|
7617
|
-
importedName,
|
|
7618
|
-
kind
|
|
7619
|
-
});
|
|
7620
|
-
if (!resolved && importSource.startsWith("/")) resolved = removeExtensionDeep(importSource);
|
|
7621
|
-
if (!resolved) continue;
|
|
7622
|
-
autoUsingComponentsMap[localName] = resolved;
|
|
7623
|
-
autoComponentMeta[localName] = resolved;
|
|
7624
|
-
}
|
|
7625
|
-
} catch (error) {
|
|
7626
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
7627
|
-
autoUsingComponents.warn?.(`[Vue 编译] 解析 ${filename} 的 <script setup> 导入失败:${message}`);
|
|
7628
|
-
}
|
|
7629
|
-
}
|
|
7630
7787
|
let scriptCode;
|
|
7631
7788
|
let scriptMap = null;
|
|
7632
7789
|
if (descriptor.script || descriptor.scriptSetup) {
|
|
@@ -7728,8 +7885,23 @@ async function compileVueFile(source, filename, options) {
|
|
|
7728
7885
|
} };
|
|
7729
7886
|
const autoUsingComponents = options?.autoUsingComponents?.enabled && parsed.descriptor.scriptSetup && parsed.descriptor.template && options.autoUsingComponents.resolveUsingComponentPath ? options.autoUsingComponents : void 0;
|
|
7730
7887
|
const autoImportTags = options?.autoImportTags?.enabled && parsed.descriptor.template && options.autoImportTags.resolveUsingComponent ? options.autoImportTags : void 0;
|
|
7731
|
-
const
|
|
7732
|
-
|
|
7888
|
+
const componentSourceInfo = await collectComponentSourceInfo({
|
|
7889
|
+
descriptor: parsed.descriptor,
|
|
7890
|
+
descriptorForCompile: parsed.descriptorForCompile,
|
|
7891
|
+
filename,
|
|
7892
|
+
compileOptions: options,
|
|
7893
|
+
autoUsingComponents,
|
|
7894
|
+
autoImportTags
|
|
7895
|
+
});
|
|
7896
|
+
const templateOptions = componentSourceInfo.wevuComponentTags.size ? {
|
|
7897
|
+
...options?.template,
|
|
7898
|
+
wevuComponentTags: componentSourceInfo.wevuComponentTags
|
|
7899
|
+
} : {
|
|
7900
|
+
...options?.template,
|
|
7901
|
+
wevuComponentTags: []
|
|
7902
|
+
};
|
|
7903
|
+
const templateCompiled = compileTemplatePhase(parsed.descriptor, filename, templateOptions, result);
|
|
7904
|
+
const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo);
|
|
7733
7905
|
result.script = scriptPhase.script;
|
|
7734
7906
|
result.scriptMap = scriptPhase.scriptMap;
|
|
7735
7907
|
compileStylePhase(parsed.descriptor, filename, result);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.15.
|
|
4
|
+
"version": "6.15.18",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"merge": "^2.1.1",
|
|
51
51
|
"pathe": "^2.0.3",
|
|
52
52
|
"vue": "^3.5.33",
|
|
53
|
-
"@weapp-core/constants": "^0.1.
|
|
53
|
+
"@weapp-core/constants": "^0.1.4",
|
|
54
54
|
"@weapp-core/shared": "3.0.4",
|
|
55
|
-
"@weapp-vite/ast": "6.15.
|
|
55
|
+
"@weapp-vite/ast": "6.15.18",
|
|
56
56
|
"rolldown-require": "2.0.15"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|