@wevu/compiler 6.16.27 → 6.16.28

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 CHANGED
@@ -251,6 +251,7 @@ interface TemplateCompileResult {
251
251
  code: string;
252
252
  warnings: string[];
253
253
  scopedSlotComponents?: ScopedSlotComponentAsset[];
254
+ slotFallbackWrapperComponent?: SlotFallbackWrapperComponentAsset;
254
255
  componentGenerics?: Record<string, true>;
255
256
  classStyleRuntime?: ClassStyleRuntime;
256
257
  classStyleBindings?: ClassStyleBinding[];
@@ -288,6 +289,7 @@ interface TemplateCompileOptions {
288
289
  scopedSlotsRequireProps?: boolean;
289
290
  slotSingleRootNoWrapper?: boolean;
290
291
  slotFallbackWrapper?: SlotFallbackWrapperConfig;
292
+ slotFallbackWrapperStrategy?: SlotFallbackWrapperStrategy;
291
293
  slotMultipleInstance?: boolean;
292
294
  classStyleRuntime?: ClassStyleRuntime | 'auto';
293
295
  objectLiteralBindMode?: ObjectLiteralBindMode;
@@ -303,6 +305,20 @@ interface TemplateCompileOptions {
303
305
  * 作用域插槽编译模式。
304
306
  */
305
307
  type ScopedSlotsCompilerMode = 'auto' | 'augmented' | 'off';
308
+ /**
309
+ * 命名插槽 fallback 容器默认策略。
310
+ */
311
+ type SlotFallbackWrapperStrategy = 'view' | 'virtual-host';
312
+ /**
313
+ * 命名插槽 fallback 虚拟宿主组件资源描述。
314
+ */
315
+ interface SlotFallbackWrapperComponentAsset {
316
+ tagName: string;
317
+ componentBase: string;
318
+ template: string;
319
+ script: string;
320
+ config: Record<string, any>;
321
+ }
306
322
  /**
307
323
  * 命名插槽 fallback 容器策略匹配器。
308
324
  */
@@ -440,6 +456,7 @@ interface VueTransformResult {
440
456
  config?: string;
441
457
  cssModules?: Record<string, Record<string, string>>;
442
458
  scopedSlotComponents?: TemplateCompileResult['scopedSlotComponents'];
459
+ slotFallbackWrapperComponent?: TemplateCompileResult['slotFallbackWrapperComponent'];
443
460
  componentGenerics?: TemplateCompileResult['componentGenerics'];
444
461
  classStyleWxs?: boolean;
445
462
  meta?: {
@@ -917,4 +934,4 @@ interface CollectVueTemplateTagsOptions {
917
934
  */
918
935
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
919
936
  //#endregion
920
- 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, WevuPageFeatureFlag, 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 };
937
+ 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 SlotFallbackWrapperComponentAsset, type SlotFallbackWrapperStrategy, 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, WevuPageFeatureFlag, 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_FUNCTION_PROP_PATHS_KEY, 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_ALIASES_KEY, WEVU_PROPS_DERIVED_KEYS_KEY, WEVU_PROPS_KEY, WEVU_SLOT_NAMES_ATTR, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_OWNER_PROXY_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, WEVU_TEMPLATE_REF_CLASS_PREFIX } from "@weapp-core/constants";
16
+ import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_FUNCTION_PROP_PATHS_KEY, 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_ALIASES_KEY, WEVU_PROPS_DERIVED_KEYS_KEY, WEVU_PROPS_KEY, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME, WEVU_SLOT_NAMES_ATTR, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_OWNER_PROXY_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, WEVU_TEMPLATE_REF_CLASS_PREFIX } 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";
@@ -7766,13 +7766,23 @@ const HTML_VOID_TAGS = new Set([
7766
7766
  "track",
7767
7767
  "wbr"
7768
7768
  ]);
7769
- function resolveSlotFallbackWrapperConfig(config) {
7769
+ function resolveSlotFallbackWrapperComponent(strategy) {
7770
+ if (strategy !== "virtual-host") return;
7771
+ return {
7772
+ tagName: WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME,
7773
+ componentBase: WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE,
7774
+ template: "<slot></slot>",
7775
+ script: "Component({options:{virtualHost:true,multipleSlots:true}})",
7776
+ config: { component: true }
7777
+ };
7778
+ }
7779
+ function resolveSlotFallbackWrapperConfig(config, strategy) {
7770
7780
  if (typeof config === "string") return {
7771
7781
  tag: config || "view",
7772
7782
  rules: []
7773
7783
  };
7774
7784
  return {
7775
- tag: config?.tag || "view",
7785
+ tag: config?.tag || (strategy === "virtual-host" ? WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME : "view"),
7776
7786
  attrs: config?.attrs,
7777
7787
  singleRootNoWrapper: config?.singleRootNoWrapper,
7778
7788
  rules: config?.rules ?? []
@@ -7788,7 +7798,9 @@ function compileVueTemplateToWxml(template, filename, options) {
7788
7798
  const wxsExtension = options?.wxsExtension;
7789
7799
  const scopedSlotsRequireProps = options?.scopedSlotsRequireProps ?? options?.scopedSlotsCompiler !== "augmented";
7790
7800
  const slotSingleRootNoWrapper = options?.slotSingleRootNoWrapper ?? false;
7791
- const slotFallbackWrapper = resolveSlotFallbackWrapperConfig(options?.slotFallbackWrapper);
7801
+ const slotFallbackWrapperStrategy = options?.slotFallbackWrapperStrategy ?? "view";
7802
+ const slotFallbackWrapper = resolveSlotFallbackWrapperConfig(options?.slotFallbackWrapper, slotFallbackWrapperStrategy);
7803
+ const slotFallbackWrapperComponent = slotFallbackWrapper.tag === WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME ? resolveSlotFallbackWrapperComponent(slotFallbackWrapperStrategy) : void 0;
7792
7804
  const htmlTagToWxmlMap = resolveHtmlTagToWxmlMap(options?.htmlTagToWxml);
7793
7805
  try {
7794
7806
  const ast = parse$1(template, {
@@ -7811,6 +7823,7 @@ function compileVueTemplateToWxml(template, filename, options) {
7811
7823
  scopedSlotsRequireProps,
7812
7824
  slotSingleRootNoWrapper,
7813
7825
  slotFallbackWrapper,
7826
+ slotFallbackWrapperComponent,
7814
7827
  slotMultipleInstance: options?.slotMultipleInstance ?? true,
7815
7828
  scopedSlotComponents: [],
7816
7829
  componentGenerics: {},
@@ -7846,6 +7859,7 @@ function compileVueTemplateToWxml(template, filename, options) {
7846
7859
  warnings
7847
7860
  };
7848
7861
  if (context.scopedSlotComponents.length) result.scopedSlotComponents = context.scopedSlotComponents;
7862
+ if (context.slotFallbackWrapperComponent && wxml.includes(`<${context.slotFallbackWrapperComponent.tagName}`)) result.slotFallbackWrapperComponent = context.slotFallbackWrapperComponent;
7849
7863
  if (Object.keys(context.componentGenerics).length) result.componentGenerics = context.componentGenerics;
7850
7864
  if (context.classStyleWxs) result.classStyleWxs = true;
7851
7865
  if (context.classStyleBindings.length) {
@@ -8715,6 +8729,89 @@ function composeSourceMaps(transformedMap, originalMap) {
8715
8729
  return null;
8716
8730
  }
8717
8731
  //#endregion
8732
+ //#region src/plugins/vue/transform/compileVueFile/reservedProps.ts
8733
+ const RESERVED_SCRIPT_SETUP_PROPS = new Set([
8734
+ "id",
8735
+ "class",
8736
+ "slot"
8737
+ ]);
8738
+ const RESERVED_PROPS_WARNING = "defineProps 中声明 id/class/slot 可能无法在小程序 properties 中正确取值,请改用其他 prop 名称。";
8739
+ function getStaticKeyName(key) {
8740
+ if (t.isIdentifier(key)) return key.name;
8741
+ if (t.isStringLiteral(key)) return key.value;
8742
+ }
8743
+ function getTypePropertyName(key) {
8744
+ if (t.isIdentifier(key)) return key.name;
8745
+ if (t.isStringLiteral(key)) return key.value;
8746
+ }
8747
+ function isReservedScriptSetupProp(name) {
8748
+ return name != null && RESERVED_SCRIPT_SETUP_PROPS.has(name);
8749
+ }
8750
+ function runtimePropsContainReservedName(node) {
8751
+ if (t.isObjectExpression(node)) return node.properties.some((prop) => t.isObjectProperty(prop) && !prop.computed && isReservedScriptSetupProp(getStaticKeyName(prop.key)));
8752
+ if (t.isArrayExpression(node)) return node.elements.some((element) => t.isStringLiteral(element) && isReservedScriptSetupProp(element.value));
8753
+ return false;
8754
+ }
8755
+ function createTypeScope(ast) {
8756
+ const scope = /* @__PURE__ */ new Map();
8757
+ traverse(ast, {
8758
+ TSInterfaceDeclaration(path) {
8759
+ scope.set(path.node.id.name, path.node.body);
8760
+ },
8761
+ TSTypeAliasDeclaration(path) {
8762
+ scope.set(path.node.id.name, path.node.typeAnnotation);
8763
+ }
8764
+ });
8765
+ return scope;
8766
+ }
8767
+ function typePropsContainReservedName(typeNode, scope, seen = /* @__PURE__ */ new Set()) {
8768
+ if (!typeNode) return false;
8769
+ if (t.isTSTypeLiteral(typeNode)) return typeNode.members.some((member) => {
8770
+ return t.isTSPropertySignature(member) && !member.computed && isReservedScriptSetupProp(getTypePropertyName(member.key));
8771
+ });
8772
+ if (t.isTSInterfaceBody(typeNode)) return typeNode.body.some((member) => {
8773
+ return t.isTSPropertySignature(member) && !member.computed && isReservedScriptSetupProp(getTypePropertyName(member.key));
8774
+ });
8775
+ if (t.isTSIntersectionType(typeNode)) return typeNode.types.some((item) => typePropsContainReservedName(item, scope, seen));
8776
+ if (t.isTSTypeReference(typeNode) && t.isIdentifier(typeNode.typeName)) {
8777
+ const typeName = typeNode.typeName.name;
8778
+ if (seen.has(typeName)) return false;
8779
+ const resolved = scope.get(typeName);
8780
+ if (!resolved) return false;
8781
+ seen.add(typeName);
8782
+ return typePropsContainReservedName(resolved, scope, seen);
8783
+ }
8784
+ return false;
8785
+ }
8786
+ function hasDefinePropsReservedName(scriptSetupCode) {
8787
+ let hasReservedName = false;
8788
+ try {
8789
+ const ast = parseJsLike(scriptSetupCode);
8790
+ const typeScope = createTypeScope(ast);
8791
+ traverse(ast, { CallExpression(path) {
8792
+ const callee = path.node.callee;
8793
+ if (!t.isIdentifier(callee, { name: "defineProps" })) return;
8794
+ if (runtimePropsContainReservedName(path.node.arguments[0])) {
8795
+ hasReservedName = true;
8796
+ path.stop();
8797
+ return;
8798
+ }
8799
+ const typeParam = path.node.typeParameters?.params?.[0];
8800
+ if (typePropsContainReservedName(typeParam, typeScope)) {
8801
+ hasReservedName = true;
8802
+ path.stop();
8803
+ }
8804
+ } });
8805
+ } catch {
8806
+ return false;
8807
+ }
8808
+ return hasReservedName;
8809
+ }
8810
+ function warnReservedScriptSetupProps(scriptSetupCode, warn) {
8811
+ if (!scriptSetupCode || !hasDefinePropsReservedName(scriptSetupCode)) return;
8812
+ warn?.(RESERVED_PROPS_WARNING);
8813
+ }
8814
+ //#endregion
8718
8815
  //#region src/plugins/vue/transform/compileVueFile/script.ts
8719
8816
  const TYPE_ONLY_DEFINE_PROPS_RE = /\bdefineProps\s*</;
8720
8817
  function resolveScriptSetupPropsAliases(bindings) {
@@ -8815,6 +8912,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
8815
8912
  id: filename,
8816
8913
  isProd: false
8817
8914
  });
8915
+ warnReservedScriptSetupProps(descriptorForCompile.scriptSetup?.content, options?.warn);
8818
8916
  propsAliases ??= resolveScriptSetupPropsAliases(scriptCompiled.bindings);
8819
8917
  scriptCode = scriptCompiled.content;
8820
8918
  propsDerivedKeys = resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCode);
@@ -8898,6 +8996,7 @@ function compileTemplatePhase(descriptor, filename, options, result) {
8898
8996
  const templateCompiled = compileVueTemplateToWxml(descriptor.template.content, filename, options);
8899
8997
  result.template = templateCompiled.code;
8900
8998
  if (templateCompiled.scopedSlotComponents?.length) result.scopedSlotComponents = templateCompiled.scopedSlotComponents;
8999
+ if (templateCompiled.slotFallbackWrapperComponent) result.slotFallbackWrapperComponent = templateCompiled.slotFallbackWrapperComponent;
8901
9000
  if (templateCompiled.componentGenerics && Object.keys(templateCompiled.componentGenerics).length) result.componentGenerics = templateCompiled.componentGenerics;
8902
9001
  if (templateCompiled.classStyleWxs) result.classStyleWxs = true;
8903
9002
  return templateCompiled;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.27",
4
+ "version": "6.16.28",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -45,14 +45,14 @@
45
45
  "@vue/compiler-core": "^3.5.35",
46
46
  "@vue/compiler-dom": "^3.5.35",
47
47
  "comment-json": "^5.0.0",
48
- "lru-cache": "^11.5.0",
48
+ "lru-cache": "^11.5.1",
49
49
  "magic-string": "^0.30.21",
50
50
  "merge": "^2.1.1",
51
51
  "pathe": "^2.0.3",
52
52
  "vue": "^3.5.35",
53
- "@weapp-core/constants": "0.1.10",
53
+ "@weapp-core/constants": "0.1.11",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.27",
55
+ "@weapp-vite/ast": "6.16.28",
56
56
  "rolldown-require": "2.0.18"
57
57
  },
58
58
  "publishConfig": {