@wevu/compiler 6.17.7 → 6.18.0

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
@@ -4,6 +4,7 @@ import { Expression } from "@weapp-vite/ast/babelTypes";
4
4
  import { LRUCache } from "lru-cache";
5
5
  import { AstEngineName, AstEngineName as AstEngineName$1 } from "@weapp-vite/ast";
6
6
  import { SFCBlock, SFCDescriptor, SFCParseResult, SFCStyleBlock } from "vue/compiler-sfc";
7
+ import "@weapp-vite/ast/babelTraverse";
7
8
  //#region src/auto-import-components/builtin.d.ts
8
9
  /**
9
10
  * 内置组件集合(来自自动生成的组件列表)。
@@ -170,6 +171,14 @@ interface ReadAndParseSfcOptions {
170
171
  * 直接传入源码以跳过文件读取。
171
172
  */
172
173
  source?: string;
174
+ /**
175
+ * 已完成 `<script src>` 预处理的源码。
176
+ */
177
+ preprocessedSource?: string;
178
+ /**
179
+ * 是否忽略空 SFC block。
180
+ */
181
+ ignoreEmpty?: boolean;
173
182
  /**
174
183
  * 是否按 mtime+size 检查文件变更(dev 推荐开启)。
175
184
  */
@@ -525,6 +534,10 @@ interface AutoImportTagsOptions {
525
534
  } & ResolvedUsingComponentInfo) | undefined>;
526
535
  warn?: (message: string) => void;
527
536
  }
537
+ interface VueSfcStaticComponentMeta {
538
+ componentName?: string;
539
+ isMiniProgramComponent: boolean;
540
+ }
528
541
  /**
529
542
  * 编译 Vue SFC 的选项集合。
530
543
  */
@@ -536,6 +549,10 @@ interface CompileVueFileOptions {
536
549
  * 是否压缩生成的 wevu 脚本输出。
537
550
  */
538
551
  minify?: boolean;
552
+ /**
553
+ * 是否生成脚本 sourcemap。默认开启;构建工具可在未启用 sourcemap 时显式关闭以减少 codegen 成本。
554
+ */
555
+ sourceMap?: boolean;
539
556
  warn?: (message: string) => void;
540
557
  autoUsingComponents?: AutoUsingComponentsOptions;
541
558
  autoImportTags?: AutoImportTagsOptions;
@@ -547,6 +564,10 @@ interface CompileVueFileOptions {
547
564
  };
548
565
  sfcSrc?: ResolveSfcBlockSrcOptions;
549
566
  wevuDefaults?: WevuDefaults;
567
+ /**
568
+ * 缓存被当前 SFC 引用的 Vue 组件静态元信息,避免重复读取和解析同一组件。
569
+ */
570
+ componentMetaCache?: Map<string, Promise<VueSfcStaticComponentMeta>>;
550
571
  }
551
572
  //#endregion
552
573
  //#region src/plugins/jsx/compileJsxFile.d.ts
@@ -686,6 +707,9 @@ declare function compileConfigBlocks(blocks: SFCBlock[], filename: string, optio
686
707
  merge?: (target: Record<string, any>, source: Record<string, any>) => Record<string, any> | void;
687
708
  }): Promise<string | undefined>;
688
709
  //#endregion
710
+ //#region src/plugins/vue/transform/jsonMacros/parse.d.ts
711
+ declare function mayContainJsonMacro(content: string): boolean;
712
+ //#endregion
689
713
  //#region src/plugins/vue/transform/jsonMacros/rewrite.d.ts
690
714
  /**
691
715
  * 从任意代码中剥离 JSON 宏调用。
@@ -760,6 +784,10 @@ interface TransformScriptOptions {
760
784
  * 是否压缩生成的脚本代码。
761
785
  */
762
786
  minify?: boolean;
787
+ /**
788
+ * 是否生成脚本 sourcemap。
789
+ */
790
+ sourceMap?: boolean;
763
791
  /**
764
792
  * 编译期警告回调
765
793
  */
