@wevu/compiler 6.15.0 → 6.15.3

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
@@ -681,7 +681,7 @@ declare function collectWevuPageFeatureFlagsFromCode(code: string, options?: {
681
681
  astEngine?: AstEngineName$1;
682
682
  }): Set<WevuPageFeatureFlag>;
683
683
  //#endregion
684
- //#region src/plugins/wevu/pageFeatures/moduleAnalysis.d.ts
684
+ //#region src/plugins/wevu/pageFeatures/moduleAnalysis/types.d.ts
685
685
  type FunctionLike = t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression | t.ObjectMethod | {
686
686
  type: string;
687
687
  [key: string]: any;
package/dist/index.mjs CHANGED
@@ -13,6 +13,7 @@ import os from "node:os";
13
13
  import process from "node:process";
14
14
  import { collectFeatureFlagsFromCode, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
15
15
  import { LRUCache } from "lru-cache";
16
+ import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_LAYOUT_HOSTS_KEY, WEVU_LAYOUT_HOST_ID_PREFIX, WEVU_LAYOUT_HOST_REF_PREFIX, WEVU_MODEL_HANDLER, WEVU_OWNER_HANDLER, WEVU_PROPS_KEY, WEVU_SLOT_OWNER_ATTR, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_PROPS_DATA_KEY, WEVU_SLOT_PROPS_KEY, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY, WEVU_TEMPLATE_REFS_KEY } from "@weapp-core/constants";
16
17
  import { compileScript, parse } from "vue/compiler-sfc";
17
18
  import { fileURLToPath } from "node:url";
18
19
  import { parse as parse$1 } from "@vue/compiler-dom";
@@ -845,7 +846,7 @@ function collectWevuPageFeatureFlagsFromCode(code, options) {
845
846
  }
846
847
  }
847
848
  //#endregion
848
- //#region src/plugins/wevu/pageFeatures/moduleAnalysis.ts
849
+ //#region src/plugins/wevu/pageFeatures/moduleAnalysis/shared.ts
849
850
  function createEmptyModuleAnalysis(id, engine) {
850
851
  return {
851
852
  id,
@@ -870,6 +871,15 @@ function getFunctionLikeFromExpression(node) {
870
871
  if (t.isFunctionExpression(node) || t.isArrowFunctionExpression(node)) return node;
871
872
  return null;
872
873
  }
874
+ function isOxcFunctionLike(node) {
875
+ return node?.type === "FunctionDeclaration" || node?.type === "FunctionExpression" || node?.type === "ArrowFunctionExpression";
876
+ }
877
+ function getImportedSpecifierName(node) {
878
+ if (node?.type === "Identifier") return node.name;
879
+ if ((node?.type === "StringLiteral" || node?.type === "Literal") && typeof node.value === "string") return node.value;
880
+ }
881
+ //#endregion
882
+ //#region src/plugins/wevu/pageFeatures/moduleAnalysis/babel.ts
873
883
  function createModuleAnalysis(id, ast) {
874
884
  const localFunctions = /* @__PURE__ */ new Map();
875
885
  const exports = /* @__PURE__ */ new Map();
@@ -999,13 +1009,8 @@ function createModuleAnalysis(id, ast) {
999
1009
  exports
1000
1010
  };
1001
1011
  }
1002
- function isOxcFunctionLike(node) {
1003
- return node?.type === "FunctionDeclaration" || node?.type === "FunctionExpression" || node?.type === "ArrowFunctionExpression";
1004
- }
1005
- function getImportedSpecifierName(node) {
1006
- if (node?.type === "Identifier") return node.name;
1007
- if ((node?.type === "StringLiteral" || node?.type === "Literal") && typeof node.value === "string") return node.value;
1008
- }
1012
+ //#endregion
1013
+ //#region src/plugins/wevu/pageFeatures/moduleAnalysis/oxc.ts
1009
1014
  function resolveOxcParseFilename(id) {
1010
1015
  if (path.extname(id)) return id;
1011
1016
  return `${id}.js`;
@@ -1133,6 +1138,8 @@ function createModuleAnalysisWithOxc(id, code) {
1133
1138
  exports
1134
1139
  };
1135
1140
  }
1141
+ //#endregion
1142
+ //#region src/plugins/wevu/pageFeatures/moduleAnalysis/index.ts
1136
1143
  function createModuleAnalysisFromCode(id, code, options) {
1137
1144
  const engine = options?.astEngine ?? "babel";
1138
1145
  const cacheKey = createModuleAnalysisCacheKey(id, engine);
@@ -2204,13 +2211,13 @@ function createValidIdentifier(name, fallback) {
2204
2211
  function buildNormalizedExpression(binding, helpers) {
2205
2212
  if (binding.type === "bind") {
2206
2213
  const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.identifier("undefined");
2207
- return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(exp)]), t.catchClause(t.identifier("__wv_expr_err"), t.blockStatement([t.returnStatement(t.identifier("undefined"))])), null)])), []);
2214
+ return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(exp)]), t.catchClause(t.identifier(WEVU_EXPRESSION_ERROR_IDENTIFIER), t.blockStatement([t.returnStatement(t.identifier("undefined"))])), null)])), []);
2208
2215
  }
