@weapp-vite/ast 6.18.7 → 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.
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ import { FeatureFlagOptions, collectFeatureFlagsFromCode, collectFeatureFlagsWit
|
|
|
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
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-D-n7saS4.mjs";
|
|
9
9
|
import { hasPlatformApiMemberExpression, isPlatformApiIdentifier, isPlatformApiMemberExpression, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, platformApiIdentifierList, platformApiIdentifiers } from "./operations/platformApi.mjs";
|
|
10
|
-
import { RequireToken, collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral } from "./operations/require.mjs";
|
|
10
|
+
import { DynamicImportToken, RequireCallbackToken, RequireToken, collectRequireTokens, getDynamicImportLiteralToken, getRequireAsyncLiteralToken, getRequireCallbackLiteralToken, 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
13
|
//#region src/engines/babel.d.ts
|
|
@@ -53,4 +53,4 @@ declare function analyzeScript<TFeature extends string = string>(code: string, o
|
|
|
53
53
|
*/
|
|
54
54
|
declare function analyzeScripts<TFeature extends string = string>(inputs: ScriptAnalysisBatchInput<TFeature>[], options?: ScriptAnalysisOptions<TFeature>): Array<ScriptAnalysisResult<TFeature>>;
|
|
55
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 };
|
|
56
|
+
export { type AstEngineName, type AstParserLike, BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, type ComponentPropMap, type DynamicImportToken, type FeatureFlagOptions, type JsxAutoComponentAnalysisOptions, type JsxAutoComponentContext, type JsxBabelModuleAnalysisOptions, type JsxImportedComponent, type RequireCallbackToken, 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, getDynamicImportLiteralToken, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, getLocationFromOffset, getMemberExpressionPropertyName, getObjectPropertyByKey, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, getRenderPropertyFromComponentOptions, getRequireAsyncLiteralToken, getRequireCallbackLiteralToken, 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
|
@@ -7,7 +7,7 @@ import { collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatu
|
|
|
7
7
|
import { collectJsxAutoComponentsFromCode, collectJsxAutoComponentsWithBabel, collectJsxAutoComponentsWithOxc, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, collectJsxTemplateTagsFromOxc, createJsxImportedComponent, defaultIsDefineComponentSource, defaultResolveBabelComponentExpression, defaultResolveBabelRenderExpression, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, isJsxDefineComponentImportSpecifier, mayContainJsxAutoComponentEntry, resolveOxcComponentExpression, resolveOxcRenderExpression, unwrapOxcExpression } from "./operations/jsxAutoComponents.mjs";
|
|
8
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";
|
|
9
9
|
import { hasPlatformApiMemberExpression, isPlatformApiIdentifier, isPlatformApiMemberExpression, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, platformApiIdentifierList, platformApiIdentifiers } from "./operations/platformApi.mjs";
|
|
10
|
-
import { collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral } from "./operations/require.mjs";
|
|
10
|
+
import { collectRequireTokens, getDynamicImportLiteralToken, getRequireAsyncLiteralToken, getRequireCallbackLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral } from "./operations/require.mjs";
|
|
11
11
|
import { 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
13
|
//#region src/operations/scriptAnalysis.ts
|
|
@@ -65,4 +65,4 @@ function analyzeScripts(inputs, options) {
|
|
|
65
65
|
}));
|
|
66
66
|
}
|
|
67
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 };
|
|
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, getDynamicImportLiteralToken, getJsxImportLocalName, getJsxImportedName, getJsxOxcStaticPropertyName, getLocationFromOffset, getMemberExpressionPropertyName, getObjectPropertyByKey, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, getRenderPropertyFromComponentOptions, getRequireAsyncLiteralToken, getRequireCallbackLiteralToken, 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 };
|
|
@@ -7,13 +7,38 @@ interface RequireToken {
|
|
|
7
7
|
value: string;
|
|
8
8
|
async?: boolean;
|
|
9
9
|
}
|
|
10
|
+
interface DynamicImportToken {
|
|
11
|
+
callEnd: number;
|
|
12
|
+
callStart: number;
|
|
13
|
+
end: number;
|
|
14
|
+
start: number;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
interface RequireCallbackToken extends RequireToken {
|
|
18
|
+
callEnd: number;
|
|
19
|
+
callStart: number;
|
|
20
|
+
errorCallbackEnd?: number;
|
|
21
|
+
errorCallbackStart?: number;
|
|
22
|
+
successCallbackEnd: number;
|
|
23
|
+
successCallbackStart: number;
|
|
24
|
+
}
|
|
10
25
|
declare function mayContainRequireCallByText(code: string): boolean;
|
|
11
26
|
declare function getStaticRequireLiteralValue(node: any): any;
|
|
12
27
|
/**
|
|
13
28
|
* 收集 `require.async()` 依赖字面量。
|
|
14
29
|
*/
|
|
15
30
|
declare function getRequireAsyncLiteralToken(node: any): RequireToken | null;
|
|
31
|
+
/**
|
|
32
|
+
* 收集 `require(path, callback)` 依赖字面量。
|
|
33
|
+
*/
|
|
34
|
+
declare function getRequireCallbackLiteralToken(node: any): RequireCallbackToken | null;
|
|
35
|
+
/**
|
|
36
|
+
* 收集静态 `import()` 依赖字面量。
|
|
37
|
+
*/
|
|
38
|
+
declare function getDynamicImportLiteralToken(node: any): DynamicImportToken | null;
|
|
16
39
|
declare function collectRequireTokens(ast: unknown): {
|
|
40
|
+
dynamicImportTokens: DynamicImportToken[];
|
|
41
|
+
requireCallbackTokens: RequireCallbackToken[];
|
|
17
42
|
requireTokens: RequireToken[];
|
|
18
43
|
};
|
|
19
44
|
declare function isStaticRequireCall(node: any): boolean;
|
|
@@ -26,4 +51,4 @@ declare function mayContainStaticRequireLiteral(code: string, options?: {
|
|
|
26
51
|
parserLike?: AstParserLike;
|
|
27
52
|
}): boolean;
|
|
28
53
|
//#endregion
|
|
29
|
-
export { RequireToken, collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral };
|
|
54
|
+
export { DynamicImportToken, RequireCallbackToken, RequireToken, collectRequireTokens, getDynamicImportLiteralToken, getRequireAsyncLiteralToken, getRequireCallbackLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral };
|
|
@@ -11,27 +11,86 @@ function getStaticRequireLiteralValue(node) {
|
|
|
11
11
|
if (node.type === "TemplateLiteral" && Array.isArray(node.expressions) && node.expressions.length === 0 && Array.isArray(node.quasis) && node.quasis.length === 1) return node.quasis[0]?.value?.cooked ?? node.quasis[0]?.value?.raw ?? null;
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
|
+
function createAsyncRequireToken(node) {
|
|
15
|
+
const argv0 = node.arguments?.[0];
|
|
16
|
+
const value = getStaticRequireLiteralValue(argv0);
|
|
17
|
+
if (!argv0 || value === null) return null;
|
|
18
|
+
return {
|
|
19
|
+
start: argv0.start,
|
|
20
|
+
end: argv0.end,
|
|
21
|
+
value,
|
|
22
|
+
async: true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
14
25
|
/**
|
|
15
26
|
* 收集 `require.async()` 依赖字面量。
|
|
16
27
|
*/
|
|
17
28
|
function getRequireAsyncLiteralToken(node) {
|
|
18
29
|
if (node?.type !== "CallExpression" || node.callee?.type !== "MemberExpression" || node.callee.object?.type !== "Identifier" || node.callee.object.name !== "require" || node.callee.property?.type !== "Identifier" || node.callee.property.name !== "async") return null;
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
return createAsyncRequireToken(node);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 收集 `require(path, callback)` 依赖字面量。
|
|
34
|
+
*/
|
|
35
|
+
function getRequireCallbackLiteralToken(node) {
|
|
36
|
+
if (node?.type !== "CallExpression" || node.callee?.type !== "Identifier" || node.callee.name !== "require" || !Array.isArray(node.arguments) || node.arguments.length < 2) return null;
|
|
37
|
+
const token = createAsyncRequireToken(node);
|
|
38
|
+
const successCallback = node.arguments[1];
|
|
39
|
+
const errorCallback = node.arguments[2];
|
|
40
|
+
if (!token || !successCallback) return null;
|
|
21
41
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
...token,
|
|
43
|
+
callStart: node.start,
|
|
44
|
+
callEnd: node.end,
|
|
45
|
+
successCallbackStart: successCallback.start,
|
|
46
|
+
successCallbackEnd: successCallback.end,
|
|
47
|
+
...errorCallback ? {
|
|
48
|
+
errorCallbackStart: errorCallback.start,
|
|
49
|
+
errorCallbackEnd: errorCallback.end
|
|
50
|
+
} : {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 收集静态 `import()` 依赖字面量。
|
|
55
|
+
*/
|
|
56
|
+
function getDynamicImportLiteralToken(node) {
|
|
57
|
+
if (node?.type !== "ImportExpression") return null;
|
|
58
|
+
const value = getStaticRequireLiteralValue(node.source);
|
|
59
|
+
if (!node.source || value === null) return null;
|
|
60
|
+
return {
|
|
61
|
+
callEnd: node.end,
|
|
62
|
+
callStart: node.start,
|
|
63
|
+
end: node.source.end,
|
|
64
|
+
start: node.source.start,
|
|
65
|
+
value
|
|
26
66
|
};
|
|
27
67
|
}
|
|
28
68
|
function collectRequireTokens(ast) {
|
|
69
|
+
const dynamicImportTokens = [];
|
|
29
70
|
const requireTokens = [];
|
|
71
|
+
const requireCallbackTokens = [];
|
|
30
72
|
walk(ast, { enter(node) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
73
|
+
const dynamicImportToken = getDynamicImportLiteralToken(node);
|
|
74
|
+
if (dynamicImportToken) {
|
|
75
|
+
dynamicImportTokens.push(dynamicImportToken);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const asyncToken = getRequireAsyncLiteralToken(node);
|
|
79
|
+
if (asyncToken) {
|
|
80
|
+
requireTokens.push(asyncToken);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const callbackToken = getRequireCallbackLiteralToken(node);
|
|
84
|
+
if (callbackToken) {
|
|
85
|
+
requireTokens.push(callbackToken);
|
|
86
|
+
requireCallbackTokens.push(callbackToken);
|
|
87
|
+
}
|
|
33
88
|
} });
|
|
34
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
dynamicImportTokens,
|
|
91
|
+
requireCallbackTokens,
|
|
92
|
+
requireTokens
|
|
93
|
+
};
|
|
35
94
|
}
|
|
36
95
|
function isStaticRequireCall(node) {
|
|
37
96
|
if (node?.type !== "CallExpression") return false;
|
|
@@ -70,4 +129,4 @@ function mayContainStaticRequireLiteral(code, options) {
|
|
|
70
129
|
}
|
|
71
130
|
}
|
|
72
131
|
//#endregion
|
|
73
|
-
export { collectRequireTokens, getRequireAsyncLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral };
|
|
132
|
+
export { collectRequireTokens, getDynamicImportLiteralToken, getRequireAsyncLiteralToken, getRequireCallbackLiteralToken, getStaticRequireLiteralValue, hasStaticRequireCall, isStaticRequireCall, mayContainRequireCallByText, mayContainStaticRequireLiteral };
|
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.19.1",
|
|
5
5
|
"description": "weapp-vite 共享 AST 分析工具包,统一 Babel/Oxc 解析与常用分析操作",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -106,10 +106,10 @@
|
|
|
106
106
|
"@babel/parser": "^8.0.4",
|
|
107
107
|
"@babel/traverse": "^8.0.4",
|
|
108
108
|
"@babel/types": "^8.0.4",
|
|
109
|
-
"@oxc-project/types": "^0.
|
|
110
|
-
"oxc-parser": "^0.
|
|
111
|
-
"oxc-walker": "^1.
|
|
112
|
-
"@weapp-core/shared": "3.0
|
|
109
|
+
"@oxc-project/types": "^0.143.0",
|
|
110
|
+
"oxc-parser": "^0.143.0",
|
|
111
|
+
"oxc-walker": "^1.1.1",
|
|
112
|
+
"@weapp-core/shared": "3.1.0"
|
|
113
113
|
},
|
|
114
114
|
"publishConfig": {
|
|
115
115
|
"access": "public",
|