@wevu/compiler 6.16.47 → 6.17.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.
Files changed (2) hide show
  1. package/dist/index.mjs +70 -49
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -242,7 +242,7 @@ function resolveWevuInternalImportModuleId(apiName) {
242
242
  }
243
243
  //#endregion
244
244
  //#region src/utils/vueTemplateTags.ts
245
- const RESERVED_VUE_COMPONENT_TAGS = new Set([
245
+ const RESERVED_VUE_COMPONENT_TAGS = /* @__PURE__ */ new Set([
246
246
  "template",
247
247
  "slot",
248
248
  "component",
@@ -490,6 +490,10 @@ function rewriteJsLikeImportsForTempDir(source, fromDir, tempDir) {
490
490
  const sourceNode = p.node?.source;
491
491
  if (sourceNode && t.isStringLiteral(sourceNode)) rewriteLiteral(sourceNode, sourceNode.value);
492
492
  },
493
+ ImportExpression(p) {
494
+ const sourceNode = p.node?.source;
495
+ if (sourceNode && t.isStringLiteral(sourceNode)) rewriteLiteral(sourceNode, sourceNode.value);
496
+ },
493
497
  CallExpression(p) {
494
498
  const callee = p.node?.callee;
495
499
  if (!callee) return;
@@ -614,7 +618,7 @@ const __weapp_defineThemeJson = (config) => (__weapp_json_macro_values.push(conf
614
618
  }
615
619
  //#endregion
616
620
  //#region src/plugins/vue/transform/jsonMacros/parse.ts
617
- const JSON_MACROS = new Set([
621
+ const JSON_MACROS = /* @__PURE__ */ new Set([
618
622
  "defineAppJson",
619
623
  "definePageJson",
620
624
  "defineComponentJson",
@@ -1294,7 +1298,7 @@ function collectWevuPageFeatureFlagsFromCode(code, options) {
1294
1298
  }
1295
1299
  //#endregion
1296
1300
  //#region src/plugins/wevu/pageFeatures/optionsObjects.ts
1297
- const WEVU_FACTORY_NAMES = new Set([WE_VU_RUNTIME_APIS.defineComponent, WE_VU_RUNTIME_APIS.createWevuComponent]);
1301
+ const WEVU_FACTORY_NAMES = /* @__PURE__ */ new Set([WE_VU_RUNTIME_APIS.defineComponent, WE_VU_RUNTIME_APIS.createWevuComponent]);
1298
1302
  const REGEXP_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
1299
1303
  function escapeRegExp(value) {
1300
1304
  return value.replace(REGEXP_META_CHARS_RE, "\\$&");
@@ -1517,6 +1521,11 @@ function getCallCalleeName(callee) {
1517
1521
  object: callee.object.name,
1518
1522
  property: callee.property.name
1519
1523
  };
1524
+ if (t.isOptionalMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) return {
1525
+ type: "member",
1526
+ object: callee.object.name,
1527
+ property: callee.property.name
1528
+ };
1520
1529
  return null;
1521
1530
  }
1522
1531
  function collectCalledBindingsFromFunctionBody(fn, engine = "babel") {
@@ -1562,6 +1571,23 @@ function collectCalledBindingsFromFunctionBody(fn, engine = "babel") {
1562
1571
  }
1563
1572
  //#endregion
1564
1573
  //#region src/plugins/wevu/pageFeatures/reachability/hooks.ts
1574
+ function getMemberHookName(callee) {
1575
+ if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) return {
1576
+ object: callee.object.name,
1577
+ hook: callee.property.name
1578
+ };
1579
+ if (t.isOptionalMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) return {
1580
+ object: callee.object.name,
1581
+ hook: callee.property.name
1582
+ };
1583
+ return null;
1584
+ }
1585
+ function addNamespaceHookFeature(module, callee, enabled) {
1586
+ const memberHook = getMemberHookName(callee);
1587
+ if (!memberHook || !module.wevuNamespaceLocals.has(memberHook.object)) return;
1588
+ const matched = WE_VU_PAGE_HOOK_TO_FEATURE[memberHook.hook];
1589
+ if (matched) enabled.add(matched);
1590
+ }
1565
1591
  function collectWevuHookCallsInFunctionBody(module, fn) {
1566
1592
  const enabled = /* @__PURE__ */ new Set();
1567
1593
  if (module.engine === "oxc") {
@@ -1600,11 +1626,7 @@ function collectWevuHookCallsInFunctionBody(module, fn) {
1600
1626
  if (matched) enabled.add(matched);
1601
1627
  return;
1602
1628
  }
1603
- if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) {
1604
- if (!module.wevuNamespaceLocals.has(callee.object.name)) return;
1605
- const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
1606
- if (matched) enabled.add(matched);
1607
- }
1629
+ addNamespaceHookFeature(module, callee, enabled);
1608
1630
  } else if (t.isOptionalCallExpression(node)) {
1609
1631
  const callee = node.callee;
1610
1632
  if (t.isIdentifier(callee)) {
@@ -1612,11 +1634,7 @@ function collectWevuHookCallsInFunctionBody(module, fn) {
1612
1634
  if (matched) enabled.add(matched);
1613
1635
  return;
1614
1636
  }
1615
- if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property)) {
1616
- if (!module.wevuNamespaceLocals.has(callee.object.name)) return;
1617
- const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
1618
- if (matched) enabled.add(matched);
1619
- }
1637
+ addNamespaceHookFeature(module, callee, enabled);
1620
1638
  }
1621
1639
  });
1622
1640
  return enabled;
@@ -1768,7 +1786,7 @@ async function collectWevuFeaturesFromSetupReachableImports(pageModule, setupFn,
1768
1786
  async function collectWevuFeaturesFromCodeReachableImports(code, options) {
1769
1787
  const { optionsObjects, module } = collectTargetOptionsObjectsFromCode(code, options.id, { astEngine: options.astEngine });
1770
1788
  if (!optionsObjects.length) return /* @__PURE__ */ new Set();
1771
- const moduleCache = new Map([[options.id, module]]);
1789
+ const moduleCache = /* @__PURE__ */ new Map([[options.id, module]]);
1772
1790
  const enabled = /* @__PURE__ */ new Set();
1773
1791
  for (const optionsObject of optionsObjects) {
1774
1792
  const setupFn = getSetupFunctionFromOptionsObject(optionsObject);
@@ -2144,7 +2162,7 @@ function ensureRuntimeImport(program, importedName, localName = importedName) {
2144
2162
  }
2145
2163
  //#endregion
2146
2164
  //#region src/plugins/vue/transform/transformScript/imports.ts
2147
- const INTERNAL_RUNTIME_VALUE_EXPORTS = new Set([
2165
+ const INTERNAL_RUNTIME_VALUE_EXPORTS = /* @__PURE__ */ new Set([
2148
2166
  "addMutationRecorder",
2149
2167
  "batch",
2150
2168
  "computed",
@@ -2314,7 +2332,7 @@ function splitWevuNamedImportsToInternalRuntime(path, program, state) {
2314
2332
  function createImportVisitors(program, state) {
2315
2333
  return { ImportDeclaration(path) {
2316
2334
  if (path.node.source.value === "vue") {
2317
- const movedVueRuntimeAPIs = new Set([
2335
+ const movedVueRuntimeAPIs = /* @__PURE__ */ new Set([
2318
2336
  "useAttrs",
2319
2337
  "useSlots",
2320
2338
  "useModel",
@@ -2475,6 +2493,18 @@ function stripOptionalFromPattern(pattern) {
2475
2493
  }
2476
2494
  //#endregion
2477
2495
  //#region src/plugins/vue/transform/transformScript/macros/stripTypes.ts
2496
+ function stripTypeArguments(node) {
2497
+ let stripped = false;
2498
+ if (node.typeParameters) {
2499
+ node.typeParameters = null;
2500
+ stripped = true;
2501
+ }
2502
+ if (node.typeArguments) {
2503
+ node.typeArguments = null;
2504
+ stripped = true;
2505
+ }
2506
+ return stripped;
2507
+ }
2478
2508
  function createStripTypesVisitors(state) {
2479
2509
  return {
2480
2510
  ExportNamedDeclaration(path) {
@@ -2506,16 +2536,10 @@ function createStripTypesVisitors(state) {
2506
2536
  return;
2507
2537
  }
2508
2538
  }
2509
- if (path.node.typeParameters) {
2510
- path.node.typeParameters = null;
2511
- state.transformed = true;
2512
- }
2539
+ if (stripTypeArguments(path.node)) state.transformed = true;
2513
2540
  },
2514
2541
  NewExpression(path) {
2515
- if (path.node.typeParameters) {
2516
- path.node.typeParameters = null;
2517
- state.transformed = true;
2518
- }
2542
+ if (stripTypeArguments(path.node)) state.transformed = true;
2519
2543
  },
2520
2544
  ObjectProperty(path) {
2521
2545
  if (t.isIdentifier(path.node.key, { name: "__name" }) || t.isStringLiteral(path.node.key, { value: "__name" })) {
@@ -2572,10 +2596,7 @@ function createStripTypesVisitors(state) {
2572
2596
  path.node.returnType = null;
2573
2597
  state.transformed = true;
2574
2598
  }
2575
- if (path.node.typeParameters) {
2576
- path.node.typeParameters = null;
2577
- state.transformed = true;
2578
- }
2599
+ if (stripTypeArguments(path.node)) state.transformed = true;
2579
2600
  for (const param of path.node.params) if (stripOptionalFromPattern(param)) state.transformed = true;
2580
2601
  },
2581
2602
  ClassMethod(path) {
@@ -3444,7 +3465,7 @@ function hasStaticPropertyInComponentExpression(componentExpr, keyName, program)
3444
3465
  if (t.isObjectExpression(expr) && hasStaticPropertyWithSpreads(expr, keyName, program)) return true;
3445
3466
  if (t.isIdentifier(expr)) {
3446
3467
  const resolved = resolveObjectExpressionFromProgram(program, expr.name);
3447
- if (resolved && hasStaticPropertyWithSpreads(resolved, keyName, program, new Set([expr.name]))) return true;
3468
+ if (resolved && hasStaticPropertyWithSpreads(resolved, keyName, program, /* @__PURE__ */ new Set([expr.name]))) return true;
3448
3469
  }
3449
3470
  }
3450
3471
  return false;
@@ -3520,7 +3541,7 @@ function transformScript(source, options) {
3520
3541
  const warn = resolveWarnHandler(options?.warn);
3521
3542
  const state = {
3522
3543
  transformed: false,
3523
- defineComponentAliases: new Set([WE_VU_RUNTIME_APIS.defineComponent, "_defineComponent"]),
3544
+ defineComponentAliases: /* @__PURE__ */ new Set([WE_VU_RUNTIME_APIS.defineComponent, "_defineComponent"]),
3524
3545
  defineComponentDecls: /* @__PURE__ */ new Map(),
3525
3546
  defaultExportPath: null
3526
3547
  };
@@ -3778,7 +3799,7 @@ function stripRenderOptionFromScript(source, filename, warn) {
3778
3799
  } catch {
3779
3800
  return source;
3780
3801
  }
3781
- const defineComponentAliases = new Set(["defineComponent", "_defineComponent"]);
3802
+ const defineComponentAliases = /* @__PURE__ */ new Set(["defineComponent", "_defineComponent"]);
3782
3803
  const defineComponentDecls = /* @__PURE__ */ new Map();
3783
3804
  let removedRender = false;
3784
3805
  let removedJsonMacroImport = false;
@@ -4859,7 +4880,7 @@ function normalizeFsResolvedId(id, options) {
4859
4880
  }
4860
4881
  //#endregion
4861
4882
  //#region src/plugins/utils/vueSfcBlockSrc.ts
4862
- const SCRIPT_LANG_EXT = new Map([
4883
+ const SCRIPT_LANG_EXT = /* @__PURE__ */ new Map([
4863
4884
  [".ts", "ts"],
4864
4885
  [".tsx", "tsx"],
4865
4886
  [".js", "js"],
@@ -4867,7 +4888,7 @@ const SCRIPT_LANG_EXT = new Map([
4867
4888
  [".mjs", "js"],
4868
4889
  [".cjs", "js"]
4869
4890
  ]);
4870
- const STYLE_LANG_EXT = new Map([
4891
+ const STYLE_LANG_EXT = /* @__PURE__ */ new Map([
4871
4892
  [".css", "css"],
4872
4893
  [".scss", "scss"],
4873
4894
  [".sass", "sass"],
@@ -4875,7 +4896,7 @@ const STYLE_LANG_EXT = new Map([
4875
4896
  [".styl", "styl"],
4876
4897
  [".stylus", "styl"]
4877
4898
  ]);
4878
- const TEMPLATE_LANG_EXT = new Map([
4899
+ const TEMPLATE_LANG_EXT = /* @__PURE__ */ new Map([
4879
4900
  [".html", "html"],
4880
4901
  [".htm", "html"],
4881
4902
  [".pug", "pug"],
@@ -5794,7 +5815,7 @@ function findSlotDirective(node) {
5794
5815
  }
5795
5816
  //#endregion
5796
5817
  //#region src/plugins/vue/compiler/template/expression/scopedSlot.ts
5797
- const SCOPED_SLOT_GLOBALS = new Set([
5818
+ const SCOPED_SLOT_GLOBALS = /* @__PURE__ */ new Set([
5798
5819
  "Math",
5799
5820
  "Number",
5800
5821
  "Date",
@@ -6016,7 +6037,7 @@ function normalizeStyleBindingExpression(exp, context) {
6016
6037
  }
6017
6038
  //#endregion
6018
6039
  //#region src/plugins/vue/compiler/template/expression/inline.ts
6019
- const INLINE_GLOBALS = new Set([
6040
+ const INLINE_GLOBALS = /* @__PURE__ */ new Set([
6020
6041
  "Math",
6021
6042
  "Number",
6022
6043
  "Date",
@@ -6063,7 +6084,7 @@ const INLINE_GLOBALS = new Set([
6063
6084
  ]);
6064
6085
  const IDENTIFIER_RE$2 = /^[A-Z_$][\w$]*$/i;
6065
6086
  const SIMPLE_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
6066
- const SCRIPT_SETUP_REF_BINDINGS = new Set(["setup-ref", "setup-maybe-ref"]);
6087
+ const SCRIPT_SETUP_REF_BINDINGS = /* @__PURE__ */ new Set(["setup-ref", "setup-maybe-ref"]);
6067
6088
  function createMemberAccess$1(target, prop) {
6068
6089
  if (IDENTIFIER_RE$2.test(prop)) return t.memberExpression(t.identifier(target), t.identifier(prop));
6069
6090
  return t.memberExpression(t.identifier(target), t.stringLiteral(prop), true);
@@ -6244,7 +6265,7 @@ function registerInlineExpression(exp, context) {
6244
6265
  }
6245
6266
  //#endregion
6246
6267
  //#region src/plugins/vue/compiler/template/expression/js.ts
6247
- const JS_RUNTIME_GLOBALS = new Set([
6268
+ const JS_RUNTIME_GLOBALS = /* @__PURE__ */ new Set([
6248
6269
  "Math",
6249
6270
  "Number",
6250
6271
  "Date",
@@ -6696,7 +6717,7 @@ const SIMPLE_IDENTIFIER_RE$1 = /^[A-Z_$][\w$]*$/i;
6696
6717
  const SIMPLE_MEMBER_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
6697
6718
  const isSimpleIdentifier = (value) => SIMPLE_IDENTIFIER_RE$1.test(value);
6698
6719
  const isSimpleMemberPath = (value) => SIMPLE_MEMBER_PATH_RE.test(value);
6699
- const COMPONENT_NON_PROP_BINDINGS = new Set([
6720
+ const COMPONENT_NON_PROP_BINDINGS = /* @__PURE__ */ new Set([
6700
6721
  "class",
6701
6722
  "style",
6702
6723
  "id",
@@ -6802,7 +6823,7 @@ function transformBindDirective(node, context, forInfo, options) {
6802
6823
  //#region src/plugins/vue/compiler/template/directives/custom.ts
6803
6824
  const IDENTIFIER_RE$1 = /^[a-z_$][\w$]*$/i;
6804
6825
  function transformCustomDirective(name, exp, arg, context) {
6805
- if (new Set([
6826
+ if ((/* @__PURE__ */ new Set([
6806
6827
  "bind",
6807
6828
  "on",
6808
6829
  "model",
@@ -6816,7 +6837,7 @@ function transformCustomDirective(name, exp, arg, context) {
6816
6837
  "slot",
6817
6838
  "cloak",
6818
6839
  "once"
6819
- ]).has(name)) return null;
6840
+ ])).has(name)) return null;
6820
6841
  const dataAttrName = `data-v-${name}`;
6821
6842
  if (exp && exp.type === NodeTypes.SIMPLE_EXPRESSION) {
6822
6843
  const expValue = normalizeWxmlExpressionWithContext(exp.content, context);
@@ -6839,7 +6860,7 @@ function getElementType(element) {
6839
6860
  const QUOTE_RE$1 = /"/g;
6840
6861
  const CAMELIZE_RE = /-([a-z0-9])/gi;
6841
6862
  const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
6842
- const NATIVE_MODEL_TAGS = new Set([
6863
+ const NATIVE_MODEL_TAGS = /* @__PURE__ */ new Set([
6843
6864
  "input",
6844
6865
  "textarea",
6845
6866
  "select",
@@ -8274,7 +8295,7 @@ function transformNode(node, context) {
8274
8295
  }
8275
8296
  //#endregion
8276
8297
  //#region src/plugins/vue/compiler/template.ts
8277
- const HTML_VOID_TAGS = new Set([
8298
+ const HTML_VOID_TAGS = /* @__PURE__ */ new Set([
8278
8299
  "area",
8279
8300
  "base",
8280
8301
  "br",
@@ -8834,7 +8855,7 @@ function isIdentifierLikeKey(key) {
8834
8855
  function getObjectTag(value) {
8835
8856
  return OBJECT_TO_STRING.call(value);
8836
8857
  }
8837
- const SERIALIZABLE_NATIVE_FUNCTIONS = new Map([
8858
+ const SERIALIZABLE_NATIVE_FUNCTIONS = /* @__PURE__ */ new Map([
8838
8859
  [String, "String"],
8839
8860
  [Number, "Number"],
8840
8861
  [Boolean, "Boolean"],
@@ -9245,7 +9266,7 @@ async function parseVueFile(source, filename, options) {
9245
9266
  const resolvedNext = await resolveSfcBlockSrc(nextDescriptor, filename, options.sfcSrc);
9246
9267
  descriptorForCompile = resolvedNext.descriptor;
9247
9268
  if (resolvedNext.deps.length) {
9248
- sfcSrcDeps = [...new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
9269
+ sfcSrcDeps = [.../* @__PURE__ */ new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
9249
9270
  meta.sfcSrcDeps = sfcSrcDeps;
9250
9271
  }
9251
9272
  } else descriptorForCompile = nextDescriptor;
@@ -9282,7 +9303,7 @@ async function parseVueFile(source, filename, options) {
9282
9303
  const resolvedNext = await resolveSfcBlockSrc(nextDescriptor, filename, options.sfcSrc);
9283
9304
  descriptorForCompile = resolvedNext.descriptor;
9284
9305
  if (resolvedNext.deps.length) {
9285
- sfcSrcDeps = [...new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
9306
+ sfcSrcDeps = [.../* @__PURE__ */ new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
9286
9307
  meta.sfcSrcDeps = sfcSrcDeps;
9287
9308
  }
9288
9309
  } else descriptorForCompile = nextDescriptor;
@@ -9316,7 +9337,7 @@ function composeSourceMaps(transformedMap, originalMap) {
9316
9337
  }
9317
9338
  //#endregion
9318
9339
  //#region src/plugins/vue/transform/compileVueFile/reservedProps.ts
9319
- const RESERVED_SCRIPT_SETUP_PROPS = new Set([
9340
+ const RESERVED_SCRIPT_SETUP_PROPS = /* @__PURE__ */ new Set([
9320
9341
  "id",
9321
9342
  "class",
9322
9343
  "slot"
@@ -9402,7 +9423,7 @@ function detectDefinePropsReservedName(scriptSetupCode) {
9402
9423
  path.stop();
9403
9424
  return;
9404
9425
  }
9405
- const typeParam = path.node.typeParameters?.params?.[0];
9426
+ const typeParam = (path.node.typeParameters ?? path.node.typeArguments)?.params?.[0];
9406
9427
  if (typePropsContainReservedName(typeParam, typeScope)) {
9407
9428
  result = { location: getDefinePropsLocation(path.node) };
9408
9429
  path.stop();
@@ -9454,7 +9475,7 @@ function resolveScriptSetupPropsDerivedKeys(bindings) {
9454
9475
  }
9455
9476
  function collectScriptSetupReturnInfo(scriptCode) {
9456
9477
  const keys = /* @__PURE__ */ new Set();
9457
- const propsObjectAliases = new Set(["__props"]);
9478
+ const propsObjectAliases = /* @__PURE__ */ new Set(["__props"]);
9458
9479
  const propsRefsAliases = /* @__PURE__ */ new Set();
9459
9480
  const destructuredPropsKeys = /* @__PURE__ */ new Set();
9460
9481
  const addObjectPatternKeys = (pattern) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.16.47",
4
+ "version": "6.17.1",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "vue": "^3.5.38",
53
53
  "@weapp-core/constants": "0.1.12",
54
54
  "@weapp-core/shared": "3.0.4",
55
- "@weapp-vite/ast": "6.16.47",
55
+ "@weapp-vite/ast": "6.17.1",
56
56
  "rolldown-require": "2.0.19"
57
57
  },
58
58
  "publishConfig": {