@wevu/compiler 6.24.0 → 6.25.1

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
@@ -769,6 +769,29 @@ declare function resolveClassStyleWxsLocation(options: {
769
769
  */
770
770
  declare function getClassStyleWxsSource(options?: ClassStyleWxsSourceOptions): string;
771
771
  //#endregion
772
+ //#region src/plugins/vue/hmr/sfcSignature.d.ts
773
+ declare const VUE_SFC_BLOCK_TYPES: readonly ["script", "template", "style", "config"];
774
+ type VueSfcBlockType = typeof VUE_SFC_BLOCK_TYPES[number];
775
+ type VueSfcBlockSignatures = Readonly<Record<VueSfcBlockType, string>>;
776
+ type VueSfcBlockChanges = VueSfcBlockType[];
777
+ interface VueSfcHmrSignatures {
778
+ readonly blockSignatures?: VueSfcBlockSignatures;
779
+ readonly hasTemplate?: boolean;
780
+ readonly nonJsonSignature?: string;
781
+ readonly scriptSignature?: string;
782
+ readonly styleIndependentSignature?: string;
783
+ readonly tailwindContentSignature?: string;
784
+ readonly tailwindScriptContentSignature?: string;
785
+ readonly tailwindTemplateContentSignature?: string;
786
+ }
787
+ declare function resolveVueSfcHmrSignatures(source: string, filename: string): VueSfcHmrSignatures;
788
+ declare function classifyVueSfcBlockChanges(previous: VueSfcBlockSignatures, current: VueSfcBlockSignatures): VueSfcBlockChanges;
789
+ declare function resolveVueSfcNonJsonSignature(source: string, filename: string): string | undefined;
790
+ declare function resolveVueSfcScriptSignature(source: string, filename: string): string | undefined;
791
+ declare function resolveVueSfcStyleIndependentSignature(source: string, filename: string): string | undefined;
792
+ declare function resolveVueSfcTailwindContentSignature(source: string, filename: string): string | undefined;
793
+ declare function resolveVueSfcHasTemplate(source: string, filename: string): boolean | undefined;
794
+ //#endregion
772
795
  //#region src/plugins/vue/transform/classStyleComputed.d.ts
773
796
  interface ClassStyleHelperNames {
774
797
  normalizeClassName: string;
@@ -1132,4 +1155,4 @@ interface CollectVueTemplateTagsOptions {
1132
1155
  */
1133
1156
  declare function collectVueTemplateTags(template: string, options: CollectVueTemplateTagsOptions): Set<string>;
1134
1157
  //#endregion
1135
- 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, type TransformUniAppSourceOptions, type UniAppCompatibilityTarget, VUE_COMPONENT_TAG_RE, type VueTransformResult, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, 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, isUniAppCompatibilityFile, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformNestedWxssVars, transformScript, transformScript as transformSfcScript, transformUniAppConditionalCode, transformUniAppSource, transformVueDeepSelectors, ttPlatform, wechatPlatform };
1158
+ 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, type TransformUniAppSourceOptions, type UniAppCompatibilityTarget, VUE_COMPONENT_TAG_RE, VUE_SFC_BLOCK_TYPES, type VueSfcBlockChanges, type VueSfcBlockSignatures, type VueSfcBlockType, type VueSfcHmrSignatures, type VueTransformResult, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, 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, classifyVueSfcBlockChanges, 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, isUniAppCompatibilityFile, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveVueSfcHasTemplate, resolveVueSfcHmrSignatures, resolveVueSfcNonJsonSignature, resolveVueSfcScriptSignature, resolveVueSfcStyleIndependentSignature, resolveVueSfcTailwindContentSignature, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformNestedWxssVars, transformScript, transformScript as transformSfcScript, transformUniAppConditionalCode, transformUniAppSource, transformVueDeepSelectors, ttPlatform, wechatPlatform };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { WEAPP_I18N_RUNTIME_MARKER, WEAPP_VITE_RUNTIME_REACTIVITY_VIRTUAL_ID, WEAPP_VITE_RUNTIME_TEMPLATE_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_ID, WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_CSS_MODULES_KEY, WEVU_CSS_VARS_STYLE_KEY, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_FUNCTION_PROP_PATHS_KEY, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_JSX_ISLAND_DATA_KEY, WEVU_JSX_ISLAND_HANDLER, WEVU_JSX_ISLAND_TEMPLATE_NAME, 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_FUNCTION_TOKEN, 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";
3
- import { escapeWxmlAttribute, escapeWxmlText, getMiniProgramRuntimeGlobalKeys, getMiniProgramTemplatePreset, removeExtensionDeep } from "@weapp-core/shared";
3
+ import { escapeWxmlAttribute, escapeWxmlText, getMiniProgramRuntimeGlobalKeys, getMiniProgramTemplatePreset, isObject, removeExtensionDeep } from "@weapp-core/shared";
4
4
  import path from "pathe";
5
5
  import { NodeTypes, baseParse } from "@vue/compiler-core";
6
6
  import { createHash } from "node:crypto";
@@ -15,7 +15,7 @@ import fs, { readFileSync } from "node:fs";
15
15
  import os from "node:os";
16
16
  import process from "node:process";
17
17
  import { LRUCache } from "lru-cache";
18
- import { collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getObjectPropertyByKey, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
18
+ import { collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, collectScriptCallStringLiterals, collectScriptStringLiterals, getObjectPropertyByKey, getRenderPropertyFromComponentOptions, mayContainScriptCallOrModuleSyntax, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
19
19
  import vueJsxPlugin from "@vue/babel-plugin-jsx";
20
20
  import { transformSync } from "@weapp-vite/ast/babelCore";
21
21
  import { compileScript, compileStyleAsync, parse } from "vue/compiler-sfc";
@@ -715,9 +715,9 @@ function stripScriptSetupMacroStatements(content, ast, filename) {
715
715
  };
716
716
  }
717
717
  /**
718
- * 从任意代码中剥离 JSON 宏调用。
718
+ * 从任意代码中拆分 JSON 宏调用与运行时代码。
719
719
  */
720
- function stripJsonMacroCallsFromCode(code, filename) {
720
+ function splitJsonMacroCallsFromCode(code, filename) {
721
721
  let ast;
722
722
  try {
723
723
  ast = parse$3(code, BABEL_TS_MODULE_PARSER_OPTIONS);
@@ -731,15 +731,28 @@ function stripJsonMacroCallsFromCode(code, filename) {
731
731
  }
732
732
  }
733
733
  const ms = new MagicString(code);
734
+ const macroSources = [];
734
735
  traverse(ast, { ExpressionStatement(path) {
735
736
  const expr = path.node.expression;
736
737
  if (!t.isCallExpression(expr) || !t.isIdentifier(expr.callee)) return;
737
738
  if (!JSON_MACROS.has(expr.callee.name)) return;
738
739
  const start = path.node.start;
739
740
  const end = path.node.end;
740
- if (typeof start === "number" && typeof end === "number") ms.remove(start, end);
741
+ if (typeof start === "number" && typeof end === "number") {
742
+ macroSources.push(code.slice(start, end));
743
+ ms.remove(start, end);
744
+ }
741
745
  } });
742
- return ms.toString();
746
+ return {
747
+ macroSources,
748
+ stripped: ms.toString()
749
+ };
750
+ }
751
+ /**
752
+ * 从任意代码中剥离 JSON 宏调用。
753
+ */
754
+ function stripJsonMacroCallsFromCode(code, filename) {
755
+ return splitJsonMacroCallsFromCode(code, filename).stripped;
743
756
  }
744
757
  //#endregion
745
758
  //#region src/plugins/vue/transform/jsonMacros/static.ts
@@ -3932,11 +3945,31 @@ function transformScript(source, options) {
3932
3945
  };
3933
3946
  }
3934
3947
  //#endregion
3948
+ //#region src/utils/text.ts
3949
+ const CRLF_RE = /\r\n?/g;
3950
+ const HYPHENATE_RE = /\B([A-Z])/g;
3951
+ function hyphenate(value) {
3952
+ return value.replace(HYPHENATE_RE, "-$1").toLowerCase();
3953
+ }
3954
+ function normalizeComponentHostName(value) {
3955
+ return value.startsWith("__wv") ? value : hyphenate(value);
3956
+ }
3957
+ /**
3958
+ * 统一文本换行符为 LF,消除不同系统(CRLF/CR/LF)差异。
3959
+ */
3960
+ function normalizeLineEndings(source) {
3961
+ if (!source.includes("\r")) return source;
3962
+ return source.replace(CRLF_RE, "\n");
3963
+ }
3964
+ //#endregion
3935
3965
  //#region src/inlineDataset.ts
3936
3966
  const NON_ALNUM_RE = /[^a-z0-9]+/gi;
3937
3967
  const LEADING_TRAILING_DASH_RE = /^-+|-+$/g;
3968
+ function normalizeMiniProgramEventName(eventName) {
3969
+ return eventName.includes(":") ? eventName.replaceAll(":", "-").toLowerCase() : hyphenate(eventName);
3970
+ }
3938
3971
  function normalizeEventDatasetSuffix(eventName) {
3939
- return eventName.trim().replace(NON_ALNUM_RE, "-").replace(LEADING_TRAILING_DASH_RE, "").toLowerCase() || "event";
3972
+ return normalizeMiniProgramEventName(eventName.trim()).replace(NON_ALNUM_RE, "-").replace(LEADING_TRAILING_DASH_RE, "") || "event";
3940
3973
  }
3941
3974
  function createInlineExpressionId(seed) {
3942
3975
  return `i${seed.toString(36)}`;
@@ -4555,9 +4588,12 @@ const eventMap$3 = {
4555
4588
  longtap: "longtap",
4556
4589
  longpress: "longpress"
4557
4590
  };
4591
+ const PASCALIZE_EVENT_RE = /(^|-)([a-z0-9])/g;
4592
+ function toPascalEventName(eventName) {
4593
+ return eventName.replace(PASCALIZE_EVENT_RE, (_match, _separator, character) => character.toUpperCase());
4594
+ }
4558
4595
  function toOnEventName(eventName) {
4559
- if (!eventName) return "on";
4560
- return `on${(eventName[0] ?? "").toUpperCase()}${eventName.slice(1)}`;
4596
+ return `on${toPascalEventName(eventName)}`;
4561
4597
  }
4562
4598
  const EVENT_BINDING_PREFIX_RE$3 = /^(bind|catch|capture-bind|capture-catch|mut-bind):(.+)$/;
4563
4599
  function parseEventBinding$3(eventName) {
@@ -4573,7 +4609,7 @@ function parseEventBinding$3(eventName) {
4573
4609
  }
4574
4610
  function toAlipayDirectiveEvent(prefix, eventName) {
4575
4611
  if (!eventName) return "on";
4576
- const pascalEvent = `${(eventName[0] ?? "").toUpperCase()}${eventName.slice(1)}`;
4612
+ const pascalEvent = toPascalEventName(eventName);
4577
4613
  switch (prefix) {
4578
4614
  case "catch": return `catch${pascalEvent}`;
4579
4615
  case "capture-bind": return `capture${pascalEvent}`;
@@ -4581,9 +4617,6 @@ function toAlipayDirectiveEvent(prefix, eventName) {
4581
4617
  default: return toOnEventName(eventName);
4582
4618
  }
4583
4619
  }
4584
- function normalizeMiniProgramEventName$3(name) {
4585
- return name.includes(":") ? name.replaceAll(":", "-").toLowerCase() : name;
4586
- }
4587
4620
  /**
4588
4621
  * 支付宝小程序平台适配器。
4589
4622
  */
@@ -4602,10 +4635,10 @@ const alipayPlatform = {
4602
4635
  },
4603
4636
  keyThisValue: "*this",
4604
4637
  keyAttr: (value) => `${directives$3.keyAttr}="${value}"`,
4605
- mapEventName: (eventName) => eventMap$3[eventName] || eventName,
4638
+ mapEventName: (eventName) => eventMap$3[eventName.toLowerCase()] || eventName,
4606
4639
  eventBindingAttr: (eventName) => {
4607
4640
  const { prefix, name } = parseEventBinding$3(eventName);
4608
- return toAlipayDirectiveEvent(prefix, normalizeMiniProgramEventName$3(name));
4641
+ return toAlipayDirectiveEvent(prefix, normalizeMiniProgramEventName(name));
4609
4642
  }
4610
4643
  };
4611
4644
  //#endregion
@@ -4647,9 +4680,6 @@ function parseEventBinding$2(eventName) {
4647
4680
  function shouldUseColonEventBinding$2(name) {
4648
4681
  return name.includes(":") || name.includes("-");
4649
4682
  }
4650
- function normalizeMiniProgramEventName$2(name) {
4651
- return name.includes(":") ? name.replaceAll(":", "-").toLowerCase() : name;
4652
- }
4653
4683
  const directives$2 = createMiniProgramDirectiveAttrs("wx");
4654
4684
  /**
4655
4685
  * 默认小程序模板平台实现。
@@ -4671,10 +4701,10 @@ const defaultMiniProgramPlatform = {
4671
4701
  },
4672
4702
  keyThisValue: "*this",
4673
4703
  keyAttr: (value) => `${directives$2.keyAttr}="${value}"`,
4674
- mapEventName: (eventName) => eventMap$2[eventName] || eventName,
4704
+ mapEventName: (eventName) => eventMap$2[eventName.toLowerCase()] || eventName,
4675
4705
  eventBindingAttr: (eventName) => {
4676
4706
  const { prefix, name } = parseEventBinding$2(eventName);
4677
- const normalizedName = normalizeMiniProgramEventName$2(name);
4707
+ const normalizedName = normalizeMiniProgramEventName(name);
4678
4708
  switch (prefix) {
4679
4709
  case "catch": return shouldUseColonEventBinding$2(normalizedName) ? `catch:${normalizedName}` : `catch${normalizedName}`;
4680
4710
  case "capture-bind": return `capture-bind:${normalizedName}`;
@@ -4727,9 +4757,6 @@ function parseEventBinding$1(eventName) {
4727
4757
  function shouldUseColonEventBinding$1(name) {
4728
4758
  return name.includes(":") || name.includes("-");
4729
4759
  }
4730
- function normalizeMiniProgramEventName$1(name) {
4731
- return name.includes(":") ? name.replaceAll(":", "-").toLowerCase() : name;
4732
- }
4733
4760
  /**
4734
4761
  * 百度智能小程序平台适配器。
4735
4762
  */
@@ -4748,10 +4775,10 @@ const swanPlatform = {
4748
4775
  },
4749
4776
  keyThisValue: "*this",
4750
4777
  keyAttr: (value) => `${directives$1.keyAttr}="${value}"`,
4751
- mapEventName: (eventName) => eventMap$1[eventName] || eventName,
4778
+ mapEventName: (eventName) => eventMap$1[eventName.toLowerCase()] || eventName,
4752
4779
  eventBindingAttr: (eventName) => {
4753
4780
  const { prefix, name } = parseEventBinding$1(eventName);
4754
- const normalizedName = normalizeMiniProgramEventName$1(name);
4781
+ const normalizedName = normalizeMiniProgramEventName(name);
4755
4782
  switch (prefix) {
4756
4783
  case "catch": return shouldUseColonEventBinding$1(normalizedName) ? `catch:${normalizedName}` : `catch${normalizedName}`;
4757
4784
  case "capture-bind": return `capture-bind:${normalizedName}`;
@@ -4800,9 +4827,6 @@ function parseEventBinding(eventName) {
4800
4827
  function shouldUseColonEventBinding(name) {
4801
4828
  return name.includes(":") || name.includes("-");
4802
4829
  }
4803
- function normalizeMiniProgramEventName(name) {
4804
- return name.includes(":") ? name.replaceAll(":", "-").toLowerCase() : name;
4805
- }
4806
4830
  /**
4807
4831
  * 抖音小程序平台适配器。
4808
4832
  */
@@ -4821,7 +4845,7 @@ const ttPlatform = {
4821
4845
  },
4822
4846
  keyThisValue: "*this",
4823
4847
  keyAttr: (value) => `${directives.keyAttr}="${value}"`,
4824
- mapEventName: (eventName) => eventMap[eventName] || eventName,
4848
+ mapEventName: (eventName) => eventMap[eventName.toLowerCase()] || eventName,
4825
4849
  eventBindingAttr: (eventName) => {
4826
4850
  const { prefix, name } = parseEventBinding(eventName);
4827
4851
  const normalizedName = normalizeMiniProgramEventName(name);
@@ -5080,22 +5104,23 @@ const UPPERCASE_STYLE_RE = /[A-Z]/g;
5080
5104
  function isEventBinding(name) {
5081
5105
  return ON_EVENT_RE.test(name) || CATCH_EVENT_RE.test(name) || CAPTURE_BIND_EVENT_RE.test(name) || CAPTURE_CATCH_EVENT_RE.test(name) || MUT_BIND_EVENT_RE.test(name);
5082
5106
  }
5083
- const LEADING_UPPER_RE = /^[A-Z]/;
5084
- const UPPER_CHAR_RE = /[A-Z]/g;
5085
- function lowerEventName(name) {
5107
+ function lowerFirstEventName(name) {
5086
5108
  if (!name) return name;
5087
- return name.replace(LEADING_UPPER_RE, (s) => s.toLowerCase()).replace(UPPER_CHAR_RE, (s) => s.toLowerCase());
5109
+ return `${name.charAt(0).toLowerCase()}${name.slice(1)}`;
5088
5110
  }
5089
- function resolveMappedEventName(rawName, context) {
5090
- const resolveEvent = (name) => context.platform.mapEventName(lowerEventName(name));
5111
+ function resolveMappedEventName(rawName, context, isComponent) {
5112
+ const resolveEvent = (name) => {
5113
+ const eventName = lowerFirstEventName(name);
5114
+ return isComponent ? eventName : context.platform.mapEventName(eventName);
5115
+ };
5091
5116
  if (CAPTURE_BIND_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(11));
5092
5117
  if (CAPTURE_CATCH_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(12));
5093
5118
  if (MUT_BIND_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(7));
5094
5119
  if (CATCH_EVENT_RE.test(rawName)) return resolveEvent(rawName.slice(5));
5095
5120
  return resolveEvent(rawName.slice(2));
5096
5121
  }
5097
- function toEventBindingName(rawName, context) {
5098
- const eventName = resolveMappedEventName(rawName, context);
5122
+ function toEventBindingName(rawName, context, isComponent) {
5123
+ const eventName = resolveMappedEventName(rawName, context, isComponent);
5099
5124
  if (CAPTURE_BIND_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`capture-bind:${eventName}`);
5100
5125
  if (CAPTURE_CATCH_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`capture-catch:${eventName}`);
5101
5126
  if (MUT_BIND_EVENT_RE.test(rawName)) return context.platform.eventBindingAttr(`mut-bind:${eventName}`);
@@ -5120,9 +5145,9 @@ function extractJsxKeyExpression(node) {
5120
5145
  }
5121
5146
  return null;
5122
5147
  }
5123
- function compileEventAttribute(name, value, context) {
5124
- const bindAttr = toEventBindingName(name, context);
5125
- const eventSuffix = normalizeEventDatasetSuffix(resolveMappedEventName(name, context));
5148
+ function compileEventAttribute(name, value, context, isComponent) {
5149
+ const bindAttr = toEventBindingName(name, context, isComponent);
5150
+ const eventSuffix = normalizeEventDatasetSuffix(resolveMappedEventName(name, context, isComponent));
5126
5151
  const exp = readJsxAttributeExpression(value);
5127
5152
  if (!exp) return [];
5128
5153
  if (t.isStringLiteral(exp) && exp.value) return [`${bindAttr}="${escapeAttr(exp.value)}"`];
@@ -5135,8 +5160,8 @@ function compileEventAttribute(name, value, context) {
5135
5160
  });
5136
5161
  return attrs;
5137
5162
  }
5138
- function compileNormalAttribute(name, value, context) {
5139
- const normalizedName = name === "className" ? "class" : name;
5163
+ function compileNormalAttribute(name, value, context, isComponent) {
5164
+ const normalizedName = name === "className" ? "class" : isComponent ? normalizeComponentHostName(name) : name;
5140
5165
  const exp = readJsxAttributeExpression(value);
5141
5166
  if (!exp) return null;
5142
5167
  if (t.isStringLiteral(exp)) return `${normalizedName}="${escapeAttr(exp.value)}"`;
@@ -5151,7 +5176,7 @@ function compileNormalAttribute(name, value, context) {
5151
5176
  }
5152
5177
  return `${normalizedName}="${renderMustache$1(normalizeInterpolationExpression(exp), context)}"`;
5153
5178
  }
5154
- function compileNamedAttribute(name, value, context) {
5179
+ function compileNamedAttribute(name, value, context, isComponent) {
5155
5180
  if (name === "key") return [];
5156
5181
  if (name === "v-html") {
5157
5182
  context.warnings.push("小程序不支持 JSX v-html,请使用 rich-text 组件替代。");
@@ -5170,11 +5195,12 @@ function compileNamedAttribute(name, value, context) {
5170
5195
  context.warnings.push(`小程序不支持 JSX DOM property ${name},已移除该属性。`);
5171
5196
  return [];
5172
5197
  }
5173
- if (isEventBinding(name)) return compileEventAttribute(name, value, context);
5174
- const normalAttr = compileNormalAttribute(name, value, context);
5198
+ if (isEventBinding(name)) return compileEventAttribute(name, value, context, isComponent);
5199
+ const normalAttr = compileNormalAttribute(name, value, context, isComponent);
5175
5200
  return normalAttr ? [normalAttr] : [];
5176
5201
  }
5177
- function compileJsxAttributes(attributes, context) {
5202
+ function compileJsxAttributes(attributes, context, options) {
5203
+ const isComponent = options?.isComponent === true;
5178
5204
  const output = [];
5179
5205
  for (const attr of attributes) {
5180
5206
  if (t.isJSXSpreadAttribute(attr)) {
@@ -5183,7 +5209,7 @@ function compileJsxAttributes(attributes, context) {
5183
5209
  const value = property.value;
5184
5210
  if (t.isExpression(value)) {
5185
5211
  const name = t.isIdentifier(property.key) ? property.key.name : property.key.value;
5186
- output.push(...compileNamedAttribute(name, t.jsxExpressionContainer(value), context));
5212
+ output.push(...compileNamedAttribute(name, t.jsxExpressionContainer(value), context, isComponent));
5187
5213
  }
5188
5214
  } else context.warnings.push("JSX spread attributes 包含无法静态展开的属性,已保留为 dynamic island。");
5189
5215
  else context.warnings.push("动态 JSX spread attributes 无法映射为静态 WXML,已生成确定性诊断。");
@@ -5201,7 +5227,7 @@ function compileJsxAttributes(attributes, context) {
5201
5227
  continue;
5202
5228
  }
5203
5229
  const name = attr.name.name;
5204
- output.push(...compileNamedAttribute(name, attr.value, context));
5230
+ output.push(...compileNamedAttribute(name, attr.value, context, isComponent));
5205
5231
  }
5206
5232
  return output;
5207
5233
  }
@@ -5515,23 +5541,25 @@ function compileJsxElement(node, context) {
5515
5541
  context.warnings.push("动态 JSX spread attributes 无法映射为静态 WXML,已生成 dynamic island。");
5516
5542
  return registerDynamicIsland(node, context, "dynamic-spread");
5517
5543
  }
5518
- const tag = toJsxTagName(node.openingElement.name, context);
5519
- if (tag === "component") {
5544
+ const rawTag = toJsxTagName(node.openingElement.name, context);
5545
+ if (rawTag === "component") {
5520
5546
  context.warnings.push("JSX 动态 component 无法映射为静态 WXML,已生成 dynamic island。");
5521
5547
  return registerDynamicIsland(node, context, "dynamic-component");
5522
5548
  }
5523
- if (tag === "Teleport") {
5549
+ if (rawTag === "Teleport") {
5524
5550
  context.warnings.push("小程序不支持 JSX <Teleport>,已生成 dynamic island。");
5525
5551
  return registerDynamicIsland(node, context, "dynamic-component");
5526
5552
  }
5527
- if (tag === "Transition") {
5553
+ if (rawTag === "Transition") {
5528
5554
  context.warnings.push("JSX <Transition> 需要 Web 动画运行时,当前仅渲染子节点。");
5529
5555
  return compileJsxChildren(node.children, context);
5530
5556
  }
5531
- if (tag === "KeepAlive") {
5557
+ if (rawTag === "KeepAlive") {
5532
5558
  context.warnings.push("JSX <KeepAlive> 需要运行时缓存管理,当前仅保留标记并渲染子节点。");
5533
5559
  return `<block data-keep-alive="true">${compileJsxChildren(node.children, context)}</block>`;
5534
5560
  }
5561
+ const isComponent = !isBuiltinComponent(rawTag);
5562
+ const tag = isComponent ? hyphenate(rawTag) : rawTag;
5535
5563
  if (node.children.some((child) => {
5536
5564
  if (!t.isJSXExpressionContainer(child) || t.isJSXEmptyExpression(child.expression)) return false;
5537
5565
  const expression = unwrapTsExpression$2(child.expression);
@@ -5567,7 +5595,7 @@ function compileJsxElement(node, context) {
5567
5595
  context.warnings.push(`JSX ${directive} 无法直接映射当前静态 WXML,已生成 dynamic island。`);
5568
5596
  return registerDynamicIsland(node, context, "closure");
5569
5597
  }
5570
- const attrs = compileJsxAttributes(node.openingElement.attributes, context);
5598
+ const attrs = compileJsxAttributes(node.openingElement.attributes, context, { isComponent });
5571
5599
  const showExpression = directives.get("v-show");
5572
5600
  if (showExpression) attrs.push(`hidden="${renderMustache$1(`!(${normalizeInterpolationExpression(showExpression)})`, context)}"`);
5573
5601
  const attrsSegment = attrs.length ? ` ${attrs.join(" ")}` : "";
@@ -6088,16 +6116,6 @@ function isUniAppCompatibilityFile(filename, srcRoot, include) {
6088
6116
  });
6089
6117
  }
6090
6118
  //#endregion
6091
- //#region src/utils/text.ts
6092
- const CRLF_RE = /\r\n?/g;
6093
- /**
6094
- * 统一文本换行符为 LF,消除不同系统(CRLF/CR/LF)差异。
6095
- */
6096
- function normalizeLineEndings(source) {
6097
- if (!source.includes("\r")) return source;
6098
- return source.replace(CRLF_RE, "\n");
6099
- }
6100
- //#endregion
6101
6119
  //#region src/plugins/utils/cache.ts
6102
6120
  const mtimeCache = /* @__PURE__ */ new Map();
6103
6121
  const loadCache = new LRUCache({ max: 1024 });
@@ -8220,8 +8238,9 @@ function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
8220
8238
  const indexAccess = buildForIndexAccess(context);
8221
8239
  return `style="${renderMustache(`${binding.name}${indexAccess}`, context)}"`;
8222
8240
  }
8223
- function transformAttribute(node, _context) {
8224
- const { name, value } = node;
8241
+ function transformAttribute(node, _context, nameOverride) {
8242
+ const { value } = node;
8243
+ const name = nameOverride ?? node.name;
8225
8244
  if (!value) return name;
8226
8245
  if (value.type === NodeTypes.TEXT) return `${name}="${escapeWxmlAttribute(value.content)}"`;
8227
8246
  return `${name}=""`;
@@ -8478,17 +8497,18 @@ function transformBindDirective(node, context, forInfo, options) {
8478
8497
  const { arg } = node;
8479
8498
  if (!arg) return null;
8480
8499
  const argValue = arg.type === NodeTypes.SIMPLE_EXPRESSION ? arg.content : "";
8500
+ const outputArgValue = options?.isComponent ? normalizeComponentHostName(argValue) : argValue;
8481
8501
  const rawExpValue = getBindDirectiveExpression(node);
8482
8502
  if (!rawExpValue) return null;
8483
8503
  if (options?.isComponent && !COMPONENT_NON_PROP_BINDINGS.has(argValue)) {
8484
8504
  const path = collectFunctionPropPath(rawExpValue);
8485
8505
  if (path) {
8486
8506
  if (shouldWrapStaticMemberFunctionProp(argValue, path, context)) {
8487
- const runtimeAttr = createFunctionPropRuntimeAttr(argValue, rawExpValue, context);
8507
+ const runtimeAttr = createFunctionPropRuntimeAttr(outputArgValue, rawExpValue, context);
8488
8508
  if (runtimeAttr) return runtimeAttr;
8489
8509
  } else context.functionPropPaths.add(path);
8490
8510
  } else if (shouldUseRuntimeFunctionPropBinding(argValue, context) && isComputedMemberExpression(rawExpValue)) {
8491
- const runtimeAttr = createFunctionPropRuntimeAttr(argValue, rawExpValue, context);
8511
+ const runtimeAttr = createFunctionPropRuntimeAttr(outputArgValue, rawExpValue, context);
8492
8512
  if (runtimeAttr) return runtimeAttr;
8493
8513
  }
8494
8514
  }
@@ -8504,14 +8524,14 @@ function transformBindDirective(node, context, forInfo, options) {
8504
8524
  return context.platform.keyAttr(expValue);
8505
8525
  }
8506
8526
  if (isTopLevelObjectLiteral(rawExpValue)) {
8507
- if (context.objectLiteralBindMode === "inline" || isStaticObjectLiteral(rawExpValue)) return createInlineObjectLiteralAttr(argValue, rawExpValue, context);
8508
- return createBindRuntimeAttr(argValue, rawExpValue, context);
8527
+ if (context.objectLiteralBindMode === "inline" || isStaticObjectLiteral(rawExpValue)) return createInlineObjectLiteralAttr(outputArgValue, rawExpValue, context);
8528
+ return createBindRuntimeAttr(outputArgValue, rawExpValue, context);
8509
8529
  }
8510
8530
  if (shouldFallbackToRuntimeBinding(rawExpValue, context.templateSafeCallNames)) {
8511
- const runtimeAttr = createBindRuntimeAttr(argValue, rawExpValue, context);
8531
+ const runtimeAttr = createBindRuntimeAttr(outputArgValue, rawExpValue, context);
8512
8532
  if (runtimeAttr) return runtimeAttr;
8513
8533
  }
8514
- return `${argValue}="${renderMustache(normalizeWxmlExpressionWithContext(rawExpValue, context), context)}"`;
8534
+ return `${outputArgValue}="${renderMustache(normalizeWxmlExpressionWithContext(rawExpValue, context), context)}"`;
8515
8535
  }
8516
8536
  //#endregion
8517
8537
  //#region src/plugins/vue/compiler/template/directives/custom.ts
@@ -8616,7 +8636,7 @@ function transformComponentModelDirective(node, context) {
8616
8636
  context.warnings.push(`v-model="${rawExpValue}" 需要是可赋值的成员表达式。`);
8617
8637
  return null;
8618
8638
  }
8619
- const modelAttr = modelProp === "modelValue" ? `modelValue="${renderMustache(normalizeWxmlExpressionWithContext(rawExpValue, context), context)}"` : transformBindDirective(node, context);
8639
+ const modelAttr = modelProp === "modelValue" ? `model-value="${renderMustache(normalizeWxmlExpressionWithContext(rawExpValue, context), context)}"` : transformBindDirective(node, context, void 0, { isComponent: true });
8620
8640
  const updateAttr = [
8621
8641
  `data-wd-${eventSuffix}="1"`,
8622
8642
  `data-wi-${eventSuffix}="${inlineExpression.id}"`,
@@ -8624,7 +8644,7 @@ function transformComponentModelDirective(node, context) {
8624
8644
  ].filter(Boolean).join(" ");
8625
8645
  const modifierNames = node.modifiers.map((modifier) => modifier.content.trim()).filter(Boolean);
8626
8646
  const modifierProperties = modifierNames.map((name) => `${JSON.stringify(name)}:true`).join(",");
8627
- const modifiersProp = modelProp === "modelValue" ? "modelModifiers" : `${modelProp}Modifiers`;
8647
+ const modifiersProp = normalizeComponentHostName(modelProp === "modelValue" ? "modelModifiers" : `${modelProp}Modifiers`);
8628
8648
  const modifiersRef = modifierNames.length ? registerRuntimeBindingExpression(`{${modifierProperties}}`, context, { hint: "v-model modifiers" }) : null;
8629
8649
  return [
8630
8650
  modelAttr,
@@ -8813,7 +8833,7 @@ function collectElementAttributes(node, context, options) {
8813
8833
  staticStyle = prop.value.content;
8814
8834
  continue;
8815
8835
  }
8816
- const attr = transformAttribute(prop, context);
8836
+ const attr = transformAttribute(prop, context, isComponentElement ? normalizeComponentHostName(prop.name) : void 0);
8817
8837
  if (attr) attrs.push(attr);
8818
8838
  continue;
8819
8839
  }
@@ -9789,7 +9809,7 @@ function transformComponentElement(node, context, transformNode) {
9789
9809
  props: otherProps
9790
9810
  }, context, transformNode, { extraAttrs: [`data-is="${renderMustache(componentVar, context)}"`] });
9791
9811
  for (const prop of otherProps) if (prop.type === NodeTypes.ATTRIBUTE) {
9792
- const attr = transformAttribute(prop, context);
9812
+ const attr = transformAttribute(prop, context, normalizeComponentHostName(prop.name));
9793
9813
  if (attr) attrs.push(attr);
9794
9814
  } else if (prop.type === NodeTypes.DIRECTIVE) {
9795
9815
  const dir = transformDirective(prop, context, node, void 0, { isComponent: true });
@@ -10225,6 +10245,253 @@ function compileVueTemplateToWxml(template, filename, options) {
10225
10245
  }
10226
10246
  }
10227
10247
  //#endregion
10248
+ //#region src/plugins/vue/native.ts
10249
+ const require = createRequire(import.meta.url);
10250
+ let binding;
10251
+ function resolveNativeAstModulePath() {
10252
+ return process.env.WEAPP_VITE_NATIVE_AST_PATH?.trim() || void 0;
10253
+ }
10254
+ function shouldUseNativeSfc() {
10255
+ return process.env.WEAPP_VITE_NATIVE === "1" && Boolean(resolveNativeAstModulePath());
10256
+ }
10257
+ function loadNativeSfcBindingSync() {
10258
+ if (!shouldUseNativeSfc()) return;
10259
+ if (binding !== void 0) return binding || void 0;
10260
+ try {
10261
+ binding = require(resolveNativeAstModulePath());
10262
+ } catch {
10263
+ binding = false;
10264
+ }
10265
+ return binding || void 0;
10266
+ }
10267
+ //#endregion
10268
+ //#region src/plugins/vue/hmr/tailwindContent.ts
10269
+ const CLASS_LIKE_TEMPLATE_ATTR_RE = /(?:^|[\s<])(?:[\w-]*class[\w-]*|v-bind(?::[\w-]*class[\w-]*)?|:[\w-]*class[\w-]*)(?:\.[\w-]+)*\s*=\s*(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`|[^\s>]+)/g;
10270
+ const VUE_DYNAMIC_CLASS_LIKE_BINDING_RE = /(?:^|[\s<])(?:v-bind(?::[\w-]*class[\w-]*)?|:[\w-]*class[\w-]*)(?:\.[\w-]+)*\s*=/;
10271
+ function hashPayload$1(payload) {
10272
+ return createHash("sha256").update(JSON.stringify(payload)).digest("hex").slice(0, 16);
10273
+ }
10274
+ function collectTemplateTailwindCandidates(content) {
10275
+ const candidates = /* @__PURE__ */ new Set();
10276
+ for (const match of content.matchAll(CLASS_LIKE_TEMPLATE_ATTR_RE)) candidates.add(match[0].trim());
10277
+ return Array.from(candidates).sort();
10278
+ }
10279
+ function normalizeTailwindContentPayload(payload) {
10280
+ const scriptLiterals = VUE_DYNAMIC_CLASS_LIKE_BINDING_RE.test(payload.template) ? payload.scriptLiterals : payload.hasScriptTailwindClassHint ? payload.scriptCallLiterals : [];
10281
+ return {
10282
+ ...payload,
10283
+ template: collectTemplateTailwindCandidates(payload.template),
10284
+ scriptLiterals,
10285
+ scriptCallLiterals: []
10286
+ };
10287
+ }
10288
+ function buildTailwindContentPayload(template, scriptContent, scriptSetupContent) {
10289
+ return {
10290
+ template,
10291
+ scriptLiterals: [...collectScriptStringLiterals(scriptContent), ...collectScriptStringLiterals(scriptSetupContent)],
10292
+ scriptCallLiterals: [...collectScriptCallStringLiterals(scriptContent), ...collectScriptCallStringLiterals(scriptSetupContent)],
10293
+ hasScriptTailwindClassHint: mayContainScriptCallOrModuleSyntax(`${scriptContent}\n${scriptSetupContent}`)
10294
+ };
10295
+ }
10296
+ function hashTailwindContentPayload(payload) {
10297
+ return hashPayload$1(normalizeTailwindContentPayload(payload));
10298
+ }
10299
+ function hashTailwindTemplateContentPayload(payload) {
10300
+ return hashPayload$1({ template: normalizeTailwindContentPayload(payload).template });
10301
+ }
10302
+ function hashTailwindScriptContentPayload(payload) {
10303
+ return hashPayload$1({ scriptLiterals: normalizeTailwindContentPayload(payload).scriptLiterals });
10304
+ }
10305
+ //#endregion
10306
+ //#region src/plugins/vue/hmr/sfcPayload.ts
10307
+ const signaturePayloadCache = /* @__PURE__ */ new Map();
10308
+ function serializeAttrs(attrs) {
10309
+ return Object.fromEntries(Object.entries(attrs).sort(([a], [b]) => a.localeCompare(b)));
10310
+ }
10311
+ function serializeBlock(block) {
10312
+ if (!block) return null;
10313
+ return {
10314
+ type: block.type,
10315
+ attrs: serializeAttrs(block.attrs),
10316
+ content: block.content
10317
+ };
10318
+ }
10319
+ function buildRawVueSfcPayload(descriptor) {
10320
+ const configBlocks = [];
10321
+ const templateBlocks = [];
10322
+ for (const block of descriptor.customBlocks) {
10323
+ const serialized = serializeBlock(block);
10324
+ if (block.type === "json" || block.type === "config") configBlocks.push(serialized);
10325
+ else templateBlocks.push(serialized);
10326
+ }
10327
+ return {
10328
+ script: {
10329
+ script: serializeBlock(descriptor.script),
10330
+ scriptSetup: serializeBlock(descriptor.scriptSetup)
10331
+ },
10332
+ template: {
10333
+ template: serializeBlock(descriptor.template),
10334
+ customBlocks: templateBlocks
10335
+ },
10336
+ style: { styles: descriptor.styles.map((style) => serializeBlock(style)) },
10337
+ config: { customBlocks: configBlocks },
10338
+ hasTemplate: Boolean(descriptor.template?.content.trim())
10339
+ };
10340
+ }
10341
+ function normalizeScriptBlock(block, filename) {
10342
+ if (!block) return {
10343
+ block: null,
10344
+ macroSources: []
10345
+ };
10346
+ try {
10347
+ const split = splitJsonMacroCallsFromCode(block.content, filename);
10348
+ return {
10349
+ block: {
10350
+ ...block,
10351
+ content: split.stripped
10352
+ },
10353
+ macroSources: split.macroSources
10354
+ };
10355
+ } catch {
10356
+ return {
10357
+ block,
10358
+ macroSources: []
10359
+ };
10360
+ }
10361
+ }
10362
+ function normalizeVueSfcPayload(raw, filename) {
10363
+ const script = normalizeScriptBlock(raw.script.script, filename);
10364
+ const scriptSetup = normalizeScriptBlock(raw.script.scriptSetup, filename);
10365
+ const scriptPayload = {
10366
+ script: script.block,
10367
+ scriptSetup: scriptSetup.block
10368
+ };
10369
+ return {
10370
+ ...raw,
10371
+ script: scriptPayload,
10372
+ config: {
10373
+ ...raw.config,
10374
+ macroSources: [...script.macroSources, ...scriptSetup.macroSources]
10375
+ },
10376
+ tailwindContent: buildTailwindContentPayload(raw.template.template?.content ?? "", script.block?.content ?? "", scriptSetup.block?.content ?? "")
10377
+ };
10378
+ }
10379
+ function isSerializedSfcBlock(value) {
10380
+ return isObject(value) && isObject(value.attrs) && Object.values(value.attrs).every((attr) => typeof attr === "boolean" || typeof attr === "string") && typeof value.content === "string" && typeof value.type === "string";
10381
+ }
10382
+ function isSerializedSfcBlockList(value) {
10383
+ return Array.isArray(value) && value.every(isSerializedSfcBlock);
10384
+ }
10385
+ function parseNativePayload(payload) {
10386
+ try {
10387
+ const parsed = JSON.parse(payload);
10388
+ if (!isObject(parsed) || !isObject(parsed.script) || !isObject(parsed.template) || !isObject(parsed.style) || !isObject(parsed.config) || typeof parsed.hasTemplate !== "boolean") return;
10389
+ const script = parsed.script.script;
10390
+ const scriptSetup = parsed.script.scriptSetup;
10391
+ const template = parsed.template.template;
10392
+ if (script !== null && !isSerializedSfcBlock(script) || scriptSetup !== null && !isSerializedSfcBlock(scriptSetup) || template !== null && !isSerializedSfcBlock(template) || !isSerializedSfcBlockList(parsed.template.customBlocks) || !isSerializedSfcBlockList(parsed.style.styles) || !isSerializedSfcBlockList(parsed.config.customBlocks)) return;
10393
+ return {
10394
+ config: { customBlocks: parsed.config.customBlocks },
10395
+ hasTemplate: parsed.hasTemplate,
10396
+ script: {
10397
+ script,
10398
+ scriptSetup
10399
+ },
10400
+ style: { styles: parsed.style.styles },
10401
+ template: {
10402
+ template,
10403
+ customBlocks: parsed.template.customBlocks
10404
+ }
10405
+ };
10406
+ } catch {
10407
+ return;
10408
+ }
10409
+ }
10410
+ function buildVueSfcSignaturePayloadWithNative(source, filename) {
10411
+ try {
10412
+ const payload = loadNativeSfcBindingSync()?.getVueSfcSignaturePayloadNative?.(source);
10413
+ if (!payload) return;
10414
+ const raw = parseNativePayload(payload);
10415
+ return raw ? normalizeVueSfcPayload(raw, filename) : void 0;
10416
+ } catch {
10417
+ return;
10418
+ }
10419
+ }
10420
+ function buildVueSfcSignaturePayloadWithTs(source, filename) {
10421
+ const { descriptor, errors } = parse(source, { filename });
10422
+ if (errors.length) return;
10423
+ return normalizeVueSfcPayload(buildRawVueSfcPayload(descriptor), filename);
10424
+ }
10425
+ function resolveVueSfcSignaturePayload(source, filename) {
10426
+ const cacheKey = `${filename}\0${source}\0${shouldUseNativeSfc() ? "native" : "ts"}`;
10427
+ if (signaturePayloadCache.has(cacheKey)) return signaturePayloadCache.get(cacheKey);
10428
+ const payload = shouldUseNativeSfc() ? buildVueSfcSignaturePayloadWithNative(source, filename) ?? buildVueSfcSignaturePayloadWithTs(source, filename) : buildVueSfcSignaturePayloadWithTs(source, filename);
10429
+ signaturePayloadCache.set(cacheKey, payload);
10430
+ return payload;
10431
+ }
10432
+ //#endregion
10433
+ //#region src/plugins/vue/hmr/sfcSignature.ts
10434
+ const VUE_SFC_BLOCK_TYPES = [
10435
+ "script",
10436
+ "template",
10437
+ "style",
10438
+ "config"
10439
+ ];
10440
+ const hmrSignaturesCache = /* @__PURE__ */ new WeakMap();
10441
+ function hashPayload(payload) {
10442
+ return createHash("sha256").update(JSON.stringify(payload)).digest("hex").slice(0, 16);
10443
+ }
10444
+ function resolveVueSfcHmrSignatures(source, filename) {
10445
+ const payload = resolveVueSfcSignaturePayload(source, filename);
10446
+ if (!payload) return {};
10447
+ const cached = hmrSignaturesCache.get(payload);
10448
+ if (cached) return cached;
10449
+ const blockSignatures = {
10450
+ script: hashPayload(payload.script),
10451
+ template: hashPayload(payload.template),
10452
+ style: hashPayload(payload.style),
10453
+ config: hashPayload(payload.config)
10454
+ };
10455
+ const signatures = {
10456
+ blockSignatures,
10457
+ nonJsonSignature: hashPayload([
10458
+ blockSignatures.script,
10459
+ blockSignatures.template,
10460
+ blockSignatures.style
10461
+ ]),
10462
+ scriptSignature: blockSignatures.script,
10463
+ styleIndependentSignature: hashPayload([
10464
+ blockSignatures.script,
10465
+ blockSignatures.template,
10466
+ blockSignatures.config
10467
+ ]),
10468
+ tailwindContentSignature: hashTailwindContentPayload(payload.tailwindContent),
10469
+ tailwindTemplateContentSignature: hashTailwindTemplateContentPayload(payload.tailwindContent),
10470
+ tailwindScriptContentSignature: hashTailwindScriptContentPayload(payload.tailwindContent),
10471
+ hasTemplate: payload.hasTemplate
10472
+ };
10473
+ hmrSignaturesCache.set(payload, signatures);
10474
+ return signatures;
10475
+ }
10476
+ function classifyVueSfcBlockChanges(previous, current) {
10477
+ return VUE_SFC_BLOCK_TYPES.filter((type) => previous[type] !== current[type]);
10478
+ }
10479
+ function resolveVueSfcNonJsonSignature(source, filename) {
10480
+ return resolveVueSfcHmrSignatures(source, filename).nonJsonSignature;
10481
+ }
10482
+ function resolveVueSfcScriptSignature(source, filename) {
10483
+ return resolveVueSfcHmrSignatures(source, filename).blockSignatures?.script;
10484
+ }
10485
+ function resolveVueSfcStyleIndependentSignature(source, filename) {
10486
+ return resolveVueSfcHmrSignatures(source, filename).styleIndependentSignature;
10487
+ }
10488
+ function resolveVueSfcTailwindContentSignature(source, filename) {
10489
+ return resolveVueSfcHmrSignatures(source, filename).tailwindContentSignature;
10490
+ }
10491
+ function resolveVueSfcHasTemplate(source, filename) {
10492
+ return resolveVueSfcHmrSignatures(source, filename).hasTemplate;
10493
+ }
10494
+ //#endregion
10228
10495
  //#region src/plugins/vue/transform/scopedId.ts
10229
10496
  const SOURCE_ROOT_RE = /(?:^|\/)src\/(.+)$/;
10230
10497
  function normalizeScopedIdInput(filename) {
@@ -10244,26 +10511,6 @@ function generateScopedId(filename) {
10244
10511
  return (hash >>> 0).toString(36);
10245
10512
  }
10246
10513
  //#endregion
10247
- //#region src/ast/native.ts
10248
- const require = createRequire(import.meta.url);
10249
- let binding;
10250
- function resolveNativeAstModulePath() {
10251
- return process.env.WEAPP_VITE_NATIVE_AST_PATH?.trim() || void 0;
10252
- }
10253
- function shouldUseNativeAst() {
10254
- return process.env.WEAPP_VITE_NATIVE === "1" && Boolean(resolveNativeAstModulePath());
10255
- }
10256
- function loadNativeAstBindingSync() {
10257
- if (!shouldUseNativeAst()) return;
10258
- if (binding !== void 0) return binding || void 0;
10259
- try {
10260
- binding = require(resolveNativeAstModulePath());
10261
- } catch {
10262
- binding = false;
10263
- }
10264
- return binding || void 0;
10265
- }
10266
- //#endregion
10267
10514
  //#region src/plugins/vue/transform/compileVueFile/componentSources.ts
10268
10515
  function normalizeResolvedUsingComponent(result) {
10269
10516
  if (!result) return;
@@ -10323,11 +10570,14 @@ function extractStaticComponentMeta(scriptSetupContent) {
10323
10570
  };
10324
10571
  }
10325
10572
  function readNativeVueSfcScriptSetupContent(source) {
10326
- if (!shouldUseNativeAst()) return;
10327
- const payload = loadNativeAstBindingSync()?.getVueSfcSignaturePayloadNative?.(source);
10328
- if (!payload) return;
10573
+ if (!shouldUseNativeSfc()) return;
10329
10574
  try {
10330
- return JSON.parse(payload).script?.scriptSetup?.content;
10575
+ const payload = loadNativeSfcBindingSync()?.getVueSfcSignaturePayloadNative?.(source);
10576
+ if (!payload) return;
10577
+ const parsed = JSON.parse(payload);
10578
+ if (!isObject(parsed) || !isObject(parsed.script) || !isObject(parsed.script.scriptSetup)) return;
10579
+ const content = parsed.script.scriptSetup.content;
10580
+ return typeof content === "string" ? content : void 0;
10331
10581
  } catch {
10332
10582
  return;
10333
10583
  }
@@ -11835,4 +12085,4 @@ async function compileVueFile(source, filename, options) {
11835
12085
  return result;
11836
12086
  }
11837
12087
  //#endregion
11838
- export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, 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, isUniAppCompatibilityFile, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformNestedWxssVars, transformScript, transformScript as transformSfcScript, transformUniAppConditionalCode, transformUniAppSource, transformVueDeepSelectors, ttPlatform, wechatPlatform };
12088
+ export { CLASS_STYLE_WXS_FILE, CLASS_STYLE_WXS_MODULE, RESERVED_VUE_COMPONENT_TAGS, VUE_COMPONENT_TAG_RE, VUE_SFC_BLOCK_TYPES, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, 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, classifyVueSfcBlockChanges, 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, isUniAppCompatibilityFile, isWevuRuntimeModuleId, loadCache, mayContainJsonMacro, mergeJsonWithStrategy, mtimeCache, normalizeConfigLang, pathExists, preprocessScriptSetupSrc, preprocessScriptSrc, readAndParseSfc, readFile, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, resolveJsLikeLang, resolveSfcBlockSrc, resolveVueSfcHasTemplate, resolveVueSfcHmrSignatures, resolveVueSfcNonJsonSignature, resolveVueSfcScriptSignature, resolveVueSfcStyleIndependentSignature, resolveVueSfcTailwindContentSignature, resolveWevuInternalImportModuleId, restoreScriptSetupSrc, restoreScriptSrc, stripJsonMacroCallsFromCode, swanPlatform, transformNestedWxssVars, transformScript, transformScript as transformSfcScript, transformUniAppConditionalCode, transformUniAppSource, transformVueDeepSelectors, ttPlatform, wechatPlatform };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.24.0",
4
+ "version": "6.25.1",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -53,10 +53,16 @@
53
53
  "postcss": "^8.5.26",
54
54
  "postcss-selector-parser": "^7.1.5",
55
55
  "vue": "^3.5.42",
56
- "@weapp-core/shared": "3.2.0",
56
+ "@weapp-core/constants": "0.2.0",
57
+ "@weapp-vite/ast": "6.25.1",
57
58
  "rolldown-require": "2.0.27",
58
- "@weapp-vite/ast": "6.24.0",
59
- "@weapp-core/constants": "0.2.0"
59
+ "@weapp-core/shared": "3.2.0"
60
+ },
61
+ "tsd": {
62
+ "compilerOptions": {
63
+ "module": "NodeNext",
64
+ "moduleResolution": "NodeNext"
65
+ }
60
66
  },
61
67
  "publishConfig": {
62
68
  "access": "public",
@@ -67,6 +73,7 @@
67
73
  "build": "tsdown",
68
74
  "test": "vitest run",
69
75
  "test:dev": "vitest",
76
+ "test:types": "pnpm build && tsd",
70
77
  "typecheck": "tsc --noEmit",
71
78
  "release": "pnpm publish",
72
79
  "lint": "eslint .",