2209
2216
  const normalizeHelper = binding.type === "class" ? helpers.normalizeClass : helpers.normalizeStyle;
2210
2217
  const errorFallback = binding.errorFallback ?? "";
2211
2218
  const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.stringLiteral("");
2212
2219
  const normalizedCall = t.callExpression(t.cloneNode(normalizeHelper), [exp]);
2213
- return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.identifier("__wv_expr_err"), t.blockStatement([t.returnStatement(t.stringLiteral(errorFallback))])), null)])), []);
2220
+ return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.identifier(WEVU_EXPRESSION_ERROR_IDENTIFIER), t.blockStatement([t.returnStatement(t.stringLiteral(errorFallback))])), null)])), []);
2214
2221
  }
2215
2222
  function buildArrayMapExpression(binding, forStack, level, listId, helpers) {
2216
2223
  const itemParam = createValidIdentifier(forStack[level].item, `__wv_item_${level}`);
@@ -2574,7 +2581,7 @@ function buildMethodsMergeFromSpreadSources(componentExpr, inlineMapExpr) {
2574
2581
  return t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("assign")), [
2575
2582
  t.objectExpression([]),
2576
2583
  ...spreadSources,
2577
- t.objectExpression([t.objectProperty(createStaticObjectKey$1("__weapp_vite_inline_map"), inlineMapExpr)])
2584
+ t.objectExpression([t.objectProperty(createStaticObjectKey$1(WEVU_INLINE_MAP_KEY), inlineMapExpr)])
2578
2585
  ]);
2579
2586
  }
2580
2587
  function injectInlineExpressions(componentExpr, inlineExpressions) {
@@ -2587,13 +2594,13 @@ function injectInlineExpressions(componentExpr, inlineExpressions) {
2587
2594
  componentExpr.properties.push(t.objectProperty(createStaticObjectKey$1("methods"), mergedMethods));
2588
2595
  return true;
2589
2596
  }
2590
- componentExpr.properties.push(t.objectProperty(createStaticObjectKey$1("methods"), t.objectExpression([t.objectProperty(createStaticObjectKey$1("__weapp_vite_inline_map"), inlineMapExpr)])));
2597
+ componentExpr.properties.push(t.objectProperty(createStaticObjectKey$1("methods"), t.objectExpression([t.objectProperty(createStaticObjectKey$1(WEVU_INLINE_MAP_KEY), inlineMapExpr)])));
2591
2598
  return true;
2592
2599
  }
2593
2600
  if (!t.isObjectExpression(methodsProp.value)) return false;
2594
- const mapProp = getObjectPropertyByKey$1(methodsProp.value, "__weapp_vite_inline_map");
2601
+ const mapProp = getObjectPropertyByKey$1(methodsProp.value, WEVU_INLINE_MAP_KEY);
2595
2602
  if (!mapProp) {
2596
- methodsProp.value.properties.push(t.objectProperty(createStaticObjectKey$1("__weapp_vite_inline_map"), inlineMapExpr));
2603
+ methodsProp.value.properties.push(t.objectProperty(createStaticObjectKey$1(WEVU_INLINE_MAP_KEY), inlineMapExpr));
2597
2604
  return true;
2598
2605
  }
