@wevu/compiler 6.19.0 → 6.19.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 +29 -15
  2. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -565,7 +565,8 @@ function resolveMacroAlias(macroName) {
565
565
  }
566
566
  async function evaluateScriptSetupJsonMacro(params) {
567
567
  const { preambleContent, originalContent, filename, lang, macroName, macroStatements, bodyPaths, keptStatementPaths, options } = params;
568
- const ms = new MagicString(preambleContent ? `${preambleContent}\n${originalContent}` : originalContent);
568
+ const combinedContent = preambleContent ? `${preambleContent}\n${originalContent}` : originalContent;
569
+ const ms = new MagicString(combinedContent);
569
570
  const dir = path.dirname(filename);
570
571
  const tempRoot = resolveWevuConfigTempDir(dir);
571
572
  const basename = path.basename(filename, path.extname(filename));
@@ -930,7 +931,8 @@ function collectWevuPageFeatureFlags(ast) {
930
931
  for (const stmt of ast.program.body) {
931
932
  if (!t.isImportDeclaration(stmt) || !isWevuRuntimeModuleId(stmt.source.value)) continue;
932
933
  for (const specifier of stmt.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
933
- const matched = WE_VU_PAGE_HOOK_TO_FEATURE[specifier.imported.name];
934
+ const importedName = specifier.imported.name;
935
+ const matched = WE_VU_PAGE_HOOK_TO_FEATURE[importedName];
934
936
  if (matched) namedHookLocals.set(specifier.local.name, matched);
935
937
  } else if (t.isImportNamespaceSpecifier(specifier)) namespaceLocals.add(specifier.local.name);
936
938
  }
@@ -1071,7 +1073,8 @@ function createModuleAnalysis(id, ast) {
1071
1073
  for (const specifier of stmt.specifiers) if (t.isImportSpecifier(specifier)) {
1072
1074
  const imported = specifier.imported;
1073
1075
  if (isWevuRuntimeModuleId(source) && t.isIdentifier(imported)) {
1074
- const matched = WE_VU_PAGE_HOOK_TO_FEATURE[imported.name];
1076
+ const importedName = imported.name;
1077
+ const matched = WE_VU_PAGE_HOOK_TO_FEATURE[importedName];
1075
1078
  if (matched) wevuNamedHookLocals.set(specifier.local.name, matched);
1076
1079
  }
1077
1080
  importedBindings.set(specifier.local.name, {
@@ -1304,9 +1307,10 @@ function createModuleAnalysisWithOxc(id, code) {
1304
1307
  //#region src/plugins/wevu/pageFeatures/moduleAnalysis/index.ts
1305
1308
  const TS_WITHOUT_JSX_RE = /\.[cm]?ts(?:[?#].*)?$/i;
1306
1309
  function parseModuleAnalysisAst(id, code) {
1310
+ const plugins = TS_WITHOUT_JSX_RE.test(id) ? BABEL_TS_MODULE_PLUGINS.filter((plugin) => plugin !== "jsx") : BABEL_TS_MODULE_PLUGINS;
1307
1311
  return parse$3(code, {
1308
1312
  sourceType: "module",
1309
- plugins: TS_WITHOUT_JSX_RE.test(id) ? BABEL_TS_MODULE_PLUGINS.filter((plugin) => plugin !== "jsx") : BABEL_TS_MODULE_PLUGINS
1313
+ plugins
1310
1314
  });
1311
1315
  }
1312
1316
  function createModuleAnalysisFromCode(id, code, options) {
@@ -1358,7 +1362,8 @@ function collectWithOxc(code) {
1358
1362
  if (matched) enabled.add(matched);
1359
1363
  } else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
1360
1364
  if (module.wevuNamespaceLocals.has(callee.object.name)) {
1361
- const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
1365
+ const hook = callee.property.name;
1366
+ const matched = WE_VU_PAGE_HOOK_TO_FEATURE[hook];
1362
1367
  if (matched) enabled.add(matched);
1363
1368
  }
1364
1369
  }
@@ -1692,7 +1697,8 @@ function collectWevuHookCallsInFunctionBody(module, fn) {
1692
1697
  if (matched) enabled.add(matched);
1693
1698
  } else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
1694
1699
  if (module.wevuNamespaceLocals.has(callee.object.name)) {
1695
- const matched = WE_VU_PAGE_HOOK_TO_FEATURE[callee.property.name];
1700
+ const hook = callee.property.name;
1701
+ const matched = WE_VU_PAGE_HOOK_TO_FEATURE[hook];
1696
1702
  if (matched) enabled.add(matched);
1697
1703
  }
1698
1704
  }
@@ -3793,7 +3799,7 @@ function transformScript(source, options) {
3793
3799
  const macroVisitors = createMacroVisitors(ast.program, state);
3794
3800
  const importVisitors = createImportVisitors(ast.program, state);
3795
3801
  const collectVisitors = createCollectVisitors(state);
3796
- traverse(ast, {
3802
+ const visitor = {
3797
3803
  ...vueSfcVisitors,
3798
3804
  ...macroVisitors,
3799
3805
  ...importVisitors,
@@ -3806,7 +3812,8 @@ function transformScript(source, options) {
3806
3812
  runVisitor(vueSfcVisitors.CallExpression, path);
3807
3813
  if (!path.removed) runVisitor(macroVisitors.CallExpression, path);
3808
3814
  }
3809
- });
3815
+ };
3816
+ traverse(ast, visitor);
3810
3817
  if (options?.templateComponentMeta) state.transformed = pruneTemplateComponentMeta(ast, options.templateComponentMeta) || state.transformed;
3811
3818
  state.transformed = rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializedWevuDefaults, parsedWevuDefaults) || state.transformed;
3812
3819
  if (!state.transformed) return {
@@ -4041,7 +4048,8 @@ function collectExpressionScopeBindings(exp, context) {
4041
4048
  if (!localSet.size) return [];
4042
4049
  const used = [];
4043
4050
  const usedSet = /* @__PURE__ */ new Set();
4044
- traverse(t.file(t.program([t.expressionStatement(t.cloneNode(exp, true))])), { Identifier(path) {
4051
+ const file = t.file(t.program([t.expressionStatement(t.cloneNode(exp, true))]));
4052
+ traverse(file, { Identifier(path) {
4045
4053
  if (!path.isReferencedIdentifier()) return;
4046
4054
  const name = path.node.name;
4047
4055
  if (!localSet.has(name)) return;
@@ -5157,12 +5165,13 @@ function analyzeScript(source, filename) {
5157
5165
  usesFreeUni: false,
5158
5166
  virtualHostTrueRanges: []
5159
5167
  };
5168
+ const isJsx = /\.[cm]?[jt]sx$/i.test(filename);
5160
5169
  const ast = parse$3(source, {
5161
5170
  sourceType: "module",
5162
5171
  plugins: [
5163
5172
  "typescript",
5164
5173
  "decorators-legacy",
5165
- .../\.[cm]?[jt]sx$/i.test(filename) ? ["jsx"] : []
5174
+ ...isJsx ? ["jsx"] : []
5166
5175
  ]
5167
5176
  });
5168
5177
  const importSources = [];
@@ -7860,7 +7869,8 @@ function collectElementAttributes(node, context, options) {
7860
7869
  }
7861
7870
  if (mappedTagClass) staticClass = prependStaticClass(staticClass, mappedTagClass);
7862
7871
  if (templateRef) {
7863
- const className = `${WEVU_TEMPLATE_REF_CLASS_PREFIX}${context.templateRefIndexSeed++}`;
7872
+ const refIndex = context.templateRefIndexSeed++;
7873
+ const className = `${WEVU_TEMPLATE_REF_CLASS_PREFIX}${refIndex}`;
7864
7874
  staticClass = staticClass ? `${staticClass} ${className}` : className;
7865
7875
  context.templateRefs.push({
7866
7876
  selector: `.${className}`,
@@ -8069,7 +8079,8 @@ const SLOT_PRESENCE_IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
8069
8079
  function createSlotPresenceExpression(info) {
8070
8080
  const slotName = resolveSlotStaticName(info);
8071
8081
  if (!slotName) return;
8072
- return `${WEVU_SLOT_NAMES_PROP}&&${SLOT_PRESENCE_IDENTIFIER_RE.test(slotName) ? `${WEVU_SLOT_NAMES_PROP}.${slotName}` : `${WEVU_SLOT_NAMES_PROP}['${slotName.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}']`}`;
8082
+ const access = SLOT_PRESENCE_IDENTIFIER_RE.test(slotName) ? `${WEVU_SLOT_NAMES_PROP}.${slotName}` : `${WEVU_SLOT_NAMES_PROP}['${slotName.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}']`;
8083
+ return `${WEVU_SLOT_NAMES_PROP}&&${access}`;
8073
8084
  }
8074
8085
  function buildSlotDeclaration(name, propsExp, children, context, options) {
8075
8086
  return {
@@ -9528,7 +9539,8 @@ async function evaluateJsLikeConfig(source, filename, lang) {
9528
9539
  return await withTempDirLock(tempRoot, async () => {
9529
9540
  await ensureDir(tempDir);
9530
9541
  const tempFile = path.join(tempDir, `${basename}.${unique}.${extension}`);
9531
- await writeFile(tempFile, rewriteJsLikeImportsForTempDir(source, dir, tempDir), "utf8");
9542
+ const rewritten = rewriteJsLikeImportsForTempDir(source, dir, tempDir);
9543
+ await writeFile(tempFile, rewritten, "utf8");
9532
9544
  try {
9533
9545
  const { mod } = await bundleRequire({
9534
9546
  filepath: tempFile,
@@ -9706,7 +9718,8 @@ function tryConvertObjectMethodSourceToFunctionExpression(source) {
9706
9718
  if (!firstProperty) return null;
9707
9719
  if (t.isObjectMethod(firstProperty)) {
9708
9720
  const functionName = t.isIdentifier(firstProperty.key) ? t.identifier(firstProperty.key.name) : null;
9709
- return generate(t.functionExpression(functionName, firstProperty.params, firstProperty.body, firstProperty.generator, firstProperty.async)).code;
9721
+ const functionExpression = t.functionExpression(functionName, firstProperty.params, firstProperty.body, firstProperty.generator, firstProperty.async);
9722
+ return generate(functionExpression).code;
9710
9723
  }
9711
9724
  if (t.isObjectProperty(firstProperty) && (t.isFunctionExpression(firstProperty.value) || t.isArrowFunctionExpression(firstProperty.value))) return generate(firstProperty.value).code;
9712
9725
  } catch {}
@@ -10341,7 +10354,8 @@ function collectScriptSetupReturnInfo(scriptCode) {
10341
10354
  }
10342
10355
  };
10343
10356
  try {
10344
- traverse(parseJsLike(scriptCode), {
10357
+ const ast = parseJsLike(scriptCode);
10358
+ traverse(ast, {
10345
10359
  VariableDeclarator(path) {
10346
10360
  const init = path.node.init;
10347
10361
  if (t.isIdentifier(path.node.id) && t.isIdentifier(init) && propsObjectAliases.has(init.name)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.19.0",
4
+ "version": "6.19.1",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -49,13 +49,13 @@
49
49
  "magic-string": "^1.1.0",
50
50
  "merge": "^2.1.1",
51
51
  "pathe": "^2.0.3",
52
- "postcss": "^8.5.24",
52
+ "postcss": "^8.5.25",
53
53
  "postcss-selector-parser": "^7.1.4",
54
54
  "vue": "^3.5.40",
55
55
  "@weapp-core/constants": "0.1.15",
56
56
  "@weapp-core/shared": "3.1.0",
57
- "@weapp-vite/ast": "6.19.0",
58
- "rolldown-require": "2.0.22"
57
+ "@weapp-vite/ast": "6.19.1",
58
+ "rolldown-require": "2.0.23"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public",