@weapp-vite/ast 7.5.0 → 7.6.0
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 +2 -1
- package/dist/babelLoader.d.mts +4 -0
- package/dist/babelLoader.mjs +33 -0
- package/dist/index.d.mts +73 -4
- package/dist/index.mjs +68 -24
- package/dist/native-Bt7ZuZIc.mjs +362 -0
- package/dist/{onPageScroll-n3Vptu1_.d.mts → onPageScroll-D-n7saS4.d.mts} +1 -1
- package/dist/{onPageScroll-tuvgNooK.mjs → onPageScroll-DvBA8vNH.mjs} +1 -1
- package/dist/operations/featureFlags.mjs +1 -1
- package/dist/operations/onPageScroll.d.mts +1 -1
- package/dist/operations/onPageScroll.mjs +1 -1
- package/dist/operations/platformApi.mjs +1 -1
- package/dist/operations/require.mjs +1 -1
- package/package.json +14 -4
- package/dist/native-C-xcrMBn.mjs +0 -54
package/dist/babel.d.mts
CHANGED
|
@@ -16,4 +16,5 @@ export declare const generate: GenerateFn;
|
|
|
16
16
|
export declare const parse: BabelParse;
|
|
17
17
|
export declare function getVisitorKeys(): typeof import('@babel/types').VISITOR_KEYS;
|
|
18
18
|
export declare function parseJsLike(source: string): t.File;
|
|
19
|
-
//#endregion
|
|
19
|
+
//#endregion
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region src/babelLoader.ts
|
|
3
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
4
|
+
let babelPrimed = false;
|
|
5
|
+
function primeBabelDependencies() {
|
|
6
|
+
if (babelPrimed) return;
|
|
7
|
+
nodeRequire("@babel/core");
|
|
8
|
+
nodeRequire("@babel/parser");
|
|
9
|
+
nodeRequire("@babel/generator");
|
|
10
|
+
nodeRequire("@babel/traverse");
|
|
11
|
+
nodeRequire("@babel/types");
|
|
12
|
+
babelPrimed = true;
|
|
13
|
+
}
|
|
14
|
+
/** 创建按需加载的 Babel 后端入口,在首次异步导入前完成同步 AST 依赖初始化。 */
|
|
15
|
+
function createBabelBackendLoader(importer) {
|
|
16
|
+
let pending;
|
|
17
|
+
return () => {
|
|
18
|
+
if (pending) return pending;
|
|
19
|
+
try {
|
|
20
|
+
primeBabelDependencies();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return Promise.reject(error);
|
|
23
|
+
}
|
|
24
|
+
const loading = Promise.resolve().then(importer);
|
|
25
|
+
pending = loading;
|
|
26
|
+
loading.catch(() => {
|
|
27
|
+
if (pending === loading) pending = void 0;
|
|
28
|
+
});
|
|
29
|
+
return loading;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createBabelBackendLoader };
|
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, 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 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-
|
|
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
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";
|
|
@@ -28,6 +28,75 @@ export declare const oxcAstEngine: {
|
|
|
28
28
|
parseJsLike(code: string, filename?: string): import("oxc-parser").Program;
|
|
29
29
|
};
|
|
30
30
|
//#endregion
|
|
31
|
+
//#region src/native/npmChunks.d.ts
|
|
32
|
+
interface NativeNpmChunkAnalysisInput {
|
|
33
|
+
code: string;
|
|
34
|
+
filename?: string;
|
|
35
|
+
}
|
|
36
|
+
interface NativeNpmRequireFact {
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
importee: string;
|
|
40
|
+
}
|
|
41
|
+
interface NativeNpmPlatformApiFact {
|
|
42
|
+
start: number;
|
|
43
|
+
end: number;
|
|
44
|
+
}
|
|
45
|
+
interface NativeNpmLocalRootFact {
|
|
46
|
+
kind: 'alias' | 'require' | 'interop';
|
|
47
|
+
requireIndex?: number;
|
|
48
|
+
bindingName?: string;
|
|
49
|
+
referenceName?: string;
|
|
50
|
+
importee?: string;
|
|
51
|
+
secondArgumentStart?: number;
|
|
52
|
+
secondArgumentEnd?: number;
|
|
53
|
+
}
|
|
54
|
+
interface NativeNpmChunkAnalysis {
|
|
55
|
+
requires: NativeNpmRequireFact[];
|
|
56
|
+
platformApiRanges: NativeNpmPlatformApiFact[];
|
|
57
|
+
localRootFacts: NativeNpmLocalRootFact[];
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/native.d.ts
|
|
61
|
+
interface NativeCompilerScriptInput {
|
|
62
|
+
code: string;
|
|
63
|
+
filename?: string;
|
|
64
|
+
}
|
|
65
|
+
interface NativeCompilerScriptImport {
|
|
66
|
+
local: string;
|
|
67
|
+
imported?: string;
|
|
68
|
+
source: string;
|
|
69
|
+
kind: 'default' | 'namespace' | 'named';
|
|
70
|
+
typeOnly: boolean;
|
|
71
|
+
}
|
|
72
|
+
interface NativeCompilerRegisteredComponent {
|
|
73
|
+
name: string;
|
|
74
|
+
local: string;
|
|
75
|
+
}
|
|
76
|
+
interface NativeCompilerScriptSpan {
|
|
77
|
+
start: number;
|
|
78
|
+
end: number;
|
|
79
|
+
}
|
|
80
|
+
interface NativeCompilerScriptAnalysis {
|
|
81
|
+
imports: NativeCompilerScriptImport[];
|
|
82
|
+
/** 旧 binding 缺失该事实时,由编译阶段执行原有默认导出检查。 */
|
|
83
|
+
hasDefaultExport?: boolean;
|
|
84
|
+
defineOptionsStatements: NativeCompilerScriptSpan[];
|
|
85
|
+
registeredComponents?: NativeCompilerRegisteredComponent[];
|
|
86
|
+
/** 缺失表示旧 binding 或需由 Babel 完成诊断;空对象表示已确认无警告。 */
|
|
87
|
+
reservedPropsDiagnostic?: {
|
|
88
|
+
warningOffset?: number;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 编译器前端批量摘要的显式 native 快速路径;失败时由调用方继续使用 Babel/Oxc。
|
|
93
|
+
*/
|
|
94
|
+
export declare function analyzeCompilerScriptsWithNative(inputs: NativeCompilerScriptInput[]): (NativeCompilerScriptAnalysis | null)[] | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* 批量读取最终 chunk 的重写事实;默认关闭,任何批次或单项校验失败都交回 JS。
|
|
97
|
+
*/
|
|
98
|
+
export declare function analyzeNpmChunksWithNative(inputs: NativeNpmChunkAnalysisInput[]): (NativeNpmChunkAnalysis | null)[] | undefined;
|
|
99
|
+
//#endregion
|
|
31
100
|
//#region src/operations/scriptAnalysis.d.ts
|
|
32
101
|
interface ScriptAnalysisOptions<TFeature extends string = string> {
|
|
33
102
|
engine?: AstEngineName;
|
|
@@ -45,11 +114,11 @@ interface ScriptAnalysisBatchInput<TFeature extends string = string> {
|
|
|
45
114
|
featureFlags?: FeatureFlagOptions<TFeature>;
|
|
46
115
|
}
|
|
47
116
|
/**
|
|
48
|
-
*
|
|
117
|
+
* 同一份脚本只尝试一次 native;失败后显式选择完整的 JS fallback 服务。
|
|
49
118
|
*/
|
|
50
119
|
export declare function analyzeScript<TFeature extends string = string>(code: string, options?: ScriptAnalysisOptions<TFeature>): ScriptAnalysisResult<TFeature>;
|
|
51
120
|
/**
|
|
52
|
-
*
|
|
121
|
+
* 批次只跨 native 边界一次,失败项各自执行一次完整 JS fallback。
|
|
53
122
|
*/
|
|
54
123
|
export declare function analyzeScripts<TFeature extends string = string>(inputs: ScriptAnalysisBatchInput<TFeature>[], options?: ScriptAnalysisOptions<TFeature>): Array<ScriptAnalysisResult<TFeature>>;
|
|
55
124
|
//#endregion
|
|
@@ -67,4 +136,4 @@ export declare function collectScriptCallStringLiterals(code: string): string[];
|
|
|
67
136
|
*/
|
|
68
137
|
export declare function mayContainScriptCallOrModuleSyntax(code: string): boolean;
|
|
69
138
|
//#endregion
|
|
70
|
-
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, 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, parse, parseJsLike, parseJsLikeWithEngine, platformApiIdentifierList, platformApiIdentifiers, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveOxcComponentExpression, resolveOxcRenderExpression, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, resolveTypeFromNode, toStaticObjectKey, traverse, unwrapOxcExpression, unwrapTypeScriptExpression };
|
|
139
|
+
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 NativeCompilerRegisteredComponent, type NativeCompilerScriptAnalysis, type NativeCompilerScriptImport, type NativeCompilerScriptInput, type NativeCompilerScriptSpan, type NativeNpmChunkAnalysis, type NativeNpmChunkAnalysisInput, type NativeNpmLocalRootFact, type NativeNpmPlatformApiFact, type NativeNpmRequireFact, type RequireCallbackToken, type RequireToken, type ScriptAnalysisBatchInput, type ScriptAnalysisOptions, type ScriptAnalysisResult, type ScriptSetupImport, type WeappAstConfig, 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, parse, parseJsLike, parseJsLikeWithEngine, platformApiIdentifierList, platformApiIdentifiers, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveOxcComponentExpression, resolveOxcRenderExpression, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, resolveTypeFromNode, toStaticObjectKey, traverse, unwrapOxcExpression, unwrapTypeScriptExpression };
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,51 @@
|
|
|
1
1
|
import { BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, generate, getVisitorKeys, parse, parseJsLike, traverse } from "./babel.mjs";
|
|
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
|
+
import { i as analyzeScriptsWithNative, n as analyzeNpmChunksWithNative, o as shouldUseNativeAst, r as analyzeScriptWithNative, t as analyzeCompilerScriptsWithNative } from "./native-Bt7ZuZIc.mjs";
|
|
4
5
|
import { collectComponentPropsFromCode, collectComponentPropsWithBabel, collectComponentPropsWithOxc, extractComponentProperties, extractPropertiesObject, getStaticPropertyName, mapConstructorName, mayContainComponentPropsShape, mergeComponentPropTypes, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveTypeFromNode } from "./operations/componentProps.mjs";
|
|
5
|
-
import { i as shouldUseNativeAst, n as analyzeScriptsWithNative, t as analyzeScriptWithNative } from "./native-C-xcrMBn.mjs";
|
|
6
6
|
import { collectFeatureFlagsFromCode, collectFeatureFlagsWithBabel, collectFeatureFlagsWithNative, collectFeatureFlagsWithNativeBatch, collectFeatureFlagsWithOxc, consumeNamedFeatureFlag, consumeNamespaceFeatureFlag, mayContainFeatureFlagHints, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal } from "./operations/featureFlags.mjs";
|
|
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
|
-
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-
|
|
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-DvBA8vNH.mjs";
|
|
9
9
|
import { hasPlatformApiMemberExpression, isPlatformApiIdentifier, isPlatformApiMemberExpression, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, platformApiIdentifierList, platformApiIdentifiers } from "./operations/platformApi.mjs";
|
|
10
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
|
+
//#region src/operations/internal/scriptAnalysis.ts
|
|
14
|
+
/** 复用既有 JS collector 的预筛选和失败语义,不尝试 native。 */
|
|
15
|
+
function collectFeatureFlagsWithJs(code, options) {
|
|
16
|
+
if (!mayContainFeatureFlagHints(code, options.moduleId, options.hookToFeature)) return /* @__PURE__ */ new Set();
|
|
17
|
+
try {
|
|
18
|
+
return options.astEngine === "oxc" ? collectFeatureFlagsWithOxc(code, options.moduleId, options.hookToFeature) : collectFeatureFlagsWithBabel(code, options.moduleId, options.hookToFeature);
|
|
19
|
+
} catch {
|
|
20
|
+
return /* @__PURE__ */ new Set();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** 复用既有文本与 AST predicate,保留默认保守结果和 parserLike。 */
|
|
24
|
+
function mayContainScriptFactWithJs(code, options, mayContainByText, inspectAst) {
|
|
25
|
+
const engine = options?.engine ?? "babel";
|
|
26
|
+
if (engine !== "oxc") return true;
|
|
27
|
+
if (!mayContainByText(code)) return false;
|
|
28
|
+
try {
|
|
29
|
+
return inspectAst(parseJsLikeWithEngine(code, {
|
|
30
|
+
engine,
|
|
31
|
+
filename: "inline.ts",
|
|
32
|
+
parserLike: options?.parserLike
|
|
33
|
+
}));
|
|
34
|
+
} catch {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** 完整 fallback 的内部服务;该模块不属于 package entry。 */
|
|
39
|
+
const jsScriptAnalysisService = {
|
|
40
|
+
collectFeatureFlags: collectFeatureFlagsWithJs,
|
|
41
|
+
mayContainPlatformApiAccess(code, options) {
|
|
42
|
+
return mayContainScriptFactWithJs(code, options, mayContainPlatformApiIdentifierByText, hasPlatformApiMemberExpression);
|
|
43
|
+
},
|
|
44
|
+
mayContainStaticRequireLiteral(code, options) {
|
|
45
|
+
return mayContainScriptFactWithJs(code, options, mayContainRequireCallByText, hasStaticRequireCall);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
13
49
|
//#region src/operations/scriptAnalysis.ts
|
|
14
50
|
function normalizeNativeAnalysis(nativeAnalysis, featureFlags) {
|
|
15
51
|
const validFeatures = new Set(Object.values(featureFlags?.hookToFeature ?? {}));
|
|
@@ -21,8 +57,21 @@ function normalizeNativeAnalysis(nativeAnalysis, featureFlags) {
|
|
|
21
57
|
hasStaticRequireLiteral: nativeAnalysis.hasStaticRequireLiteral
|
|
22
58
|
};
|
|
23
59
|
}
|
|
60
|
+
function analyzeScriptWithJs(code, options) {
|
|
61
|
+
return {
|
|
62
|
+
featureFlags: options?.featureFlags ? jsScriptAnalysisService.collectFeatureFlags(code, options.featureFlags) : /* @__PURE__ */ new Set(),
|
|
63
|
+
hasPlatformApiAccess: jsScriptAnalysisService.mayContainPlatformApiAccess(code, {
|
|
64
|
+
engine: options?.engine,
|
|
65
|
+
parserLike: options?.parserLike
|
|
66
|
+
}),
|
|
67
|
+
hasStaticRequireLiteral: jsScriptAnalysisService.mayContainStaticRequireLiteral(code, {
|
|
68
|
+
engine: options?.engine,
|
|
69
|
+
parserLike: options?.parserLike
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
24
73
|
/**
|
|
25
|
-
*
|
|
74
|
+
* 同一份脚本只尝试一次 native;失败后显式选择完整的 JS fallback 服务。
|
|
26
75
|
*/
|
|
27
76
|
function analyzeScript(code, options) {
|
|
28
77
|
if (shouldUseNativeAst()) try {
|
|
@@ -32,37 +81,32 @@ function analyzeScript(code, options) {
|
|
|
32
81
|
});
|
|
33
82
|
if (nativeAnalysis) return normalizeNativeAnalysis(nativeAnalysis, options?.featureFlags);
|
|
34
83
|
} 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
|
-
};
|
|
84
|
+
return analyzeScriptWithJs(code, options);
|
|
46
85
|
}
|
|
47
86
|
/**
|
|
48
|
-
*
|
|
87
|
+
* 批次只跨 native 边界一次,失败项各自执行一次完整 JS fallback。
|
|
49
88
|
*/
|
|
50
89
|
function analyzeScripts(inputs, options) {
|
|
90
|
+
let nativeResults;
|
|
51
91
|
if (shouldUseNativeAst() && inputs.length > 0) try {
|
|
52
|
-
|
|
92
|
+
nativeResults = analyzeScriptsWithNative(inputs.map((input) => ({
|
|
53
93
|
code: input.code,
|
|
54
94
|
filename: input.filename,
|
|
55
95
|
hookToFeature: input.featureFlags?.hookToFeature ?? options?.featureFlags?.hookToFeature,
|
|
56
96
|
moduleId: input.featureFlags?.moduleId ?? options?.featureFlags?.moduleId
|
|
57
97
|
})));
|
|
58
|
-
if (nativeResults?.length === inputs.length) return nativeResults.map((nativeAnalysis, index) => {
|
|
59
|
-
return normalizeNativeAnalysis(nativeAnalysis, inputs[index]?.featureFlags ?? options?.featureFlags);
|
|
60
|
-
});
|
|
61
98
|
} catch {}
|
|
62
|
-
return inputs.map((input) =>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
99
|
+
return inputs.map((input, index) => {
|
|
100
|
+
const featureFlags = input.featureFlags ?? options?.featureFlags;
|
|
101
|
+
const nativeAnalysis = nativeResults?.[index];
|
|
102
|
+
if (nativeAnalysis) try {
|
|
103
|
+
return normalizeNativeAnalysis(nativeAnalysis, featureFlags);
|
|
104
|
+
} catch {}
|
|
105
|
+
return analyzeScriptWithJs(input.code, {
|
|
106
|
+
...options,
|
|
107
|
+
featureFlags
|
|
108
|
+
});
|
|
109
|
+
});
|
|
66
110
|
}
|
|
67
111
|
//#endregion
|
|
68
112
|
//#region src/operations/scriptLiterals.ts
|
|
@@ -92,4 +136,4 @@ function mayContainScriptCallOrModuleSyntax(code) {
|
|
|
92
136
|
return SCRIPT_CALL_OR_MODULE_RE.test(code);
|
|
93
137
|
}
|
|
94
138
|
//#endregion
|
|
95
|
-
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, collectScriptCallStringLiterals, collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, collectScriptStringLiterals, 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, mayContainScriptCallOrModuleSyntax, mayContainStaticRequireLiteral, mergeComponentPropTypes, oxcAstEngine, parse, parseJsLike, parseJsLikeWithEngine, platformApiIdentifierList, platformApiIdentifiers, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveOxcComponentExpression, resolveOxcRenderExpression, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, resolveTypeFromNode, toStaticObjectKey, traverse, unwrapOxcExpression, unwrapTypeScriptExpression };
|
|
139
|
+
export { BABEL_TS_MODULE_PARSER_OPTIONS, BABEL_TS_MODULE_PLUGINS, analyzeCompilerScriptsWithNative, analyzeNpmChunksWithNative, 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, collectScriptCallStringLiterals, collectScriptSetupImportsFromCode, collectScriptSetupImportsWithBabel, collectScriptSetupImportsWithOxc, collectScriptStringLiterals, 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, mayContainScriptCallOrModuleSyntax, mayContainStaticRequireLiteral, mergeComponentPropTypes, oxcAstEngine, parse, parseJsLike, parseJsLikeWithEngine, platformApiIdentifierList, platformApiIdentifiers, registerNamedFeatureFlagLocal, registerNamespaceFeatureFlagLocal, resolveOptionsObjectExpression, resolveOptionsObjectExpressionWithBabel, resolveOxcComponentExpression, resolveOxcRenderExpression, resolveRenderExpressionFromComponentOptions, resolveRenderableExpression, resolveTypeFromNode, toStaticObjectKey, traverse, unwrapOxcExpression, unwrapTypeScriptExpression };
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
//#region src/native/compilerAnalysis.ts
|
|
4
|
+
function isUtf16Boundary(code, offset) {
|
|
5
|
+
const before = code.charCodeAt(offset - 1);
|
|
6
|
+
const after = code.charCodeAt(offset);
|
|
7
|
+
return !(before >= 55296 && before <= 56319 && after >= 56320 && after <= 57343);
|
|
8
|
+
}
|
|
9
|
+
function readDenseArray$2(value, read) {
|
|
10
|
+
if (!Array.isArray(value)) return;
|
|
11
|
+
const length = value.length;
|
|
12
|
+
if (!Number.isSafeInteger(length) || length < 0) return;
|
|
13
|
+
const items = [];
|
|
14
|
+
for (let index = 0; index < length; index++) {
|
|
15
|
+
if (!Object.hasOwn(value, index)) return;
|
|
16
|
+
const item = read(value[index]);
|
|
17
|
+
if (item === void 0) return;
|
|
18
|
+
items.push(item);
|
|
19
|
+
}
|
|
20
|
+
return items;
|
|
21
|
+
}
|
|
22
|
+
function readImport(value) {
|
|
23
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
24
|
+
const raw = value;
|
|
25
|
+
const local = raw.local;
|
|
26
|
+
const imported = raw.imported;
|
|
27
|
+
const source = raw.source;
|
|
28
|
+
const kind = raw.kind;
|
|
29
|
+
const typeOnly = raw.typeOnly;
|
|
30
|
+
if (typeof local !== "string" || typeof source !== "string" || typeof typeOnly !== "boolean" || imported !== void 0 && typeof imported !== "string" || kind !== "default" && kind !== "namespace" && kind !== "named") return;
|
|
31
|
+
return {
|
|
32
|
+
local,
|
|
33
|
+
source,
|
|
34
|
+
kind,
|
|
35
|
+
typeOnly,
|
|
36
|
+
...imported === void 0 ? {} : { imported }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function readComponent(value) {
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
41
|
+
const raw = value;
|
|
42
|
+
const name = raw.name;
|
|
43
|
+
const local = raw.local;
|
|
44
|
+
return typeof name === "string" && typeof local === "string" ? {
|
|
45
|
+
name,
|
|
46
|
+
local
|
|
47
|
+
} : void 0;
|
|
48
|
+
}
|
|
49
|
+
/** 只保留校验后的自有摘要,不把可选 binding 的 getter 或可变容器传到编译阶段。 */
|
|
50
|
+
function readNativeCompilerScriptAnalysis(value, code) {
|
|
51
|
+
try {
|
|
52
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
53
|
+
const raw = value;
|
|
54
|
+
const imports = readDenseArray$2(raw.imports, readImport);
|
|
55
|
+
const hasDefaultExport = raw.hasDefaultExport;
|
|
56
|
+
let previousEnd = 0;
|
|
57
|
+
const defineOptionsStatements = readDenseArray$2(raw.defineOptionsStatements, (value) => {
|
|
58
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
59
|
+
const span = value;
|
|
60
|
+
const start = span.start;
|
|
61
|
+
const end = span.end;
|
|
62
|
+
if (typeof start !== "number" || typeof end !== "number" || !Number.isInteger(start) || !Number.isInteger(end) || start < previousEnd || end <= start || end > code.length || !isUtf16Boundary(code, start) || !isUtf16Boundary(code, end)) return;
|
|
63
|
+
previousEnd = end;
|
|
64
|
+
return {
|
|
65
|
+
start,
|
|
66
|
+
end
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
const rawComponents = raw.registeredComponents;
|
|
70
|
+
const registeredComponents = rawComponents === void 0 ? void 0 : readDenseArray$2(rawComponents, readComponent);
|
|
71
|
+
if (imports === void 0 || defineOptionsStatements === void 0 || hasDefaultExport !== void 0 && typeof hasDefaultExport !== "boolean" || rawComponents !== void 0 && registeredComponents === void 0) return;
|
|
72
|
+
const rawDiagnostic = raw.reservedPropsDiagnostic;
|
|
73
|
+
let reservedPropsDiagnostic;
|
|
74
|
+
if (rawDiagnostic !== void 0) {
|
|
75
|
+
if (!rawDiagnostic || typeof rawDiagnostic !== "object" || Array.isArray(rawDiagnostic)) return;
|
|
76
|
+
const warningOffset = rawDiagnostic.warningOffset;
|
|
77
|
+
if (warningOffset !== void 0 && (typeof warningOffset !== "number" || !Number.isInteger(warningOffset) || warningOffset < 0 || warningOffset >= code.length || !isUtf16Boundary(code, warningOffset))) return;
|
|
78
|
+
reservedPropsDiagnostic = warningOffset === void 0 ? {} : { warningOffset };
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
imports,
|
|
82
|
+
...hasDefaultExport === void 0 ? {} : { hasDefaultExport },
|
|
83
|
+
defineOptionsStatements,
|
|
84
|
+
...registeredComponents === void 0 ? {} : { registeredComponents },
|
|
85
|
+
...reservedPropsDiagnostic === void 0 ? {} : { reservedPropsDiagnostic }
|
|
86
|
+
};
|
|
87
|
+
} catch {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/native/npmChunks.ts
|
|
93
|
+
function record(value) {
|
|
94
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
95
|
+
}
|
|
96
|
+
function readDenseArray$1(value, read) {
|
|
97
|
+
if (!Array.isArray(value)) return;
|
|
98
|
+
const length = value.length;
|
|
99
|
+
if (!Number.isSafeInteger(length) || length < 0) return;
|
|
100
|
+
const values = [];
|
|
101
|
+
for (let index = 0; index < length; index++) {
|
|
102
|
+
if (!Object.hasOwn(value, index)) return;
|
|
103
|
+
const item = read(value[index]);
|
|
104
|
+
if (item === void 0) return;
|
|
105
|
+
values.push(item);
|
|
106
|
+
}
|
|
107
|
+
return values;
|
|
108
|
+
}
|
|
109
|
+
function readRange(value, code, startKey = "start", endKey = "end") {
|
|
110
|
+
const start = value[startKey];
|
|
111
|
+
const end = value[endKey];
|
|
112
|
+
if (typeof start !== "number" || typeof end !== "number" || !Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end <= start || end > code.length) return;
|
|
113
|
+
return {
|
|
114
|
+
start,
|
|
115
|
+
end
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** 校验并复制普通快照,避免后续消费者持有 native binding 的 getter 或稀疏数组。 */
|
|
119
|
+
function readNativeNpmChunkAnalysis(value, code) {
|
|
120
|
+
try {
|
|
121
|
+
const raw = record(value);
|
|
122
|
+
if (!raw) return;
|
|
123
|
+
const requires = readDenseArray$1(raw.requires, (item) => {
|
|
124
|
+
const fact = record(item);
|
|
125
|
+
const range = fact && readRange(fact, code);
|
|
126
|
+
const importee = fact?.importee;
|
|
127
|
+
if (!fact || !range || typeof importee !== "string") return;
|
|
128
|
+
const literal = code.slice(range.start, range.end);
|
|
129
|
+
if (!/^['"`]/.test(literal) || literal.at(-1) !== literal[0]) return;
|
|
130
|
+
if (literal.includes("\\")) {
|
|
131
|
+
if (literal[0] !== "\"" || JSON.parse(literal) !== importee) return;
|
|
132
|
+
} else if (literal.slice(1, -1) !== importee) return;
|
|
133
|
+
return {
|
|
134
|
+
...range,
|
|
135
|
+
importee
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const platformApiRanges = readDenseArray$1(raw.platformApiRanges, (item) => {
|
|
139
|
+
const fact = record(item);
|
|
140
|
+
const range = fact && readRange(fact, code);
|
|
141
|
+
if (!range || !/^(?:wx|my|tt|swan|jd|xhs)$/.test(code.slice(range.start, range.end))) return;
|
|
142
|
+
return range;
|
|
143
|
+
});
|
|
144
|
+
if (!requires || !platformApiRanges) return;
|
|
145
|
+
const localRootFacts = readDenseArray$1(raw.localRootFacts, (item) => {
|
|
146
|
+
const fact = record(item);
|
|
147
|
+
if (!fact) return;
|
|
148
|
+
const kind = fact.kind;
|
|
149
|
+
const bindingName = fact.bindingName;
|
|
150
|
+
const referenceName = fact.referenceName;
|
|
151
|
+
const importee = fact.importee;
|
|
152
|
+
if (kind === "require") {
|
|
153
|
+
const requireIndex = fact.requireIndex;
|
|
154
|
+
if (typeof requireIndex !== "number" || !Number.isSafeInteger(requireIndex) || requireIndex < 0 || requireIndex >= requires.length || bindingName != null && typeof bindingName !== "string") return;
|
|
155
|
+
return {
|
|
156
|
+
kind,
|
|
157
|
+
requireIndex,
|
|
158
|
+
bindingName: bindingName ?? void 0
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (kind !== "alias" && kind !== "interop") return;
|
|
162
|
+
if (typeof referenceName !== "string" && typeof importee !== "string" || referenceName != null && typeof referenceName !== "string" || importee != null && typeof importee !== "string") return;
|
|
163
|
+
const source = {
|
|
164
|
+
referenceName: typeof referenceName === "string" ? referenceName : void 0,
|
|
165
|
+
importee: typeof importee === "string" ? importee : void 0
|
|
166
|
+
};
|
|
167
|
+
if (kind === "alias") return typeof bindingName === "string" ? {
|
|
168
|
+
kind,
|
|
169
|
+
bindingName,
|
|
170
|
+
...source
|
|
171
|
+
} : void 0;
|
|
172
|
+
const range = readRange(fact, code, "secondArgumentStart", "secondArgumentEnd");
|
|
173
|
+
if (!range || Number(code.slice(range.start, range.end)) !== 1) return;
|
|
174
|
+
return {
|
|
175
|
+
kind,
|
|
176
|
+
...source,
|
|
177
|
+
secondArgumentStart: range.start,
|
|
178
|
+
secondArgumentEnd: range.end
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
if (!localRootFacts) return;
|
|
182
|
+
const seen = /* @__PURE__ */ new Set();
|
|
183
|
+
for (const fact of localRootFacts) if (fact.kind === "require") {
|
|
184
|
+
if (seen.has(fact.requireIndex)) return;
|
|
185
|
+
seen.add(fact.requireIndex);
|
|
186
|
+
}
|
|
187
|
+
const allRanges = [...requires, ...platformApiRanges].sort((left, right) => left.start - right.start);
|
|
188
|
+
if (seen.size !== requires.length || allRanges.some((range, index) => index > 0 && range.start < allRanges[index - 1].end)) return;
|
|
189
|
+
return {
|
|
190
|
+
requires,
|
|
191
|
+
platformApiRanges,
|
|
192
|
+
localRootFacts
|
|
193
|
+
};
|
|
194
|
+
} catch {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/native/scriptAnalysis.ts
|
|
200
|
+
/** 批次形状读取失败时进入同一校验失败分支,避免漏记或重复记录回退。 */
|
|
201
|
+
function isNativeScriptAnalysisBatchShape(value, expectedLength) {
|
|
202
|
+
try {
|
|
203
|
+
return Array.isArray(value) && value.length === expectedLength;
|
|
204
|
+
} catch {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function readDenseArray(value, read) {
|
|
209
|
+
if (!Array.isArray(value)) return;
|
|
210
|
+
const length = value.length;
|
|
211
|
+
if (!Number.isSafeInteger(length) || length < 0) return;
|
|
212
|
+
const snapshot = [];
|
|
213
|
+
for (let index = 0; index < length; index++) {
|
|
214
|
+
if (!Object.hasOwn(value, index)) return;
|
|
215
|
+
const item = read(value[index]);
|
|
216
|
+
if (item === void 0) return;
|
|
217
|
+
snapshot.push(item);
|
|
218
|
+
}
|
|
219
|
+
return snapshot;
|
|
220
|
+
}
|
|
221
|
+
/** 读取并校验普通脚本摘要;缓存只持有自己的 plain snapshot,不保留 binding 的 getter 或 iterator。 */
|
|
222
|
+
function readNativeScriptAnalysis(value) {
|
|
223
|
+
try {
|
|
224
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
225
|
+
const raw = value;
|
|
226
|
+
const hasStaticRequireLiteral = raw.hasStaticRequireLiteral;
|
|
227
|
+
const hasPlatformApiAccess = raw.hasPlatformApiAccess;
|
|
228
|
+
const featureFlags = readDenseArray(raw.featureFlags, (flag) => typeof flag === "string" ? flag : void 0);
|
|
229
|
+
if (typeof hasStaticRequireLiteral !== "boolean" || typeof hasPlatformApiAccess !== "boolean" || featureFlags === void 0) return;
|
|
230
|
+
return {
|
|
231
|
+
hasStaticRequireLiteral,
|
|
232
|
+
hasPlatformApiAccess,
|
|
233
|
+
featureFlags
|
|
234
|
+
};
|
|
235
|
+
} catch {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/native.ts
|
|
241
|
+
const require = createRequire(import.meta.url);
|
|
242
|
+
let binding;
|
|
243
|
+
let lastScriptAnalysis;
|
|
244
|
+
function resolveNativeAstModulePath() {
|
|
245
|
+
return process.env.WEAPP_VITE_NATIVE_AST_PATH?.trim() || void 0;
|
|
246
|
+
}
|
|
247
|
+
function createScriptAnalysisKey(code, filename, moduleId, hookToFeatureJson) {
|
|
248
|
+
return [
|
|
249
|
+
code,
|
|
250
|
+
filename,
|
|
251
|
+
moduleId ?? "",
|
|
252
|
+
hookToFeatureJson ?? ""
|
|
253
|
+
].join("\0");
|
|
254
|
+
}
|
|
255
|
+
function shouldUseNativeAst() {
|
|
256
|
+
return process.env.WEAPP_VITE_NATIVE === "1" && Boolean(resolveNativeAstModulePath());
|
|
257
|
+
}
|
|
258
|
+
function shouldUseNativeNpmChunkAnalysis() {
|
|
259
|
+
return shouldUseNativeAst() && process.env.WEAPP_VITE_NATIVE_NPM_CHUNK === "1";
|
|
260
|
+
}
|
|
261
|
+
function loadNativeAstBindingSync() {
|
|
262
|
+
if (!shouldUseNativeAst()) return;
|
|
263
|
+
if (binding !== void 0) return binding || void 0;
|
|
264
|
+
try {
|
|
265
|
+
binding = require(resolveNativeAstModulePath());
|
|
266
|
+
} catch {
|
|
267
|
+
binding = false;
|
|
268
|
+
}
|
|
269
|
+
return binding || void 0;
|
|
270
|
+
}
|
|
271
|
+
function analyzeScriptWithNative(code, options) {
|
|
272
|
+
const analyzeNative = loadNativeAstBindingSync()?.analyzeScriptNative;
|
|
273
|
+
if (!analyzeNative) return;
|
|
274
|
+
const hookToFeatureJson = options?.hookToFeature ? JSON.stringify(options.hookToFeature) : void 0;
|
|
275
|
+
const filename = options?.filename ?? "inline.ts";
|
|
276
|
+
const key = createScriptAnalysisKey(code, filename, options?.moduleId, hookToFeatureJson);
|
|
277
|
+
if (lastScriptAnalysis?.key === key) return lastScriptAnalysis.result;
|
|
278
|
+
const result = readNativeScriptAnalysis(analyzeNative(code, options?.moduleId, hookToFeatureJson, filename));
|
|
279
|
+
if (!result) return;
|
|
280
|
+
lastScriptAnalysis = {
|
|
281
|
+
key,
|
|
282
|
+
result
|
|
283
|
+
};
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
function analyzeScriptsWithNative(inputs) {
|
|
287
|
+
const analyzeNative = loadNativeAstBindingSync()?.analyzeScriptsNative;
|
|
288
|
+
if (!analyzeNative) return;
|
|
289
|
+
const nativeInputs = inputs.map((input) => {
|
|
290
|
+
return {
|
|
291
|
+
code: input.code,
|
|
292
|
+
filename: input.filename ?? "inline.ts",
|
|
293
|
+
hookToFeatureJson: input.hookToFeature ? JSON.stringify(input.hookToFeature) : void 0,
|
|
294
|
+
moduleId: input.moduleId
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
const rawResults = analyzeNative(nativeInputs);
|
|
298
|
+
if (!isNativeScriptAnalysisBatchShape(rawResults, nativeInputs.length)) return;
|
|
299
|
+
const results = nativeInputs.map((_, index) => {
|
|
300
|
+
try {
|
|
301
|
+
const result = readNativeScriptAnalysis(rawResults[index]);
|
|
302
|
+
if (result) return result;
|
|
303
|
+
} catch {}
|
|
304
|
+
return null;
|
|
305
|
+
});
|
|
306
|
+
const lastInput = nativeInputs.at(-1);
|
|
307
|
+
const lastResult = results.at(-1);
|
|
308
|
+
if (lastInput && lastResult && results.length === nativeInputs.length) lastScriptAnalysis = {
|
|
309
|
+
key: createScriptAnalysisKey(lastInput.code, lastInput.filename, lastInput.moduleId, lastInput.hookToFeatureJson),
|
|
310
|
+
result: lastResult
|
|
311
|
+
};
|
|
312
|
+
return results;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* 编译器前端批量摘要的显式 native 快速路径;失败时由调用方继续使用 Babel/Oxc。
|
|
316
|
+
*/
|
|
317
|
+
function analyzeCompilerScriptsWithNative(inputs) {
|
|
318
|
+
if (!shouldUseNativeAst()) return;
|
|
319
|
+
if (!inputs.length) return [];
|
|
320
|
+
const fallback = () => null;
|
|
321
|
+
const analyzeNative = loadNativeAstBindingSync()?.analyzeCompilerScriptsNative;
|
|
322
|
+
if (!analyzeNative) return inputs.map(fallback);
|
|
323
|
+
let results;
|
|
324
|
+
try {
|
|
325
|
+
results = analyzeNative(inputs);
|
|
326
|
+
} catch {
|
|
327
|
+
return inputs.map(fallback);
|
|
328
|
+
}
|
|
329
|
+
if (!Array.isArray(results) || results.length !== inputs.length) return inputs.map(fallback);
|
|
330
|
+
return inputs.map((input, index) => {
|
|
331
|
+
try {
|
|
332
|
+
const result = results[index];
|
|
333
|
+
return readNativeCompilerScriptAnalysis(result, input.code) ?? fallback();
|
|
334
|
+
} catch {
|
|
335
|
+
return fallback();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* 批量读取最终 chunk 的重写事实;默认关闭,任何批次或单项校验失败都交回 JS。
|
|
341
|
+
*/
|
|
342
|
+
function analyzeNpmChunksWithNative(inputs) {
|
|
343
|
+
if (!shouldUseNativeNpmChunkAnalysis() || inputs.length === 0) return;
|
|
344
|
+
let rawResults;
|
|
345
|
+
try {
|
|
346
|
+
const analyzeNative = loadNativeAstBindingSync()?.analyzeNpmChunksNative;
|
|
347
|
+
if (!analyzeNative) return inputs.map(() => null);
|
|
348
|
+
rawResults = analyzeNative(inputs);
|
|
349
|
+
} catch {
|
|
350
|
+
return inputs.map(() => null);
|
|
351
|
+
}
|
|
352
|
+
if (!isNativeScriptAnalysisBatchShape(rawResults, inputs.length)) return inputs.map(() => null);
|
|
353
|
+
return inputs.map((input, index) => {
|
|
354
|
+
try {
|
|
355
|
+
return Object.hasOwn(rawResults, index) ? readNativeNpmChunkAnalysis(rawResults[index], input.code) ?? null : null;
|
|
356
|
+
} catch {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
//#endregion
|
|
362
|
+
export { loadNativeAstBindingSync as a, analyzeScriptsWithNative as i, analyzeNpmChunksWithNative as n, shouldUseNativeAst as o, analyzeScriptWithNative as r, analyzeCompilerScriptsWithNative as t };
|
|
@@ -26,7 +26,7 @@ declare function isOnPageScrollCallee(callee: t.Expression | t.V8IntrinsicIdenti
|
|
|
26
26
|
declare function getCallExpressionCalleeName(callee: t.Expression | t.V8IntrinsicIdentifier): string | undefined;
|
|
27
27
|
declare function getOnPageScrollCallbackArgument(node: {
|
|
28
28
|
arguments?: Array<t.Expression | t.SpreadElement | t.ArgumentPlaceholder | null>;
|
|
29
|
-
}): t.
|
|
29
|
+
}): t.ArrowFunctionExpression | t.FunctionExpression | undefined;
|
|
30
30
|
declare function createWarningPrefix(filename: string, line?: number, column?: number): string;
|
|
31
31
|
declare function getOxcStaticPropertyName(node: any): string | undefined;
|
|
32
32
|
declare function getOxcMemberExpressionPropertyName(node: any): string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseJsLike, traverse } from "./babel.mjs";
|
|
2
2
|
import { t as parseJsLikeWithEngine } from "./engine-CBE2OpFp.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as loadNativeAstBindingSync, o as shouldUseNativeAst } from "./native-Bt7ZuZIc.mjs";
|
|
4
4
|
import { walk } from "oxc-walker";
|
|
5
5
|
//#region src/operations/onPageScroll/shared.ts
|
|
6
6
|
function isStaticPropertyName(key) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseJsLike, traverse } from "../babel.mjs";
|
|
2
2
|
import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as loadNativeAstBindingSync, o as shouldUseNativeAst, r as analyzeScriptWithNative } from "../native-Bt7ZuZIc.mjs";
|
|
4
4
|
import * as t from "@babel/types";
|
|
5
5
|
import { walk } from "oxc-walker";
|
|
6
6
|
//#region src/operations/featureFlags.ts
|
|
@@ -1,2 +1,2 @@
|
|
|
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-
|
|
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-D-n7saS4.mjs";
|
|
2
2
|
export { collectOnPageScrollPerformanceWarnings, collectOnPageScrollWarningsWithBabel, collectOnPageScrollWarningsWithNative, collectOnPageScrollWarningsWithOxc, collectPageScrollInspection, collectPageScrollInspectionWithOxc, createLineStartOffsets, createWarningPrefix, getCallExpressionCalleeName, getLocationFromOffset, getMemberExpressionPropertyName, getOnPageScrollCallbackArgument, getOxcCallExpressionCalleeName, getOxcMemberExpressionPropertyName, getOxcStaticPropertyName, isOnPageScrollCallee, isOxcFunctionLike, isOxcOnPageScrollCallee, isStaticPropertyName };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as collectOnPageScrollPerformanceWarnings, a as collectOnPageScrollWarningsWithBabel, n as collectOnPageScrollWarningsWithNative, r as collectOnPageScrollWarningsWithOxc, o as collectPageScrollInspection, i as collectPageScrollInspectionWithOxc, s as createLineStartOffsets, c as createWarningPrefix, l as getCallExpressionCalleeName, u as getLocationFromOffset, d as getMemberExpressionPropertyName, f as getOnPageScrollCallbackArgument, p as getOxcCallExpressionCalleeName, m as getOxcMemberExpressionPropertyName, h as getOxcStaticPropertyName, g as isOnPageScrollCallee, _ as isOxcFunctionLike, v as isOxcOnPageScrollCallee, y as isStaticPropertyName } from "../onPageScroll-
|
|
1
|
+
export { t as collectOnPageScrollPerformanceWarnings, a as collectOnPageScrollWarningsWithBabel, n as collectOnPageScrollWarningsWithNative, r as collectOnPageScrollWarningsWithOxc, o as collectPageScrollInspection, i as collectPageScrollInspectionWithOxc, s as createLineStartOffsets, c as createWarningPrefix, l as getCallExpressionCalleeName, u as getLocationFromOffset, d as getMemberExpressionPropertyName, f as getOnPageScrollCallbackArgument, p as getOxcCallExpressionCalleeName, m as getOxcMemberExpressionPropertyName, h as getOxcStaticPropertyName, g as isOnPageScrollCallee, _ as isOxcFunctionLike, v as isOxcOnPageScrollCallee, y as isStaticPropertyName } from "../onPageScroll-DvBA8vNH.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { a as loadNativeAstBindingSync, o as shouldUseNativeAst, r as analyzeScriptWithNative } from "../native-Bt7ZuZIc.mjs";
|
|
3
3
|
import { walk } from "oxc-walker";
|
|
4
4
|
//#region src/operations/platformApi.ts
|
|
5
5
|
const platformApiIdentifierList = [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as parseJsLikeWithEngine } from "../engine-CBE2OpFp.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { a as loadNativeAstBindingSync, o as shouldUseNativeAst, r as analyzeScriptWithNative } from "../native-Bt7ZuZIc.mjs";
|
|
3
3
|
import { walk } from "oxc-walker";
|
|
4
4
|
//#region src/operations/require.ts
|
|
5
5
|
function mayContainRequireCallByText(code) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/ast",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.6.0",
|
|
5
5
|
"description": "weapp-vite 共享 AST 分析工具包,统一 Babel/Oxc 解析与常用分析操作",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"types": "./dist/babelCore.d.mts",
|
|
42
42
|
"import": "./dist/babelCore.mjs"
|
|
43
43
|
},
|
|
44
|
+
"./babelLoader": {
|
|
45
|
+
"types": "./dist/babelLoader.d.mts",
|
|
46
|
+
"import": "./dist/babelLoader.mjs"
|
|
47
|
+
},
|
|
44
48
|
"./babelTraverse": {
|
|
45
49
|
"types": "./dist/babelTraverse.d.mts",
|
|
46
50
|
"import": "./dist/babelTraverse.mjs"
|
|
@@ -111,11 +115,17 @@
|
|
|
111
115
|
"@babel/parser": "^8.0.7",
|
|
112
116
|
"@babel/traverse": "^8.0.7",
|
|
113
117
|
"@babel/types": "^8.0.6",
|
|
114
|
-
"@oxc-project/types": "^0.
|
|
115
|
-
"@weapp-core/shared": "3.
|
|
116
|
-
"oxc-parser": "^0.
|
|
118
|
+
"@oxc-project/types": "^0.154.0",
|
|
119
|
+
"@weapp-core/shared": "3.3.0",
|
|
120
|
+
"oxc-parser": "^0.154.0",
|
|
117
121
|
"oxc-walker": "^1.1.1"
|
|
118
122
|
},
|
|
123
|
+
"tsd": {
|
|
124
|
+
"compilerOptions": {
|
|
125
|
+
"module": "NodeNext",
|
|
126
|
+
"moduleResolution": "NodeNext"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
119
129
|
"publishConfig": {
|
|
120
130
|
"access": "public",
|
|
121
131
|
"registry": "https://registry.npmjs.org"
|
package/dist/native-C-xcrMBn.mjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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 };
|