2599
2606
  if (t.isObjectExpression(mapProp.value)) {
@@ -2616,8 +2623,8 @@ function injectLayoutHosts(optionsObject, bindings, warn) {
2616
2623
  const warnHandler = resolveWarnHandler(warn);
2617
2624
  const entries = bindings.map((binding) => buildLayoutHostEntry(binding));
2618
2625
  const hostsArray = t.arrayExpression(entries);
2619
- const key = createStaticObjectKey$1("__wevuLayoutHosts");
2620
- const existing = getObjectPropertyByKey$1(optionsObject, "__wevuLayoutHosts");
2626
+ const key = createStaticObjectKey$1(WEVU_LAYOUT_HOSTS_KEY);
2627
+ const existing = getObjectPropertyByKey$1(optionsObject, WEVU_LAYOUT_HOSTS_KEY);
2621
2628
  if (!existing) {
2622
2629
  optionsObject.properties.push(t.objectProperty(key, hostsArray));
2623
2630
  return true;
@@ -2630,7 +2637,7 @@ function injectLayoutHosts(optionsObject, bindings, warn) {
2630
2637
  existing.value = t.arrayExpression([...entries, t.spreadElement(t.cloneNode(existing.value, true))]);
2631
2638
  return true;
2632
2639
  }
2633
- warnHandler("无法自动注入 layout host 元数据,请手动合并 __wevuLayoutHosts。");
2640
+ warnHandler(`无法自动注入 layout host 元数据,请手动合并 ${WEVU_LAYOUT_HOSTS_KEY}。`);
2634
2641
  return false;
2635
2642
  }
2636
2643
  //#endregion
@@ -2754,8 +2761,8 @@ function injectTemplateRefs(optionsObject, bindings, warn) {
2754
2761
  const warnHandler = resolveWarnHandler(warn);
2755
2762
  const entries = bindings.map((binding) => buildTemplateRefEntry(binding));
2756
2763
  const refsArray = t.arrayExpression(entries);
2757
- const key = createStaticObjectKey$1("__wevuTemplateRefs");
2758
- const existing = getObjectPropertyByKey$1(optionsObject, "__wevuTemplateRefs");
2764
+ const key = createStaticObjectKey$1(WEVU_TEMPLATE_REFS_KEY);
2765
+ const existing = getObjectPropertyByKey$1(optionsObject, WEVU_TEMPLATE_REFS_KEY);
2759
2766
  if (!existing) {
2760
2767
  optionsObject.properties.push(t.objectProperty(key, refsArray));
2761
2768
  return true;
@@ -2768,7 +2775,7 @@ function injectTemplateRefs(optionsObject, bindings, warn) {
2768
2775
  existing.value = t.arrayExpression([...entries, t.spreadElement(t.cloneNode(existing.value, true))]);
2769
2776
  return true;
2770
2777
  }
2771
- warnHandler("无法自动注入 template ref 元数据,请手动合并 __wevuTemplateRefs。");
2778
+ warnHandler(`无法自动注入 template ref 元数据,请手动合并 ${WEVU_TEMPLATE_REFS_KEY}。`);
2772
2779
  return false;
2773
2780
  }
2774
2781
  //#endregion
@@ -2875,9 +2882,9 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
2875
2882
  const exportPath = state.defaultExportPath;
2876
2883
  const componentExpr = resolveComponentExpression(exportPath.node.declaration, state.defineComponentDecls, state.defineComponentAliases);
2877
2884
  const componentOptionsObject = resolveComponentOptionsObject(componentExpr);
2878
- const hasPageMarker = componentExpr ? hasStaticPropertyInComponentExpression(componentExpr, "__wevu_isPage", ast.program) : false;
2885
+ const hasPageMarker = componentExpr ? hasStaticPropertyInComponentExpression(componentExpr, WEVU_IS_PAGE_KEY, ast.program) : false;
2879
2886
  if (componentOptionsObject && options?.isPage && !options?.isApp && !hasPageMarker) {
2880
- componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier("__wevu_isPage"), t.booleanLiteral(true)));
2887
+ componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier(WEVU_IS_PAGE_KEY), t.booleanLiteral(true)));
2881
2888
  transformed = true;
2882
2889
  }
2883
2890
  if (componentOptionsObject && enabledPageFeatures.size) transformed = injectWevuPageFeatureFlagsIntoOptionsObject(componentOptionsObject, enabledPageFeatures) || transformed;
