@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0-alpha.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/esm/cache.js +7 -0
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +35 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +230 -89
- package/esm/eval/broker.js.map +1 -1
- package/esm/eval/protocol.js.map +1 -1
- package/esm/eval/runner.js +143 -24
- package/esm/eval/runner.js.map +1 -1
- package/esm/module.js +70 -43
- package/esm/module.js.map +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +35 -20
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +48 -2
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
- package/esm/transform/generators/transform.js +57 -45
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +33 -4
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform.js +3 -1
- package/esm/transform.js.map +1 -1
- package/esm/utils/EventEmitter.js +42 -9
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
- package/esm/utils/applyOxcProcessors/displayName.js +93 -0
- package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/shared.js +29 -0
- package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
- package/esm/utils/applyOxcProcessors/types.js +2 -0
- package/esm/utils/applyOxcProcessors/types.js.map +1 -0
- package/esm/utils/applyOxcProcessors.js +1 -1216
- package/esm/utils/applyOxcProcessors.js.map +1 -1
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
- package/esm/utils/collectOxcRuntime/types.js +2 -0
- package/esm/utils/collectOxcRuntime/types.js.map +1 -0
- package/esm/utils/collectOxcRuntime.js +5 -193
- package/esm/utils/collectOxcRuntime.js.map +1 -1
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
- package/esm/utils/nativeResolver.js +93 -0
- package/esm/utils/nativeResolver.js.map +1 -0
- package/esm/utils/oxc/ast.js +28 -0
- package/esm/utils/oxc/ast.js.map +1 -0
- package/esm/utils/oxc/parse.js +3 -0
- package/esm/utils/oxc/parse.js.map +1 -0
- package/esm/utils/oxc/replacements.js +14 -0
- package/esm/utils/oxc/replacements.js.map +1 -0
- package/esm/utils/oxc/sourceLocations.js +59 -0
- package/esm/utils/oxc/sourceLocations.js.map +1 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
- package/esm/utils/oxcPreevalStage/processors.js +17 -0
- package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
- package/esm/utils/oxcPreevalStage/types.js +2 -0
- package/esm/utils/oxcPreevalStage/types.js.map +1 -0
- package/esm/utils/oxcPreevalStage.js +17 -73
- package/esm/utils/oxcPreevalStage.js.map +1 -1
- package/esm/utils/oxcPreevalTransforms.js +12 -1
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +3 -3
- package/esm/utils/resolveWithConditions.js.map +1 -1
- package/package.json +4 -3
- package/types/cache.js +8 -0
- package/types/debug/fileReporter.js +46 -1
- package/types/eval/broker.d.ts +6 -2
- package/types/eval/broker.js +244 -95
- package/types/eval/protocol.d.ts +15 -1
- package/types/module.d.ts +4 -1
- package/types/module.js +97 -48
- package/types/transform/Entrypoint.types.d.ts +3 -0
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +49 -2
- package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
- package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
- package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
- package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
- package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
- package/types/transform/generators/transform.js +63 -49
- package/types/transform/helpers/loadWywOptions.js +23 -3
- package/types/transform.js +3 -1
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +44 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
- package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
- package/types/utils/applyOxcProcessors/displayName.js +113 -0
- package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
- package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
- package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
- package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
- package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
- package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
- package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
- package/types/utils/applyOxcProcessors/shared.js +37 -0
- package/types/utils/applyOxcProcessors/types.d.ts +88 -0
- package/types/utils/applyOxcProcessors/types.js +1 -0
- package/types/utils/applyOxcProcessors.d.ts +1 -16
- package/types/utils/applyOxcProcessors.js +1 -1391
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
- package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
- package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
- package/types/utils/collectOxcRuntime/types.d.ts +16 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +2 -12
- package/types/utils/collectOxcRuntime.js +5 -224
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
- package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
- package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
- package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
- package/types/utils/collectOxcTemplateDependencies.js +3 -1580
- package/types/utils/nativeResolver.d.ts +13 -0
- package/types/utils/nativeResolver.js +91 -0
- package/types/utils/oxc/ast.d.ts +4 -0
- package/types/utils/oxc/ast.js +37 -0
- package/types/utils/oxc/parse.d.ts +3 -0
- package/types/utils/oxc/parse.js +2 -0
- package/types/utils/oxc/replacements.d.ts +12 -0
- package/types/utils/oxc/replacements.js +18 -0
- package/types/utils/oxc/sourceLocations.d.ts +5 -0
- package/types/utils/oxc/sourceLocations.js +63 -0
- package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
- package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
- package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
- package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
- package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
- package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
- package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
- package/types/utils/oxcPreevalStage/processors.js +16 -0
- package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
- package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
- package/types/utils/oxcPreevalStage/types.d.ts +22 -0
- package/types/utils/oxcPreevalStage/types.js +1 -0
- package/types/utils/oxcPreevalStage.d.ts +2 -18
- package/types/utils/oxcPreevalStage.js +17 -79
- package/types/utils/oxcPreevalTransforms.js +14 -1
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.js +3 -3
- package/esm/eval/resolverStrategy.js +0 -51
- package/esm/eval/resolverStrategy.js.map +0 -1
- package/types/eval/resolverStrategy.d.ts +0 -13
- package/types/eval/resolverStrategy.js +0 -46
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { collectImportBindings, isSafeLiteral, unwrapExpression } from "./staticExpression.js";
|
|
2
|
+
export const collectLocalConstExpressions = (program) => {
|
|
3
|
+
const result = new Map();
|
|
4
|
+
const collect = (declaration) => {
|
|
5
|
+
if (declaration.kind !== "const") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
declaration.declarations.forEach((declarator) => {
|
|
9
|
+
if (declarator.id.type === "Identifier" && declarator.init) {
|
|
10
|
+
result.set(declarator.id.name, declarator.init);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
program.body.forEach((statement) => {
|
|
15
|
+
if (statement.type === "VariableDeclaration") {
|
|
16
|
+
collect(statement);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (statement.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration") {
|
|
20
|
+
collect(statement.declaration);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
export const objectPropertyKeyName = (node) => {
|
|
26
|
+
const unwrapped = unwrapExpression(node);
|
|
27
|
+
if (unwrapped.type === "Identifier") {
|
|
28
|
+
return unwrapped.name;
|
|
29
|
+
}
|
|
30
|
+
if (isSafeLiteral(unwrapped) && typeof unwrapped.value === "string") {
|
|
31
|
+
return unwrapped.value;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
export const findObjectPropertyValue = (expr, name) => {
|
|
36
|
+
const unwrapped = unwrapExpression(expr);
|
|
37
|
+
if (unwrapped.type !== "ObjectExpression") {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
for (const property of unwrapped.properties) {
|
|
41
|
+
if (property.type === "SpreadElement") {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const propertyNode = property;
|
|
45
|
+
if (propertyNode.computed) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const key = propertyNode.key;
|
|
49
|
+
const value = propertyNode.value;
|
|
50
|
+
if (key && value && objectPropertyKeyName(key) === name) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
export const topLevelStatements = (program) => {
|
|
57
|
+
const result = [];
|
|
58
|
+
program.body.forEach((statement) => {
|
|
59
|
+
if (statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration") {
|
|
60
|
+
result.push(statement.declaration ?? statement);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
result.push(statement);
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
export const findTopLevelConstExpression = (program, name) => {
|
|
68
|
+
for (const statement of topLevelStatements(program)) {
|
|
69
|
+
if (statement.type !== "VariableDeclaration" || statement.kind !== "const") {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
for (const declarator of statement.declarations) {
|
|
73
|
+
if (declarator.id.type === "Identifier" && declarator.id.name === name && declarator.init) {
|
|
74
|
+
return declarator.init;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
export const hasTopLevelBinding = (program, name) => {
|
|
81
|
+
if (collectImportBindings(program).has(name)) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return topLevelStatements(program).some((statement) => {
|
|
85
|
+
if (statement.type === "VariableDeclaration") {
|
|
86
|
+
return statement.declarations.some((declarator) => declarator.id.type === "Identifier" && declarator.id.name === name);
|
|
87
|
+
}
|
|
88
|
+
if (statement.type === "FunctionDeclaration") {
|
|
89
|
+
return statement.id?.name === name;
|
|
90
|
+
}
|
|
91
|
+
if (statement.type === "ClassDeclaration") {
|
|
92
|
+
return statement.id?.name === name;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
export const isTopLevelFunctionOrClass = (program, name) => topLevelStatements(program).some((statement) => {
|
|
98
|
+
if (statement.type === "FunctionDeclaration") {
|
|
99
|
+
return statement.id?.name === name;
|
|
100
|
+
}
|
|
101
|
+
if (statement.type === "ClassDeclaration") {
|
|
102
|
+
return statement.id?.name === name;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
});
|
|
106
|
+
export const functionReturnExpression = (expr, options = {}) => {
|
|
107
|
+
const unwrapped = unwrapExpression(expr);
|
|
108
|
+
if (unwrapped.type !== "ArrowFunctionExpression" && unwrapped.type !== "FunctionExpression") {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (unwrapped.async || !options.allowParams && unwrapped.params.length > 0 || !unwrapped.body) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
if (unwrapped.body.type !== "BlockStatement") {
|
|
115
|
+
return unwrapped.body;
|
|
116
|
+
}
|
|
117
|
+
if (unwrapped.body.body.length !== 1) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const [statement] = unwrapped.body.body;
|
|
121
|
+
return statement.type === "ReturnStatement" && statement.argument ? statement.argument : null;
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=programAnalysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AASA,SACE,uBACA,eACA,wBACK;AAGP,OAAO,MAAM,gCACX,YAC4B;CAC5B,MAAM,SAAS,IAAI,KAAyB;CAE5C,MAAM,WAAW,gBAA2C;AAC1D,MAAI,YAAY,SAAS,SAAS;AAChC;;AAGF,cAAY,aAAa,SAAS,eAAe;AAC/C,OAAI,WAAW,GAAG,SAAS,gBAAgB,WAAW,MAAM;AAC1D,WAAO,IAAI,WAAW,GAAG,MAAM,WAAW,KAAK;;IAEjD;;AAGJ,SAAQ,KAAK,SAAS,cAAc;AAClC,MAAI,UAAU,SAAS,uBAAuB;AAC5C,WAAQ,UAAU;AAClB;;AAGF,MACE,UAAU,SAAS,4BACnB,UAAU,aAAa,SAAS,uBAChC;AACA,WAAQ,UAAU,YAAY;;GAEhC;AAEF,QAAO;;AAET,OAAO,MAAM,yBAAyB,SAA8B;CAClE,MAAM,YAAY,iBAAiB,KAAK;AAExC,KAAI,UAAU,SAAS,cAAc;AACnC,SAAO,UAAU;;AAGnB,KAAI,cAAc,UAAU,IAAI,OAAO,UAAU,UAAU,UAAU;AACnE,SAAO,UAAU;;AAGnB,QAAO;;AAGT,OAAO,MAAM,2BACX,MACA,SACsB;CACtB,MAAM,YAAY,iBAAiB,KAAK;AACxC,KAAI,UAAU,SAAS,oBAAoB;AACzC,SAAO;;AAGT,MAAK,MAAM,YAAY,UAAU,YAAY;AAC3C,MAAI,SAAS,SAAS,iBAAiB;AACrC;;EAGF,MAAM,eAAe;AACrB,MAAI,aAAa,UAAU;AACzB;;EAGF,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O,UAAU,IAAI,SAAS;;AAGhC,QAAO;EACP;AAEJ,OAAO,MAAM,4BACX,MACA,UAAqC,EAAE,KACjB;CACtB,MAAM,YAAY,iBAAiB,KAAK;AACxC,KACE,UAAU,SAAS,6BACnB,UAAU,SAAS,sBACnB;AACA,SAAO;;AAGT,KACE,UAAU,SACT,CAAC,QAAQ,eAAe,UAAU,OAAO,SAAS,KACnD,CAAC,UAAU,MACX;AACA,SAAO;;AAGT,KAAI,UAAU,KAAK,SAAS,kBAAkB;AAC5C,SAAO,UAAU;;AAGnB,KAAI,UAAU,KAAK,KAAK,WAAW,GAAG;AACpC,SAAO;;CAGT,MAAM,CAAC,aAAa,UAAU,KAAK;AACnC,QAAO,UAAU,SAAS,qBAAqB,UAAU,WACrD,UAAU,WACV","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/programAnalysis.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type {\n Expression,\n Node,\n Program,\n VariableDeclaration,\n} from 'oxc-parser';\n\nimport {\n collectImportBindings,\n isSafeLiteral,\n unwrapExpression,\n} from './staticExpression';\nimport type { AnyNode } from './types';\n\nexport const collectLocalConstExpressions = (\n program: Program\n): Map<string, Expression> => {\n const result = new Map<string, Expression>();\n\n const collect = (declaration: VariableDeclaration): void => {\n if (declaration.kind !== 'const') {\n return;\n }\n\n declaration.declarations.forEach((declarator) => {\n if (declarator.id.type === 'Identifier' && declarator.init) {\n result.set(declarator.id.name, declarator.init);\n }\n });\n };\n\n program.body.forEach((statement) => {\n if (statement.type === 'VariableDeclaration') {\n collect(statement);\n return;\n }\n\n if (\n statement.type === 'ExportNamedDeclaration' &&\n statement.declaration?.type === 'VariableDeclaration'\n ) {\n collect(statement.declaration);\n }\n });\n\n return result;\n};\nexport const objectPropertyKeyName = (node: Node): string | null => {\n const unwrapped = unwrapExpression(node);\n\n if (unwrapped.type === 'Identifier') {\n return unwrapped.name;\n }\n\n if (isSafeLiteral(unwrapped) && typeof unwrapped.value === 'string') {\n return unwrapped.value;\n }\n\n return null;\n};\n\nexport const findObjectPropertyValue = (\n expr: Node,\n name: string\n): Expression | null => {\n const unwrapped = unwrapExpression(expr);\n if (unwrapped.type !== 'ObjectExpression') {\n return null;\n }\n\n for (const property of unwrapped.properties) {\n if (property.type === 'SpreadElement') {\n continue;\n }\n\n const propertyNode = property as AnyNode;\n if (propertyNode.computed) {\n continue;\n }\n\n const key = propertyNode.key as Node | undefined;\n const value = propertyNode.value as Expression | undefined;\n if (key && value && objectPropertyKeyName(key) === name) {\n return value;\n }\n }\n\n return null;\n};\nexport const topLevelStatements = (program: Program): Node[] => {\n const result: Node[] = [];\n\n program.body.forEach((statement) => {\n if (\n statement.type === 'ExportNamedDeclaration' ||\n statement.type === 'ExportDefaultDeclaration'\n ) {\n result.push(statement.declaration ?? statement);\n return;\n }\n\n result.push(statement);\n });\n\n return result;\n};\n\nexport const findTopLevelConstExpression = (\n program: Program,\n name: string\n): Expression | null => {\n for (const statement of topLevelStatements(program)) {\n if (\n statement.type !== 'VariableDeclaration' ||\n statement.kind !== 'const'\n ) {\n continue;\n }\n\n for (const declarator of statement.declarations) {\n if (\n declarator.id.type === 'Identifier' &&\n declarator.id.name === name &&\n declarator.init\n ) {\n return declarator.init;\n }\n }\n }\n\n return null;\n};\n\nexport const hasTopLevelBinding = (program: Program, name: string): boolean => {\n if (collectImportBindings(program).has(name)) {\n return true;\n }\n\n return topLevelStatements(program).some((statement) => {\n if (statement.type === 'VariableDeclaration') {\n return statement.declarations.some(\n (declarator) =>\n declarator.id.type === 'Identifier' && declarator.id.name === name\n );\n }\n\n if (statement.type === 'FunctionDeclaration') {\n return statement.id?.name === name;\n }\n\n if (statement.type === 'ClassDeclaration') {\n return statement.id?.name === name;\n }\n\n return false;\n });\n};\n\nexport const isTopLevelFunctionOrClass = (\n program: Program,\n name: string\n): boolean =>\n topLevelStatements(program).some((statement) => {\n if (statement.type === 'FunctionDeclaration') {\n return statement.id?.name === name;\n }\n\n if (statement.type === 'ClassDeclaration') {\n return statement.id?.name === name;\n }\n\n return false;\n });\n\nexport const functionReturnExpression = (\n expr: Node,\n options: { allowParams?: boolean } = {}\n): Expression | null => {\n const unwrapped = unwrapExpression(expr);\n if (\n unwrapped.type !== 'ArrowFunctionExpression' &&\n unwrapped.type !== 'FunctionExpression'\n ) {\n return null;\n }\n\n if (\n unwrapped.async ||\n (!options.allowParams && unwrapped.params.length > 0) ||\n !unwrapped.body\n ) {\n return null;\n }\n\n if (unwrapped.body.type !== 'BlockStatement') {\n return unwrapped.body as Expression;\n }\n\n if (unwrapped.body.body.length !== 1) {\n return null;\n }\n\n const [statement] = unwrapped.body.body;\n return statement.type === 'ReturnStatement' && statement.argument\n ? statement.argument\n : null;\n};\n"],"file":"programAnalysis.js"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { getOxcNodeChildren } from "../../../utils/oxc/ast.js";
|
|
2
|
+
import { applyOxcReplacements } from "../../../utils/oxc/replacements.js";
|
|
3
|
+
import { parseProgram } from "./environment.js";
|
|
4
|
+
import { collectImportBindings, unwrapExpression } from "./staticExpression.js";
|
|
5
|
+
import { findWYWMetaExtendsExpression, staticWYWMetaExtendsReplacementCode } from "./processorStaticModel.js";
|
|
6
|
+
export const isIdentifierBindingPosition = (node, parent) => {
|
|
7
|
+
if (node.type !== "Identifier" || !parent) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (parent.type === "VariableDeclarator" && parent.id === node || parent.type === "FunctionDeclaration" && parent.id === node || parent.type === "FunctionExpression" && parent.id === node || parent.type === "ClassDeclaration" && parent.id === node || parent.type === "ClassExpression" && parent.id === node) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if ((parent.type === "ArrowFunctionExpression" || parent.type === "FunctionDeclaration" || parent.type === "FunctionExpression") && parent.params.some((param) => param === node)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return parent.type === "ImportSpecifier" && parent.local === node || parent.type === "ImportDefaultSpecifier" && parent.local === node || parent.type === "ImportNamespaceSpecifier" && parent.local === node;
|
|
17
|
+
};
|
|
18
|
+
export const isPropertyKeyOnlyIdentifier = (node, parent) => node.type === "Identifier" && !!parent && (parent.type === "MemberExpression" && parent.property === node && !parent.computed || parent.type === "Property" && parent.key === node && !parent.computed && !parent.shorthand);
|
|
19
|
+
export const collectUsedIdentifierNames = (program) => {
|
|
20
|
+
const used = new Set();
|
|
21
|
+
const walk = (node, parent) => {
|
|
22
|
+
if (node.type === "ImportDeclaration") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (node.type === "Identifier" && !isIdentifierBindingPosition(node, parent) && !isPropertyKeyOnlyIdentifier(node, parent)) {
|
|
26
|
+
used.add(node.name);
|
|
27
|
+
}
|
|
28
|
+
getOxcNodeChildren(node).forEach((child) => walk(child, node));
|
|
29
|
+
};
|
|
30
|
+
walk(program, null);
|
|
31
|
+
return used;
|
|
32
|
+
};
|
|
33
|
+
export const removableStaticHelperNames = (program, staticValueNames) => {
|
|
34
|
+
const used = collectUsedIdentifierNames(program);
|
|
35
|
+
const result = new Set();
|
|
36
|
+
program.body.forEach((statement) => {
|
|
37
|
+
if (statement.type !== "VariableDeclaration") {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
statement.declarations.forEach((declarator) => {
|
|
41
|
+
if (declarator.id.type === "Identifier" && staticValueNames.has(declarator.id.name) && !used.has(declarator.id.name)) {
|
|
42
|
+
result.add(declarator.id.name);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
export const collectImportLocalReferences = (node, importLocals, result) => {
|
|
49
|
+
const walk = (item, parent) => {
|
|
50
|
+
if (item.type === "Identifier" && importLocals.has(item.name) && !isIdentifierBindingPosition(item, parent) && !isPropertyKeyOnlyIdentifier(item, parent)) {
|
|
51
|
+
result.add(item.name);
|
|
52
|
+
}
|
|
53
|
+
getOxcNodeChildren(item).forEach((child) => walk(child, item));
|
|
54
|
+
};
|
|
55
|
+
walk(node, null);
|
|
56
|
+
};
|
|
57
|
+
export const removeStaticHelperDeclarations = (code, filename, staticValueNames) => {
|
|
58
|
+
if (staticValueNames.size === 0) {
|
|
59
|
+
return {
|
|
60
|
+
code,
|
|
61
|
+
removed: new Set(),
|
|
62
|
+
removedImportLocals: new Set()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const program = parseProgram(code, filename);
|
|
66
|
+
const removableNames = removableStaticHelperNames(program, staticValueNames);
|
|
67
|
+
const importLocals = new Set();
|
|
68
|
+
collectImportBindings(program).forEach((_, local) => importLocals.add(local));
|
|
69
|
+
const removedImportLocals = new Set();
|
|
70
|
+
const ranges = [];
|
|
71
|
+
const replacements = [];
|
|
72
|
+
program.body.forEach((statement) => {
|
|
73
|
+
if (statement.type !== "VariableDeclaration" || statement.declarations.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const removableIndexes = statement.declarations.flatMap((declarator, index) => declarator.id.type === "Identifier" && removableNames.has(declarator.id.name) ? [index] : []);
|
|
77
|
+
if (removableIndexes.length === 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
removableIndexes.forEach((index) => {
|
|
81
|
+
collectImportLocalReferences(statement.declarations[index], importLocals, removedImportLocals);
|
|
82
|
+
});
|
|
83
|
+
if (removableIndexes.length === statement.declarations.length) {
|
|
84
|
+
ranges.push({
|
|
85
|
+
end: statement.end,
|
|
86
|
+
start: statement.start
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const keptDeclarations = statement.declarations.filter((_, index) => !removableIndexes.includes(index)).map((declarator) => code.slice(declarator.start, declarator.end));
|
|
91
|
+
replacements.push({
|
|
92
|
+
end: statement.end,
|
|
93
|
+
start: statement.start,
|
|
94
|
+
text: `${statement.kind} ${keptDeclarations.join(", ")};`
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
code: applyOxcReplacements(code, [...ranges.map((range) => ({
|
|
99
|
+
...range,
|
|
100
|
+
text: ""
|
|
101
|
+
})), ...replacements]),
|
|
102
|
+
removed: removableNames,
|
|
103
|
+
removedImportLocals
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export const importSpecifierLocalName = (specifier) => specifier.local?.name ?? null;
|
|
107
|
+
export const removeUnusedStaticImports = (code, filename, staticImportLocals, sideEffectImportLocals) => {
|
|
108
|
+
if (staticImportLocals.size === 0) {
|
|
109
|
+
return code;
|
|
110
|
+
}
|
|
111
|
+
const program = parseProgram(code, filename);
|
|
112
|
+
const used = collectUsedIdentifierNames(program);
|
|
113
|
+
const ranges = [];
|
|
114
|
+
const replacements = [];
|
|
115
|
+
program.body.forEach((statement) => {
|
|
116
|
+
if (statement.type !== "ImportDeclaration" || statement.specifiers.length === 0) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const removable = statement.specifiers.flatMap((specifier, index) => {
|
|
120
|
+
const localName = importSpecifierLocalName(specifier);
|
|
121
|
+
return localName && staticImportLocals.has(localName) && !used.has(localName) ? [{
|
|
122
|
+
index,
|
|
123
|
+
localName
|
|
124
|
+
}] : [];
|
|
125
|
+
});
|
|
126
|
+
if (removable.length === 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (removable.length === statement.specifiers.length) {
|
|
130
|
+
if (removable.some((item) => sideEffectImportLocals.has(item.localName))) {
|
|
131
|
+
replacements.push({
|
|
132
|
+
end: statement.end,
|
|
133
|
+
start: statement.start,
|
|
134
|
+
text: `import ${code.slice(statement.source.start, statement.source.end)};`
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
ranges.push({
|
|
139
|
+
end: statement.end,
|
|
140
|
+
start: statement.start
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return applyOxcReplacements(code, [...ranges.map((range) => ({
|
|
145
|
+
...range,
|
|
146
|
+
text: ""
|
|
147
|
+
})), ...replacements]);
|
|
148
|
+
};
|
|
149
|
+
export const replaceStaticWYWMetaExtendsHelpers = (code, filename, helperValues) => {
|
|
150
|
+
if (helperValues.size === 0) {
|
|
151
|
+
return code;
|
|
152
|
+
}
|
|
153
|
+
const program = parseProgram(code, filename);
|
|
154
|
+
const replacements = [];
|
|
155
|
+
const visit = (node) => {
|
|
156
|
+
if (node.type === "ObjectExpression") {
|
|
157
|
+
const extendsExpression = findWYWMetaExtendsExpression(node);
|
|
158
|
+
if (extendsExpression) {
|
|
159
|
+
const unwrapped = unwrapExpression(extendsExpression);
|
|
160
|
+
if (unwrapped.type === "CallExpression" && unwrapped.callee.type === "Identifier" && unwrapped.arguments.length === 0 && helperValues.has(unwrapped.callee.name)) {
|
|
161
|
+
const replacement = staticWYWMetaExtendsReplacementCode(helperValues.get(unwrapped.callee.name));
|
|
162
|
+
if (replacement) {
|
|
163
|
+
replacements.push({
|
|
164
|
+
end: extendsExpression.end,
|
|
165
|
+
start: extendsExpression.start,
|
|
166
|
+
text: replacement
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
getOxcNodeChildren(node).forEach(visit);
|
|
173
|
+
};
|
|
174
|
+
visit(program);
|
|
175
|
+
return applyOxcReplacements(code, replacements);
|
|
176
|
+
};
|
|
177
|
+
export const pruneStaticPreevalCode = (code, filename, staticValueNames, staticImportLocals, staticExtendsHelperValues, sideEffectImportLocals) => {
|
|
178
|
+
const codeWithMetadataPruned = replaceStaticWYWMetaExtendsHelpers(code, filename, staticExtendsHelperValues);
|
|
179
|
+
const helpersRemoved = removeStaticHelperDeclarations(codeWithMetadataPruned, filename, staticValueNames);
|
|
180
|
+
if (helpersRemoved.removed.size === 0) {
|
|
181
|
+
return codeWithMetadataPruned;
|
|
182
|
+
}
|
|
183
|
+
const importLocalsToPrune = new Set([...staticImportLocals, ...helpersRemoved.removedImportLocals]);
|
|
184
|
+
return removeUnusedStaticImports(helpersRemoved.code, filename, importLocalsToPrune, sideEffectImportLocals);
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=prune.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAIA,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB,wBAAwB;AACxD,SACE,8BACA,2CACK;AAGP,OAAO,MAAM,+BACX,MACA,WACY;AACZ,KAAI,KAAK,SAAS,gBAAgB,CAAC,QAAQ;AACzC,SAAO;;AAGT,KACG,OAAO,SAAS,wBAAwB,OAAO,OAAO,QACtD,OAAO,SAAS,yBAAyB,OAAO,OAAO,QACvD,OAAO,SAAS,wBAAwB,OAAO,OAAO,QACtD,OAAO,SAAS,sBAAsB,OAAO,OAAO,QACpD,OAAO,SAAS,qBAAqB,OAAO,OAAO,MACpD;AACA,SAAO;;AAGT,MACG,OAAO,SAAS,6BACf,OAAO,SAAS,yBAChB,OAAO,SAAS,yBAClB,OAAO,OAAO,MAAM,UAAU,UAAU,KAAK,EAC7C;AACA,SAAO;;AAGT,QACG,OAAO,SAAS,qBAAqB,OAAO,UAAU,QACtD,OAAO,SAAS,4BAA4B,OAAO,UAAU,QAC7D,OAAO,SAAS,8BAA8B,OAAO,UAAU;;AAIpE,OAAO,MAAM,+BACX,MACA,WAEA,KAAK,SAAS,gBACd,CAAC,CAAC,WACA,OAAO,SAAS,sBAChB,OAAO,aAAa,QACpB,CAAC,OAAO,YACP,OAAO,SAAS,cACf,OAAO,QAAQ,QACf,CAAC,OAAO,YACR,CAAC,OAAO;AAEd,OAAO,MAAM,8BAA8B,YAAkC;CAC3E,MAAM,OAAO,IAAI,KAAa;CAE9B,MAAM,QAAQ,MAAY,WAA8B;AACtD,MAAI,KAAK,SAAS,qBAAqB;AACrC;;AAGF,MACE,KAAK,SAAS,gBACd,CAAC,4BAA4B,MAA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KAAK,CACxC;AACD,SAAI,aAAa;AACf,mBAAa,KAAK;OAChB,KAAK,kBAAkB;OACvB,OAAO,kBAAkB;OACzB,MAAM;OACP,CAAC;;;;;AAMV,qBAAmB,KAAK,CAAC,QAAQ,MAAM;;AAGzC,OAAM,QAAQ;AACd,QAAO,qBAAqB,MAAM,aAAa;;AAGjD,OAAO,MAAM,0BACX,MACA,UACA,kBACA,oBACA,2BACA,2BACW;CACX,MAAM,yBAAyB,mCAC7B,MACA,UACA,0BACD;CACD,MAAM,iBAAiB,+BACrB,wBACA,UACA,iBACD;AACD,KAAI,eAAe,QAAQ,SAAS,GAAG;AACrC,SAAO;;CAGT,MAAM,sBAAsB,IAAI,IAAI,CAClC,GAAG,oBACH,GAAG,eAAe,oBACnB,CAAC;AAEF,QAAO,0BACL,eAAe,MACf,UACA,qBACA,uBACD","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/prune.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type { ImportDeclaration, Node, Program } from 'oxc-parser';\n\nimport { getOxcNodeChildren } from '../../../utils/oxc/ast';\nimport { applyOxcReplacements } from '../../../utils/oxc/replacements';\nimport { parseProgram } from './environment';\nimport { collectImportBindings, unwrapExpression } from './staticExpression';\nimport {\n findWYWMetaExtendsExpression,\n staticWYWMetaExtendsReplacementCode,\n} from './processorStaticModel';\nimport type { Range, Replacement } from './types';\n\nexport const isIdentifierBindingPosition = (\n node: Node,\n parent: Node | null\n): boolean => {\n if (node.type !== 'Identifier' || !parent) {\n return false;\n }\n\n if (\n (parent.type === 'VariableDeclarator' && parent.id === node) ||\n (parent.type === 'FunctionDeclaration' && parent.id === node) ||\n (parent.type === 'FunctionExpression' && parent.id === node) ||\n (parent.type === 'ClassDeclaration' && parent.id === node) ||\n (parent.type === 'ClassExpression' && parent.id === node)\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ArrowFunctionExpression' ||\n parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression') &&\n parent.params.some((param) => param === node)\n ) {\n return true;\n }\n\n return (\n (parent.type === 'ImportSpecifier' && parent.local === node) ||\n (parent.type === 'ImportDefaultSpecifier' && parent.local === node) ||\n (parent.type === 'ImportNamespaceSpecifier' && parent.local === node)\n );\n};\n\nexport const isPropertyKeyOnlyIdentifier = (\n node: Node,\n parent: Node | null\n): boolean =>\n node.type === 'Identifier' &&\n !!parent &&\n ((parent.type === 'MemberExpression' &&\n parent.property === node &&\n !parent.computed) ||\n (parent.type === 'Property' &&\n parent.key === node &&\n !parent.computed &&\n !parent.shorthand));\n\nexport const collectUsedIdentifierNames = (program: Program): Set<string> => {\n const used = new Set<string>();\n\n const walk = (node: Node, parent: Node | null): void => {\n if (node.type === 'ImportDeclaration') {\n return;\n }\n\n if (\n node.type === 'Identifier' &&\n !isIdentifierBindingPosition(node, parent) &&\n !isPropertyKeyOnlyIdentifier(node, parent)\n ) {\n used.add(node.name);\n }\n\n getOxcNodeChildren(node).forEach((child) => walk(child, node));\n };\n\n walk(program, null);\n return used;\n};\n\nexport const removableStaticHelperNames = (\n program: Program,\n staticValueNames: Set<string>\n): Set<string> => {\n const used = collectUsedIdentifierNames(program);\n const result = new Set<string>();\n\n program.body.forEach((statement) => {\n if (statement.type !== 'VariableDeclaration') {\n return;\n }\n\n statement.declarations.forEach((declarator) => {\n if (\n declarator.id.type === 'Identifier' &&\n staticValueNames.has(declarator.id.name) &&\n !used.has(declarator.id.name)\n ) {\n result.add(declarator.id.name);\n }\n });\n });\n\n return result;\n};\n\nexport const collectImportLocalReferences = (\n node: Node,\n importLocals: Set<string>,\n result: Set<string>\n): void => {\n const walk = (item: Node, parent: Node | null): void => {\n if (\n item.type === 'Identifier' &&\n importLocals.has(item.name) &&\n !isIdentifierBindingPosition(item, parent) &&\n !isPropertyKeyOnlyIdentifier(item, parent)\n ) {\n result.add(item.name);\n }\n\n getOxcNodeChildren(item).forEach((child) => walk(child, item));\n };\n\n walk(node, null);\n};\nexport const removeStaticHelperDeclarations = (\n code: string,\n filename: string,\n staticValueNames: Set<string>\n): { code: string; removed: Set<string>; removedImportLocals: Set<string> } => {\n if (staticValueNames.size === 0) {\n return { code, removed: new Set(), removedImportLocals: new Set() };\n }\n\n const program = parseProgram(code, filename);\n const removableNames = removableStaticHelperNames(program, staticValueNames);\n const importLocals = new Set<string>();\n collectImportBindings(program).forEach((_, local) => importLocals.add(local));\n const removedImportLocals = new Set<string>();\n const ranges: Range[] = [];\n const replacements: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (\n statement.type !== 'VariableDeclaration' ||\n statement.declarations.length === 0\n ) {\n return;\n }\n\n const removableIndexes = statement.declarations.flatMap(\n (declarator, index) =>\n declarator.id.type === 'Identifier' &&\n removableNames.has(declarator.id.name)\n ? [index]\n : []\n );\n if (removableIndexes.length === 0) {\n return;\n }\n\n removableIndexes.forEach((index) => {\n collectImportLocalReferences(\n statement.declarations[index],\n importLocals,\n removedImportLocals\n );\n });\n\n if (removableIndexes.length === statement.declarations.length) {\n ranges.push({\n end: statement.end,\n start: statement.start,\n });\n return;\n }\n\n const keptDeclarations = statement.declarations\n .filter((_, index) => !removableIndexes.includes(index))\n .map((declarator) => code.slice(declarator.start, declarator.end));\n replacements.push({\n end: statement.end,\n start: statement.start,\n text: `${statement.kind} ${keptDeclarations.join(', ')};`,\n });\n });\n\n return {\n code: applyOxcReplacements(code, [\n ...ranges.map((range) => ({ ...range, text: '' })),\n ...replacements,\n ]),\n removed: removableNames,\n removedImportLocals,\n };\n};\n\nexport const importSpecifierLocalName = (\n specifier: ImportDeclaration['specifiers'][number]\n): string | null => specifier.local?.name ?? null;\n\nexport const removeUnusedStaticImports = (\n code: string,\n filename: string,\n staticImportLocals: Set<string>,\n sideEffectImportLocals: Set<string>\n): string => {\n if (staticImportLocals.size === 0) {\n return code;\n }\n\n const program = parseProgram(code, filename);\n const used = collectUsedIdentifierNames(program);\n const ranges: Range[] = [];\n const replacements: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (\n statement.type !== 'ImportDeclaration' ||\n statement.specifiers.length === 0\n ) {\n return;\n }\n\n const removable = statement.specifiers.flatMap((specifier, index) => {\n const localName = importSpecifierLocalName(specifier);\n return localName &&\n staticImportLocals.has(localName) &&\n !used.has(localName)\n ? [{ index, localName }]\n : [];\n });\n\n if (removable.length === 0) {\n return;\n }\n\n if (removable.length === statement.specifiers.length) {\n if (\n removable.some((item) => sideEffectImportLocals.has(item.localName))\n ) {\n replacements.push({\n end: statement.end,\n start: statement.start,\n text: `import ${code.slice(\n statement.source.start,\n statement.source.end\n )};`,\n });\n return;\n }\n\n ranges.push({\n end: statement.end,\n start: statement.start,\n });\n }\n });\n\n return applyOxcReplacements(code, [\n ...ranges.map((range) => ({ ...range, text: '' })),\n ...replacements,\n ]);\n};\n\nexport const replaceStaticWYWMetaExtendsHelpers = (\n code: string,\n filename: string,\n helperValues: Map<string, unknown>\n): string => {\n if (helperValues.size === 0) {\n return code;\n }\n\n const program = parseProgram(code, filename);\n const replacements: Replacement[] = [];\n\n const visit = (node: Node): void => {\n if (node.type === 'ObjectExpression') {\n const extendsExpression = findWYWMetaExtendsExpression(node);\n if (extendsExpression) {\n const unwrapped = unwrapExpression(extendsExpression);\n if (\n unwrapped.type === 'CallExpression' &&\n unwrapped.callee.type === 'Identifier' &&\n unwrapped.arguments.length === 0 &&\n helperValues.has(unwrapped.callee.name)\n ) {\n const replacement = staticWYWMetaExtendsReplacementCode(\n helperValues.get(unwrapped.callee.name)\n );\n if (replacement) {\n replacements.push({\n end: extendsExpression.end,\n start: extendsExpression.start,\n text: replacement,\n });\n }\n }\n }\n }\n\n getOxcNodeChildren(node).forEach(visit);\n };\n\n visit(program);\n return applyOxcReplacements(code, replacements);\n};\n\nexport const pruneStaticPreevalCode = (\n code: string,\n filename: string,\n staticValueNames: Set<string>,\n staticImportLocals: Set<string>,\n staticExtendsHelperValues: Map<string, unknown>,\n sideEffectImportLocals: Set<string>\n): string => {\n const codeWithMetadataPruned = replaceStaticWYWMetaExtendsHelpers(\n code,\n filename,\n staticExtendsHelperValues\n );\n const helpersRemoved = removeStaticHelperDeclarations(\n codeWithMetadataPruned,\n filename,\n staticValueNames\n );\n if (helpersRemoved.removed.size === 0) {\n return codeWithMetadataPruned;\n }\n\n const importLocalsToPrune = new Set([\n ...staticImportLocals,\n ...helpersRemoved.removedImportLocals,\n ]);\n\n return removeUnusedStaticImports(\n helpersRemoved.code,\n filename,\n importLocalsToPrune,\n sideEffectImportLocals\n );\n};\n"],"file":"prune.js"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { isAbsolute } from "path";
|
|
3
|
+
import { appendOxcWywPreval } from "../../../utils/oxcPreevalStage.js";
|
|
4
|
+
import { stripQueryAndHash } from "../../../utils/parseRequest.js";
|
|
5
|
+
import { resolveCandidateValue, resolveOpaqueRuntimeCandidateValue } from "./candidateResolver.js";
|
|
6
|
+
import { debugStaticResolve, getEvalStrategy, getStaticStrategyFailure, parseProgram } from "./environment.js";
|
|
7
|
+
import { collectWYWMetaExtendsHelperNames, createSameFileStaticWYWMetaHelperResolver } from "./processorStaticModel.js";
|
|
8
|
+
import { pruneStaticPreevalCode } from "./prune.js";
|
|
9
|
+
import { runtimeCallbackPlaceholder } from "./staticExpression.js";
|
|
10
|
+
export function* resolveStaticOxcPreevalValues() {
|
|
11
|
+
const preevalResult = this.entrypoint.getPreevalResult();
|
|
12
|
+
if (!preevalResult) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const candidates = preevalResult.staticValueCandidates ?? [];
|
|
16
|
+
const evalDependencyNames = new Set(preevalResult.dependencyNames ?? []);
|
|
17
|
+
if (candidates.length === 0 && evalDependencyNames.size === 0) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const filename = this.entrypoint.loadedAndParsed.evaluator === "ignored" ? this.entrypoint.name : this.entrypoint.loadedAndParsed.evalConfig.filename ?? this.entrypoint.name;
|
|
21
|
+
const evalStrategy = getEvalStrategy(this);
|
|
22
|
+
if (evalStrategy === "execute") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const staticOnly = evalStrategy === "static";
|
|
26
|
+
const staticValueCache = preevalResult.staticValueCache ?? new Map();
|
|
27
|
+
const staticDependencies = new Set(preevalResult.staticDependencies ?? []);
|
|
28
|
+
const staticImportLocals = new Set();
|
|
29
|
+
const sideEffectImportLocals = new Set();
|
|
30
|
+
const staticNullWYWMetaExtendsHelpers = new Set(preevalResult.staticNullWYWMetaExtendsHelpers ?? []);
|
|
31
|
+
const memo = new Map();
|
|
32
|
+
const opaqueRuntimeBaseHelpers = collectWYWMetaExtendsHelperNames(parseProgram(preevalResult.baseCode ?? preevalResult.code, filename));
|
|
33
|
+
// Names of candidates resolved to runtime callbacks (function values).
|
|
34
|
+
// They keep the file out of evalFile but their helper declarations must
|
|
35
|
+
// not be pruned — the runtime call site relies on them.
|
|
36
|
+
const runtimeOnlyCandidateNames = new Set(preevalResult.runtimeOnlyStaticValueNames ?? []);
|
|
37
|
+
let changed = false;
|
|
38
|
+
let hasKnownStaticCandidate = false;
|
|
39
|
+
const resolveSameFileStaticWYWMetaHelpers = createSameFileStaticWYWMetaHelperResolver(preevalResult.baseCode ?? preevalResult.code, filename);
|
|
40
|
+
const applySameFileStaticWYWMetaHelpers = () => {
|
|
41
|
+
let appliedAny = false;
|
|
42
|
+
for (;;) {
|
|
43
|
+
let applied = false;
|
|
44
|
+
const values = resolveSameFileStaticWYWMetaHelpers(staticValueCache);
|
|
45
|
+
values.forEach((value, name) => {
|
|
46
|
+
if (staticValueCache.has(name) || !evalDependencyNames.has(name) && !opaqueRuntimeBaseHelpers.has(name)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
staticValueCache.set(name, value);
|
|
50
|
+
debugStaticResolve(this, {
|
|
51
|
+
candidate: name,
|
|
52
|
+
filename,
|
|
53
|
+
phase: "candidate",
|
|
54
|
+
reason: "same-file-static-metadata",
|
|
55
|
+
status: "resolved"
|
|
56
|
+
});
|
|
57
|
+
applied = true;
|
|
58
|
+
});
|
|
59
|
+
if (!applied) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
appliedAny = true;
|
|
63
|
+
}
|
|
64
|
+
if (appliedAny) {
|
|
65
|
+
changed = true;
|
|
66
|
+
hasKnownStaticCandidate = true;
|
|
67
|
+
}
|
|
68
|
+
return appliedAny;
|
|
69
|
+
};
|
|
70
|
+
applySameFileStaticWYWMetaHelpers();
|
|
71
|
+
for (const candidate of candidates) {
|
|
72
|
+
applySameFileStaticWYWMetaHelpers();
|
|
73
|
+
const isOpaqueRuntimeBaseHelper = opaqueRuntimeBaseHelpers.has(candidate.name);
|
|
74
|
+
if (!evalDependencyNames.has(candidate.name) && !isOpaqueRuntimeBaseHelper && !staticValueCache.has(candidate.name)) {
|
|
75
|
+
debugStaticResolve(this, {
|
|
76
|
+
candidate: candidate.name,
|
|
77
|
+
filename,
|
|
78
|
+
phase: "candidate",
|
|
79
|
+
reason: "not-eval-dependency",
|
|
80
|
+
status: "skipped"
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (staticValueCache.has(candidate.name)) {
|
|
85
|
+
hasKnownStaticCandidate = true;
|
|
86
|
+
candidate.imports.forEach((item) => staticImportLocals.add(item.importLocal ?? item.local));
|
|
87
|
+
if (isOpaqueRuntimeBaseHelper && staticValueCache.get(candidate.name) === null) {
|
|
88
|
+
staticNullWYWMetaExtendsHelpers.add(candidate.name);
|
|
89
|
+
}
|
|
90
|
+
debugStaticResolve(this, {
|
|
91
|
+
candidate: candidate.name,
|
|
92
|
+
filename,
|
|
93
|
+
phase: "candidate",
|
|
94
|
+
reason: "already-static",
|
|
95
|
+
status: "skipped"
|
|
96
|
+
});
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
let resolved;
|
|
100
|
+
let resolvedOpaqueRuntimeBase = false;
|
|
101
|
+
if (isOpaqueRuntimeBaseHelper) {
|
|
102
|
+
resolved = yield* resolveOpaqueRuntimeCandidateValue(this, candidate, filename);
|
|
103
|
+
resolvedOpaqueRuntimeBase = !!resolved;
|
|
104
|
+
if (!resolved) {
|
|
105
|
+
resolved = yield* resolveCandidateValue(this, candidate, filename, memo);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
resolved = yield* resolveCandidateValue(this, candidate, filename, memo);
|
|
109
|
+
}
|
|
110
|
+
if (!resolved) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (resolvedOpaqueRuntimeBase) {
|
|
114
|
+
debugStaticResolve(this, {
|
|
115
|
+
candidate: candidate.name,
|
|
116
|
+
filename,
|
|
117
|
+
phase: "candidate",
|
|
118
|
+
reason: "opaque-runtime-component",
|
|
119
|
+
status: "resolved"
|
|
120
|
+
});
|
|
121
|
+
staticNullWYWMetaExtendsHelpers.add(candidate.name);
|
|
122
|
+
}
|
|
123
|
+
if (resolved.runtimeOnly) {
|
|
124
|
+
// Runtime callback — seed a callable placeholder for collect() but
|
|
125
|
+
// track it separately so the `_exp = () => target` helper survives
|
|
126
|
+
// pruning. The runtime call site relies on that helper declaration.
|
|
127
|
+
runtimeOnlyCandidateNames.add(candidate.name);
|
|
128
|
+
staticValueCache.set(candidate.name, runtimeCallbackPlaceholder);
|
|
129
|
+
} else {
|
|
130
|
+
staticValueCache.set(candidate.name, resolved.value);
|
|
131
|
+
}
|
|
132
|
+
hasKnownStaticCandidate = true;
|
|
133
|
+
candidate.imports.forEach((item) => staticImportLocals.add(item.importLocal ?? item.local));
|
|
134
|
+
resolved.dependencies.forEach((dependency) => staticDependencies.add(dependency));
|
|
135
|
+
resolved.sideEffectImportLocals?.forEach((local) => sideEffectImportLocals.add(local));
|
|
136
|
+
changed = true;
|
|
137
|
+
applySameFileStaticWYWMetaHelpers();
|
|
138
|
+
}
|
|
139
|
+
if (!changed && (!hasKnownStaticCandidate || preevalResult.staticValuesApplied)) {
|
|
140
|
+
if (staticOnly && evalDependencyNames.size > 0) {
|
|
141
|
+
throw getStaticStrategyFailure(filename, evalDependencyNames);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
const dependencyNames = (preevalResult.dependencyNames ?? []).filter((name) => !staticValueCache.has(name) && !runtimeOnlyCandidateNames.has(name));
|
|
146
|
+
if (staticOnly && dependencyNames.length > 0) {
|
|
147
|
+
throw getStaticStrategyFailure(filename, dependencyNames);
|
|
148
|
+
}
|
|
149
|
+
preevalResult.dependencyNames = dependencyNames;
|
|
150
|
+
preevalResult.staticValueCache = staticValueCache;
|
|
151
|
+
preevalResult.staticDependencies = [...staticDependencies];
|
|
152
|
+
preevalResult.staticNullWYWMetaExtendsHelpers = [...staticNullWYWMetaExtendsHelpers];
|
|
153
|
+
preevalResult.runtimeOnlyStaticValueNames = [...runtimeOnlyCandidateNames];
|
|
154
|
+
preevalResult.staticValuesApplied = true;
|
|
155
|
+
const originalBaseCode = preevalResult.baseCode ?? preevalResult.code;
|
|
156
|
+
const prunableStaticValueNames = new Set([...staticValueCache.keys()].filter((name) => !runtimeOnlyCandidateNames.has(name)));
|
|
157
|
+
const staticExtendsHelperValues = new Map([...staticValueCache].filter(([name]) => !runtimeOnlyCandidateNames.has(name)));
|
|
158
|
+
staticNullWYWMetaExtendsHelpers.forEach((name) => {
|
|
159
|
+
if (!staticExtendsHelperValues.has(name)) {
|
|
160
|
+
staticExtendsHelperValues.set(name, null);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const baseCode = pruneStaticPreevalCode(originalBaseCode, filename, prunableStaticValueNames, staticImportLocals, staticExtendsHelperValues, sideEffectImportLocals);
|
|
164
|
+
const evalBaseCode = sideEffectImportLocals.size > 0 ? pruneStaticPreevalCode(originalBaseCode, filename, prunableStaticValueNames, staticImportLocals, staticExtendsHelperValues, new Set()) : baseCode;
|
|
165
|
+
preevalResult.baseCode = baseCode;
|
|
166
|
+
preevalResult.code = appendOxcWywPreval(baseCode, filename, dependencyNames);
|
|
167
|
+
preevalResult.evalCode = appendOxcWywPreval(evalBaseCode, filename, dependencyNames);
|
|
168
|
+
preevalResult.staticSideEffectImportLocals = [...sideEffectImportLocals];
|
|
169
|
+
for (const dependency of staticDependencies) {
|
|
170
|
+
const strippedDependency = stripQueryAndHash(dependency);
|
|
171
|
+
if (isAbsolute(strippedDependency)) {
|
|
172
|
+
this.services.cache.checkFreshness(dependency, strippedDependency);
|
|
173
|
+
}
|
|
174
|
+
this.entrypoint.addInvalidationDependency({
|
|
175
|
+
only: ["*"],
|
|
176
|
+
resolved: dependency,
|
|
177
|
+
source: dependency
|
|
178
|
+
});
|
|
179
|
+
this.entrypoint.markInvalidateOnDependencyChange(dependency);
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=resolveStaticOxcPreevalValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAEA,SAAS,kBAAkB;AAE3B,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAElC,SACE,uBACA,0CACK;AACP,SACE,oBACA,iBACA,0BACA,oBACK;AACP,SACE,kCACA,iDACK;AACP,SAAS,8BAA8B;AACvC,SAAS,kCAAkC;AAG3C,OAAO,UAAU,gCAEW;CAC1B,MAAM,gBAAgB,KAAK,WAAW,kBAAkB;AACxD,KAAI,CAAC,eAAe;AAClB,SAAO;;CAGT,MAAM,aAAa,cAAc,yBAAyB,EAAE;CAC5D,MAAM,sBAAsB,IAAI,IAAI,cAAc,mBAAmB,EAAE,CAAC;AACxE,KAAI,WAAW,WAAW,KAAK,oBAAoB,SAAS,GAAG;AAC7D,SAAO;;CAGT,MAAM,WACJ,KAAK,WAAW,gBAAgB,cAAc,YAC1C,KAAK,WAAW,OAChB,KAAK,WAAW,gBAAgB,WAAW,YAC3C,KAAK,WAAW;CACtB,MAAM,eAAe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AK,MAAM,cAAc,oBAAoB;EAC3C,MAAM,qBAAqB,kBAAkB,WAAW;AACxD,MAAI,WAAW,mBAAmB,EAAE;AAClC,QAAK,SAAS,MAAM,eAAe,YAAY,mBAAmB;;AAGpE,OAAK,WAAW,0BAA0B;GACxC,MAAM,CAAC,IAAI;GACX,UAAU;GACV,QAAQ;GACT,CAAC;AACF,OAAK,WAAW,iCAAiC,WAAW;;AAG9D,QAAO","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport { isAbsolute } from 'path';\n\nimport { appendOxcWywPreval } from '../../../utils/oxcPreevalStage';\nimport { stripQueryAndHash } from '../../../utils/parseRequest';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport {\n resolveCandidateValue,\n resolveOpaqueRuntimeCandidateValue,\n} from './candidateResolver';\nimport {\n debugStaticResolve,\n getEvalStrategy,\n getStaticStrategyFailure,\n parseProgram,\n} from './environment';\nimport {\n collectWYWMetaExtendsHelperNames,\n createSameFileStaticWYWMetaHelperResolver,\n} from './processorStaticModel';\nimport { pruneStaticPreevalCode } from './prune';\nimport { runtimeCallbackPlaceholder } from './staticExpression';\nimport type { StaticExportResult } from './types';\n\nexport function* resolveStaticOxcPreevalValues(\n this: ITransformAction\n): SyncScenarioFor<boolean> {\n const preevalResult = this.entrypoint.getPreevalResult();\n if (!preevalResult) {\n return false;\n }\n\n const candidates = preevalResult.staticValueCandidates ?? [];\n const evalDependencyNames = new Set(preevalResult.dependencyNames ?? []);\n if (candidates.length === 0 && evalDependencyNames.size === 0) {\n return false;\n }\n\n const filename =\n this.entrypoint.loadedAndParsed.evaluator === 'ignored'\n ? this.entrypoint.name\n : this.entrypoint.loadedAndParsed.evalConfig.filename ??\n this.entrypoint.name;\n const evalStrategy = getEvalStrategy(this);\n if (evalStrategy === 'execute') {\n return false;\n }\n const staticOnly = evalStrategy === 'static';\n\n const staticValueCache =\n preevalResult.staticValueCache ?? new Map<string, unknown>();\n const staticDependencies = new Set(preevalResult.staticDependencies ?? []);\n const staticImportLocals = new Set<string>();\n const sideEffectImportLocals = new Set<string>();\n const staticNullWYWMetaExtendsHelpers = new Set(\n preevalResult.staticNullWYWMetaExtendsHelpers ?? []\n );\n const memo = new Map<string, StaticExportResult | null>();\n const opaqueRuntimeBaseHelpers = collectWYWMetaExtendsHelperNames(\n parseProgram(preevalResult.baseCode ?? preevalResult.code, filename)\n );\n // Names of candidates resolved to runtime callbacks (function values).\n // They keep the file out of evalFile but their helper declarations must\n // not be pruned — the runtime call site relies on them.\n const runtimeOnlyCandidateNames = new Set<string>(\n preevalResult.runtimeOnlyStaticValueNames ?? []\n );\n let changed = false;\n let hasKnownStaticCandidate = false;\n const resolveSameFileStaticWYWMetaHelpers =\n createSameFileStaticWYWMetaHelperResolver(\n preevalResult.baseCode ?? preevalResult.code,\n filename\n );\n const applySameFileStaticWYWMetaHelpers = (): boolean => {\n let appliedAny = false;\n\n for (;;) {\n let applied = false;\n const values = resolveSameFileStaticWYWMetaHelpers(staticValueCache);\n values.forEach((value, name) => {\n if (\n staticValueCache.has(name) ||\n (!evalDependencyNames.has(name) &&\n !opaqueRuntimeBaseHelpers.has(name))\n ) {\n return;\n }\n\n staticValueCache.set(name, value);\n debugStaticResolve(this, {\n candidate: name,\n filename,\n phase: 'candidate',\n reason: 'same-file-static-metadata',\n status: 'resolved',\n });\n applied = true;\n });\n\n if (!applied) {\n break;\n }\n\n appliedAny = true;\n }\n\n if (appliedAny) {\n changed = true;\n hasKnownStaticCandidate = true;\n }\n\n return appliedAny;\n };\n\n applySameFileStaticWYWMetaHelpers();\n\n for (const candidate of candidates) {\n applySameFileStaticWYWMetaHelpers();\n\n const isOpaqueRuntimeBaseHelper = opaqueRuntimeBaseHelpers.has(\n candidate.name\n );\n if (\n !evalDependencyNames.has(candidate.name) &&\n !isOpaqueRuntimeBaseHelper &&\n !staticValueCache.has(candidate.name)\n ) {\n debugStaticResolve(this, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'not-eval-dependency',\n status: 'skipped',\n });\n continue;\n }\n\n if (staticValueCache.has(candidate.name)) {\n hasKnownStaticCandidate = true;\n candidate.imports.forEach((item) =>\n staticImportLocals.add(item.importLocal ?? item.local)\n );\n if (\n isOpaqueRuntimeBaseHelper &&\n staticValueCache.get(candidate.name) === null\n ) {\n staticNullWYWMetaExtendsHelpers.add(candidate.name);\n }\n debugStaticResolve(this, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'already-static',\n status: 'skipped',\n });\n continue;\n }\n\n let resolved: StaticExportResult | null;\n let resolvedOpaqueRuntimeBase = false;\n if (isOpaqueRuntimeBaseHelper) {\n resolved = yield* resolveOpaqueRuntimeCandidateValue(\n this,\n candidate,\n filename\n );\n resolvedOpaqueRuntimeBase = !!resolved;\n if (!resolved) {\n resolved = yield* resolveCandidateValue(\n this,\n candidate,\n filename,\n memo\n );\n }\n } else {\n resolved = yield* resolveCandidateValue(this, candidate, filename, memo);\n }\n if (!resolved) {\n continue;\n }\n\n if (resolvedOpaqueRuntimeBase) {\n debugStaticResolve(this, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'opaque-runtime-component',\n status: 'resolved',\n });\n staticNullWYWMetaExtendsHelpers.add(candidate.name);\n }\n\n if (resolved.runtimeOnly) {\n // Runtime callback — seed a callable placeholder for collect() but\n // track it separately so the `_exp = () => target` helper survives\n // pruning. The runtime call site relies on that helper declaration.\n runtimeOnlyCandidateNames.add(candidate.name);\n staticValueCache.set(candidate.name, runtimeCallbackPlaceholder);\n } else {\n staticValueCache.set(candidate.name, resolved.value);\n }\n hasKnownStaticCandidate = true;\n candidate.imports.forEach((item) =>\n staticImportLocals.add(item.importLocal ?? item.local)\n );\n resolved.dependencies.forEach((dependency) =>\n staticDependencies.add(dependency)\n );\n resolved.sideEffectImportLocals?.forEach((local) =>\n sideEffectImportLocals.add(local)\n );\n changed = true;\n applySameFileStaticWYWMetaHelpers();\n }\n\n if (\n !changed &&\n (!hasKnownStaticCandidate || preevalResult.staticValuesApplied)\n ) {\n if (staticOnly && evalDependencyNames.size > 0) {\n throw getStaticStrategyFailure(filename, evalDependencyNames);\n }\n return false;\n }\n\n const dependencyNames = (preevalResult.dependencyNames ?? []).filter(\n (name) =>\n !staticValueCache.has(name) && !runtimeOnlyCandidateNames.has(name)\n );\n if (staticOnly && dependencyNames.length > 0) {\n throw getStaticStrategyFailure(filename, dependencyNames);\n }\n preevalResult.dependencyNames = dependencyNames;\n preevalResult.staticValueCache = staticValueCache;\n preevalResult.staticDependencies = [...staticDependencies];\n preevalResult.staticNullWYWMetaExtendsHelpers = [\n ...staticNullWYWMetaExtendsHelpers,\n ];\n preevalResult.runtimeOnlyStaticValueNames = [...runtimeOnlyCandidateNames];\n preevalResult.staticValuesApplied = true;\n const originalBaseCode = preevalResult.baseCode ?? preevalResult.code;\n const prunableStaticValueNames = new Set(\n [...staticValueCache.keys()].filter(\n (name) => !runtimeOnlyCandidateNames.has(name)\n )\n );\n const staticExtendsHelperValues = new Map(\n [...staticValueCache].filter(\n ([name]) => !runtimeOnlyCandidateNames.has(name)\n )\n );\n staticNullWYWMetaExtendsHelpers.forEach((name) => {\n if (!staticExtendsHelperValues.has(name)) {\n staticExtendsHelperValues.set(name, null);\n }\n });\n const baseCode = pruneStaticPreevalCode(\n originalBaseCode,\n filename,\n prunableStaticValueNames,\n staticImportLocals,\n staticExtendsHelperValues,\n sideEffectImportLocals\n );\n const evalBaseCode =\n sideEffectImportLocals.size > 0\n ? pruneStaticPreevalCode(\n originalBaseCode,\n filename,\n prunableStaticValueNames,\n staticImportLocals,\n staticExtendsHelperValues,\n new Set()\n )\n : baseCode;\n preevalResult.baseCode = baseCode;\n preevalResult.code = appendOxcWywPreval(baseCode, filename, dependencyNames);\n preevalResult.evalCode = appendOxcWywPreval(\n evalBaseCode,\n filename,\n dependencyNames\n );\n preevalResult.staticSideEffectImportLocals = [...sideEffectImportLocals];\n\n for (const dependency of staticDependencies) {\n const strippedDependency = stripQueryAndHash(dependency);\n if (isAbsolute(strippedDependency)) {\n this.services.cache.checkFreshness(dependency, strippedDependency);\n }\n\n this.entrypoint.addInvalidationDependency({\n only: ['*'],\n resolved: dependency,\n source: dependency,\n });\n this.entrypoint.markInvalidateOnDependencyChange(dependency);\n }\n\n return true;\n}\n"],"file":"resolveStaticOxcPreevalValues.js"}
|