@@ -917,6 +945,7 @@ declare function injectWevuPageFeatureFlagsIntoOptionsObject(optionsObject: t.Ob
917
945
  declare function injectWevuPageFeaturesInJs(source: string, options?: {
918
946
  astEngine?: AstEngineName$1;
919
947
  minify?: boolean;
948
+ sourceMap?: boolean;
920
949
  }): {
921
950
  code: string;
922
951
  transformed: boolean;
@@ -930,6 +959,7 @@ declare function injectWevuPageFeaturesInJsWithResolver(source: string, options:
930
959
  resolver: ModuleResolver;
931
960
  astEngine?: AstEngineName$1;
932
961
  minify?: boolean;
962
+ sourceMap?: boolean;
933
963
  }): Promise<{
934
964
  code: string;
935
965
  transformed: boolean;
@@ -981,4 +1011,4 @@ interface CollectVueTemplateTagsOptions {
981
1011
  */
982
1012
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
983
1013
  //#endregion
984
- 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_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, 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, isWevuRuntimeModuleId, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
1014
+ 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_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, 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, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import { getMiniProgramRuntimeGlobalKeys, getMiniProgramTemplatePreset, removeExtensionDeep } from "@weapp-core/shared";
2
3
  import path from "pathe";
3
4
  import { NodeTypes, baseParse } from "@vue/compiler-core";
@@ -7,7 +8,7 @@ import MagicString from "magic-string";
7
8
  import { recursive } from "merge";
8
9
  import { bundleRequire } from "rolldown-require";
9
10
  import { access, mkdir, readFile as readFile$1, rm, stat, writeFile } from "node:fs/promises";
10
- import { BABEL_TS_MODULE_PARSER_OPTIONS, generate, parse as parse$3, parseJsLike, traverse } from "@weapp-vite/ast/babel";
11
+ import { BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, generate, parse as parse$3, parseJsLike, traverse } from "@weapp-vite/ast/babel";
11
12
  import fs from "node:fs";
12
13
  import os from "node:os";
13
14
  import process from "node:process";
@@ -625,6 +626,10 @@ const JSON_MACROS = /* @__PURE__ */ new Set([
625
626
  "defineSitemapJson",
626
627
  "defineThemeJson"
627
628
  ]);
629
+ const JSON_MACRO_HINT_RE = /\bdefine(?:App|Page|Component|Sitemap|Theme)Json\s*\(/;
630
+ function mayContainJsonMacro(content) {
631
+ return JSON_MACRO_HINT_RE.test(content);
632
+ }
628
633
  function parseScriptSetupAst(content, filename) {
629
634
  try {
630
635
  return parse$3(content, BABEL_TS_MODULE_PARSER_OPTIONS);
@@ -713,6 +718,58 @@ function stripJsonMacroCallsFromCode(code, filename) {
713
718
  return ms.toString();
714
719
  }
715
720
  //#endregion
721
+ //#region src/plugins/vue/transform/jsonMacros/static.ts
722
+ function unwrapTsExpression$3(node) {
723
+ if (t.isTSAsExpression(node) || t.isTSNonNullExpression(node) || t.isTSTypeAssertion(node)) return unwrapTsExpression$3(node.expression);
724
+ return node;
725
+ }
726
+ function resolveStaticLiteralValue(node) {
727
+ const normalized = unwrapTsExpression$3(node);
728
+ if (t.isStringLiteral(normalized) || t.isNumericLiteral(normalized) || t.isBooleanLiteral(normalized)) return normalized.value;
729
+ if (t.isNullLiteral(normalized)) return null;
730
+ if (t.isUnaryExpression(normalized) && (normalized.operator === "-" || normalized.operator === "+") && t.isNumericLiteral(normalized.argument)) return normalized.operator === "-" ? -normalized.argument.value : normalized.argument.value;
731
+ if (t.isArrayExpression(normalized)) {
732
+ const values = [];
733
+ for (const element of normalized.elements) {
734
+ if (!element || t.isSpreadElement(element) || !t.isExpression(element)) throw new Error("unsupported static json macro array item");
735
+ values.push(resolveStaticLiteralValue(element));
736
+ }
737
+ return values;
738
+ }
739
+ if (t.isObjectExpression(normalized)) {
740
+ const value = {};
741
+ for (const property of normalized.properties) {
742
+ if (!t.isObjectProperty(property) || property.computed || !t.isExpression(property.value)) throw new Error("unsupported static json macro object property");
743
+ const key = property.key;
744
+ const keyName = t.isIdentifier(key) ? key.name : t.isStringLiteral(key) || t.isNumericLiteral(key) ? String(key.value) : void 0;
745
+ if (!keyName) throw new Error("unsupported static json macro object key");
746
+ value[keyName] = resolveStaticLiteralValue(property.value);
747
+ }
748
+ return value;
749
+ }
750
+ throw new Error("unsupported static json macro value");
751
+ }
752
+ function resolveStaticJsonMacroConfig(macroStatements, options) {
753
+ let accumulator = {};
754
+ for (const statementPath of macroStatements) {
755
+ const arg = statementPath.get("expression").get("arguments.0")?.node;
756
+ if (!arg || !t.isExpression(arg)) return;
757
+ let next;
758
+ try {
759
+ next = resolveStaticLiteralValue(arg);
760
+ } catch {
761
+ return;
762
+ }
763
+ if (!next || typeof next !== "object" || Array.isArray(next)) return;
764
+ if (hasOwn(next, "$schema")) delete next.$schema;
765
+ if (options?.merge) {
766
+ const merged = options.merge(accumulator, next);
767
+ if (merged && typeof merged === "object" && !Array.isArray(merged)) accumulator = merged;
768
+ } else recursive(accumulator, next);
769
+ }
770
+ return Object.keys(accumulator).length ? accumulator : void 0;
771
+ }
772
+ //#endregion
716
773
  //#region src/plugins/vue/transform/jsonMacros/index.ts
717
774
  async function evaluateJsonMacroConfig(content, filename, lang, options) {
718
775
  const ast = parseScriptSetupAst(options?.preambleContent ? `${options.preambleContent}\n${content}` : content, filename);
@@ -738,12 +795,20 @@ async function evaluateJsonMacroConfig(content, filename, lang, options) {
738
795
  * 从 `<script setup>` 中提取 JSON 宏配置并返回剥离后的代码。
739
796
  */
740
797
  async function extractJsonMacroFromScriptSetup(content, filename, lang, options) {
798
+ if (!mayContainJsonMacro(content)) return { stripped: content };
741
799
  const ast = parseScriptSetupAst(content, filename);
742
- const { macroNames } = collectMacroCallPaths(ast, filename);
800
+ const { macroNames, macroStatements } = collectMacroCallPaths(ast, filename);
743
801
  assertSingleMacro(macroNames, filename);
744
802
  const { stripped, macroStatementSources } = stripScriptSetupMacroStatements(content, ast, filename);
745
803
  if (macroNames.size === 0) return { stripped };
746
804
  const macroHash = createHash("sha256").update(macroStatementSources.join("\n")).digest("hex").slice(0, 12);
805
+ const staticConfig = resolveStaticJsonMacroConfig(macroStatements, options);
806
+ if (staticConfig) return {
807
+ stripped,
808
+ config: staticConfig,
809
+ macroHash,
810
+ dependencies: []
811
+ };
747
812
  const result = await evaluateJsonMacroConfig(content, filename, lang, options);
748
813
  return result ? {
749
814
  stripped,
@@ -1217,6 +1282,13 @@ function createModuleAnalysisWithOxc(id, code) {
1217
1282
  }
1218
1283
  //#endregion
1219
1284
  //#region src/plugins/wevu/pageFeatures/moduleAnalysis/index.ts
1285
+ const TS_WITHOUT_JSX_RE = /\.[cm]?ts(?:[?#].*)?$/i;
1286
+ function parseModuleAnalysisAst(id, code) {
1287
+ return parse$3(code, {
1288
+ sourceType: "module",
1289
+ plugins: TS_WITHOUT_JSX_RE.test(id) ? BABEL_TS_MODULE_PLUGINS.filter((plugin) => plugin !== "jsx") : BABEL_TS_MODULE_PLUGINS
1290
+ });
1291
+ }
1220
1292
  function createModuleAnalysisFromCode(id, code, options) {
1221
1293
  const engine = options?.astEngine ?? "babel";
1222
1294
  const cacheKey = createModuleAnalysisCacheKey(id, engine);
@@ -1225,7 +1297,7 @@ function createModuleAnalysisFromCode(id, code, options) {
1225
1297
  let analysis;
1226
1298
  if (engine === "oxc") if (!code.includes("import") && !code.includes("export")) analysis = createEmptyModuleAnalysis(id, "oxc");
1227
1299
  else analysis = createModuleAnalysisWithOxc(id, code);
1228
- else analysis = createModuleAnalysis(id, parseJsLike(code));
1300
+ else analysis = createModuleAnalysis(id, parseModuleAnalysisAst(id, code));
1229
1301
  moduleAnalysisCache.set(cacheKey, {
1230
1302
  code,
1231
1303
  analysis
@@ -1819,17 +1891,18 @@ function injectWevuPageFeaturesInJs(source, options) {
1819
1891
  code: source,
1820
1892
  transformed: false
1821
1893
  };
1894
+ const sourceMap = options?.sourceMap !== false;
1822
1895
  const generated = generate(ast, {
1823
1896
  compact: options?.minify === true,
1824
1897
  minified: options?.minify === true,
1825
1898
  retainLines: options?.minify !== true,
1826
- sourceMaps: true,
1899
+ sourceMaps: sourceMap,
1827
1900
  sourceFileName: "inline.js"
1828
1901
  }, source);
1829
1902
  return {
1830
1903
  code: generated.code,
1831
1904
  transformed: true,
1832
- map: generated.map
1905
+ map: sourceMap ? generated.map : null
1833
1906
  };
1834
1907
  }
1835
1908
  /**
@@ -1867,17 +1940,18 @@ async function injectWevuPageFeaturesInJsWithResolver(source, options) {
1867
1940
  code: source,
1868
1941
  transformed: false
1869
1942
  };
1943
+ const sourceMap = options?.sourceMap !== false;
1870
1944
  const generated = generate(ast, {
1871
1945
  compact: options?.minify === true,
1872
1946
  minified: options?.minify === true,
1873
1947
  retainLines: options?.minify !== true,
1874
- sourceMaps: true,
1948
+ sourceMaps: sourceMap,
1875
1949
  sourceFileName: "inline.js"
1876
1950
  }, source);
1877
1951
  return {
1878
1952
  code: generated.code,
1879
1953
  transformed: true,
1880
- map: generated.map
1954
+ map: sourceMap ? generated.map : null
1881
1955
  };
1882
1956
  }
1883
1957
  //#endregion
@@ -1894,7 +1968,8 @@ function createPageEntryMatcher(source) {
1894
1968
  try {
1895
1969
  entries = await source.loadEntries();
1896
1970
  } catch (error) {
1897
- warn(`[wevu] 解析页面入口失败:${error instanceof Error ? error.message : String(error)}`);
1971
+ const message = error instanceof Error ? error.message : String(error);
1972
+ warn(`[wevu] 解析页面入口失败:${message}`);
1898
1973
  return /* @__PURE__ */ new Set();
1899
1974
  }
1900
1975
  const set = /* @__PURE__ */ new Set();
@@ -2145,6 +2220,109 @@ function createCollectVisitors(state) {
2145
2220
  };
2146
2221
  }
2147
2222
  //#endregion
2223
+ //#region src/plugins/vue/transform/constants.ts
2224
+ const RUNTIME_IMPORT_PATH = WE_VU_INTERNAL_RUNTIME_MODULE_ID;
2225
+ //#endregion
2226
+ //#region src/plugins/vue/transform/transformScript/fastSetup.ts
2227
+ const COMPILED_DEFINE_COMPONENT_IMPORT_RE = /^import\s+\{\s*defineComponent\s+as\s+([A-Za-z_$][\w$]*)\s*\}\s+from\s+['"]vue['"];?\n/;
2228
+ const EXPORT_DEFAULT_PURE_RE = /export\s+default\s+\/\*@__PURE__\*\/\s*/;
2229
+ const JSON_MACRO_RE = /\bdefine(?:App|Page|Component|Sitemap|Theme)Json\s*\(/;
2230
+ const PAGE_META_RE = /\bdefinePageMeta\s*\(/;
2231
+ function hasMetadataInjectionOptions(options) {
2232
+ const hasWevuDefaults = options?.wevuDefaults && Object.keys(options.wevuDefaults).length > 0;
2233
+ return Boolean(options?.isApp || options?.skipComponentTransform || options?.minify || options?.sourceMap !== false || options?.templateComponentMeta || hasWevuDefaults || options?.classStyleBindings?.length || options?.templateRefs?.length || options?.layoutHosts?.length || options?.inlineExpressions?.length || options?.functionPropPaths?.length || options?.propsAliases || options?.propsDerivedKeys?.length || options?.relaxStructuredTypeOnlyProps || options?.scopedSlotHostProperties);
2234
+ }
2235
+ function findMatchingCallEnd(source, openParenIndex) {
2236
+ let depth = 0;
2237
+ let quote;
2238
+ let escaped = false;
2239
+ let lineComment = false;
2240
+ let blockComment = false;
2241
+ for (let index = openParenIndex; index < source.length; index += 1) {
2242
+ const current = source[index];
2243
+ const next = source[index + 1];
2244
+ if (lineComment) {
2245
+ if (current === "\n" || current === "\r") lineComment = false;
2246
+ continue;
2247
+ }
2248
+ if (blockComment) {
2249
+ if (current === "*" && next === "/") {
2250
+ blockComment = false;
2251
+ index += 1;
2252
+ }
2253
+ continue;
2254
+ }
2255
+ if (quote) {
2256
+ if (escaped) escaped = false;
2257
+ else if (current === "\\") escaped = true;
2258
+ else if (current === quote) quote = void 0;
2259
+ continue;
2260
+ }
2261
+ if (current === "/" && next === "/") {
2262
+ lineComment = true;
2263
+ index += 1;
2264
+ continue;
2265
+ }
2266
+ if (current === "/" && next === "*") {
2267
+ blockComment = true;
2268
+ index += 1;
2269
+ continue;
2270
+ }
2271
+ if (current === "\"" || current === "'" || current === "`") {
2272
+ quote = current;
2273
+ continue;
2274
+ }
2275
+ if (current === "(") {
2276
+ depth += 1;
2277
+ continue;
2278
+ }
2279
+ if (current === ")") {
2280
+ depth -= 1;
2281
+ if (depth === 0) return index;
2282
+ }
2283
+ }
2284
+ return -1;
2285
+ }
2286
+ function stripCompiledScriptSetupMarkers(optionsSource) {
2287
+ return optionsSource.replace(/^\s*__name:\s*['"][^'"]+['"],?\n?/m, "").replace(/\{\s*expose:\s*__expose\s*\}/g, "{ expose }").replace(/\b__expose\s*\(\s*\);?/g, "expose();").replace(/^\s*Object\.defineProperty\(\s*__returned__\s*,\s*['"]__isScriptSetup['"]\s*,\s*\{\s*enumerable:\s*false\s*,\s*value:\s*true\s*\}\s*\);?\n?/m, "");
2288
+ }
2289
+ /**
2290
+ * 转换 Vue compileScript 产出的标准 `<script setup>` 脚本。
2291
+ */
2292
+ function tryFastTransformCompiledScriptSetup(source, options) {
2293
+ if (hasMetadataInjectionOptions(options)) return;
2294
+ if (JSON_MACRO_RE.test(source) || PAGE_META_RE.test(source)) return;
2295
+ const importMatch = source.match(COMPILED_DEFINE_COMPONENT_IMPORT_RE);
2296
+ if (!importMatch) return;
2297
+ const defineComponentLocal = importMatch[1];
2298
+ const afterImport = source.slice(importMatch[0].length);
2299
+ if (/from\s+['"]vue['"]/.test(afterImport)) return;
2300
+ const exportMatch = EXPORT_DEFAULT_PURE_RE.exec(afterImport);
2301
+ if (!exportMatch || exportMatch.index < 0) return;
2302
+ const beforeExport = afterImport.slice(0, exportMatch.index);
2303
+ const callStart = exportMatch.index + exportMatch[0].length;
2304
+ const expectedCall = `${defineComponentLocal}(`;
2305
+ if (!afterImport.startsWith(expectedCall, callStart)) return;
2306
+ const openParenIndex = callStart + defineComponentLocal.length;
2307
+ const callEnd = findMatchingCallEnd(afterImport, openParenIndex);
2308
+ if (callEnd < 0) return;
2309
+ const trailing = afterImport.slice(callEnd + 1).trim();
2310
+ if (trailing && trailing !== ";") return;
2311
+ const componentOptions = stripCompiledScriptSetupMarkers(afterImport.slice(openParenIndex + 1, callEnd).trim());
2312
+ const pageMarker = options?.isPage ? " __wevu_isPage: true,\n" : "";
2313
+ return {
2314
+ code: [
2315
+ `import { ${WE_VU_RUNTIME_APIS.createWevuComponent} } from "${RUNTIME_IMPORT_PATH}";`,
2316
+ beforeExport.trim(),
2317
+ `const __wevuOptions = {\n${pageMarker}${componentOptions.replace(/^\{\s*/, "").replace(/\s*\}$/, "")}\n};`,
2318
+ "export default __wevuOptions;",
2319
+ `${WE_VU_RUNTIME_APIS.createWevuComponent}(__wevuOptions);`
2320
+ ].filter(Boolean).join("\n"),
2321
+ map: null,
2322
+ transformed: true
2323
+ };
2324
+ }
2325
+ //#endregion
2148
2326
  //#region src/plugins/vue/transform/scriptRuntimeImport.ts
2149
2327
  function ensureRuntimeImport(program, importedName, localName = importedName) {
2150
2328
  const runtimeImportPath = resolveWevuInternalImportModuleId(importedName);
@@ -3028,9 +3206,11 @@ function rewriteComponentExport(params) {
3028
3206
  return true;
3029
3207
  }
3030
3208
  ensureRuntimeImport(ast.program, WE_VU_RUNTIME_APIS.createWevuComponent);
3031
- exportPath.replaceWith(t.variableDeclaration("const", [t.variableDeclarator(t.identifier(DEFAULT_OPTIONS_IDENTIFIER), componentExpr)]));
3032
- exportPath.insertAfter(t.expressionStatement(t.callExpression(t.identifier(WE_VU_RUNTIME_APIS.createWevuComponent), [t.identifier(DEFAULT_OPTIONS_IDENTIFIER)])));
3033
- exportPath.insertAfter(t.exportDefaultDeclaration(t.identifier(DEFAULT_OPTIONS_IDENTIFIER)));
3209
+ exportPath.replaceWithMultiple([
3210
+ t.variableDeclaration("const", [t.variableDeclarator(t.identifier(DEFAULT_OPTIONS_IDENTIFIER), componentExpr)]),
3211
+ t.expressionStatement(t.callExpression(t.identifier(WE_VU_RUNTIME_APIS.createWevuComponent), [t.identifier(DEFAULT_OPTIONS_IDENTIFIER)])),
3212
+ t.exportDefaultDeclaration(t.identifier(DEFAULT_OPTIONS_IDENTIFIER))
3213
+ ]);
3034
3214
  return true;
3035
3215
  }
3036
3216
  //#endregion
@@ -3533,10 +3713,15 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
3533
3713
  }
3534
3714
  //#endregion
3535
3715
  //#region src/plugins/vue/transform/transformScript/index.ts
3716
+ function runVisitor(visitor, path) {
3717
+ if (typeof visitor === "function") visitor(path);
3718
+ }
3536
3719
  /**
3537
3720
  * 转换 Vue SFC 脚本:处理宏、导入、默认导出与 wevu 相关注入。
3538
3721
  */
3539
3722
  function transformScript(source, options) {
3723
+ const fastResult = tryFastTransformCompiledScriptSetup(source, options);
3724
+ if (fastResult) return fastResult;
3540
3725
  const ast = parse$3(source, BABEL_TS_MODULE_PARSER_OPTIONS);
3541
3726
  const warn = resolveWarnHandler(options?.warn);
3542
3727
  const state = {
@@ -3548,11 +3733,23 @@ function transformScript(source, options) {
3548
3733
  const enabledPageFeatures = options?.isPage ? collectWevuPageFeatureFlags(ast) : /* @__PURE__ */ new Set();
3549
3734
  const serializedWevuDefaults = options?.wevuDefaults && Object.keys(options.wevuDefaults).length > 0 ? serializeWevuDefaults(options.wevuDefaults, warn) : void 0;
3550
3735
  const parsedWevuDefaults = serializedWevuDefaults ? JSON.parse(serializedWevuDefaults) : void 0;
3551
- traverse(ast, vueSfcTransformPlugin().visitor);
3736
+ const vueSfcVisitors = vueSfcTransformPlugin().visitor;
3737
+ const macroVisitors = createMacroVisitors(ast.program, state);
3738
+ const importVisitors = createImportVisitors(ast.program, state);
3739
+ const collectVisitors = createCollectVisitors(state);
3552
3740
  traverse(ast, {
3553
- ...createMacroVisitors(ast.program, state),
3554
- ...createImportVisitors(ast.program, state),
3555
- ...createCollectVisitors(state)
3741
+ ...vueSfcVisitors,
3742
+ ...macroVisitors,
3743
+ ...importVisitors,
3744
+ ...collectVisitors,
3745
+ ImportDeclaration(path) {
3746
+ runVisitor(vueSfcVisitors.ImportDeclaration, path);
3747
+ if (!path.removed) runVisitor(importVisitors.ImportDeclaration, path);
3748
+ },
3749
+ CallExpression(path) {
3750
+ runVisitor(vueSfcVisitors.CallExpression, path);
3751
+ if (!path.removed) runVisitor(macroVisitors.CallExpression, path);
3752
+ }
3556
3753
  });
3557
3754
  if (options?.templateComponentMeta) state.transformed = pruneTemplateComponentMeta(ast, options.templateComponentMeta) || state.transformed;
3558
3755
  state.transformed = rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializedWevuDefaults, parsedWevuDefaults) || state.transformed;
@@ -3560,16 +3757,17 @@ function transformScript(source, options) {
3560
3757
  code: source,
3561
3758
  transformed: false
3562
3759
  };
3760
+ const sourceMap = options?.sourceMap !== false;
3563
3761
  const generated = generate(ast, {
3564
3762
  compact: options?.minify === true,
3565
3763
  minified: options?.minify === true,
3566
3764
  retainLines: options?.minify !== true,
3567
- sourceMaps: true,
3765
+ sourceMaps: sourceMap,
3568
3766
  sourceFileName: "inline.ts"
3569
3767
  }, source);
3570
3768
  return {
3571
3769
  code: generated.code,
3572
- map: generated.map,
3770
+ map: sourceMap ? generated.map : null,
3573
3771
  transformed: state.transformed
3574
3772
  };
3575
3773
  }
@@ -4341,7 +4539,8 @@ const wechatPlatform = defaultMiniProgramPlatform;
4341
4539
  * 获取指定平台的模板适配器,默认回退到默认模板平台。
4342
4540
  */
4343
4541
  function getMiniProgramTemplatePlatform(platform) {
4344
- return TEMPLATE_PRESET_PLATFORMS[getMiniProgramTemplatePreset(platform)] ?? getDefaultMiniProgramTemplatePlatform();
4542
+ const preset = getMiniProgramTemplatePreset(platform);
4543
+ return TEMPLATE_PRESET_PLATFORMS[preset] ?? getDefaultMiniProgramTemplatePlatform();
4345
4544
  }
4346
4545
  //#endregion
4347
4546
  //#region src/plugins/jsx/compileJsx/analysis.ts
@@ -4659,7 +4858,7 @@ async function compileJsxFile(source, filename, options) {
4659
4858
  let scriptMacroConfig;
4660
4859
  let scriptMacroHash;
4661
4860
  const scriptLang = path.extname(filename).replace(LEADING_DOT_RE, "") || void 0;
4662
- try {
4861
+ if (mayContainJsonMacro(source)) try {
4663
4862
  const extracted = await extractJsonMacroFromScriptSetup(source, filename, scriptLang, { merge: (target, incoming) => mergeJson(target, incoming, "macro") });
4664
4863
  scriptSource = extracted.stripped;
4665
4864
  scriptMacroConfig = extracted.config;
@@ -4699,6 +4898,7 @@ async function compileJsxFile(source, filename, options) {
4699
4898
  isApp: options?.isApp,
4700
4899
  isPage: options?.isPage,
4701
4900
  minify: options?.minify,
4901
+ sourceMap: options?.sourceMap,
4702
4902
  warn: options?.warn,
4703
4903
  wevuDefaults: options?.wevuDefaults,
4704
4904
  inlineExpressions
@@ -4722,6 +4922,7 @@ async function compileJsxFile(source, filename, options) {
4722
4922
  if (scriptMacroConfig && Object.keys(scriptMacroConfig).length > 0) configObj = mergeJson(configObj ?? {}, scriptMacroConfig, "macro");
4723
4923
  return {
4724
4924
  script: transformedScript.code,
4925
+ scriptMap: transformedScript.map ?? null,
4725
4926
  template: compiledTemplateStr,
4726
4927
  config: configObj && Object.keys(configObj).length > 0 ? JSON.stringify(configObj, null, 2) : void 0,
4727
4928
  meta: {
@@ -5032,7 +5233,7 @@ function restoreScriptSrc(descriptor) {
5032
5233
  async function readAndParseSfc(filename, options) {
5033
5234
  const checkMtime = options?.checkMtime ?? true;
5034
5235
  const source = normalizeLineEndings(options?.source ?? await readFile(filename, { checkMtime }));
5035
- const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(source));
5236
+ const normalizedSource = options?.preprocessedSource ?? preprocessScriptSrc(preprocessScriptSetupSrc(source));
5036
5237
  const signature = checkMtime ? (() => {
5037
5238
  const cached = mtimeCache.get(filename);
5038
5239
  if (!cached) return;
@@ -5055,7 +5256,7 @@ async function readAndParseSfc(filename, options) {
5055
5256
  }
5056
5257
  const parsed = parse(normalizedSource, {
5057
5258
  filename,
5058
- ignoreEmpty: normalizedSource === source
5259
+ ignoreEmpty: options?.ignoreEmpty ?? normalizedSource === source
5059
5260
  });
5060
5261
  restoreScriptSetupSrc(parsed.descriptor);
5061
5262
  restoreScriptSrc(parsed.descriptor);
@@ -8432,6 +8633,26 @@ function compileVueTemplateToWxml(template, filename, options) {
8432
8633
  }
8433
8634
  }
8434
8635
  //#endregion
8636
+ //#region src/ast/native.ts
8637
+ const require = createRequire(import.meta.url);
8638
+ let binding;
8639
+ function resolveNativeAstModulePath() {
8640
+ return process.env.WEAPP_VITE_NATIVE_AST_PATH?.trim() || void 0;
8641
+ }
8642
+ function shouldUseNativeAst() {
8643
+ return process.env.WEAPP_VITE_NATIVE === "1" && Boolean(resolveNativeAstModulePath());
8644
+ }
8645
+ function loadNativeAstBindingSync() {
8646
+ if (!shouldUseNativeAst()) return;
8647
+ if (binding !== void 0) return binding || void 0;
8648
+ try {
8649
+ binding = require(resolveNativeAstModulePath());
8650
+ } catch {
8651
+ binding = false;
8652
+ }
8653
+ return binding || void 0;
8654
+ }
8655
+ //#endregion
8435
8656
  //#region src/plugins/vue/transform/compileVueFile/componentSources.ts
8436
8657
  function normalizeResolvedUsingComponent(result) {
8437
8658
  if (!result) return;
@@ -8455,73 +8676,71 @@ function extractStringPropertyFromObject(node, keyName) {
8455
8676
  return property.value.value;
8456
8677
  }
8457
8678
  }
8458
- function extractStaticDefineOptionsName(scriptSetupContent) {
8679
+ function extractStaticComponentMeta(scriptSetupContent) {
8459
8680
  let ast;
8460
8681
  try {
8461
8682
  ast = parse$3(scriptSetupContent, BABEL_TS_MODULE_PARSER_OPTIONS);
8462
8683
  } catch {
8463
- return;
8684
+ return { isMiniProgramComponent: false };
8464
8685
  }
8465
8686
  let componentName;
8687
+ let isMiniProgramComponent = false;
8466
8688
  traverse(ast, { CallExpression(path) {
8467
- if (componentName) return;
8468
8689
  const callee = path.node.callee;
8469
- if (!t.isIdentifier(callee, { name: "defineOptions" })) return;
8470
8690
  const arg = path.node.arguments[0];
8471
8691
  if (!t.isObjectExpression(arg)) return;
8472
- componentName = extractStringPropertyFromObject(arg, "name");
8473
- } });
8474
- return componentName;
8475
- }
8476
- function extractStaticDefineComponentJsonIsComponent(scriptSetupContent) {
8477
- let ast;
8478
- try {
8479
- ast = parse$3(scriptSetupContent, BABEL_TS_MODULE_PARSER_OPTIONS);
8480
- } catch {
8481
- return false;
8482
- }
8483
- let isComponent = false;
8484
- traverse(ast, { CallExpression(path) {
8485
- if (isComponent) return;
8486
- const callee = path.node.callee;
8692
+ if (t.isIdentifier(callee, { name: "defineOptions" })) {
8693
+ componentName ??= extractStringPropertyFromObject(arg, "name");
8694
+ return;
8695
+ }
8487
8696
  if (!t.isIdentifier(callee, { name: "defineComponentJson" })) return;
8488
- const arg = path.node.arguments[0];
8489
- if (!t.isObjectExpression(arg)) return;
8490
8697
  for (const property of arg.properties) {
8491
8698
  if (!t.isObjectProperty(property)) continue;
8492
8699
  const key = property.key;
8493
8700
  if ((t.isIdentifier(key) ? key.name === "component" : t.isStringLiteral(key) ? key.value === "component" : false) && t.isBooleanLiteral(property.value) && property.value.value) {
8494
- isComponent = true;
8495
- path.stop();
8701
+ isMiniProgramComponent = true;
8496
8702
  return;
8497
8703
  }
8498
8704
  }
8499
8705
  } });
8500
- return isComponent;
8706
+ return {
8707
+ componentName,
8708
+ isMiniProgramComponent
8709
+ };
8501
8710
  }
8502
- async function resolveVueSfcComponentName(resolvedId, warn) {
8503
- if (!resolvedId?.endsWith(".vue")) return;
8711
+ function readNativeVueSfcScriptSetupContent(source) {
8712
+ if (!shouldUseNativeAst()) return;
8713
+ const payload = loadNativeAstBindingSync()?.getVueSfcSignaturePayloadNative?.(source);
8714
+ if (!payload) return;
8504
8715
  try {
8505
- const { descriptor, errors } = parse(await readFile$1(resolvedId, "utf8"), { filename: resolvedId });
8506
- if (errors.length > 0 || !descriptor.scriptSetup?.content) return;
8507
- return extractStaticDefineOptionsName(descriptor.scriptSetup.content);
8508
- } catch (error) {
8509
- const message = error instanceof Error ? error.message : String(error);
8510
- warn?.(`[Vue 编译] 解析 ${resolvedId} 的 defineOptions.name 失败:${message}`);
8716
+ return JSON.parse(payload).script?.scriptSetup?.content;
8717
+ } catch {
8511
8718
  return;
8512
8719
  }
8513
8720
  }
8514
- async function resolveVueSfcIsMiniProgramComponent(resolvedId, warn) {
8515
- if (!resolvedId?.endsWith(".vue")) return false;
8516
- try {
8517
- const { descriptor, errors } = parse(await readFile$1(resolvedId, "utf8"), { filename: resolvedId });
8518
- if (errors.length > 0 || !descriptor.scriptSetup?.content) return false;
8519
- return extractStaticDefineComponentJsonIsComponent(descriptor.scriptSetup.content);
8520
- } catch (error) {
8521
- const message = error instanceof Error ? error.message : String(error);
8522
- warn?.(`[Vue 编译] 解析 ${resolvedId} 的 defineComponentJson.component 失败:${message}`);
8523
- return false;
8524
- }
8721
+ function readVueSfcScriptSetupContent(source, resolvedId) {
8722
+ const nativeContent = readNativeVueSfcScriptSetupContent(source);
8723
+ if (typeof nativeContent === "string") return nativeContent;
8724
+ const { descriptor, errors } = parse(source, { filename: resolvedId });
8725
+ if (errors.length > 0 || !descriptor.scriptSetup?.content) return;
8726
+ return descriptor.scriptSetup.content;
8727
+ }
8728
+ async function resolveVueSfcStaticComponentMeta(resolvedId, options) {
8729
+ if (!resolvedId?.endsWith(".vue")) return { isMiniProgramComponent: false };
8730
+ const cached = options?.cache?.get(resolvedId);
8731
+ if (cached) return await cached;
8732
+ const task = (async () => {
8733
+ try {
8734
+ const scriptSetupContent = readVueSfcScriptSetupContent(await readFile$1(resolvedId, "utf8"), resolvedId);
8735
+ return scriptSetupContent ? extractStaticComponentMeta(scriptSetupContent) : { isMiniProgramComponent: false };
8736
+ } catch (error) {
8737
+ const message = error instanceof Error ? error.message : String(error);
8738
+ options?.warn?.(`[Vue 编译] 解析 ${resolvedId} 的静态组件元信息失败:${message}`);
8739
+ return { isMiniProgramComponent: false };
8740
+ }
8741
+ })();
8742
+ options?.cache?.set(resolvedId, task);
8743
+ return await task;
8525
8744
  }
8526
8745
  function registerComponentName(result, tag, componentName) {
8527
8746
  if (!componentName) return;
@@ -8533,25 +8752,46 @@ function registerMiniProgramComponentTag(result, tag, isComponent) {
8533
8752
  result.miniProgramComponentTags.add(tag);
8534
8753
  result.miniProgramComponentTags.add(pascalToKebab(tag));
8535
8754
  }
8536
- function collectTemplateComponentNames(template, filename, warn) {
8755
+ function createComponentSourceInfo() {
8756
+ return {
8757
+ autoUsingComponentsMap: {},
8758
+ autoImportTagsMap: {},
8759
+ autoComponentMeta: {},
8760
+ wevuComponentTags: /* @__PURE__ */ new Set(),
8761
+ miniProgramComponentTags: /* @__PURE__ */ new Set(),
8762
+ componentNameMap: {}
8763
+ };
8764
+ }
8765
+ function mergeComponentSourceInfo(target, source) {
8766
+ Object.assign(target.autoUsingComponentsMap, source.autoUsingComponentsMap);
8767
+ Object.assign(target.autoImportTagsMap, source.autoImportTagsMap);
8768
+ Object.assign(target.autoComponentMeta, source.autoComponentMeta);
8769
+ Object.assign(target.componentNameMap, source.componentNameMap);
8770
+ for (const tag of source.wevuComponentTags) target.wevuComponentTags.add(tag);
8771
+ for (const tag of source.miniProgramComponentTags) target.miniProgramComponentTags.add(tag);
8772
+ }
8773
+ function collectTemplateComponentTagInfo(template, filename, warn) {
8537
8774
  const warnHandler = resolveWarnHandler(warn);
8538
8775
  const tags = collectVueTemplateTags(template, {
8539
8776
  filename,
8540
- warnLabel: "自动 usingComponents",
8777
+ warnLabel: "组件标签",
8541
8778
  warn: (message) => warnHandler(message),
8542
8779
  shouldCollect: isAutoImportCandidateTag
8543
8780
  });
8544
- for (const tag of [...tags]) if (tag.includes("-")) {
8781
+ const componentNames = new Set(tags);
8782
+ for (const tag of tags) if (tag.includes("-")) {
8545
8783
  const pascalName = tag.split("-").filter(Boolean).map((segment) => `${segment.charAt(0).toUpperCase()}${segment.slice(1)}`).join("");
8546
- if (pascalName) tags.add(pascalName);
8784
+ if (pascalName) componentNames.add(pascalName);
8547
8785
  }
8548
- return tags;
8786
+ return {
8787
+ autoImportTags: tags,
8788
+ componentNames
8789
+ };
8549
8790
  }
8550
8791
  async function collectScriptSetupUsingComponents(options) {
8551
- const { descriptor, descriptorForCompile, filename, compileOptions, autoUsingComponents, result } = options;
8792
+ const { descriptor, descriptorForCompile, filename, compileOptions, autoUsingComponents, templateComponentNames, result } = options;
8552
8793
  if (!descriptor.scriptSetup || !descriptor.template) return;
8553
- const templateComponentNames = collectTemplateComponentNames(descriptor.template.content, filename, autoUsingComponents?.warn ?? compileOptions?.warn);
8554
- if (!templateComponentNames.size) return;
8794
+ if (!templateComponentNames?.size) return;
8555
8795
  try {
8556
8796
  const setupAst = parse$3(descriptorForCompile.scriptSetup.content, BABEL_TS_MODULE_PARSER_OPTIONS);
8557
8797
  const pending = [];
@@ -8581,7 +8821,7 @@ async function collectScriptSetupUsingComponents(options) {
8581
8821
  }
8582
8822
  }
8583
8823
  } });
8584
- for (const { localName, importSource, importedName, kind } of pending) {
8824
+ const resolvedComponents = await Promise.all(pending.map(async ({ localName, importSource, importedName, kind }) => {
8585
8825
  let resolved = autoUsingComponents?.resolveUsingComponentPath ? normalizeResolvedUsingComponent(await autoUsingComponents.resolveUsingComponentPath(importSource, filename, {
8586
8826
  localName,
8587
8827
  importedName,
@@ -8595,6 +8835,18 @@ async function collectScriptSetupUsingComponents(options) {
8595
8835
  ...resolved ?? {},
8596
8836
  resolvedId: path.resolve(path.dirname(filename), importSource)
8597
8837
  };
8838
+ const componentMeta = await resolveVueSfcStaticComponentMeta(resolved?.resolvedId, {
8839
+ cache: compileOptions?.componentMetaCache,
8840
+ warn: autoUsingComponents?.warn ?? compileOptions?.warn
8841
+ });
8842
+ return {
8843
+ localName,
8844
+ importSource,
8845
+ resolved,
8846
+ componentMeta
8847
+ };
8848
+ }));
8849
+ for (const { localName, importSource, resolved, componentMeta } of resolvedComponents) {
8598
8850
  if (resolved?.from) {
8599
8851
  result.autoUsingComponentsMap[localName] = resolved.from;
8600
8852
  result.autoComponentMeta[localName] = resolved.from;
@@ -8603,8 +8855,8 @@ async function collectScriptSetupUsingComponents(options) {
8603
8855
  result.wevuComponentTags.add(localName);
8604
8856
  result.wevuComponentTags.add(pascalToKebab(localName));
8605
8857
  }
8606
- registerComponentName(result, localName, await resolveVueSfcComponentName(resolved?.resolvedId, autoUsingComponents?.warn ?? compileOptions?.warn));
8607
- registerMiniProgramComponentTag(result, localName, await resolveVueSfcIsMiniProgramComponent(resolved?.resolvedId, autoUsingComponents?.warn ?? compileOptions?.warn));
8858
+ registerComponentName(result, localName, componentMeta.componentName);
8859
+ registerMiniProgramComponentTag(result, localName, componentMeta.isMiniProgramComponent);
8608
8860
  }
8609
8861
  } catch (error) {
8610
8862
  const message = error instanceof Error ? error.message : String(error);
@@ -8612,60 +8864,65 @@ async function collectScriptSetupUsingComponents(options) {
8612
8864
  }
8613
8865
  }
8614
8866
  async function collectAutoImportWevuComponents(options) {
8615
- const { descriptor, filename, autoImportTags, warn, result } = options;
8867
+ const { descriptor, filename, compileOptions, autoImportTags, templateAutoImportTags, warn, result } = options;
8616
8868
  if (!autoImportTags || !descriptor.template) return;
8617
- const warnHandler = resolveWarnHandler(autoImportTags.warn ?? warn);
8618
- const tags = collectVueTemplateTags(descriptor.template.content, {
8619
- filename,
8620
- warnLabel: "自动导入标签",
8621
- warn: (message) => warnHandler(message),
8622
- shouldCollect: isAutoImportCandidateTag
8623
- });
8624
- for (const tag of tags) {
8869
+ const resolvedTags = await Promise.all([...templateAutoImportTags ?? []].map(async (tag) => {
8625
8870
  let resolved;
8626
8871
  try {
8627
8872
  resolved = await autoImportTags.resolveUsingComponent(tag, filename);
8628
8873
  } catch {
8629
8874
  resolved = void 0;
8630
8875
  }
8876
+ const componentMeta = await resolveVueSfcStaticComponentMeta(resolved?.resolvedId, {
8877
+ cache: compileOptions?.componentMetaCache,
8878
+ warn: autoImportTags.warn ?? warn
8879
+ });
8880
+ return {
8881
+ tag,
8882
+ resolved,
8883
+ componentMeta
8884
+ };
8885
+ }));
8886
+ for (const { tag, resolved, componentMeta } of resolvedTags) {
8631
8887
  if (!resolved?.from) continue;
8888
+ result.autoImportTagsMap[resolved.name || tag] = resolved.from;
8632
8889
  if (isWevuSfcComponent(resolved)) {
8633
8890
  result.wevuComponentTags.add(tag);
8634
8891
  if (resolved.name) result.wevuComponentTags.add(resolved.name);
8635
8892
  }
8636
- const componentName = await resolveVueSfcComponentName(resolved.resolvedId, autoImportTags.warn ?? warn);
8637
- registerComponentName(result, tag, componentName);
8638
- const isMiniProgramComponent = await resolveVueSfcIsMiniProgramComponent(resolved.resolvedId, autoImportTags.warn ?? warn);
8893
+ registerComponentName(result, tag, componentMeta.componentName);
8894
+ const isMiniProgramComponent = componentMeta.isMiniProgramComponent;
8639
8895
  registerMiniProgramComponentTag(result, tag, isMiniProgramComponent);
8640
8896
  if (resolved.name) {
8641
- registerComponentName(result, resolved.name, componentName);
8897
+ registerComponentName(result, resolved.name, componentMeta.componentName);
8642
8898
  registerMiniProgramComponentTag(result, resolved.name, isMiniProgramComponent);
8643
8899
  }
8644
8900
  }
8645
8901
  }
8646
8902
  async function collectComponentSourceInfo(options) {
8647
- const result = {
8648
- autoUsingComponentsMap: {},
8649
- autoComponentMeta: {},
8650
- wevuComponentTags: /* @__PURE__ */ new Set(),
8651
- miniProgramComponentTags: /* @__PURE__ */ new Set(),
8652
- componentNameMap: {}
8653
- };
8654
- await collectScriptSetupUsingComponents({
8903
+ const result = createComponentSourceInfo();
8904
+ const templateComponentTagInfo = options.descriptor.template ? collectTemplateComponentTagInfo(options.descriptor.template.content, options.filename, options.autoUsingComponents?.warn ?? options.autoImportTags?.warn ?? options.compileOptions?.warn) : void 0;
8905
+ const scriptSetupResult = createComponentSourceInfo();
8906
+ const autoImportResult = createComponentSourceInfo();
8907
+ await Promise.all([collectScriptSetupUsingComponents({
8655
8908
  descriptor: options.descriptor,
8656
8909
  descriptorForCompile: options.descriptorForCompile,
8657
8910
  filename: options.filename,
8658
8911
  compileOptions: options.compileOptions,
8659
8912
  autoUsingComponents: options.autoUsingComponents,
8660
- result
8661
- });
8662
- await collectAutoImportWevuComponents({
8913
+ templateComponentNames: templateComponentTagInfo?.componentNames,
8914
+ result: scriptSetupResult
8915
+ }), collectAutoImportWevuComponents({
8663
8916
  descriptor: options.descriptor,
8664
8917
  filename: options.filename,
8918
+ compileOptions: options.compileOptions,
8665
8919
  autoImportTags: options.autoImportTags,
8920
+ templateAutoImportTags: templateComponentTagInfo?.autoImportTags,
8666
8921
  warn: options.compileOptions?.warn,
8667
- result
8668
- });
8922
+ result: autoImportResult
8923
+ })]);
8924
+ mergeComponentSourceInfo(result, scriptSetupResult);
8925
+ mergeComponentSourceInfo(result, autoImportResult);
8669
8926
  return result;
8670
8927
  }
8671
8928
  //#endregion
@@ -8768,7 +9025,7 @@ function collectTemplateAutoImportTags(template, filename, warn) {
8768
9025
  });
8769
9026
  }
8770
9027
  async function compileConfigPhase(params) {
8771
- const { descriptor, filename, autoUsingComponentsMap, autoUsingComponents, autoImportTags, jsonDefaults, mergeJson, scriptSetupMacroConfig, result, warn } = params;
9028
+ const { descriptor, filename, autoUsingComponentsMap, autoImportTagsMap: precomputedAutoImportTagsMap, autoUsingComponents, autoImportTags, jsonDefaults, mergeJson, scriptSetupMacroConfig, result, warn } = params;
8772
9029
  let configObj;
8773
9030
  if (descriptor.customBlocks.some((b) => b.type === "json")) {
8774
9031
  const configResult = await compileConfigBlocks(descriptor.customBlocks, filename, { merge: (target, source) => mergeJson(target, source, "json-block") });
@@ -8778,8 +9035,8 @@ async function compileConfigPhase(params) {
8778
9035
  configObj = {};
8779
9036
  }
8780
9037
  }
8781
- const autoImportTagsMap = {};
8782
- if (autoImportTags && descriptor.template) {
9038
+ const autoImportTagsMap = precomputedAutoImportTagsMap ? { ...precomputedAutoImportTagsMap } : {};
9039
+ if (!precomputedAutoImportTagsMap && autoImportTags && descriptor.template) {
8783
9040
  const tags = collectTemplateAutoImportTags(descriptor.template.content, filename, autoImportTags.warn ?? warn);
8784
9041
  for (const tag of tags) {
8785
9042
  let resolved;
@@ -8816,9 +9073,6 @@ async function compileConfigPhase(params) {
8816
9073
  if (configObj && Object.keys(configObj).length > 0) result.config = JSON.stringify(configObj, null, 2);
8817
9074
  }
8818
9075
  //#endregion
8819
- //#region src/plugins/vue/transform/constants.ts
8820
- const RUNTIME_IMPORT_PATH = WE_VU_INTERNAL_RUNTIME_MODULE_ID;
8821
- //#endregion
8822
9076
  //#region src/plugins/vue/transform/compileVueFile/finalize.ts
8823
9077
  function finalizeResult(result, options) {
8824
9078
  if (!result.script || result.script.trim() === "") result.script = `import { ${WE_VU_RUNTIME_APIS.createWevuComponent} } from '${RUNTIME_IMPORT_PATH}';\n${WE_VU_RUNTIME_APIS.createWevuComponent}({});\n`;
@@ -8960,6 +9214,24 @@ function serializeStaticValueToExpression(value, seen = /* @__PURE__ */ new Weak
8960
9214
  throw new Error(`defineOptions 的参数中包含不支持的值类型:${valueType}`);
8961
9215
  }
8962
9216
  //#endregion
9217
+ //#region src/plugins/vue/transform/defineOptions/static.ts
9218
+ function resolveStaticDefineOptionsValues(statements) {
9219
+ const values = [];
9220
+ for (const statement of statements) {
9221
+ const arg = statement.argPath?.node;
9222
+ if (!arg || !t.isExpression(arg)) return;
9223
+ let value;
9224
+ try {
9225
+ value = resolveStaticLiteralValue(arg);
9226
+ } catch {
9227
+ return;
9228
+ }
9229
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
9230
+ values.push(value);
9231
+ }
9232
+ return values;
9233
+ }
9234
+ //#endregion
8963
9235
  //#region src/plugins/vue/transform/defineOptions/inline.ts
8964
9236
  function collectDefineOptionsStatements(content, filename) {
8965
9237
  const ast = parse$3(content, BABEL_TS_MODULE_PARSER_OPTIONS);
@@ -9108,26 +9380,31 @@ async function inlineScriptSetupDefineOptionsArgs(content, filename, lang) {
9108
9380
  };
9109
9381
  let values = [];
9110
9382
  let dependencies = [];
9111
- let scopeValues = collectStaticTopLevelScopeValues(content);
9112
- try {
9113
- const evaluated = await evaluateDefineOptionsValues({
9114
- content,
9115
- filename,
9116
- lang,
9117
- statements
9118
- });
9119
- values = evaluated.values;
9120
- dependencies = evaluated.dependencies;
9121
- scopeValues = {
9122
- ...scopeValues,
9123
- ...evaluated.scopeValues
9124
- };
9125
- } catch (error) {
9126
- if (shouldFallbackToRawDefineOptions(error)) return {
9127
- code: content,
9128
- dependencies: []
9129
- };
9130
- throw error;
9383
+ let scopeValues = {};
9384
+ const staticValues = resolveStaticDefineOptionsValues(statements);
9385
+ if (staticValues) values = staticValues;
9386
+ else {
9387
+ scopeValues = collectStaticTopLevelScopeValues(content);
9388
+ try {
9389
+ const evaluated = await evaluateDefineOptionsValues({
9390
+ content,
9391
+ filename,
9392
+ lang,
9393
+ statements
9394
+ });
9395
+ values = evaluated.values;
9396
+ dependencies = evaluated.dependencies;
9397
+ scopeValues = {
9398
+ ...scopeValues,
9399
+ ...evaluated.scopeValues
9400
+ };
9401
+ } catch (error) {
9402
+ if (shouldFallbackToRawDefineOptions(error)) return {
9403
+ code: content,
9404
+ dependencies: []
9405
+ };
9406
+ throw error;
9407
+ }
9131
9408
  }
9132
9409
  const ms = new MagicString(content);
9133
9410
  for (let index = 0; index < statements.length; index += 1) {
@@ -9192,9 +9469,11 @@ function restoreTemplateImportMetaInDescriptor(descriptor) {
9192
9469
  }
9193
9470
  };
9194
9471
  }
9195
- function parseSfc(source, filename, ignoreEmpty) {
9196
- const parsed = parse(preprocessTemplateImportMeta(source), {
9197
- filename,
9472
+ async function parseSfc(source, filename, ignoreEmpty) {
9473
+ const parsed = await readAndParseSfc(filename, {
9474
+ source,
9475
+ preprocessedSource: preprocessTemplateImportMeta(source),
9476
+ checkMtime: false,
9198
9477
  ignoreEmpty
9199
9478
  });
9200
9479
  return {
@@ -9206,7 +9485,7 @@ async function parseVueFile(source, filename, options) {
9206
9485
  const normalizedInputSource = normalizeLineEndings(source);
9207
9486
  const normalizedSource = preprocessScriptSrc(preprocessScriptSetupSrc(normalizedInputSource));
9208
9487
  let descriptorForCompileSource = normalizedSource;
9209
- const { descriptor, errors } = parseSfc(normalizedSource, filename, normalizedSource === normalizedInputSource);
9488
+ const { descriptor, errors } = await parseSfc(normalizedSource, filename, normalizedSource === normalizedInputSource);
9210
9489
  restoreScriptSetupSrc(descriptor);
9211
9490
  restoreScriptSrc(descriptor);
9212
9491
  if (errors.length > 0) {
@@ -9238,43 +9517,45 @@ async function parseVueFile(source, filename, options) {
9238
9517
  });
9239
9518
  const scriptSetup = resolvedDescriptor.scriptSetup;
9240
9519
  if (scriptSetup?.content) {
9241
- const extracted = await extractJsonMacroFromScriptSetup(scriptSetup.content, filename, scriptSetup.lang, {
9242
- merge: (target, source) => mergeJson(target, source, "macro"),
9243
- preambleContent: resolvedDescriptor.script?.content
9244
- });
9245
- if (extracted.stripped !== scriptSetup.content) if (scriptSetup.src) descriptorForCompile = {
9246
- ...descriptorForCompile,
9247
- scriptSetup: {
9248
- ...descriptorForCompile.scriptSetup,
9249
- content: extracted.stripped
9250
- }
9251
- };
9252
- else {
9253
- const setupLoc = scriptSetup.loc;
9254
- const startOffset = setupLoc.start.offset;
9255
- const endOffset = setupLoc.end.offset;
9256
- const nextSource = descriptorForCompileSource.slice(0, startOffset) + extracted.stripped + descriptorForCompileSource.slice(endOffset);
9257
- const { descriptor: nextDescriptor, errors: nextErrors } = parseSfc(nextSource, filename, false);
9258
- restoreScriptSetupSrc(nextDescriptor);
9259
- restoreScriptSrc(nextDescriptor);
9260
- if (nextErrors.length > 0) {
9261
- const error = nextErrors[0];
9262
- throw new Error(`解析 ${filename} 失败:${error.message}`);
9263
- }
9264
- assertMatchingSfcScriptLang(nextDescriptor, filename);
9265
- if (options?.sfcSrc) {
9266
- const resolvedNext = await resolveSfcBlockSrc(nextDescriptor, filename, options.sfcSrc);
9267
- descriptorForCompile = resolvedNext.descriptor;
9268
- if (resolvedNext.deps.length) {
9269
- sfcSrcDeps = [.../* @__PURE__ */ new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
9270
- meta.sfcSrcDeps = sfcSrcDeps;
9520
+ if (mayContainJsonMacro(scriptSetup.content)) {
9521
+ const extracted = await extractJsonMacroFromScriptSetup(scriptSetup.content, filename, scriptSetup.lang, {
9522
+ merge: (target, source) => mergeJson(target, source, "macro"),
9523
+ preambleContent: resolvedDescriptor.script?.content
9524
+ });
9525
+ if (extracted.stripped !== scriptSetup.content) if (scriptSetup.src) descriptorForCompile = {
9526
+ ...descriptorForCompile,
9527
+ scriptSetup: {
9528
+ ...descriptorForCompile.scriptSetup,
9529
+ content: extracted.stripped
9271
9530
  }
9272
- } else descriptorForCompile = nextDescriptor;
9273
- descriptorForCompileSource = nextSource;
9531
+ };
9532
+ else {
9533
+ const setupLoc = scriptSetup.loc;
9534
+ const startOffset = setupLoc.start.offset;
9535
+ const endOffset = setupLoc.end.offset;
9536
+ const nextSource = descriptorForCompileSource.slice(0, startOffset) + extracted.stripped + descriptorForCompileSource.slice(endOffset);
9537
+ const { descriptor: nextDescriptor, errors: nextErrors } = await parseSfc(nextSource, filename, false);
9538
+ restoreScriptSetupSrc(nextDescriptor);
9539
+ restoreScriptSrc(nextDescriptor);
9540
+ if (nextErrors.length > 0) {
9541
+ const error = nextErrors[0];
9542
+ throw new Error(`解析 ${filename} 失败:${error.message}`);
9543
+ }
9544
+ assertMatchingSfcScriptLang(nextDescriptor, filename);
9545
+ if (options?.sfcSrc) {
9546
+ const resolvedNext = await resolveSfcBlockSrc(nextDescriptor, filename, options.sfcSrc);
9547
+ descriptorForCompile = resolvedNext.descriptor;
9548
+ if (resolvedNext.deps.length) {
9549
+ sfcSrcDeps = [.../* @__PURE__ */ new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
9550
+ meta.sfcSrcDeps = sfcSrcDeps;
9551
+ }
9552
+ } else descriptorForCompile = nextDescriptor;
9553
+ descriptorForCompileSource = nextSource;
9554
+ }
9555
+ scriptSetupMacroConfig = extracted.config;
9556
+ scriptSetupMacroHash = extracted.macroHash;
9274
9557
  }
9275
- scriptSetupMacroConfig = extracted.config;
9276
- scriptSetupMacroHash = extracted.macroHash;
9277
- defineOptionsHash = extractDefineOptionsHash(scriptSetup.content);
9558
+ if (DEFINE_OPTIONS_CALL_RE.test(scriptSetup.content)) defineOptionsHash = extractDefineOptionsHash(scriptSetup.content);
9278
9559
  }
9279
9560
  const compileScriptSetup = descriptorForCompile.scriptSetup;
9280
9561
  if (compileScriptSetup?.content && DEFINE_OPTIONS_CALL_RE.test(compileScriptSetup.content)) {
@@ -9291,7 +9572,7 @@ async function parseVueFile(source, filename, options) {
9291
9572
  const startOffset = setupLoc.start.offset;
9292
9573
  const endOffset = setupLoc.end.offset;
9293
9574
  const nextSource = descriptorForCompileSource.slice(0, startOffset) + inlined.code + descriptorForCompileSource.slice(endOffset);
9294
- const { descriptor: nextDescriptor, errors: nextErrors } = parseSfc(nextSource, filename, false);
9575
+ const { descriptor: nextDescriptor, errors: nextErrors } = await parseSfc(nextSource, filename, false);
9295
9576
  restoreScriptSetupSrc(nextDescriptor);
9296
9577
  restoreScriptSrc(nextDescriptor);
9297
9578
  if (nextErrors.length > 0) {
@@ -9446,6 +9727,7 @@ function warnReservedScriptSetupProps(scriptSetupCode, warn, context = {}) {
9446
9727
  const TYPE_ONLY_DEFINE_PROPS_RE = /\bdefineProps\s*</;
9447
9728
  const EXPORT_DEFAULT_RE = /\bexport\s+default\b/;
9448
9729
  function hasDefaultExport(scriptCode) {
9730
+ if (!EXPORT_DEFAULT_RE.test(scriptCode)) return false;
9449
9731
  try {
9450
9732
  const ast = parseJsLike(scriptCode);
9451
9733
  let found = false;
@@ -9473,6 +9755,13 @@ function resolveScriptSetupPropsDerivedKeys(bindings) {
9473
9755
  }
9474
9756
  return keys.size ? [...keys] : void 0;
9475
9757
  }
9758
+ function bindingsMayContainProps(bindings, scriptCode) {
9759
+ for (const [key, bindingType] of Object.entries(bindings ?? {})) if (key === "__propsAliases" || bindingType === "props" || bindingType === "props-aliased") return true;
9760
+ return scriptCode.includes("__props") || scriptCode.includes("props:");
9761
+ }
9762
+ function hasPrecomputedScriptPhaseInfo(info, key) {
9763
+ return Boolean(info) && Object.prototype.hasOwnProperty.call(info, key);
9764
+ }
9476
9765
  function collectScriptSetupReturnInfo(scriptCode) {
9477
9766
  const keys = /* @__PURE__ */ new Set();
9478
9767
  const propsObjectAliases = /* @__PURE__ */ new Set(["__props"]);
@@ -9529,6 +9818,7 @@ function collectScriptSetupReturnInfo(scriptCode) {
9529
9818
  };
9530
9819
  }
9531
9820
  function resolveEffectivePropsDerivedKeys(bindings, scriptCode) {
9821
+ if (!bindingsMayContainProps(bindings, scriptCode)) return;
9532
9822
  const directKeys = resolveScriptSetupPropsDerivedKeys(bindings) ?? [];
9533
9823
  const { returnedKeys, destructuredPropsKeys } = collectScriptSetupReturnInfo(scriptCode);
9534
9824
  const aliases = resolveScriptSetupPropsAliases(bindings) ?? {};
@@ -9543,7 +9833,7 @@ function resolveEffectivePropsDerivedKeys(bindings, scriptCode) {
9543
9833
  for (const key of propsKeys) if (!returnedKeys.has(key)) keys.add(key);
9544
9834
  return keys.size ? [...keys] : void 0;
9545
9835
  }
9546
- async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, _autoUsingComponents, templateCompiled, isAppFile, componentSourceInfo, precompiledScript) {
9836
+ async function compileScriptPhase(descriptor, descriptorForCompile, filename, options, _autoUsingComponents, templateCompiled, isAppFile, componentSourceInfo, precompiledScript, precomputedScriptPhaseInfo) {
9547
9837
  const autoUsingComponentsMap = { ...componentSourceInfo?.autoUsingComponentsMap ?? {} };
9548
9838
  const autoComponentMeta = { ...componentSourceInfo?.autoComponentMeta ?? {} };
9549
9839
  const relaxStructuredTypeOnlyProps = Boolean(descriptor.scriptSetup?.content && TYPE_ONLY_DEFINE_PROPS_RE.test(descriptor.scriptSetup.content));
@@ -9560,12 +9850,13 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
9560
9850
  filename,
9561
9851
  scriptSetupStart: descriptorForCompile.scriptSetup?.loc.start
9562
9852
  });
9853
+ if (!propsAliases && hasPrecomputedScriptPhaseInfo(precomputedScriptPhaseInfo, "propsAliases")) propsAliases = precomputedScriptPhaseInfo.propsAliases;
9563
9854
  propsAliases ??= resolveScriptSetupPropsAliases(scriptCompiled.bindings);
9564
9855
  scriptCode = scriptCompiled.content;
9565
- propsDerivedKeys = resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCode);
9566
- scriptMap = scriptCompiled.map && typeof scriptCompiled.map === "object" ? scriptCompiled.map : null;
9856
+ propsDerivedKeys = hasPrecomputedScriptPhaseInfo(precomputedScriptPhaseInfo, "propsDerivedKeys") ? precomputedScriptPhaseInfo.propsDerivedKeys : resolveEffectivePropsDerivedKeys(scriptCompiled.bindings, scriptCode);
9857
+ scriptMap = options?.sourceMap !== false && scriptCompiled.map && typeof scriptCompiled.map === "object" ? scriptCompiled.map : null;
9567
9858
  if (scriptCode.includes("defineAppJson") || scriptCode.includes("definePageJson") || scriptCode.includes("defineComponentJson")) scriptCode = stripJsonMacroCallsFromCode(scriptCode, filename);
9568
- if (!isAppFile && !hasDefaultExport(scriptCode)) scriptCode += "\nexport default {}";
9859
+ if (!isAppFile && !descriptor.scriptSetup && !hasDefaultExport(scriptCode)) scriptCode += "\nexport default {}";
9569
9860
  } else scriptCode = "export default {}";
9570
9861
  if (scriptCode) {
9571
9862
  const transformed = transformScript(scriptCode, {
@@ -9573,6 +9864,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
9573
9864
  isApp: isAppFile,
9574
9865
  isPage: options?.isPage === true,
9575
9866
  minify: options?.minify,
9867
+ sourceMap: options?.sourceMap,
9576
9868
  warn: options?.warn,
9577
9869
  templateComponentMeta: Object.keys(autoComponentMeta).length ? autoComponentMeta : void 0,
9578
9870
  wevuDefaults: options?.wevuDefaults,
@@ -9702,7 +9994,10 @@ async function compileVueFile(source, filename, options) {
9702
9994
  miniProgramComponentTags: componentSourceInfo.miniProgramComponentTags
9703
9995
  };
9704
9996
  const templateCompiled = compileTemplatePhase(parsed.descriptor, filename, templateOptions, result);
9705
- const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo, scriptCompiled);
9997
+ const scriptPhase = await compileScriptPhase(parsed.descriptor, parsed.descriptorForCompile, filename, options, autoUsingComponents, templateCompiled, parsed.isAppFile, componentSourceInfo, scriptCompiled, {
9998
+ propsAliases,
9999
+ propsDerivedKeys
10000
+ });
9706
10001
  result.script = scriptPhase.script;
9707
10002
  result.scriptMap = scriptPhase.scriptMap;
9708
10003
  compileStylePhase(parsed.descriptor, filename, result);
@@ -9710,6 +10005,7 @@ async function compileVueFile(source, filename, options) {
9710
10005
  descriptor: parsed.descriptor,
9711
10006
  filename,
9712
10007
  autoUsingComponentsMap: scriptPhase.autoUsingComponentsMap,
10008
+ autoImportTagsMap: componentSourceInfo.autoImportTagsMap,
9713
10009
  autoUsingComponents,
9714
10010
  autoImportTags,
9715
10011
  jsonDefaults: parsed.jsonDefaults,
@@ -9725,4 +10021,4 @@ async function compileVueFile(source, filename, options) {
9725
10021
  return result;
9726
10022
  }
9727
10023
  //#endregion
9728
- export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, 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, isWevuRuntimeModuleId, loadCache, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
10024
+ export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_INTERNAL_REACTIVITY_APIS, WE_VU_INTERNAL_REACTIVITY_MODULE_ID, WE_VU_INTERNAL_RUNTIME_MODULE_ID, WE_VU_INTERNAL_TEMPLATE_APIS, WE_VU_INTERNAL_TEMPLATE_MODULE_ID, WE_VU_MODULE_ID, WE_VU_PAGE_HOOK_TO_FEATURE, WE_VU_RUNTIME_APIS, WE_VU_RUNTIME_MODULE_IDS, 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, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformScript, transformScript as transformSfcScript, ttPlatform, wechatPlatform };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.17.7",
4
+ "version": "6.18.0",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -45,15 +45,15 @@
45
45
  "@vue/compiler-core": "^3.5.39",
46
46
  "@vue/compiler-dom": "^3.5.39",
47
47
  "comment-json": "^5.0.0",
48
- "lru-cache": "^11.5.1",
48
+ "lru-cache": "^11.5.2",
49
49
  "magic-string": "^0.30.21",
50
50
  "merge": "^2.1.1",
51
51
  "pathe": "^2.0.3",
52
52
  "vue": "^3.5.39",
53
- "@weapp-core/shared": "3.0.5",
54
- "@weapp-vite/ast": "6.17.7",
55
53
  "@weapp-core/constants": "0.1.12",
56
- "rolldown-require": "2.0.19"
54
+ "@weapp-core/shared": "3.0.5",
55
+ "@weapp-vite/ast": "6.18.0",
56
+ "rolldown-require": "2.0.20"
57
57
  },
58
58
  "publishConfig": {
59
59
  "access": "public",