@weapp-vite/ast 6.16.45 → 6.16.47

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
@@ -5,7 +5,7 @@ import { parseJsLikeWithEngine } from "./engine.mjs";
5
5
  import { ComponentPropMap, collectComponentPropsFromCode, collectComponentPropsWithBabel, collectComponentPropsWithOxc, extractComponentProperties, extractPropertiesObject, getStaticPropertyName, mapConstructorName, mayContainComponentPropsShape, mergeComponentPropTypes, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveTypeFromNode } from "./operations/componentProps.mjs";
6
6
  import { FeatureFlagOptions, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal } from "./operations/featureFlags.mjs";
7
7
  import { JsxAutoComponentAnalysisOptions, JsxAutoComponentContext, JsxBabelModuleAnalysisOptions, JsxImportedComponent, collectJsxAutoComponentsFromCode, collectJsxAutoComponentsWithBabel, collectJsxAutoComponentsWithOxc, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, collectJsxTemplateTagsFromOxc, createJsxImportedComponent, defaultIsDefineComponentSource, defaultResolveBabelComponentExpression, defaultResolveBabelRenderExpression, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, isJsxDefineComponentImportSpecifier, mayContainJsxAutoComponentEntry, resolveOxcComponentExpression, resolveOxcRenderExpression, unwrapOxcExpression } from "./operations/jsxAutoComponents.mjs";
8
- import { _ as collectOnPageScrollWarningsWithBabel, a as getLocationFromOffset, c as getOxcCallExpressionCalleeName, d as isOnPageScrollCallee, f as isOxcFunctionLike, g as collectPageScrollInspectionWithOxc, h as collectOnPageScrollWarningsWithOxc, i as getCallExpressionCalleeName, l as getOxcMemberExpressionPropertyName, m as isStaticPropertyName, n as createLineStartOffsets, o as getMemberExpressionPropertyName, p as isOxcOnPageScrollCallee, r as createWarningPrefix, s as getOnPageScrollCallbackArgument, t as collectOnPageScrollPerformanceWarnings, u as getOxcStaticPropertyName, v as collectPageScrollInspection } from "./onPageScroll-DpsTdS_S.mjs";
8
+ import { _ as collectOnPageScrollWarningsWithBabel, a as getLocationFromOffset, c as getOxcCallExpressionCalleeName, d as isOnPageScrollCallee, f as isOxcFunctionLike, g as collectPageScrollInspectionWithOxc, h as collectOnPageScrollWarningsWithOxc, i as getCallExpressionCalleeName, l as getOxcMemberExpressionPropertyName, m as isStaticPropertyName, n as createLineStartOffsets, o as getMemberExpressionPropertyName, p as isOxcOnPageScrollCallee, r as createWarningPrefix, s as getOnPageScrollCallbackArgument, t as collectOnPageScrollPerformanceWarnings, u as getOxcStaticPropertyName, v as collectPageScrollInspection } from "./onPageScroll-C1BbvMzn.mjs";
9
9
  import { hasPlatformApiMemberExpression, isPlatformApiIdentifier, isPlatformApiMemberExpression, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, platformApiIdentifierList, platformApiIdentifiers } from "./operations/platformApi.mjs";
10
10
  import { RequireToken, collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral } from "./operations/require.mjs";
11
11
  import { ScriptSetupImport, collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, createScriptSetupImport, getScriptSetupImportedName, mayContainRelevantScriptSetupImports } from "./operations/scriptSetupImports.mjs";
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { n as oxcAstEngine, r as babelAstEngine, t as parseJsLikeWithEngine } fr
4
4
  import { collectComponentPropsFromCode, collectComponentPropsWithBabel, collectComponentPropsWithOxc, extractComponentProperties, extractPropertiesObject, getStaticPropertyName, mapConstructorName, mayContainComponentPropsShape, mergeComponentPropTypes, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveTypeFromNode } from "./operations/componentProps.mjs";
5
5
  import { collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal } from "./operations/featureFlags.mjs";