@@ -3638,7 +3645,7 @@ function compileEventAttribute(name, value, context) {
3638
3645
  if (t.isIdentifier(exp)) return [`${bindAttr}="${escapeAttr(exp.name)}"`];
3639
3646
  if (t.isMemberExpression(exp) && !exp.computed && t.isThisExpression(exp.object) && t.isIdentifier(exp.property)) return [`${bindAttr}="${escapeAttr(exp.property.name)}"`];
3640
3647
  const inline = registerInlineExpression$1(exp, context);
3641
- const attrs = [`data-wi-${eventSuffix}="${inline.id}"`, `${bindAttr}="__weapp_vite_inline"`];
3648
+ const attrs = [`data-wi-${eventSuffix}="${inline.id}"`, `${bindAttr}="${WEVU_INLINE_HANDLER}"`];
3642
3649
  inline.scopeKeys.forEach((scopeKey, index) => {
3643
3650
  attrs.push(`data-wv-s${index}="${renderMustache$1(scopeKey, context)}"`);
3644
3651
  });
@@ -4344,11 +4351,11 @@ function generateHash(str) {
4344
4351
  /**
4345
4352
  * class/style WXS 模块名。
4346
4353
  */
4347
- const CLASS_STYLE_WXS_MODULE = "__weapp_vite";
4354
+ const CLASS_STYLE_WXS_MODULE = WEVU_CLASS_STYLE_RUNTIME_MODULE;
4348
4355
  /**
4349
4356
  * class/style WXS 文件名(不含扩展名)。
4350
4357
  */
4351
- const CLASS_STYLE_WXS_FILE = "__weapp_vite_class_style";
4358
+ const CLASS_STYLE_WXS_FILE = WEVU_CLASS_STYLE_RUNTIME_FILE;
4352
4359
  function resolveScriptModuleTag(extension) {
4353
4360
  return (extension.startsWith(".") ? extension.slice(1) : extension) === "sjs" ? "sjs" : "wxs";
4354
4361
  }
@@ -4357,7 +4364,7 @@ function resolveScriptModuleTag(extension) {
4357
4364
  */
4358
4365
  function buildClassStyleWxsTag(extension, src) {
4359
4366
  const normalized = extension.startsWith(".") ? extension.slice(1) : extension;
4360
- const resolvedSrc = src ?? `./__weapp_vite_class_style.${normalized}`;
4367
+ const resolvedSrc = src ?? `./${CLASS_STYLE_WXS_FILE}.${normalized}`;
4361
4368
  return `<${resolveScriptModuleTag(normalized)} module="${CLASS_STYLE_WXS_MODULE}" src="${resolvedSrc}"/>`;
4362
4369
  }
4363
4370
  /**
@@ -4935,10 +4942,22 @@ function withSlotProps(context, mapping, fn) {
4935
4942
  }
4936
4943
  }
4937
4944
  const IDENTIFIER_RE$3 = /^[A-Z_$][\w$]*$/i;
4945
+ const BIND_SHORTHAND_ARG_RE = /^[A-Z_$][\w$]*(?:-[A-Z_$][\w$]*)*$/i;
4938
4946
  const BACKSLASH_RE$2 = /\\/g;
4939
4947
  const SINGLE_QUOTE_RE$2 = /'/g;
4940
4948
  const CR_RE$1 = /\r/g;
4941
4949
  const LF_RE$1 = /\n/g;
4950
+ function camelizeBindShorthandArg(value) {
4951
+ return value.replace(/-([\w$])/g, (_, char) => char.toUpperCase());
4952
+ }
4953
+ function getBindDirectiveExpression(node) {
4954
+ const rawExp = node.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? node.exp.content : "";
4955
+ if (rawExp) return rawExp;
4956
+ if (node.name !== "bind" || node.arg?.type !== NodeTypes.SIMPLE_EXPRESSION || !node.arg.isStatic) return "";
4957
+ const rawArg = node.arg.content.trim();
4958
+ if (!rawArg || !BIND_SHORTHAND_ARG_RE.test(rawArg)) return "";
4959
+ return camelizeBindShorthandArg(rawArg);
4960
+ }
4942
4961
  function collectScopePropMapping(context) {
4943
4962
  const mapping = {};
4944
4963
  if (!context.slotMultipleInstance) return mapping;
@@ -4948,15 +4967,15 @@ function collectScopePropMapping(context) {
4948
4967
  }
4949
4968
  return mapping;
4950
4969
  }
4970
+ function toWxmlStringLiteral$1(value) {
4971
+ return `'${value.replace(BACKSLASH_RE$2, "\\\\").replace(SINGLE_QUOTE_RE$2, "\\'").replace(CR_RE$1, "\\r").replace(LF_RE$1, "\\n")}'`;
4972
+ }
4951
4973
  function buildScopePropsExpression(context) {
4952
4974
  const mapping = collectScopePropMapping(context);
4953
4975
  const keys = Object.keys(mapping);
4954
4976
  if (!keys.length) return null;
4955
4977
  return `[${keys.map((key) => `${toWxmlStringLiteral$1(key)},${key}`).join(",")}]`;
4956
4978
  }
4957
- function toWxmlStringLiteral$1(value) {
4958
- return `'${value.replace(BACKSLASH_RE$2, "\\\\").replace(SINGLE_QUOTE_RE$2, "\\'").replace(CR_RE$1, "\\r").replace(LF_RE$1, "\\n")}'`;
4959
- }
4960
4979
  function hashString(input) {
4961
4980
  let hash = 0;
4962
4981
  for (let i = 0; i < input.length; i++) {
@@ -5000,10 +5019,10 @@ const SCOPED_SLOT_GLOBALS = new Set([
5000
5019
  "encodeURIComponent",
5001
5020
  "require",
5002
5021
  "arguments",
5003
- "__wvOwner",
5004
- "__wvSlotProps",
5005
- "__wvSlotPropsData",
5006
- "__weapp_vite"
5022
+ WEVU_SLOT_OWNER_KEY,
5023
+ WEVU_SLOT_PROPS_KEY,
5024
+ WEVU_SLOT_PROPS_DATA_KEY,
5025
+ WEVU_CLASS_STYLE_RUNTIME_MODULE
5007
5026
  ]);
5008
5027
  function collectScopedSlotLocals(context) {
5009
5028
  const locals = /* @__PURE__ */ new Set();
@@ -5060,10 +5079,10 @@ function rewriteScopedSlotExpression(exp, context) {
5060
5079
  }
5061
5080
  if (locals.has(name)) return;
5062
5081
  if (Object.hasOwn(slotProps, name)) {
5063
- replaceIdentifierWithExpression(path, createMemberAccess("__wvSlotPropsData", slotProps[name]));
5082
+ replaceIdentifierWithExpression(path, createMemberAccess(WEVU_SLOT_PROPS_DATA_KEY, slotProps[name]));
5064
5083
  return;
5065
5084
  }
5066
- replaceIdentifierWithExpression(path, createMemberAccess("__wvOwner", name));
5085
+ replaceIdentifierWithExpression(path, createMemberAccess(WEVU_SLOT_OWNER_KEY, name));
5067
5086
  } });
