@weapp-vite/ast 6.17.8 → 6.18.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/babel.d.mts +0 -1
- package/dist/babelCore.d.mts +27 -28
- package/dist/babelNodes.d.mts +0 -1
- package/dist/engine.d.mts +0 -1
- package/dist/index.d.mts +28 -4
- package/dist/index.mjs +59 -3
- package/dist/native-C-xcrMBn.mjs +54 -0
- package/dist/{onPageScroll-DpsTdS_S.d.mts → onPageScroll-n3Vptu1_.d.mts} +3 -3
- package/dist/{onPageScroll-DYWM5bYW.mjs → onPageScroll-tuvgNooK.mjs} +25 -1
- package/dist/operations/componentProps.d.mts +0 -1
- package/dist/operations/componentProps.mjs +2 -1
- package/dist/operations/featureFlags.d.mts +3 -2
- package/dist/operations/featureFlags.mjs +25 -1
- package/dist/operations/jsxAutoComponents.d.mts +0 -1
- package/dist/operations/onPageScroll.d.mts +2 -2
- package/dist/operations/onPageScroll.mjs +2 -2
- package/dist/operations/platformApi.d.mts +0 -1
- package/dist/operations/platformApi.mjs +7 -0
- package/dist/operations/require.d.mts +0 -1
- package/dist/operations/require.mjs +7 -0
- package/dist/operations/scriptSetupImports.d.mts +0 -1
- package/dist/operations/setDataPick.d.mts +0 -1
- package/package.json +6 -6
package/dist/babel.d.mts
CHANGED
package/dist/babelCore.d.mts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
import * as BabelCore from "@babel/core";
|
|
2
2
|
import { InputOptions as TransformOptions, NodePath } from "@babel/core";
|
|
3
|
-
|
|
4
3
|
//#region src/babelCore.d.ts
|
|
5
4
|
declare const babelCore: typeof BabelCore;
|
|
6
5
|
declare const parse: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
6
|
+
(code: string, callback: {
|
|
7
|
+
(err: Error, ast: null): void;
|
|
8
|
+
(err: null, ast: import("@babel/parser").ParseResult | null): void;
|
|
9
|
+
}): void;
|
|
10
|
+
(code: string, opts: BabelCore.InputOptions | undefined | null, callback: {
|
|
11
|
+
(err: Error, ast: null): void;
|
|
12
|
+
(err: null, ast: import("@babel/parser").ParseResult | null): void;
|
|
13
|
+
}): void;
|
|
14
|
+
}, parseAsync: typeof BabelCore.parseAsync, parseSync: typeof BabelCore.parseSync, transform: {
|
|
15
|
+
(code: string, callback: {
|
|
16
|
+
(err: Error, file: null): void;
|
|
17
|
+
(err: null, file: BabelCore.FileResult | null): void;
|
|
18
|
+
}): void;
|
|
19
|
+
(code: string, opts: BabelCore.InputOptions | undefined | null, callback: {
|
|
20
|
+
(err: Error, file: null): void;
|
|
21
|
+
(err: null, file: BabelCore.FileResult | null): void;
|
|
22
|
+
}): void;
|
|
23
|
+
}, transformAsync: typeof BabelCore.transformAsync, transformFile: typeof BabelCore.transformFile, transformFileAsync: typeof BabelCore.transformFileAsync, transformFileSync: typeof BabelCore.transformFileSync, transformFromAst: {
|
|
24
|
+
(ast: BabelCore.types.File | BabelCore.types.Program, code: string, callback: {
|
|
25
|
+
(err: Error, file: null): void;
|
|
26
|
+
(err: null, file: BabelCore.FileResult | null): void;
|
|
27
|
+
}): void;
|
|
28
|
+
(ast: BabelCore.types.File | BabelCore.types.Program, code: string, opts: BabelCore.InputOptions | undefined | null, callback: {
|
|
29
|
+
(err: Error, file: null): void;
|
|
30
|
+
(err: null, file: BabelCore.FileResult | null): void;
|
|
31
|
+
}): void;
|
|
32
|
+
}, transformFromAstAsync: typeof BabelCore.transformFromAstAsync, transformFromAstSync: typeof BabelCore.transformFromAstSync, transformSync: typeof BabelCore.transformSync, types: typeof BabelCore.types, version: string;
|
|
34
33
|
//#endregion
|
|
35
34
|
export { type NodePath, type TransformOptions, babelCore as default, parse, parseAsync, parseSync, transform, transformAsync, transformFile, transformFileAsync, transformFileSync, transformFromAst, transformFromAstAsync, transformFromAstSync, transformSync, types, version };
|
package/dist/babelNodes.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { Expression, ObjectExpression, ObjectMethod, ObjectProperty, PrivateName } from "@babel/types";
|
|
3
|
-
|
|
4
3
|
//#region src/babelNodes.d.ts
|
|
5
4
|
declare function unwrapTypeScriptExpression(exp: Expression): Expression;
|
|
6
5
|
declare function toStaticObjectKey(key: Expression | PrivateName | t.Identifier): string | null;
|
package/dist/engine.d.mts
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -3,14 +3,13 @@ import { getObjectPropertyByKey, getRenderPropertyFromComponentOptions, resolveR
|
|
|
3
3
|
import { n as AstParserLike, r as WeappAstConfig, t as AstEngineName } from "./types-4qG2Ubmk.mjs";
|
|
4
4
|
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
|
-
import { FeatureFlagOptions, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal } from "./operations/featureFlags.mjs";
|
|
6
|
+
import { FeatureFlagOptions, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, 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
|
|
8
|
+
import { _ as collectPageScrollInspectionWithOxc, a as getCallExpressionCalleeName, c as getOnPageScrollCallbackArgument, d as getOxcStaticPropertyName, f as isOnPageScrollCallee, g as collectOnPageScrollWarningsWithOxc, h as isStaticPropertyName, i as createWarningPrefix, l as getOxcCallExpressionCalleeName, m as isOxcOnPageScrollCallee, n as collectOnPageScrollWarningsWithNative, o as getLocationFromOffset, p as isOxcFunctionLike, r as createLineStartOffsets, s as getMemberExpressionPropertyName, t as collectOnPageScrollPerformanceWarnings, u as getOxcMemberExpressionPropertyName, v as collectOnPageScrollWarningsWithBabel, y as collectPageScrollInspection } from "./onPageScroll-n3Vptu1_.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";
|
|
12
12
|
import { collectIdentifiersFromExpression, collectIdentifiersFromExpressionWithOxc, collectLoopScopeAliases, collectPatternBindingNames, collectSetDataPickKeysFromTemplateCode, collectSetDataPickKeysWithBabel, collectSetDataPickKeysWithOxc, extractTemplateExpressions, hasBindingInScopes } from "./operations/setDataPick.mjs";
|
|
13
|
-
|
|
14
13
|
//#region src/engines/babel.d.ts
|
|
15
14
|
/**
|
|
16
15
|
* Babel AST 引擎。
|
|
@@ -29,4 +28,29 @@ declare const oxcAstEngine: {
|
|
|
29
28
|
parseJsLike(code: string, filename?: string): import("oxc-parser").Program;
|
|
30
29
|
};
|
|
31
30
|
//#endregion
|
|
32
|
-
|
|
31
|
+
//#region src/operations/scriptAnalysis.d.ts
|
|
32
|
+
interface ScriptAnalysisOptions<TFeature extends string = string> {
|
|
33
|
+
engine?: AstEngineName;
|
|
34
|
+
parserLike?: AstParserLike;
|
|
35
|
+
featureFlags?: FeatureFlagOptions<TFeature>;
|
|
36
|
+
}
|
|
37
|
+
interface ScriptAnalysisResult<TFeature extends string = string> {
|
|
38
|
+
hasStaticRequireLiteral: boolean;
|
|
39
|
+
hasPlatformApiAccess: boolean;
|
|
40
|
+
featureFlags: Set<TFeature>;
|
|
41
|
+
}
|
|
42
|
+
interface ScriptAnalysisBatchInput<TFeature extends string = string> {
|
|
43
|
+
code: string;
|
|
44
|
+
filename?: string;
|
|
45
|
+
featureFlags?: FeatureFlagOptions<TFeature>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 对同一份脚本做批量 AST 预分析,避免多个轻量检查重复 parse 或跨 native 边界。
|
|
49
|
+
*/
|
|
50
|
+
declare function analyzeScript<TFeature extends string = string>(code: string, options?: ScriptAnalysisOptions<TFeature>): ScriptAnalysisResult<TFeature>;
|
|
51
|
+
/**
|
|
52
|
+
* 对多份脚本做批量 native 预分析,减少 JS 与 Rust 的往返次数。
|
|
53
|
+
*/
|
|
54
|
+
declare function analyzeScripts<TFeature extends string = string>(inputs: ScriptAnalysisBatchInput<TFeature>[], options?: ScriptAnalysisOptions<TFeature>): Array<ScriptAnalysisResult<TFeature>>;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { type AstEngineName, type AstParserLike, BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, type ComponentPropMap, type FeatureFlagOptions, type JsxAutoComponentAnalysisOptions, type JsxAutoComponentContext, type JsxBabelModuleAnalysisOptions, type JsxImportedComponent, type RequireToken, type ScriptAnalysisBatchInput, type ScriptAnalysisOptions, type ScriptAnalysisResult, type ScriptSetupImport, type WeappAstConfig, analyzeScript, analyzeScripts, babelAstEngine, collectComponentPropsFromCode, collectComponentPropsWithBabel, collectComponentPropsWithOxc, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, collectFeatureFlagsWithOxc, collectIdentifiersFromExpression, collectIdentifiersFromExpressionWithOxc, collectJsxAutoComponentsFromCode, collectJsxAutoComponentsWithBabel, collectJsxAutoComponentsWithOxc, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, collectJsxTemplateTagsFromOxc, collectLoopScopeAliases, collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithNative, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, collectPatternBindingNames, collectRequireTokens, collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, collectSetDataPickKeysFromTemplateCode, collectSetDataPickKeysWithBabel, collectSetDataPickKeysWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, createJsxImportedComponent, createLineStartOffsets, createScriptSetupImport, createWarningPrefix, defaultIsDefineComponentSource, defaultResolveBabelComponentExpression, defaultResolveBabelRenderExpression, extractComponentProperties, extractPropertiesObject, extractTemplateExpressions, generate, getCallExpressionCalleeName, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, getLocationFromOffset, getMemberExpressionPropertyName, getObjectPropertyByKey, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, getRenderPropertyFromComponentOptions, getRequireAsyncLiteralToken, getScriptSetupImportedName, getStaticPropertyName, getStaticRequireLiteralValue, getVisitorKeys, hasBindingInScopes, hasPlatformApiMemberExpression, hasStaticRequireCall, isJsxDefineComponentImportSpecifier, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isPlatformApiIdentifier, isPlatformApiMemberExpression, isStaticPropertyName, isStaticRequireCall, mapConstructorName, mayContainComponentPropsShape, mayContainFeatureFlagHints, mayContainJsxAutoComponentEntry, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, mayContainRelevantScriptSetupImports, mayContainRequireCallByText, mayContainStaticRequireLiteral, mergeComponentPropTypes, oxcAstEngine, parse, parseJsLike, parseJsLikeWithEngine, platformApiIdentifierList, platformApiIdentifiers, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveOxcComponentExpression, resolveOxcRenderExpression, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, resolveTypeFromNode, toStaticObjectKey, traverse, unwrapOxcExpression, unwrapTypeScriptExpression };
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,67 @@ import { BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, generate, getV
|
|
|
2
2
|
import { getObjectPropertyByKey, getRenderPropertyFromComponentOptions, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, toStaticObjectKey, unwrapTypeScriptExpression } from "./babelNodes.mjs";
|
|
3
3
|
import { n as oxcAstEngine, r as babelAstEngine, t as parseJsLikeWithEngine } from "./engine-CBE2OpFp.mjs";
|
|
4
4
|
import { collectComponentPropsFromCode, collectComponentPropsWithBabel, collectComponentPropsWithOxc, extractComponentProperties, extractPropertiesObject, getStaticPropertyName, mapConstructorName, mayContainComponentPropsShape, mergeComponentPropTypes, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveTypeFromNode } from "./operations/componentProps.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { i as shouldUseNativeAst, n as analyzeScriptsWithNative, t as analyzeScriptWithNative } from "./native-C-xcrMBn.mjs";
|
|
6
|
+
import { collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal } from "./operations/featureFlags.mjs";
|
|
6
7
|
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
|
|
8
|
+
import { _ as isOxcFunctionLike, a as collectOnPageScrollWarningsWithBabel, c as createWarningPrefix, d as getMemberExpressionPropertyName, f as getOnPageScrollCallbackArgument, g as isOnPageScrollCallee, h as getOxcStaticPropertyName, i as collectPageScrollInspectionWithOxc, l as getCallExpressionCalleeName, m as getOxcMemberExpressionPropertyName, n as collectOnPageScrollWarningsWithNative, o as collectPageScrollInspection, p as getOxcCallExpressionCalleeName, r as collectOnPageScrollWarningsWithOxc, s as createLineStartOffsets, t as collectOnPageScrollPerformanceWarnings, u as getLocationFromOffset, v as isOxcOnPageScrollCallee, y as isStaticPropertyName } from "./onPageScroll-tuvgNooK.mjs";
|
|
8
9
|
import { hasPlatformApiMemberExpression, isPlatformApiIdentifier, isPlatformApiMemberExpression, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, platformApiIdentifierList, platformApiIdentifiers } from "./operations/platformApi.mjs";
|
|
9
10
|
import { collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral } from "./operations/require.mjs";
|
|
10
11
|
import { collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, createScriptSetupImport, getScriptSetupImportedName, mayContainRelevantScriptSetupImports } from "./operations/scriptSetupImports.mjs";
|
|
11
12
|
import { collectIdentifiersFromExpression, collectIdentifiersFromExpressionWithOxc, collectLoopScopeAliases, collectPatternBindingNames, collectSetDataPickKeysFromTemplateCode, collectSetDataPickKeysWithBabel, collectSetDataPickKeysWithOxc, extractTemplateExpressions, hasBindingInScopes } from "./operations/setDataPick.mjs";
|
|
12
|
-
|
|
13
|
+
//#region src/operations/scriptAnalysis.ts
|
|
14
|
+
function normalizeNativeAnalysis(nativeAnalysis, featureFlags) {
|
|
15
|
+
const validFeatures = new Set(Object.values(featureFlags?.hookToFeature ?? {}));
|
|
16
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const feature of nativeAnalysis.featureFlags) if (!validFeatures.size || validFeatures.has(feature)) enabled.add(feature);
|
|
18
|
+
return {
|
|
19
|
+
featureFlags: enabled,
|
|
20
|
+
hasPlatformApiAccess: nativeAnalysis.hasPlatformApiAccess,
|
|
21
|
+
hasStaticRequireLiteral: nativeAnalysis.hasStaticRequireLiteral
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 对同一份脚本做批量 AST 预分析,避免多个轻量检查重复 parse 或跨 native 边界。
|
|
26
|
+
*/
|
|
27
|
+
function analyzeScript(code, options) {
|
|
28
|
+
if (shouldUseNativeAst()) try {
|
|
29
|
+
const nativeAnalysis = analyzeScriptWithNative(code, {
|
|
30
|
+
hookToFeature: options?.featureFlags?.hookToFeature,
|
|
31
|
+
moduleId: options?.featureFlags?.moduleId
|
|
32
|
+
});
|
|
33
|
+
if (nativeAnalysis) return normalizeNativeAnalysis(nativeAnalysis, options?.featureFlags);
|
|
34
|
+
} catch {}
|
|
35
|
+
return {
|
|
36
|
+
featureFlags: options?.featureFlags ? collectFeatureFlagsFromCode(code, options.featureFlags) : /* @__PURE__ */ new Set(),
|
|
37
|
+
hasPlatformApiAccess: mayContainPlatformApiAccess(code, {
|
|
38
|
+
engine: options?.engine,
|
|
39
|
+
parserLike: options?.parserLike
|
|
40
|
+
}),
|
|
41
|
+
hasStaticRequireLiteral: mayContainStaticRequireLiteral(code, {
|
|
42
|
+
engine: options?.engine,
|
|
43
|
+
parserLike: options?.parserLike
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 对多份脚本做批量 native 预分析,减少 JS 与 Rust 的往返次数。
|
|
49
|
+
*/
|
|
50
|
+
function analyzeScripts(inputs, options) {
|
|
51
|
+
if (shouldUseNativeAst() && inputs.length > 0) try {
|
|
52
|
+
const nativeResults = analyzeScriptsWithNative(inputs.map((input) => ({
|
|
53
|
+
code: input.code,
|
|
54
|
+
filename: input.filename,
|
|
55
|
+
hookToFeature: input.featureFlags?.hookToFeature ?? options?.featureFlags?.hookToFeature,
|
|
56
|
+
moduleId: input.featureFlags?.moduleId ?? options?.featureFlags?.moduleId
|
|
57
|
+
})));
|
|
58
|
+
if (nativeResults?.length === inputs.length) return nativeResults.map((nativeAnalysis, index) => {
|
|
59
|
+
return normalizeNativeAnalysis(nativeAnalysis, inputs[index]?.featureFlags ?? options?.featureFlags);
|
|
60
|
+
});
|
|
61
|
+
} catch {}
|
|
62
|
+
return inputs.map((input) => analyzeScript(input.code, {
|
|
63
|
+
...options,
|
|
64
|
+
featureFlags: input.featureFlags ?? options?.featureFlags
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, analyzeScript, analyzeScripts, babelAstEngine, collectComponentPropsFromCode, collectComponentPropsWithBabel, collectComponentPropsWithOxc, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, collectFeatureFlagsWithOxc, collectIdentifiersFromExpression, collectIdentifiersFromExpressionWithOxc, collectJsxAutoComponentsFromCode, collectJsxAutoComponentsWithBabel, collectJsxAutoComponentsWithOxc, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, collectJsxTemplateTagsFromOxc, collectLoopScopeAliases, collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithNative, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, collectPatternBindingNames, collectRequireTokens, collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, collectSetDataPickKeysFromTemplateCode, collectSetDataPickKeysWithBabel, collectSetDataPickKeysWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, createJsxImportedComponent, createLineStartOffsets, createScriptSetupImport, createWarningPrefix, defaultIsDefineComponentSource, defaultResolveBabelComponentExpression, defaultResolveBabelRenderExpression, extractComponentProperties, extractPropertiesObject, extractTemplateExpressions, generate, getCallExpressionCalleeName, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, getLocationFromOffset, getMemberExpressionPropertyName, getObjectPropertyByKey, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, getRenderPropertyFromComponentOptions, getRequireAsyncLiteralToken, getScriptSetupImportedName, getStaticPropertyName, getStaticRequireLiteralValue, getVisitorKeys, hasBindingInScopes, hasPlatformApiMemberExpression, hasStaticRequireCall, isJsxDefineComponentImportSpecifier, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isPlatformApiIdentifier, isPlatformApiMemberExpression, isStaticPropertyName, isStaticRequireCall, mapConstructorName, mayContainComponentPropsShape, mayContainFeatureFlagHints, mayContainJsxAutoComponentEntry, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, mayContainRelevantScriptSetupImports, mayContainRequireCallByText, mayContainStaticRequireLiteral, mergeComponentPropTypes, oxcAstEngine, parse, parseJsLike, parseJsLikeWithEngine, platformApiIdentifierList, platformApiIdentifiers, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveOxcComponentExpression, resolveOxcRenderExpression, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, resolveTypeFromNode, toStaticObjectKey, traverse, unwrapOxcExpression, unwrapTypeScriptExpression };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
//#region src/native.ts
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
let binding;
|
|
6
|
+
let lastScriptAnalysis;
|
|
7
|
+
function resolveNativeAstModulePath() {
|
|
8
|
+
return process.env.WEAPP_VITE_NATIVE_AST_PATH?.trim() || void 0;
|
|
9
|
+
}
|
|
10
|
+
function shouldUseNativeAst() {
|
|
11
|
+
return process.env.WEAPP_VITE_NATIVE === "1" && Boolean(resolveNativeAstModulePath());
|
|
12
|
+
}
|
|
13
|
+
function loadNativeAstBindingSync() {
|
|
14
|
+
if (!shouldUseNativeAst()) return;
|
|
15
|
+
if (binding !== void 0) return binding || void 0;
|
|
16
|
+
try {
|
|
17
|
+
binding = require(resolveNativeAstModulePath());
|
|
18
|
+
} catch {
|
|
19
|
+
binding = false;
|
|
20
|
+
}
|
|
21
|
+
return binding || void 0;
|
|
22
|
+
}
|
|
23
|
+
function analyzeScriptWithNative(code, options) {
|
|
24
|
+
const analyzeNative = loadNativeAstBindingSync()?.analyzeScriptNative;
|
|
25
|
+
if (!analyzeNative) return;
|
|
26
|
+
const hookToFeatureJson = options?.hookToFeature ? JSON.stringify(options.hookToFeature) : void 0;
|
|
27
|
+
const key = [
|
|
28
|
+
code,
|
|
29
|
+
options?.filename ?? "",
|
|
30
|
+
options?.moduleId ?? "",
|
|
31
|
+
hookToFeatureJson ?? ""
|
|
32
|
+
].join("\0");
|
|
33
|
+
if (lastScriptAnalysis?.key === key) return lastScriptAnalysis.result;
|
|
34
|
+
const result = analyzeNative(code, options?.moduleId, hookToFeatureJson, options?.filename ?? "inline.ts");
|
|
35
|
+
lastScriptAnalysis = {
|
|
36
|
+
key,
|
|
37
|
+
result
|
|
38
|
+
};
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
function analyzeScriptsWithNative(inputs) {
|
|
42
|
+
const analyzeNative = loadNativeAstBindingSync()?.analyzeScriptsNative;
|
|
43
|
+
if (!analyzeNative) return;
|
|
44
|
+
return analyzeNative(inputs.map((input) => {
|
|
45
|
+
return {
|
|
46
|
+
code: input.code,
|
|
47
|
+
filename: input.filename ?? "inline.ts",
|
|
48
|
+
hookToFeatureJson: input.hookToFeature ? JSON.stringify(input.hookToFeature) : void 0,
|
|
49
|
+
moduleId: input.moduleId
|
|
50
|
+
};
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { shouldUseNativeAst as i, analyzeScriptsWithNative as n, loadNativeAstBindingSync as r, analyzeScriptWithNative as t };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { t as AstEngineName } from "./types-4qG2Ubmk.mjs";
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
|
-
|
|
4
3
|
//#region src/operations/onPageScroll/types.d.ts
|
|
5
4
|
interface PageScrollInspection {
|
|
6
5
|
empty: boolean;
|
|
@@ -27,7 +26,7 @@ declare function isOnPageScrollCallee(callee: t.Expression | t.V8IntrinsicIdenti
|
|
|
27
26
|
declare function getCallExpressionCalleeName(callee: t.Expression | t.V8IntrinsicIdentifier): string | undefined;
|
|
28
27
|
declare function getOnPageScrollCallbackArgument(node: {
|
|
29
28
|
arguments?: Array<t.Expression | t.SpreadElement | t.ArgumentPlaceholder | null>;
|
|
30
|
-
}): t.
|
|
29
|
+
}): t.FunctionExpression | t.ArrowFunctionExpression | undefined;
|
|
31
30
|
declare function createWarningPrefix(filename: string, line?: number, column?: number): string;
|
|
32
31
|
declare function getOxcStaticPropertyName(node: any): string | undefined;
|
|
33
32
|
declare function getOxcMemberExpressionPropertyName(node: any): string | undefined;
|
|
@@ -38,6 +37,7 @@ declare function createLineStartOffsets(code: string): number[];
|
|
|
38
37
|
declare function getLocationFromOffset(offset: number | undefined, lineStarts: number[]): OxcLoc | undefined;
|
|
39
38
|
//#endregion
|
|
40
39
|
//#region src/operations/onPageScroll/index.d.ts
|
|
40
|
+
declare function collectOnPageScrollWarningsWithNative(code: string, filename: string): string[] | undefined;
|
|
41
41
|
/**
|
|
42
42
|
* 静态检测 onPageScroll 中的常见性能风险并返回告警文案。
|
|
43
43
|
*/
|
|
@@ -45,4 +45,4 @@ declare function collectOnPageScrollPerformanceWarnings(code: string, filename:
|
|
|
45
45
|
engine?: AstEngineName;
|
|
46
46
|
}): string[];
|
|
47
47
|
//#endregion
|
|
48
|
-
export {
|
|
48
|
+
export { collectPageScrollInspectionWithOxc as _, getCallExpressionCalleeName as a, getOnPageScrollCallbackArgument as c, getOxcStaticPropertyName as d, isOnPageScrollCallee as f, collectOnPageScrollWarningsWithOxc as g, isStaticPropertyName as h, createWarningPrefix as i, getOxcCallExpressionCalleeName as l, isOxcOnPageScrollCallee as m, collectOnPageScrollWarningsWithNative as n, getLocationFromOffset as o, isOxcFunctionLike as p, createLineStartOffsets as r, getMemberExpressionPropertyName as s, collectOnPageScrollPerformanceWarnings as t, getOxcMemberExpressionPropertyName as u, collectOnPageScrollWarningsWithBabel as v, collectPageScrollInspection as y };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseJsLike, traverse } from "./babel.mjs";
|
|
2
2
|
import { t as parseJsLikeWithEngine } from "./engine-CBE2OpFp.mjs";
|
|
3
|
+
import { i as shouldUseNativeAst, r as loadNativeAstBindingSync } from "./native-C-xcrMBn.mjs";
|
|
3
4
|
import { walk } from "oxc-walker";
|
|
4
5
|
//#region src/operations/onPageScroll/shared.ts
|
|
5
6
|
function isStaticPropertyName(key) {
|
|
@@ -242,6 +243,25 @@ function collectOnPageScrollWarningsWithOxc(code, filename) {
|
|
|
242
243
|
}
|
|
243
244
|
//#endregion
|
|
244
245
|
//#region src/operations/onPageScroll/index.ts
|
|
246
|
+
function formatNativeOnPageScrollWarning(diagnostic, filename) {
|
|
247
|
+
const prefix = createWarningPrefix(filename, diagnostic.line, diagnostic.column);
|
|
248
|
+
if (diagnostic.kind === "empty") return `${prefix} 检测到空的 ${diagnostic.sourceLabel} 回调,建议移除无效监听以降低滚动时调度开销。`;
|
|
249
|
+
if (diagnostic.kind === "setData") return `${prefix} 检测到 ${diagnostic.sourceLabel} 内调用 setData,建议改用节流、IntersectionObserver 或合并更新。`;
|
|
250
|
+
return `${prefix} 检测到 ${diagnostic.sourceLabel} 内调用同步 API(${diagnostic.syncApi ?? "wx.*Sync"}),可能阻塞渲染线程。`;
|
|
251
|
+
}
|
|
252
|
+
function collectOnPageScrollWarningsWithNative(code, filename) {
|
|
253
|
+
const collectNative = loadNativeAstBindingSync()?.collectOnPageScrollDiagnosticsNative;
|
|
254
|
+
if (!collectNative) return;
|
|
255
|
+
const warnings = [];
|
|
256
|
+
const warningSet = /* @__PURE__ */ new Set();
|
|
257
|
+
for (const diagnostic of collectNative(code, filename)) {
|
|
258
|
+
const warning = formatNativeOnPageScrollWarning(diagnostic, filename);
|
|
259
|
+
if (warningSet.has(warning)) continue;
|
|
260
|
+
warningSet.add(warning);
|
|
261
|
+
warnings.push(warning);
|
|
262
|
+
}
|
|
263
|
+
return warnings;
|
|
264
|
+
}
|
|
245
265
|
/**
|
|
246
266
|
* 静态检测 onPageScroll 中的常见性能风险并返回告警文案。
|
|
247
267
|
*/
|
|
@@ -252,6 +272,10 @@ function collectOnPageScrollPerformanceWarnings(code, filename, options) {
|
|
|
252
272
|
} catch {
|
|
253
273
|
return [];
|
|
254
274
|
}
|
|
275
|
+
if (shouldUseNativeAst()) try {
|
|
276
|
+
const warnings = collectOnPageScrollWarningsWithNative(code, filename);
|
|
277
|
+
if (warnings) return warnings;
|
|
278
|
+
} catch {}
|
|
255
279
|
try {
|
|
256
280
|
return collectOnPageScrollWarningsWithBabel(code, filename);
|
|
257
281
|
} catch {
|
|
@@ -259,4 +283,4 @@ function collectOnPageScrollPerformanceWarnings(code, filename, options) {
|
|
|
259
283
|
}
|
|
260
284
|
}
|
|
261
285
|
//#endregion
|
|
262
|
-
export {
|
|
286
|
+
export { isOxcFunctionLike as _, collectOnPageScrollWarningsWithBabel as a, createWarningPrefix as c, getMemberExpressionPropertyName as d, getOnPageScrollCallbackArgument as f, isOnPageScrollCallee as g, getOxcStaticPropertyName as h, collectPageScrollInspectionWithOxc as i, getCallExpressionCalleeName as l, getOxcMemberExpressionPropertyName as m, collectOnPageScrollWarningsWithNative as n, collectPageScrollInspection as o, getOxcCallExpressionCalleeName as p, collectOnPageScrollWarningsWithOxc as r, createLineStartOffsets as s, collectOnPageScrollPerformanceWarnings as t, getLocationFromOffset as u, isOxcOnPageScrollCallee as v, isStaticPropertyName as y };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { t as AstEngineName } from "../types-4qG2Ubmk.mjs";
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
3
|
import { NodePath } from "@babel/traverse";
|
|
4
|
-
|
|
5
4
|
//#region src/operations/componentProps.d.ts
|
|
6
5
|
type ComponentPropMap = Map<string, string>;
|
|
7
6
|
declare function mayContainComponentPropsShape(code: string): boolean;
|
|
@@ -27,7 +27,8 @@ function hasOwn(source, key) {
|
|
|
27
27
|
}
|
|
28
28
|
function mapConstructorName(name) {
|
|
29
29
|
if (hasOwn(CONSTRUCTOR_TYPE_MAP, name)) return CONSTRUCTOR_TYPE_MAP[name];
|
|
30
|
-
|
|
30
|
+
const normalized = name.endsWith("Constructor") ? name.slice(0, -11) : name;
|
|
31
|
+
return CONSTRUCTOR_TYPE_MAP[normalized] ?? "any";
|
|
31
32
|
}
|
|
32
33
|
function resolveTypeFromNode(node) {
|
|
33
34
|
if (!node) return "any";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { t as AstEngineName } from "../types-4qG2Ubmk.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/operations/featureFlags.d.ts
|
|
4
3
|
interface FeatureFlagOptions<TFeature extends string> {
|
|
5
4
|
astEngine?: AstEngineName;
|
|
@@ -13,9 +12,11 @@ declare function registerNamedFeatureFlagLocal<TFeature extends string>(namedHoo
|
|
|
13
12
|
declare function registerNamespaceFeatureFlagLocal(namespaceLocals: Set<string>, localName: string | undefined): void;
|
|
14
13
|
declare function collectFeatureFlagsWithBabel<TFeature extends string>(code: string, moduleId: string, hookToFeature: Record<string, TFeature>): Set<TFeature>;
|
|
15
14
|
declare function collectFeatureFlagsWithOxc<TFeature extends string>(code: string, moduleId: string, hookToFeature: Record<string, TFeature>): Set<TFeature>;
|
|
15
|
+
declare function collectFeatureFlagsWithNative<TFeature extends string>(code: string, moduleId: string, hookToFeature: Record<string, TFeature>): Set<TFeature> | undefined;
|
|
16
|
+
declare function collectFeatureFlagsWithNativeBatch<TFeature extends string>(code: string, moduleId: string, hookToFeature: Record<string, TFeature>): Set<TFeature> | undefined;
|
|
16
17
|
/**
|
|
17
18
|
* 根据模块 ID 与 hook 映射表,从源码中收集启用的特性标识。
|
|
18
19
|
*/
|
|
19
20
|
declare function collectFeatureFlagsFromCode<TFeature extends string>(code: string, options: FeatureFlagOptions<TFeature>): Set<TFeature>;
|
|
20
21
|
//#endregion
|
|
21
|
-
export { FeatureFlagOptions, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal };
|
|
22
|
+
export { FeatureFlagOptions, collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseJsLike, traverse } from "../babel.mjs";
|
|
2
2
|
import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
|
|
3
|
+
import { i as shouldUseNativeAst, r as loadNativeAstBindingSync, t as analyzeScriptWithNative } from "../native-C-xcrMBn.mjs";
|
|
3
4
|
import * as t from "@babel/types";
|
|
4
5
|
import { walk } from "oxc-walker";
|
|
5
6
|
//#region src/operations/featureFlags.ts
|
|
@@ -87,6 +88,25 @@ function collectFeatureFlagsWithOxc(code, moduleId, hookToFeature) {
|
|
|
87
88
|
} });
|
|
88
89
|
return enabled;
|
|
89
90
|
}
|
|
91
|
+
function collectFeatureFlagsWithNative(code, moduleId, hookToFeature) {
|
|
92
|
+
const collectNative = loadNativeAstBindingSync()?.collectFeatureFlagsNative;
|
|
93
|
+
if (!collectNative) return;
|
|
94
|
+
const validFeatures = new Set(Object.values(hookToFeature));
|
|
95
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
96
|
+
for (const feature of collectNative(code, moduleId, JSON.stringify(hookToFeature), "inline.ts")) if (validFeatures.has(feature)) enabled.add(feature);
|
|
97
|
+
return enabled;
|
|
98
|
+
}
|
|
99
|
+
function collectFeatureFlagsWithNativeBatch(code, moduleId, hookToFeature) {
|
|
100
|
+
const validFeatures = new Set(Object.values(hookToFeature));
|
|
101
|
+
const analysis = analyzeScriptWithNative(code, {
|
|
102
|
+
hookToFeature,
|
|
103
|
+
moduleId
|
|
104
|
+
});
|
|
105
|
+
if (!analysis) return;
|
|
106
|
+
const enabled = /* @__PURE__ */ new Set();
|
|
107
|
+
for (const feature of analysis.featureFlags) if (validFeatures.has(feature)) enabled.add(feature);
|
|
108
|
+
return enabled;
|
|
109
|
+
}
|
|
90
110
|
/**
|
|
91
111
|
* 根据模块 ID 与 hook 映射表,从源码中收集启用的特性标识。
|
|
92
112
|
*/
|
|
@@ -94,10 +114,14 @@ function collectFeatureFlagsFromCode(code, options) {
|
|
|
94
114
|
if (!mayContainFeatureFlagHints(code, options.moduleId, options.hookToFeature)) return /* @__PURE__ */ new Set();
|
|
95
115
|
const engine = options.astEngine ?? "babel";
|
|
96
116
|
try {
|
|
117
|
+
if (shouldUseNativeAst()) try {
|
|
118
|
+
const nativeEnabled = collectFeatureFlagsWithNativeBatch(code, options.moduleId, options.hookToFeature) ?? collectFeatureFlagsWithNative(code, options.moduleId, options.hookToFeature);
|
|
119
|
+
if (nativeEnabled) return nativeEnabled;
|
|
120
|
+
} catch {}
|
|
97
121
|
return engine === "oxc" ? collectFeatureFlagsWithOxc(code, options.moduleId, options.hookToFeature) : collectFeatureFlagsWithBabel(code, options.moduleId, options.hookToFeature);
|
|
98
122
|
} catch {
|
|
99
123
|
return /* @__PURE__ */ new Set();
|
|
100
124
|
}
|
|
101
125
|
}
|
|
102
126
|
//#endregion
|
|
103
|
-
export { collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal };
|
|
127
|
+
export { collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { t as AstEngineName } from "../types-4qG2Ubmk.mjs";
|
|
2
2
|
import * as t from "@babel/types";
|
|
3
3
|
import { Expression, ObjectExpression } from "@babel/types";
|
|
4
|
-
|
|
5
4
|
//#region src/operations/jsxAutoComponents/types.d.ts
|
|
6
5
|
interface JsxImportedComponent {
|
|
7
6
|
localName: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
|
|
1
|
+
import { _ as collectPageScrollInspectionWithOxc, a as getCallExpressionCalleeName, c as getOnPageScrollCallbackArgument, d as getOxcStaticPropertyName, f as isOnPageScrollCallee, g as collectOnPageScrollWarningsWithOxc, h as isStaticPropertyName, i as createWarningPrefix, l as getOxcCallExpressionCalleeName, m as isOxcOnPageScrollCallee, n as collectOnPageScrollWarningsWithNative, o as getLocationFromOffset, p as isOxcFunctionLike, r as createLineStartOffsets, s as getMemberExpressionPropertyName, t as collectOnPageScrollPerformanceWarnings, u as getOxcMemberExpressionPropertyName, v as collectOnPageScrollWarningsWithBabel, y as collectPageScrollInspection } from "../onPageScroll-n3Vptu1_.mjs";
|
|
2
|
+
export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithNative, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as
|
|
2
|
-
export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
|
|
1
|
+
import { _ as isOxcFunctionLike, a as collectOnPageScrollWarningsWithBabel, c as createWarningPrefix, d as getMemberExpressionPropertyName, f as getOnPageScrollCallbackArgument, g as isOnPageScrollCallee, h as getOxcStaticPropertyName, i as collectPageScrollInspectionWithOxc, l as getCallExpressionCalleeName, m as getOxcMemberExpressionPropertyName, n as collectOnPageScrollWarningsWithNative, o as collectPageScrollInspection, p as getOxcCallExpressionCalleeName, r as collectOnPageScrollWarningsWithOxc, s as createLineStartOffsets, t as collectOnPageScrollPerformanceWarnings, u as getLocationFromOffset, v as isOxcOnPageScrollCallee, y as isStaticPropertyName } from "../onPageScroll-tuvgNooK.mjs";
|
|
2
|
+
export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithNative, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { n as AstParserLike, t as AstEngineName } from "../types-4qG2Ubmk.mjs";
|
|
2
2
|
import { Program } from "@oxc-project/types";
|
|
3
|
-
|
|
4
3
|
//#region src/operations/platformApi.d.ts
|
|
5
4
|
declare const platformApiIdentifierList: readonly ["wx", "my", "tt", "swan", "jd", "xhs"];
|
|
6
5
|
declare const platformApiIdentifiers: Set<"wx" | "my" | "tt" | "swan" | "jd" | "xhs">;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
|
|
2
|
+
import { i as shouldUseNativeAst, r as loadNativeAstBindingSync, t as analyzeScriptWithNative } from "../native-C-xcrMBn.mjs";
|
|
2
3
|
import { walk } from "oxc-walker";
|
|
3
4
|
//#region src/operations/platformApi.ts
|
|
4
5
|
const platformApiIdentifierList = [
|
|
@@ -35,6 +36,12 @@ function mayContainPlatformApiAccess(code, options) {
|
|
|
35
36
|
const engine = options?.engine ?? "babel";
|
|
36
37
|
if (engine !== "oxc") return true;
|
|
37
38
|
if (!mayContainPlatformApiIdentifierByText(code)) return false;
|
|
39
|
+
if (shouldUseNativeAst()) try {
|
|
40
|
+
const batchAnalysis = analyzeScriptWithNative(code);
|
|
41
|
+
if (batchAnalysis) return batchAnalysis.hasPlatformApiAccess;
|
|
42
|
+
const checkNative = loadNativeAstBindingSync()?.mayContainPlatformApiAccessNative;
|
|
43
|
+
if (checkNative) return checkNative(code, "inline.ts");
|
|
44
|
+
} catch {}
|
|
38
45
|
try {
|
|
39
46
|
return hasPlatformApiMemberExpression(parseJsLikeWithEngine(code, {
|
|
40
47
|
engine,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
|
|
2
|
+
import { i as shouldUseNativeAst, r as loadNativeAstBindingSync, t as analyzeScriptWithNative } from "../native-C-xcrMBn.mjs";
|
|
2
3
|
import { walk } from "oxc-walker";
|
|
3
4
|
//#region src/operations/require.ts
|
|
4
5
|
function mayContainRequireCallByText(code) {
|
|
@@ -52,6 +53,12 @@ function mayContainStaticRequireLiteral(code, options) {
|
|
|
52
53
|
const engine = options?.engine ?? "babel";
|
|
53
54
|
if (engine !== "oxc") return true;
|
|
54
55
|
if (!mayContainRequireCallByText(code)) return false;
|
|
56
|
+
if (shouldUseNativeAst()) try {
|
|
57
|
+
const batchAnalysis = analyzeScriptWithNative(code);
|
|
58
|
+
if (batchAnalysis) return batchAnalysis.hasStaticRequireLiteral;
|
|
59
|
+
const checkNative = loadNativeAstBindingSync()?.mayContainStaticRequireLiteralNative;
|
|
60
|
+
if (checkNative) return checkNative(code, "inline.ts");
|
|
61
|
+
} catch {}
|
|
55
62
|
try {
|
|
56
63
|
return hasStaticRequireCall(parseJsLikeWithEngine(code, {
|
|
57
64
|
engine,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/ast",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.18.1",
|
|
5
5
|
"description": "weapp-vite 共享 AST 分析工具包,统一 Babel/Oxc 解析与常用分析操作",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -103,11 +103,11 @@
|
|
|
103
103
|
"dependencies": {
|
|
104
104
|
"@babel/core": "^8.0.1",
|
|
105
105
|
"@babel/generator": "^8.0.0",
|
|
106
|
-
"@babel/parser": "^8.0.
|
|
107
|
-
"@babel/traverse": "^8.0.
|
|
108
|
-
"@babel/types": "^8.0.
|
|
109
|
-
"@oxc-project/types": "^0.
|
|
110
|
-
"oxc-parser": "^0.
|
|
106
|
+
"@babel/parser": "^8.0.4",
|
|
107
|
+
"@babel/traverse": "^8.0.4",
|
|
108
|
+
"@babel/types": "^8.0.4",
|
|
109
|
+
"@oxc-project/types": "^0.139.0",
|
|
110
|
+
"oxc-parser": "^0.139.0",
|
|
111
111
|
"oxc-walker": "^1.0.0",
|
|
112
112
|
"@weapp-core/shared": "3.0.5"
|
|
113
113
|
},
|