6
6
  import { collectJsxAutoComponentsFromCode, collectJsxAutoComponentsWithBabel, collectJsxAutoComponentsWithOxc, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, collectJsxTemplateTagsFromOxc, createJsxImportedComponent, defaultIsDefineComponentSource, defaultResolveBabelComponentExpression, defaultResolveBabelRenderExpression, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, isJsxDefineComponentImportSpecifier, mayContainJsxAutoComponentEntry, resolveOxcComponentExpression, resolveOxcRenderExpression, unwrapOxcExpression } from "./operations/jsxAutoComponents.mjs";
7
- import { _ as isOxcOnPageScrollCallee, a as collectPageScrollInspection, c as getCallExpressionCalleeName, d as getOnPageScrollCallbackArgument, f as getOxcCallExpressionCalleeName, g as isOxcFunctionLike, h as isOnPageScrollCallee, i as collectOnPageScrollWarningsWithBabel, l as getLocationFromOffset, m as getOxcStaticPropertyName, n as collectOnPageScrollWarningsWithOxc, o as createLineStartOffsets, p as getOxcMemberExpressionPropertyName, r as collectPageScrollInspectionWithOxc, s as createWarningPrefix, t as collectOnPageScrollPerformanceWarnings, u as getMemberExpressionPropertyName, v as isStaticPropertyName } from "./onPageScroll-RxvH7Pi_.mjs";
7
+ import { _ as isOxcOnPageScrollCallee, a as collectPageScrollInspection, c as getCallExpressionCalleeName, d as getOnPageScrollCallbackArgument, f as getOxcCallExpressionCalleeName, g as isOxcFunctionLike, h as isOnPageScrollCallee, i as collectOnPageScrollWarningsWithBabel, l as getLocationFromOffset, m as getOxcStaticPropertyName, n as collectOnPageScrollWarningsWithOxc, o as createLineStartOffsets, p as getOxcMemberExpressionPropertyName, r as collectPageScrollInspectionWithOxc, s as createWarningPrefix, t as collectOnPageScrollPerformanceWarnings, u as getMemberExpressionPropertyName, v as isStaticPropertyName } from "./onPageScroll-BDuUZSSJ.mjs";
8
8
  import { hasPlatformApiMemberExpression, isPlatformApiIdentifier, isPlatformApiMemberExpression, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, platformApiIdentifierList, platformApiIdentifiers } from "./operations/platformApi.mjs";
9
9
  import { collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral } from "./operations/require.mjs";
10
10
  import { collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, createScriptSetupImport, getScriptSetupImportedName, mayContainRelevantScriptSetupImports } from "./operations/scriptSetupImports.mjs";
@@ -1,5 +1,6 @@
1
1
  import { parseJsLike, traverse } from "./babel.mjs";
2
2
  import { t as parseJsLikeWithEngine } from "./engine-CBE2OpFp.mjs";
3
+ import { walk } from "oxc-walker";
3
4
  //#region src/operations/onPageScroll/shared.ts