5068
5087
  const stmt = ast.program.body[0];
5069
5088
  const updatedExpression = stmt && "expression" in stmt ? stmt.expression : null;
@@ -5157,7 +5176,7 @@ function normalizeStyleBindingExpression(exp, context) {
5157
5176
  return null;
5158
5177
  };
5159
5178
  const buildStylePair = (keyExpr, valueExpr) => {
5160
- return t.callExpression(t.memberExpression(t.identifier("__weapp_vite"), t.identifier("stylePair")), [keyExpr, valueExpr]);
5179
+ return t.callExpression(t.memberExpression(t.identifier(WEVU_CLASS_STYLE_RUNTIME_MODULE), t.identifier("stylePair")), [keyExpr, valueExpr]);
5161
5180
  };
5162
5181
  const visit = (node) => {
5163
5182
  if (!node) return;
@@ -5223,7 +5242,7 @@ const INLINE_GLOBALS = new Set([
5223
5242
  "encodeURIComponent",
5224
5243
  "require",
5225
5244
  "arguments",
5226
- "__weapp_vite",
5245
+ WEVU_CLASS_STYLE_RUNTIME_MODULE,
5227
5246
  "__wevuUnref",
5228
5247
  "globalThis",
5229
5248
  "setTimeout",
@@ -5250,8 +5269,8 @@ function createMemberAccess$1(target, prop) {
5250
5269
  function resolveSlotPropBinding(slotProps, name) {
5251
5270
  if (!Object.hasOwn(slotProps, name)) return null;
5252
5271
  const prop = slotProps[name];
5253
- if (!prop) return "__wvSlotPropsData";
5254
- return generateExpression(createMemberAccess$1("__wvSlotPropsData", prop));
5272
+ if (!prop) return WEVU_SLOT_PROPS_DATA_KEY;
5273
+ return generateExpression(createMemberAccess$1(WEVU_SLOT_PROPS_DATA_KEY, prop));
5255
5274
  }
5256
5275
  function rewriteExpressionAst(ast, locals, options) {
5257
5276
  traverse(ast, {
@@ -5434,12 +5453,12 @@ function createHasOwnPropertyCall(target, key) {
5434
5453
  }
5435
5454
  function createIdentifierAccessWithPropsFallback(name) {
5436
5455
  if (name === "props") {
5437
- const propsObject = createThisMemberAccess("__wevuProps");
5456
+ const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5438
5457
  return t.conditionalExpression(t.binaryExpression("!=", propsObject, t.nullLiteral()), propsObject, createThisMemberAccess("props"));
5439
5458
  }
5440
5459
  const thisAccess = createThisMemberAccess(name);
5441
- const propsAccess = createMemberAccess(createThisMemberAccess("__wevuProps"), name);
5442
- const propsObject = createThisMemberAccess("__wevuProps");
5460
+ const propsAccess = createMemberAccess(createThisMemberAccess(WEVU_PROPS_KEY), name);
5461
+ const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
5443
5462
  const stateObject = createThisMemberAccess("$state");
5444
5463
  const hasPropsObject = t.binaryExpression("!=", propsObject, t.nullLiteral());
5445
5464
  const hasDefinedPropsValue = t.binaryExpression("!==", propsAccess, t.identifier("undefined"));
@@ -5496,10 +5515,10 @@ function normalizeJsExpressionWithContext(exp, context, options) {
5496
5515
  let replacement;
5497
5516
  if (context.rewriteScopedSlot) if (Object.hasOwn(slotProps, name)) {
5498
5517
  const prop = slotProps[name];
5499
- const base = createThisMemberAccess("__wvSlotPropsData");
5518
+ const base = createThisMemberAccess(WEVU_SLOT_PROPS_DATA_KEY);
5500
5519
  replacement = createUnrefCall(prop ? createMemberAccess(base, prop) : base);
5501
- } else if (name === "__wvOwner" || name === "__wvSlotPropsData" || name === "__wvSlotProps" || name === "__wvSlotScope") replacement = createUnrefCall(createThisMemberAccess(name));
5502
- else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess("__wvOwner"), name));
5520
+ } else if (name === WEVU_SLOT_OWNER_KEY || name === WEVU_SLOT_PROPS_DATA_KEY || name === WEVU_SLOT_PROPS_KEY || name === WEVU_SLOT_SCOPE_KEY) replacement = createUnrefCall(createThisMemberAccess(name));
5521
+ else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_KEY), name));
5503
5522
  else replacement = createUnrefCall(createIdentifierAccessWithPropsFallback(name));
5504
5523
  const parent = path.parentPath;
5505
5524
  if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
@@ -5650,7 +5669,7 @@ function renderClassAttribute(staticClass, dynamicClassExp, context) {
5650
5669
  for (const part of normalizedParts) parts.push(`(${part})`);
5651
5670
  const mergedExp = parts.length > 1 ? `[${parts.join(",")}]` : parts[0];
5652
5671
  context.classStyleWxs = true;
5653
- return `class="${renderMustache(`__weapp_vite.cls(${mergedExp})`, context)}"`;
5672
+ return `class="${renderMustache(`${WEVU_CLASS_STYLE_RUNTIME_MODULE}.cls(${mergedExp})`, context)}"`;
5654
5673
  }
5655
5674
  const jsParts = [];
5656
5675
  if (staticValue) jsParts.push(t.stringLiteral(staticValue));
@@ -5678,7 +5697,7 @@ function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
5678
5697
  }
5679
5698
  const mergedExp = parts.length > 1 ? `[${parts.join(",")}]` : parts[0] || "''";
5680
5699
  context.classStyleWxs = true;
5681
- return `style="${renderMustache(`__weapp_vite.style(${mergedExp})`, context)}"`;
5700
+ return `style="${renderMustache(`${WEVU_CLASS_STYLE_RUNTIME_MODULE}.style(${mergedExp})`, context)}"`;
5682
5701
  }
5683
5702
  const jsParts = [];
5684
5703
  if (staticValue) jsParts.push(t.stringLiteral(staticValue));
@@ -5728,11 +5747,10 @@ const SIMPLE_MEMBER_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
5728
5747
  const isSimpleIdentifier = (value) => SIMPLE_IDENTIFIER_RE$1.test(value);
5729
5748
  const isSimpleMemberPath = (value) => SIMPLE_MEMBER_PATH_RE.test(value);
5730
5749
  function transformBindDirective(node, context, forInfo) {
5731
- const { exp, arg } = node;
5750
+ const { arg } = node;
5732
5751
  if (!arg) return null;
5733
5752
  const argValue = arg.type === NodeTypes.SIMPLE_EXPRESSION ? arg.content : "";
5734
- if (!exp) return null;
5735
- const rawExpValue = exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content : "";
5753
+ const rawExpValue = getBindDirectiveExpression(node);
5736
5754
  if (!rawExpValue) return null;
5737
5755
  if (argValue === "key") {
5738
5756
  const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context);
@@ -5811,7 +5829,7 @@ const QUOTE_RE$1 = /"/g;
5811
5829
  function transformVModel(element, expValue, context) {
5812
5830
  const escapedModel = expValue.replace(QUOTE_RE$1, "&quot;");
5813
5831
  const bindModel = (event) => {
5814
- return `${context.platform.eventBindingAttr(event)}="__weapp_vite_model" data-wv-model="${escapedModel}"`;
5832
+ return `${context.platform.eventBindingAttr(event)}="${WEVU_MODEL_HANDLER}" data-wv-model="${escapedModel}"`;
5815
5833
  };
5816
5834
  if (!element) return `value="${renderMustache(expValue, context)}" ${bindModel("input")}`;
5817
5835
  const tag = element.tag;
@@ -5891,17 +5909,17 @@ function transformOnDirective(node, context, options) {
5891
5909
  `data-wi-${eventSuffix}="${inlineExpression.id}"`,
5892
5910
  ...scopeAttrs,
5893
5911
  ...indexAttrs,
5894
- `${bindAttr}="__weapp_vite_owner"`
5912
+ `${bindAttr}="${WEVU_OWNER_HANDLER}"`
5895
5913
  ].filter(Boolean).join(" ");
5896
5914
  }
5897
5915
  if (!isInlineExpression && rawExpValue) return [
5898
5916
  detailAttr,
5899
5917
  `data-wh-${eventSuffix}="${rawExpValue}"`,
5900
- `${bindAttr}="__weapp_vite_owner"`
5918
+ `${bindAttr}="${WEVU_OWNER_HANDLER}"`
5901
5919
  ].filter(Boolean).join(" ");
5902
5920
  if (isInlineExpression) {
5903
5921
  context.warnings.push("作用域插槽的事件处理解析失败,请使用简单的方法引用。");
5904
- return [detailAttr, `${bindAttr}="__weapp_vite_owner"`].filter(Boolean).join(" ");
5922
+ return [detailAttr, `${bindAttr}="${WEVU_OWNER_HANDLER}"`].filter(Boolean).join(" ");
5905
5923
  }
5906
5924
  }
5907
5925
  const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context);