4
5
  function isStaticPropertyName(key) {
5
6
  if (key.type === "Identifier") return key.name;
@@ -169,6 +170,9 @@ function collectOnPageScrollWarningsWithBabel(code, filename) {
169
170
  }
170
171
  //#endregion
171
172
  //#region src/operations/onPageScroll/oxc.ts
173
+ function isOxcNestedFunctionBoundary(node) {
174
+ return isOxcFunctionLike(node) || node?.type === "FunctionDeclaration";
175
+ }
172
176
  function collectPageScrollInspectionWithOxc(node) {
173
177
  const inspection = {
174
178
  empty: node.body?.type === "BlockStatement" && node.body.body.length === 0,
@@ -176,27 +180,20 @@ function collectPageScrollInspectionWithOxc(node) {
176
180
  syncApis: /* @__PURE__ */ new Set()
177
181
  };
178
182
  const root = node.body?.type === "BlockStatement" ? node.body : node.body;
179
- function visit(current, allowNestedFunctions = false) {
180
- if (!current) return;
181
- if (!allowNestedFunctions && (current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression")) return;
182
- if (current.type === "CallExpression") {
183
- if (getOxcCallExpressionCalleeName(current.callee) === "setData") inspection.hasSetDataCall = true;
184
- if (current.callee?.type === "MemberExpression" && current.callee.object?.type === "Identifier" && current.callee.object.name === "wx") {
185
- const propertyName = getOxcMemberExpressionPropertyName(current.callee);
186
- if (propertyName && propertyName.endsWith("Sync")) inspection.syncApis.add(`wx.${propertyName}`);
187
- }
188
- } else if (current.type === "ChainExpression") {
189
- visit(current.expression, allowNestedFunctions);
183
+ if (!root) return inspection;
184
+ walk(root, { enter(node) {
185
+ const current = node;
186
+ if (current !== root && isOxcNestedFunctionBoundary(current)) {
187
+ this.skip();
190
188
  return;
191
189
  }
192
- for (const value of Object.values(current)) {
193
- if (!value) continue;
194
- if (Array.isArray(value)) {
195
- for (const child of value) if (child && typeof child === "object" && typeof child.type === "string") visit(child);
196
- } else if (typeof value === "object" && typeof value.type === "string") visit(value);
190
+ if (current.type !== "CallExpression") return;
191
+ if (getOxcCallExpressionCalleeName(current.callee) === "setData") inspection.hasSetDataCall = true;
192
+ if (current.callee?.type === "MemberExpression" && current.callee.object?.type === "Identifier" && current.callee.object.name === "wx") {
193
+ const propertyName = getOxcMemberExpressionPropertyName(current.callee);
194
+ if (propertyName && propertyName.endsWith("Sync")) inspection.syncApis.add(`wx.${propertyName}`);
197
195
  }
198
- }
199
- if (root) visit(root, true);
196
+ } });
200
197
  return inspection;
201
198
  }
202
199
  function collectOnPageScrollWarningsWithOxc(code, filename) {
@@ -227,26 +224,20 @@ function collectOnPageScrollWarningsWithOxc(code, filename) {
227
224
  if (inspection.hasSetDataCall) addWarning(`${prefix} 检测到 ${sourceLabel} 内调用 setData,建议改用节流、IntersectionObserver 或合并更新。`);
228
225
  for (const syncApi of inspection.syncApis) addWarning(`${prefix} 检测到 ${sourceLabel} 内调用同步 API(${syncApi}),可能阻塞渲染线程。`);
229
226
  };
230
- function visit(node) {
231
- if (!node) return;
232
- if (node.type === "Property" && !node.computed && getOxcStaticPropertyName(node.key) === "onPageScroll" && isOxcFunctionLike(node.value)) {
233
- const startOffset = node.method ? node.key?.end : node.value.start;
234
- reportInspection(node.value, "onPageScroll", startOffset);
235
- } else if (node.type === "CallExpression" && isOxcOnPageScrollCallee(node.callee, onPageScrollHookNames, namespaceImports)) {
236
- const arg0 = node.arguments?.[0];
237
- if (arg0 && arg0.type !== "SpreadElement" && isOxcFunctionLike(arg0)) reportInspection(arg0, "onPageScroll(...)");
238
- } else if (node.type === "ChainExpression" && node.expression?.type === "CallExpression") {
239
- const arg0 = node.expression.arguments?.[0];
240
- if (isOxcOnPageScrollCallee(node.expression.callee, onPageScrollHookNames, namespaceImports) && arg0 && arg0.type !== "SpreadElement" && isOxcFunctionLike(arg0)) reportInspection(arg0, "onPageScroll(...)");
241
- }
242
- for (const value of Object.values(node)) {
243
- if (!value) continue;
244
- if (Array.isArray(value)) {
245
- for (const child of value) if (child && typeof child === "object" && typeof child.type === "string") visit(child);
246
- } else if (typeof value === "object" && typeof value.type === "string") visit(value);
227
+ walk(ast, { enter(node) {
228
+ const current = node;
229
+ if (current.type === "Property" && !current.computed && getOxcStaticPropertyName(current.key) === "onPageScroll" && isOxcFunctionLike(current.value)) {
230
+ const startOffset = current.method ? current.key?.end : current.value.start;
231
+ reportInspection(current.value, "onPageScroll", startOffset);
232
+ this.skip();
233
+ } else if (current.type === "CallExpression" && isOxcOnPageScrollCallee(current.callee, onPageScrollHookNames, namespaceImports)) {
234
+ const arg0 = current.arguments?.[0];
235
+ if (arg0 && arg0.type !== "SpreadElement" && isOxcFunctionLike(arg0)) {
236
+ reportInspection(arg0, "onPageScroll(...)");
237
+ this.skip();
238
+ }
247
239
  }
248
- }
249
- visit(ast);
240
+ } });
250
241
  return warnings;
251
242
  }
252
243
  //#endregion
@@ -27,7 +27,7 @@ declare function isOnPageScrollCallee(callee: t.Expression | t.V8IntrinsicIdenti
27
27
  declare function getCallExpressionCalleeName(callee: t.Expression | t.V8IntrinsicIdentifier): string | undefined;
28
28
  declare function getOnPageScrollCallbackArgument(node: {
29
29
  arguments?: Array<t.Expression | t.SpreadElement | t.ArgumentPlaceholder | null>;
30
- }): t.ArrowFunctionExpression | t.FunctionExpression | undefined;
30
+ }): t.FunctionExpression | t.ArrowFunctionExpression | undefined;
31
31
  declare function createWarningPrefix(filename: string, line?: number, column?: number): string;
32
32
  declare function getOxcStaticPropertyName(node: any): string | undefined;
33
33
  declare function getOxcMemberExpressionPropertyName(node: any): string | undefined;
@@ -3,8 +3,9 @@ import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
3
3
  import { walk } from "oxc-walker";
4
4
  //#region src/operations/componentProps.ts
5
5
  const COMPONENT_PROPS_TEXT_HINTS = ["properties", "props"];
6
+ const COMPONENT_OPTIONS_CALL_HINT_RE = /\b[a-z_$][\w$]*(?:\s*<[^(){};]+>)?\s*(?:\?\.\s*)?\(/i;
6
7
  function mayContainComponentPropsShape(code) {
7
- return COMPONENT_PROPS_TEXT_HINTS.some((hint) => code.includes(hint));
8
+ return COMPONENT_PROPS_TEXT_HINTS.some((hint) => code.includes(hint)) && COMPONENT_OPTIONS_CALL_HINT_RE.test(code);
8
9
  }
9
10
  const CONSTRUCTOR_TYPE_MAP = {
10
11
  String: "string",
@@ -150,7 +151,10 @@ function collectComponentPropsWithOxc(code) {
150
151
  const bindings = /* @__PURE__ */ new Map();
151
152
  let resolved = false;
152
153
  walk(ast, { enter(node) {
153
- if (resolved) return;
154
+ if (resolved) {
155
+ this.skip();
156
+ return;
157
+ }
154
158
  if (node.type === "VariableDeclarator" && node.id?.type === "Identifier") {
155
159
  const optionsObject = resolveOptionsObjectExpression(node.init, bindings);
156
160
  if (optionsObject) bindings.set(node.id.name, optionsObject);
@@ -162,6 +166,7 @@ function collectComponentPropsWithOxc(code) {
162
166
  if (!optionsObject) return;
163
167
  resolved = true;
164
168
  for (const [key, value] of extractComponentProperties(optionsObject)) props.set(key, value);
169
+ this.skip();
165
170
  } });
166
171
  return props;
167
172
  }
@@ -3,9 +3,10 @@ import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
3
3
  import * as t from "@babel/types";
4
4
  import { walk } from "oxc-walker";
5
5
  //#region src/operations/featureFlags.ts
6
+ const CALL_EXPRESSION_TEXT_RE = /\b[a-z_$][\w$]*(?:\s*<[^(){};]+>)?\s*(?:\?\.\s*)?\(/i;
6
7
  function mayContainFeatureFlagHints(code, moduleId, hookToFeature) {
7
8
  if (!code.includes(moduleId)) return false;
8
- return Object.keys(hookToFeature).some((hookName) => code.includes(hookName));
9
+ return CALL_EXPRESSION_TEXT_RE.test(code) && Object.keys(hookToFeature).some((hookName) => code.includes(hookName));
9
10
  }
10
11
  function consumeNamedFeatureFlag(enabled, namedHookLocals, name) {
11
12
  const matched = namedHookLocals.get(name);
@@ -1,2 +1,2 @@
1
- import { _ as collectOnPageScrollWarningsWithBabel, a as getLocationFromOffset, c as getOxcCallExpressionCalleeName, d as isOnPageScrollCallee, f as isOxcFunctionLike, g as collectPageScrollInspectionWithOxc, h as collectOnPageScrollWarningsWithOxc, i as getCallExpressionCalleeName, l as getOxcMemberExpressionPropertyName, m as isStaticPropertyName, n as createLineStartOffsets, o as getMemberExpressionPropertyName, p as isOxcOnPageScrollCallee, r as createWarningPrefix, s as getOnPageScrollCallbackArgument, t as collectOnPageScrollPerformanceWarnings, u as getOxcStaticPropertyName, v as collectPageScrollInspection } from "../onPageScroll-DpsTdS_S.mjs";
1
+ import { _ as collectOnPageScrollWarningsWithBabel, a as getLocationFromOffset, c as getOxcCallExpressionCalleeName, d as isOnPageScrollCallee, f as isOxcFunctionLike, g as collectPageScrollInspectionWithOxc, h as collectOnPageScrollWarningsWithOxc, i as getCallExpressionCalleeName, l as getOxcMemberExpressionPropertyName, m as isStaticPropertyName, n as createLineStartOffsets, o as getMemberExpressionPropertyName, p as isOxcOnPageScrollCallee, r as createWarningPrefix, s as getOnPageScrollCallbackArgument, t as collectOnPageScrollPerformanceWarnings, u as getOxcStaticPropertyName, v as collectPageScrollInspection } from "../onPageScroll-C1BbvMzn.mjs";
2
2
  export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
@@ -1,2 +1,2 @@
1
- import { _ as isOxcOnPageScrollCallee, a as collectPageScrollInspection, c as getCallExpressionCalleeName, d as getOnPageScrollCallbackArgument, f as getOxcCallExpressionCalleeName, g as isOxcFunctionLike, h as isOnPageScrollCallee, i as collectOnPageScrollWarningsWithBabel, l as getLocationFromOffset, m as getOxcStaticPropertyName, n as collectOnPageScrollWarningsWithOxc, o as createLineStartOffsets, p as getOxcMemberExpressionPropertyName, r as collectPageScrollInspectionWithOxc, s as createWarningPrefix, t as collectOnPageScrollPerformanceWarnings, u as getMemberExpressionPropertyName, v as isStaticPropertyName } from "../onPageScroll-RxvH7Pi_.mjs";
1
+ import { _ as isOxcOnPageScrollCallee, a as collectPageScrollInspection, c as getCallExpressionCalleeName, d as getOnPageScrollCallbackArgument, f as getOxcCallExpressionCalleeName, g as isOxcFunctionLike, h as isOnPageScrollCallee, i as collectOnPageScrollWarningsWithBabel, l as getLocationFromOffset, m as getOxcStaticPropertyName, n as collectOnPageScrollWarningsWithOxc, o as createLineStartOffsets, p as getOxcMemberExpressionPropertyName, r as collectPageScrollInspectionWithOxc, s as createWarningPrefix, t as collectOnPageScrollPerformanceWarnings, u as getMemberExpressionPropertyName, v as isStaticPropertyName } from "../onPageScroll-BDuUZSSJ.mjs";
2
2
  export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-vite/ast",
3
3
  "type": "module",
4
- "version": "6.16.45",
4
+ "version": "6.16.47",
5
5
  "description": "weapp-vite 共享 AST 分析工具包,统一 Babel/Oxc 解析与常用分析操作",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -106,8 +106,8 @@
106
106
  "@babel/parser": "^7.29.7",
107
107
  "@babel/traverse": "^7.29.7",
108
108
  "@babel/types": "^7.29.7",
109
- "@oxc-project/types": "^0.135.0",
110
- "oxc-parser": "^0.135.0",
109
+ "@oxc-project/types": "^0.136.0",
110
+ "oxc-parser": "^0.136.0",
111
111
  "oxc-walker": "^1.0.0",
112
112
  "@weapp-core/shared": "3.0.4"
113
113
  },