@@ -5913,13 +5931,13 @@ function transformOnDirective(node, context, options) {
5913
5931
  `data-wi-${eventSuffix}="${inlineExpression.id}"`,
5914
5932
  ...scopeAttrs,
5915
5933
  ...indexAttrs,
5916
- `${bindAttr}="__weapp_vite_inline"`
5934
+ `${bindAttr}="${WEVU_INLINE_HANDLER}"`
5917
5935
  ].filter(Boolean).join(" ");
5918
5936
  }
5919
5937
  if (isInlineExpression) return [
5920
5938
  detailAttr,
5921
5939
  `data-wv-inline-${eventSuffix}="${inlineSource.replace(QUOTE_RE, "&quot;")}"`,
5922
- `${bindAttr}="__weapp_vite_inline"`
5940
+ `${bindAttr}="${WEVU_INLINE_HANDLER}"`
5923
5941
  ].filter(Boolean).join(" ");
5924
5942
  return [detailAttr, `${bindAttr}="${expValue}"`].filter(Boolean).join(" ");
5925
5943
  }
@@ -6006,7 +6024,7 @@ function collectElementAttributes(node, context, options) {
6006
6024
  if (prop.type === NodeTypes.DIRECTIVE) {
6007
6025
  if (options?.skipSlotDirective && prop.name === "slot") continue;
6008
6026
  if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "ref") {
6009
- const rawExp = prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : "";
6027
+ const rawExp = getBindDirectiveExpression(prop);
6010
6028
  if (rawExp) {
6011
6029
  const expAst = normalizeJsExpressionWithContext(rawExp, context, { hint: "ref 绑定" });
6012
6030
  if (expAst) templateRef = { expAst };
@@ -6018,12 +6036,12 @@ function collectElementAttributes(node, context, options) {
6018
6036
  context.warnings.push("暂不支持动态 layout-host,已忽略该绑定。");
6019
6037
  continue;
6020
6038
  }
6021
- if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "class" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
6022
- dynamicClassExp = prop.exp.content;
6039
+ if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "class") {
6040
+ dynamicClassExp = getBindDirectiveExpression(prop) || void 0;
6023
6041
  continue;
6024
6042
  }
6025
- if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "style" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
6026
- dynamicStyleExp = prop.exp.content;
6043
+ if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "style") {
6044
+ dynamicStyleExp = getBindDirectiveExpression(prop) || void 0;
6027
6045
  continue;
6028
6046
  }
6029
6047
  if (prop.name === "show" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
@@ -6053,8 +6071,8 @@ function collectElementAttributes(node, context, options) {
6053
6071
  if (layoutHostKey) if (!staticId && hasDynamicIdBinding) context.warnings.push("layout-host 暂不支持与动态 id 同时使用,当前节点已忽略。");
6054
6072
  else {
6055
6073
  const hostIndex = context.layoutHostIndexSeed++;
6056
- const hostId = staticId || `__wv-layout-host-${hostIndex}`;
6057
- const hostRefName = `__wevu_layout_host_${hostIndex}`;
6074
+ const hostId = staticId || `${WEVU_LAYOUT_HOST_ID_PREFIX}${hostIndex}`;
6075
+ const hostRefName = `${WEVU_LAYOUT_HOST_REF_PREFIX}${hostIndex}`;
6058
6076
  staticId = hostId;
6059
6077
  context.templateRefs.push({
6060
6078
  selector: `#${hostId}`,
@@ -6137,7 +6155,7 @@ function collectSlotBindingExpression(node, context) {
6137
6155
  if (prop.type === NodeTypes.ATTRIBUTE && prop.name === "name") continue;
6138
6156
  if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") {
6139
6157
  if (prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
6140
- const rawExpValue = prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : "";
6158
+ const rawExpValue = getBindDirectiveExpression(prop);
6141
6159
  if (prop.arg.content === "name") continue;
6142
6160
  if (rawExpValue) namedBindings.push({
6143
6161
  key: prop.arg.content,
@@ -6195,7 +6213,7 @@ function resolveSlotNameFromSlotElement(node) {
6195
6213
  }
6196
6214
  if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") {
6197
6215
  if (prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "name") {
6198
- const raw = prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : "";
6216
+ const raw = getBindDirectiveExpression(prop);
6199
6217
  if (raw) return {
6200
6218
  type: "dynamic",
6201
6219
  exp: raw
@@ -6290,8 +6308,8 @@ function transformSlotElement(node, context, transformNode) {
6290
6308
  const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
6291
6309
  context.componentGenerics[genericKey] = true;
6292
6310
  slotPropsExp = slotPropsExp ?? "[]";
6293
- const scopedAttrs = [`__wv-owner-id="${renderMustache("__wvSlotOwnerId", context)}"`, `__wv-slot-props="${renderMustache(slotPropsExp, context)}"`];
6294
- if (context.slotMultipleInstance) scopedAttrs.push(`__wv-slot-scope="${renderMustache("__wvSlotScope", context)}"`);
6311
+ const scopedAttrs = [`${WEVU_SLOT_OWNER_ATTR}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`, `${WEVU_SLOT_PROPS_ATTR}="${renderMustache(slotPropsExp, context)}"`];
6312
+ if (context.slotMultipleInstance) scopedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(WEVU_SLOT_SCOPE_KEY, context)}"`);
6295
6313
  return `${slotTag}${`<${genericKey}${scopedAttrs.length ? ` ${scopedAttrs.join(" ")}` : ""} />`}`;
6296
6314
  }
6297
6315
  function transformSlotElementPlain(node, context, transformNode) {
@@ -6372,8 +6390,8 @@ function transformComponentWithSlots(node, context, transformNode, options) {
6372
6390
  if (slotNames.length) mergedAttrs.push(`vue-slots="${renderMustache(`[${slotNames.join(",")}]`, context)}"`);
6373
6391
  if (scopedSlotDeclarations.length) {
6374
6392
  const scopePropsExp = buildScopePropsExpression(context);
6375
- if (scopePropsExp) mergedAttrs.push(`__wv-slot-scope="${renderMustache(scopePropsExp, context)}"`);
6376
- mergedAttrs.push(`__wv-slot-owner-id="${renderMustache(`__wvOwnerId || ''`, context)}"`);
6393
+ if (scopePropsExp) mergedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(scopePropsExp, context)}"`);
6394
+ mergedAttrs.push(`${WEVU_SLOT_OWNER_ID_ATTR}="${renderMustache(`${WEVU_SLOT_OWNER_ID_KEY} || ''`, context)}"`);
6377
6395
  }
6378
6396
  const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
6379
6397
  const { tag } = node;
@@ -6434,11 +6452,15 @@ function transformComponentElement(node, context, transformNode) {
6434
6452
  break;
6435
6453
  }
6436
6454
  }
6437
- if (!isDirective || !isDirective.exp) {
6455
+ if (!isDirective) {
6456
+ context.warnings.push("<component> 未提供 :is 绑定,将按普通元素处理。");
6457
+ return transformNormalElement(node, context, transformNode);
6458
+ }
6459
+ const componentVar = getBindDirectiveExpression(isDirective);
6460
+ if (!componentVar) {
6438
6461
  context.warnings.push("<component> 未提供 :is 绑定,将按普通元素处理。");
6439
6462
  return transformNormalElement(node, context, transformNode);
6440
6463
  }
6441
- const componentVar = isDirective.exp.type === NodeTypes.SIMPLE_EXPRESSION ? isDirective.exp.content : "";
6442
6464
  const otherProps = node.props.filter((prop) => prop !== isDirective);
6443
6465
  const attrs = [];
6444
6466
  const slotDirective = findSlotDirective(node);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.15.0",
4
+ "version": "6.15.3",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -43,14 +43,15 @@
43
43
  "dependencies": {
44
44
  "@vue/compiler-core": "^3.5.32",
45
45
  "@vue/compiler-dom": "^3.5.32",
46
- "comment-json": "^4.6.2",
47
- "lru-cache": "^11.3.3",
46
+ "comment-json": "^5.0.0",
47
+ "lru-cache": "^11.3.5",
48
48
  "magic-string": "^0.30.21",
49
49
  "merge": "^2.1.1",
50
50
  "pathe": "^2.0.3",
51
51
  "vue": "^3.5.32",
52
+ "@weapp-core/constants": "0.1.0",
52
53
  "@weapp-core/shared": "3.0.3",
53
- "@weapp-vite/ast": "6.15.0",
54
+ "@weapp-vite/ast": "6.15.3",
54
55
  "rolldown-require": "2.0.13"
55
56
  },
56
57
  "publishConfig": {