@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
|
@@ -1,97 +1,41 @@
|
|
|
1
|
-
import { parseSync } from "oxc-parser";
|
|
2
|
-
import { isFeatureEnabled } from "@wyw-in-js/shared";
|
|
3
1
|
import { EventEmitter } from "./EventEmitter.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const isStaticImportValuesEnabled = (features, filename) => {
|
|
10
|
-
const envValue = process.env.WYW_STATIC_IMPORT_VALUES?.trim().toLowerCase();
|
|
11
|
-
if (envValue) {
|
|
12
|
-
return !isEnvDisabled(envValue);
|
|
13
|
-
}
|
|
14
|
-
return isFeatureEnabled(features, "staticImportValues", filename);
|
|
15
|
-
};
|
|
16
|
-
const parseSourceType = (code, filename) => {
|
|
17
|
-
const parsed = parseSync(filename, code, {
|
|
18
|
-
astType: filename.endsWith(".ts") || filename.endsWith(".tsx") ? "ts" : "js",
|
|
19
|
-
range: true,
|
|
20
|
-
sourceType: "unambiguous"
|
|
21
|
-
});
|
|
22
|
-
const fatalError = parsed.errors.find((error) => error.severity === "Error");
|
|
23
|
-
if (fatalError) {
|
|
24
|
-
throw new Error(fatalError.message);
|
|
25
|
-
}
|
|
26
|
-
return parsed.program.sourceType === "script" ? "script" : "module";
|
|
27
|
-
};
|
|
28
|
-
export const appendOxcWywPreval = (code, filename, dependencyNames) => {
|
|
29
|
-
const uniqueNames = [...new Set(dependencyNames)];
|
|
30
|
-
const properties = uniqueNames.map((name) => `${name}: ${name}`).join(", ");
|
|
31
|
-
const object = uniqueNames.length > 0 ? `{ ${properties} }` : "{}";
|
|
32
|
-
if (parseSourceType(code, filename) === "script") {
|
|
33
|
-
return `${code}\nexports.__wywPreval = ${object};`;
|
|
34
|
-
}
|
|
35
|
-
return `${code}\nexport const __wywPreval = ${object};`;
|
|
36
|
-
};
|
|
2
|
+
import { appendOxcWywPreval } from "./oxcPreevalStage/prevalExport.js";
|
|
3
|
+
import { prepareOxcPreevalCode } from "./oxcPreevalStage/prepareCode.js";
|
|
4
|
+
import { collectPreevalProcessors } from "./oxcPreevalStage/processors.js";
|
|
5
|
+
import { createStaticPreevalOverlay } from "./oxcPreevalStage/staticOverlay.js";
|
|
6
|
+
export { appendOxcWywPreval } from "./oxcPreevalStage/prevalExport.js";
|
|
37
7
|
export const runOxcPreevalStage = (code, fileContext, options) => {
|
|
38
8
|
const filename = fileContext.filename ?? "unknown.js";
|
|
39
|
-
const dependencyNames = [];
|
|
40
9
|
const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
dependencyNames.push(dependency.ex.name);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
processor.doEvaltimeReplacement();
|
|
48
|
-
}));
|
|
49
|
-
const staticValuesEnabled = isStaticImportValuesEnabled(options.features, filename);
|
|
50
|
-
const staticValueNames = staticValuesEnabled ? new Set(processed.staticValues.map((item) => item.name)) : null;
|
|
51
|
-
const evalDependencyNames = staticValuesEnabled ? dependencyNames.filter((name) => !staticValueNames.has(name)) : dependencyNames;
|
|
52
|
-
let nextCode = eventEmitter.perf("transform:preeval:importMetaEnv", () => replaceImportMetaEnvWithOxc(processed.code, filename));
|
|
53
|
-
if (isFeatureEnabled(options.features, "dangerousCodeRemover", filename)) {
|
|
54
|
-
nextCode = eventEmitter.perf("transform:preeval:removeDangerousCode", () => removeDangerousCodeWithOxc(nextCode, filename, options.codeRemover));
|
|
55
|
-
}
|
|
56
|
-
const shouldRewriteDynamicImports = DYNAMIC_IMPORT_RE.test(nextCode);
|
|
57
|
-
const shouldAddRequireFallback = REQUIRE_CALL_RE.test(nextCode);
|
|
58
|
-
if (shouldRewriteDynamicImports || shouldAddRequireFallback) {
|
|
59
|
-
nextCode = rewriteDynamicImportsAndAddRequireFallbackWithOxc(nextCode, filename, {
|
|
60
|
-
addRequireFallback: shouldAddRequireFallback,
|
|
61
|
-
eventEmitter,
|
|
62
|
-
rewriteDynamicImports: shouldRewriteDynamicImports
|
|
63
|
-
});
|
|
64
|
-
}
|
|
10
|
+
const { dependencyNames, processed } = collectPreevalProcessors(code, fileContext, options, eventEmitter);
|
|
11
|
+
const staticOverlay = createStaticPreevalOverlay(processed, dependencyNames, options);
|
|
12
|
+
const baseCode = prepareOxcPreevalCode(processed.code, filename, options, eventEmitter);
|
|
65
13
|
if (processed.processors.length === 0) {
|
|
66
14
|
return {
|
|
67
|
-
baseCode
|
|
68
|
-
code:
|
|
15
|
+
baseCode,
|
|
16
|
+
code: baseCode,
|
|
69
17
|
dependencyNames: [],
|
|
70
18
|
metadata: null,
|
|
19
|
+
processorClassNames: {},
|
|
71
20
|
staticDependencies: [],
|
|
72
21
|
staticValueCandidates: [],
|
|
73
22
|
staticValueCache: new Map()
|
|
74
23
|
};
|
|
75
24
|
}
|
|
76
|
-
const staticValueCache = new Map();
|
|
77
|
-
if (staticValuesEnabled) {
|
|
78
|
-
processed.staticValues.forEach(({ name, value }) => {
|
|
79
|
-
staticValueCache.set(name, value);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
25
|
return {
|
|
83
|
-
baseCode
|
|
84
|
-
code: appendOxcWywPreval(
|
|
85
|
-
dependencyNames: evalDependencyNames,
|
|
26
|
+
baseCode,
|
|
27
|
+
code: appendOxcWywPreval(baseCode, filename, staticOverlay.evalDependencyNames),
|
|
28
|
+
dependencyNames: staticOverlay.evalDependencyNames,
|
|
86
29
|
metadata: {
|
|
87
30
|
dependencies: [],
|
|
88
31
|
processors: processed.processors,
|
|
89
32
|
replacements: [],
|
|
90
33
|
rules: {}
|
|
91
34
|
},
|
|
35
|
+
processorClassNames: Object.fromEntries(processed.processorClassNamesByLocal),
|
|
92
36
|
staticDependencies: [],
|
|
93
|
-
|
|
94
|
-
|
|
37
|
+
staticValueCache: staticOverlay.staticValueCache,
|
|
38
|
+
staticValueCandidates: staticOverlay.staticValueCandidates
|
|
95
39
|
};
|
|
96
40
|
};
|
|
97
41
|
//# sourceMappingURL=oxcPreevalStage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAEA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAM3C,SAAS,0BAA0B;AAEnC,OAAO,MAAM,sBACX,MACA,aACA,YACqB;CACrB,MAAM,WAAW,YAAY,YAAY;CACzC,MAAM,eAAe,QAAQ,gBAAgB,aAAa;CAC1D,MAAM,EAAE,iBAAiB,cAAc,yBACrC,MACA,aACA,SACA,aACD;CACD,MAAM,gBAAgB,2BACpB,WACA,iBACA,QACD;CACD,MAAM,WAAW,sBACf,UAAU,MACV,UACA,SACA,aACD;AAED,KAAI,UAAU,WAAW,WAAW,GAAG;AACrC,SAAO;GACL;GACA,MAAM;GACN,iBAAiB,EAAE;GACnB,UAAU;GACV,qBAAqB,EAAE;GACvB,oBAAoB,EAAE;GACtB,uBAAuB,EAAE;GACzB,kBAAkB,IAAI,KAAK;GAC5B;;AAGH,QAAO;EACL;EACA,MAAM,mBACJ,UACA,UACA,cAAc,oBACf;EACD,iBAAiB,cAAc;EAC/B,UAAU;GACR,cAAc,EAAE;GAChB,YAAY,UAAU;GACtB,cAAc,EAAE;GAChB,OAAO,EAAE;GACV;EACD,qBAAqB,OAAO,YAC1B,UAAU,2BACX;EACD,oBAAoB,EAAE;EACtB,kBAAkB,cAAc;EAChC,uBAAuB,cAAc;EACtC","names":[],"sources":["../../src/utils/oxcPreevalStage.ts"],"version":3,"sourcesContent":["import type { IFileContext } from '@wyw-in-js/processor-utils';\n\nimport { EventEmitter } from './EventEmitter';\nimport { appendOxcWywPreval } from './oxcPreevalStage/prevalExport';\nimport { prepareOxcPreevalCode } from './oxcPreevalStage/prepareCode';\nimport { collectPreevalProcessors } from './oxcPreevalStage/processors';\nimport { createStaticPreevalOverlay } from './oxcPreevalStage/staticOverlay';\nimport type {\n OxcPreevalOptions,\n OxcPreevalResult,\n} from './oxcPreevalStage/types';\n\nexport { appendOxcWywPreval } from './oxcPreevalStage/prevalExport';\n\nexport const runOxcPreevalStage = (\n code: string,\n fileContext: IFileContext,\n options: OxcPreevalOptions\n): OxcPreevalResult => {\n const filename = fileContext.filename ?? 'unknown.js';\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const { dependencyNames, processed } = collectPreevalProcessors(\n code,\n fileContext,\n options,\n eventEmitter\n );\n const staticOverlay = createStaticPreevalOverlay(\n processed,\n dependencyNames,\n options\n );\n const baseCode = prepareOxcPreevalCode(\n processed.code,\n filename,\n options,\n eventEmitter\n );\n\n if (processed.processors.length === 0) {\n return {\n baseCode,\n code: baseCode,\n dependencyNames: [],\n metadata: null,\n processorClassNames: {},\n staticDependencies: [],\n staticValueCandidates: [],\n staticValueCache: new Map(),\n };\n }\n\n return {\n baseCode,\n code: appendOxcWywPreval(\n baseCode,\n filename,\n staticOverlay.evalDependencyNames\n ),\n dependencyNames: staticOverlay.evalDependencyNames,\n metadata: {\n dependencies: [],\n processors: processed.processors,\n replacements: [],\n rules: {},\n },\n processorClassNames: Object.fromEntries(\n processed.processorClassNamesByLocal\n ),\n staticDependencies: [],\n staticValueCache: staticOverlay.staticValueCache,\n staticValueCandidates: staticOverlay.staticValueCandidates,\n };\n};\n"],"file":"oxcPreevalStage.js"}
|
|
@@ -40,6 +40,7 @@ const defaultReactComponentTypes = [
|
|
|
40
40
|
"MemoExoticComponent",
|
|
41
41
|
"NamedExoticComponent"
|
|
42
42
|
];
|
|
43
|
+
const defaultReactHocs = ["forwardRef", "memo"];
|
|
43
44
|
const generatedProcessorHelperNameRe = /^_exp\d*$/;
|
|
44
45
|
const requireCallRe = /\brequire\s*\(/;
|
|
45
46
|
const windowTokenRe = /\bwindow\b/;
|
|
@@ -785,6 +786,7 @@ const isHocCall = (call, hocs, imports) => {
|
|
|
785
786
|
const matched = getImportForExpression(getInnermostCallee(call), imports);
|
|
786
787
|
return !!matched && hocs[matched[0]]?.includes(matched[1]);
|
|
787
788
|
};
|
|
789
|
+
const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === "CallExpression" && isHocCall(ancestor, hocs, imports));
|
|
788
790
|
const getComponentTypes = (options) => {
|
|
789
791
|
const componentTypes = { ...options?.componentTypes ?? { react: [defaultPlaceholder] } };
|
|
790
792
|
const reactTypes = componentTypes.react;
|
|
@@ -795,6 +797,12 @@ const getComponentTypes = (options) => {
|
|
|
795
797
|
}
|
|
796
798
|
return componentTypes;
|
|
797
799
|
};
|
|
800
|
+
const getHocs = (options) => {
|
|
801
|
+
const hocs = { ...options?.hocs ?? {} };
|
|
802
|
+
const reactHocs = new Set([...defaultReactHocs, ...hocs.react ?? []]);
|
|
803
|
+
hocs.react = [...reactHocs];
|
|
804
|
+
return hocs;
|
|
805
|
+
};
|
|
798
806
|
const getTypeImport = (node, imports) => {
|
|
799
807
|
if (node.type === "Identifier") {
|
|
800
808
|
const matched = getImportBinding(imports, node.name);
|
|
@@ -914,7 +922,7 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
|
|
|
914
922
|
const program = parseOxc(code, filename);
|
|
915
923
|
const imports = collectImportBindings(code, filename, program);
|
|
916
924
|
const componentTypes = getComponentTypes(options);
|
|
917
|
-
const hocs = options
|
|
925
|
+
const hocs = getHocs(options);
|
|
918
926
|
const hasHocs = Object.keys(hocs).length > 0;
|
|
919
927
|
const windowScopedNames = windowTokenRe.test(code) ? collectWindowScopedNames(program) : new Set();
|
|
920
928
|
const reExportedLocalNames = collectReExportedLocalNames(program);
|
|
@@ -1003,6 +1011,9 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
|
|
|
1003
1011
|
if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
|
|
1004
1012
|
return;
|
|
1005
1013
|
}
|
|
1014
|
+
if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1006
1017
|
if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
|
|
1007
1018
|
return;
|
|
1008
1019
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAYA,SAAS,mCAAmC;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAiCtC,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,mBAAmB,IAAI,IAAI;CAC/B,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,6BAA6B,IAAI,IAAI,CAAC,gBAAgB,eAAe,CAAC;AAC5E,MAAM,yBAAyB,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAU,CAAC;AACpE,MAAM,oBAAoB,IAAI,IAAI,CAChC,qBACA,wBACD,CAAC;AACF,MAAM,qBA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C;AACF;;EAGF,MAAM,mBAAmB,8BACvB,MACA,WACA,qBACD;AACD,MAAI,kBAAkB;AACpB,gBAAa,KAAK,iBAAiB;AACnC;;EAGF,MAAM,eAAe,yBAAyB,UAAU;EACxD,MAAM,QAAQ,eACV,mBAAmB,cAAc,UAAU,GAC3C,mBAAmB,MAAM,UAAU;AACvC,eAAa,KAAK;GAAE,OAAO,MAAM;GAAO,KAAK,MAAM;GAAK,OAAO;GAAI,CAAC;GAEvE;AAED,QAAO,kBAAkB,MAAM,sBAAsB,aAAa,CAAC","names":[],"sources":["../../src/utils/oxcPreevalTransforms.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type {\n CallExpression,\n Expression,\n ImportExpression,\n Node,\n Program,\n} from 'oxc-parser';\n\nimport type { CodeRemoverOptions } from '@wyw-in-js/shared';\n\nimport { collectOxcExportsAndImports } from './collectOxcExportsAndImports';\nimport { EventEmitter } from './EventEmitter';\nimport { parseOxcProgramCached } from './parseOxc';\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype Replacement = {\n end: number;\n start: number;\n value: string;\n};\n\ntype Scope = {\n bindings: Map<string, Expression | null>;\n key: string;\n names: Set<string>;\n parent: Scope | null;\n};\n\ntype ImportBinding = {\n imported: string | 'default' | '*';\n local: string;\n source: string;\n};\n\ntype OxcFunctionLikeNode = Node & {\n async: boolean;\n body: Node;\n id?: { name: string } | null;\n type:\n | 'ArrowFunctionExpression'\n | 'FunctionDeclaration'\n | 'FunctionExpression';\n};\n\nconst ssrCheckFields = new Set([\n 'document',\n 'location',\n 'navigator',\n 'sessionStorage',\n 'localStorage',\n 'window',\n]);\n\nconst forbiddenGlobals = new Set([\n ...ssrCheckFields,\n '$RefreshReg$',\n '$RefreshSig$',\n 'XMLHttpRequest',\n 'clearImmediate',\n 'clearInterval',\n 'clearTimeout',\n 'fetch',\n 'navigator',\n 'setImmediate',\n 'setInterval',\n 'setTimeout',\n]);\n\nconst alwaysForbiddenIdentifiers = new Set(['$RefreshReg$', '$RefreshSig$']);\nconst promiseCallbackMethods = new Set(['then', 'catch', 'finally']);\nconst jsxRuntimeSources = new Set([\n 'react/jsx-runtime',\n 'react/jsx-dev-runtime',\n]);\nconst defaultPlaceholder = '...';\nconst defaultReactComponentTypes = [\n 'ExoticComponent',\n 'FC',\n 'ForwardRefExoticComponent',\n 'FunctionComponent',\n 'LazyExoticComponent',\n 'MemoExoticComponent',\n 'NamedExoticComponent',\n];\nconst generatedProcessorHelperNameRe = /^_exp\\d*$/;\nconst requireCallRe = /\\brequire\\s*\\(/;\nconst windowTokenRe = /\\bwindow\\b/;\nconst removableOwnerTypes = new Set([\n 'DoWhileStatement',\n 'ExpressionStatement',\n 'ForInStatement',\n 'ForOfStatement',\n 'ForStatement',\n 'FunctionDeclaration',\n 'IfStatement',\n 'PropertyDefinition',\n 'ReturnStatement',\n 'VariableDeclaration',\n 'WhileStatement',\n]);\nconst importMetaEnvRe = /\\bimport\\s*\\.\\s*meta\\s*\\.\\s*env\\b/;\n\nconst createScope = (parent: Scope | null, key: string): Scope => ({\n bindings: new Map(),\n key,\n names: new Set(),\n parent,\n});\n\nconst createsScope = (node: Node): boolean =>\n node.type === 'Program' ||\n node.type === 'BlockStatement' ||\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst hasBinding = (scope: Scope, name: string): boolean => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n};\n\nconst getBindingKey = (scope: Scope, name: string): string | null => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return `${current.key}\\0${name}`;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst getStaticBinding = (\n scope: Scope,\n name: string\n): Expression | null | undefined => {\n let current: Scope | null = scope;\n while (current) {\n if (current.bindings.has(name)) {\n return current.bindings.get(name);\n }\n\n current = current.parent;\n }\n\n return undefined;\n};\n\nconst isFileLikeRequireSpecifier = (value: string): boolean =>\n value.startsWith('.') || value.startsWith('/') || value.startsWith('file:');\n\nconst isNode = (value: unknown): value is Node =>\n !!value &&\n typeof value === 'object' &&\n 'type' in value &&\n typeof (value as { type?: unknown }).type === 'string';\n\nconst getChildren = (node: Node): Node[] => {\n const result: Node[] = [];\n const record = node as AnyNode;\n\n Object.keys(record).forEach((key) => {\n if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {\n return;\n }\n\n const value = record[key];\n if (isNode(value)) {\n result.push(value);\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (isNode(item)) {\n result.push(item);\n }\n });\n }\n });\n\n return result;\n};\n\nconst parseOxc = (code: string, filename: string): Program => {\n return parseOxcProgramCached(filename, code, 'unambiguous');\n};\n\nconst unwrapExpression = (node: Expression): Expression => {\n if (\n node.type === 'TSAsExpression' ||\n node.type === 'TSSatisfiesExpression' ||\n node.type === 'TSNonNullExpression' ||\n node.type === 'TSTypeAssertion' ||\n node.type === 'ParenthesizedExpression'\n ) {\n return unwrapExpression(node.expression);\n }\n\n return node;\n};\n\nconst getMemberPropertyName = (node: Node): string | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst isStringLikeExpression = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (expression.type === 'TemplateLiteral') {\n return true;\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n return (\n isStringLikeExpression(expression.left) ||\n isStringLikeExpression(expression.right)\n );\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression' &&\n getMemberPropertyName(expression.callee) === 'concat'\n ) {\n return isStringLikeExpression(expression.callee.object);\n }\n\n return false;\n};\n\nconst templateLiteralToConcat = (code: string, node: Expression): string => {\n if (node.type !== 'TemplateLiteral' || node.expressions.length === 0) {\n return code.slice(node.start, node.end);\n }\n\n const parts: string[] = [];\n node.quasis.forEach((quasi, index) => {\n const cooked = quasi.value.cooked ?? quasi.value.raw;\n if (cooked !== '') {\n parts.push(JSON.stringify(cooked));\n }\n\n const expression = node.expressions[index];\n if (expression) {\n parts.push(code.slice(expression.start, expression.end));\n }\n });\n\n return parts.length > 0 ? parts.join(' + ') : '\"\"';\n};\n\nconst dynamicImportArgumentCode = (code: string, node: Expression): string => {\n if (node.type === 'TemplateLiteral') {\n return templateLiteralToConcat(code, node);\n }\n\n return code.slice(node.start, node.end);\n};\n\nconst evaluateStaticValue = (\n node: Expression,\n scope: Scope,\n seen = new Set<string>()\n): unknown | undefined => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal') {\n return expression.value;\n }\n\n if (expression.type === 'TemplateLiteral') {\n let result = '';\n\n for (let idx = 0; idx < expression.quasis.length; idx += 1) {\n result += expression.quasis[idx]?.value.cooked ?? '';\n\n const nextExpression = expression.expressions[idx];\n if (!nextExpression) {\n continue;\n }\n\n const value = evaluateStaticValue(nextExpression, scope, seen);\n if (\n value === undefined ||\n (typeof value !== 'string' && typeof value !== 'number')\n ) {\n return undefined;\n }\n\n result += String(value);\n }\n\n return result;\n }\n\n if (expression.type === 'Identifier') {\n if (seen.has(expression.name)) {\n return undefined;\n }\n\n const binding = getStaticBinding(scope, expression.name);\n if (!binding) {\n return undefined;\n }\n\n return evaluateStaticValue(\n binding,\n scope,\n new Set([...seen, expression.name])\n );\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n const left = evaluateStaticValue(expression.left, scope, seen);\n const right = evaluateStaticValue(expression.right, scope, seen);\n\n if (left === undefined || right === undefined) {\n return undefined;\n }\n\n if (typeof left === 'number' && typeof right === 'number') {\n return left + right;\n }\n\n if (\n (typeof left === 'string' || typeof left === 'number') &&\n (typeof right === 'string' || typeof right === 'number')\n ) {\n return `${left}${right}`;\n }\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression'\n ) {\n const objectValue = evaluateStaticValue(\n expression.callee.object,\n scope,\n seen\n );\n const propertyName = getMemberPropertyName(expression.callee);\n if (!propertyName) {\n return undefined;\n }\n\n if (typeof objectValue === 'string') {\n if (propertyName === 'toLowerCase' && expression.arguments.length === 0) {\n return objectValue.toLowerCase();\n }\n\n if (propertyName === 'toUpperCase' && expression.arguments.length === 0) {\n return objectValue.toUpperCase();\n }\n\n if (propertyName === 'trim' && expression.arguments.length === 0) {\n return objectValue.trim();\n }\n\n if (propertyName === 'concat') {\n const args = expression.arguments.map((argument) =>\n argument.type === 'SpreadElement'\n ? undefined\n : evaluateStaticValue(argument, scope, seen)\n );\n if (\n args.some((value) => value === undefined) ||\n args.some(\n (value) => typeof value !== 'string' && typeof value !== 'number'\n )\n ) {\n return undefined;\n }\n\n return objectValue.concat(...args.map((value) => String(value)));\n }\n }\n }\n\n return undefined;\n};\n\nconst isLiteralRequireArg = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (\n expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0\n ) {\n return true;\n }\n\n return false;\n};\n\nconst applyReplacements = (\n code: string,\n replacements: Replacement[]\n): string => {\n let result = code;\n replacements\n .sort((a, b) => b.start - a.start)\n .forEach((replacement) => {\n result =\n result.slice(0, replacement.start) +\n replacement.value +\n result.slice(replacement.end);\n });\n\n return result;\n};\n\nconst isIdentifierNamed = (value: unknown, name: string): boolean =>\n isNode(value) && value.type === 'Identifier' && value.name === name;\n\nconst isImportMeta = (node: unknown): boolean => {\n if (!isNode(node) || node.type !== 'MetaProperty') {\n return false;\n }\n\n const metaProperty = node as AnyNode;\n return (\n isIdentifierNamed(metaProperty.meta, 'import') &&\n isIdentifierNamed(metaProperty.property, 'meta')\n );\n};\n\nconst isImportMetaEnv = (node: Node): boolean => {\n if (node.type !== 'MemberExpression') {\n return false;\n }\n\n if (node.computed || !isIdentifierNamed(node.property, 'env')) {\n return false;\n }\n\n return isImportMeta(node.object);\n};\n\nconst collectBindingNames = (node: Node): string[] => {\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectBindingNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectBindingNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) =>\n element ? collectBindingNames(element) : []\n );\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingNames(node.parameter);\n }\n\n return [];\n};\n\nconst predeclareScopeNames = (node: Node, scope: Scope): void => {\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n if (node.type !== 'ArrowFunctionExpression' && node.id) {\n scope.names.add(node.id.name);\n }\n\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n });\n });\n }\n\n const visitScopeDescendants = (child: Node): void => {\n if (child.type === 'VariableDeclarator') {\n collectBindingNames(child.id).forEach((name) => {\n scope.names.add(name);\n });\n } else if (child.type === 'FunctionDeclaration' && child.id) {\n scope.names.add(child.id.name);\n } else if (child.type === 'ClassDeclaration' && child.id) {\n scope.names.add(child.id.name);\n } else if (\n child.type === 'ImportDefaultSpecifier' ||\n child.type === 'ImportNamespaceSpecifier' ||\n child.type === 'ImportSpecifier'\n ) {\n scope.names.add(child.local.name);\n }\n\n if (createsScope(child)) {\n return;\n }\n\n getChildren(child).forEach(visitScopeDescendants);\n };\n\n getChildren(node).forEach(visitScopeDescendants);\n};\n\nconst declareBindings = (node: Node, scope: Scope): void => {\n if (node.type === 'VariableDeclarator') {\n const names = collectBindingNames(node.id);\n names.forEach((name) => {\n scope.names.add(name);\n scope.bindings.set(name, null);\n });\n\n if (node.id.type === 'Identifier' && node.init) {\n scope.bindings.set(node.id.name, node.init);\n }\n return;\n }\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n }\n\n if (node.type === 'ClassDeclaration' && node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n return;\n }\n\n if (\n node.type === 'ImportDefaultSpecifier' ||\n node.type === 'ImportNamespaceSpecifier' ||\n node.type === 'ImportSpecifier'\n ) {\n scope.names.add(node.local.name);\n scope.bindings.set(node.local.name, null);\n return;\n }\n\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n scope.bindings.set(name, null);\n });\n });\n }\n};\n\nconst visit = (\n node: Node,\n scope: Scope,\n enter: (\n node: Node,\n scope: Scope,\n parent: Node | null,\n ancestors: Node[]\n ) => void,\n parent: Node | null = null,\n ancestors: Node[] = []\n): void => {\n let currentScope = scope;\n if (createsScope(node)) {\n currentScope = createScope(scope, `${node.type}:${node.start}:${node.end}`);\n predeclareScopeNames(node, currentScope);\n }\n\n declareBindings(node, currentScope);\n enter(node, currentScope, parent, ancestors);\n\n getChildren(node).forEach((child) =>\n visit(child, currentScope, enter, node, [...ancestors, node])\n );\n};\n\nexport const replaceImportMetaEnvWithOxc = (\n code: string,\n filename: string\n): string => {\n if (!importMetaEnvRe.test(code)) {\n return code;\n }\n\n const replacements: Replacement[] = [];\n\n visit(parseOxc(code, filename), createScope(null, 'root'), (node) => {\n if (!isImportMetaEnv(node)) {\n return;\n }\n\n replacements.push({\n end: node.end,\n start: node.start,\n value: '__wyw_import_meta_env',\n });\n });\n\n return applyReplacements(code, replacements);\n};\n\ntype CombinedSyntaxRewriteOptions = {\n addRequireFallback: boolean;\n eventEmitter?: EventEmitter;\n rewriteDynamicImports: boolean;\n};\n\ntype RequireFallbackCandidate = {\n call: CallExpression;\n scope: Scope;\n};\n\nfunction collectDynamicImportAndRequireFallbackReplacements(\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): Replacement[] {\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const dynamicImportCandidates: ImportExpression[] = [];\n const requireFallbackCandidates: RequireFallbackCandidate[] = [];\n\n eventEmitter.perf(\n 'transform:preeval:dynamicImportRequireFallback:scan',\n () => {\n visit(\n parseOxc(code, filename),\n createScope(null, 'root'),\n (node, scope) => {\n if (\n options.rewriteDynamicImports &&\n node.type === 'ImportExpression'\n ) {\n dynamicImportCandidates.push(node as ImportExpression);\n }\n\n if (!options.addRequireFallback || node.type !== 'CallExpression') {\n return;\n }\n\n const call = node as CallExpression;\n if (\n call.callee.type !== 'Identifier' ||\n call.callee.name !== 'require' ||\n hasBinding(scope, 'require') ||\n call.arguments.length !== 1\n ) {\n return;\n }\n\n const [firstArg] = call.arguments;\n if (\n !firstArg ||\n firstArg.type === 'SpreadElement' ||\n isLiteralRequireArg(firstArg)\n ) {\n return;\n }\n\n requireFallbackCandidates.push({\n call,\n scope,\n });\n }\n );\n }\n );\n\n const replacements: Replacement[] = [];\n\n eventEmitter.perf('transform:preeval:dynamicImport', () => {\n dynamicImportCandidates.forEach((importExpression) => {\n const argument = importExpression.source;\n const nextArgument = isStringLikeExpression(argument)\n ? unwrapExpression(argument)\n : argument;\n\n replacements.push({\n end: importExpression.end,\n start: importExpression.start,\n value: `__wyw_dynamic_import(${dynamicImportArgumentCode(\n code,\n nextArgument\n )})`,\n });\n });\n });\n\n eventEmitter.perf('transform:preeval:requireFallback', () => {\n requireFallbackCandidates.forEach(({ call, scope }) => {\n const [firstArg] = call.arguments;\n if (!firstArg || firstArg.type === 'SpreadElement') {\n return;\n }\n\n const staticValue = evaluateStaticValue(firstArg, scope);\n if (\n typeof staticValue === 'string' &&\n isFileLikeRequireSpecifier(staticValue)\n ) {\n replacements.push({\n end: firstArg.end,\n start: firstArg.start,\n value: JSON.stringify(staticValue),\n });\n return;\n }\n\n replacements.push({\n end: firstArg.end,\n start: firstArg.end,\n value: ', true',\n });\n });\n });\n\n return replacements;\n}\n\nexport const rewriteDynamicImportsWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: false,\n rewriteDynamicImports: true,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const addRequireFallbackWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: true,\n rewriteDynamicImports: false,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const rewriteDynamicImportsAndAddRequireFallbackWithOxc = (\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n options\n );\n\n return applyReplacements(code, replacements);\n};\n\nconst isBindingPosition = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'VariableDeclarator' && parent.id === node) {\n return true;\n }\n\n if (\n (parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression' ||\n parent.type === 'ClassDeclaration' ||\n parent.type === 'ClassExpression') &&\n parent.id === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ImportSpecifier' &&\n (parent.local === node || parent.imported === node)\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ImportDefaultSpecifier' ||\n parent.type === 'ImportNamespaceSpecifier') &&\n parent.local === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ExportSpecifier' &&\n (parent.local === node || parent.exported === node)\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isPropertyOnlyIdentifier = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (\n parent.type === 'MemberExpression' &&\n !parent.computed &&\n parent.property === node\n ) {\n return true;\n }\n\n if (\n (parent.type === 'Property' ||\n parent.type === 'MethodDefinition' ||\n parent.type === 'PropertyDefinition') &&\n !parent.computed &&\n parent.key === node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isTypeContext = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type.startsWith('TS') || ancestor.type.startsWith('JSDoc')\n );\n\nconst isInsideTypeof = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type === 'UnaryExpression' && ancestor.operator === 'typeof'\n );\n\nconst isInsideImportDeclaration = (ancestors: Node[]): boolean =>\n ancestors.some((ancestor) => ancestor.type === 'ImportDeclaration');\n\nfunction findLastAncestor<T extends Node>(\n ancestors: Node[],\n predicate: (ancestor: Node) => ancestor is T\n): T | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (predicate(ancestor)) {\n return ancestor;\n }\n }\n\n return null;\n}\n\nconst findRemovableOwner = (node: Node, ancestors: Node[]): Node => {\n let owner: Node = node;\n let ownerAncestorIndex = -1;\n\n if (!removableOwnerTypes.has(node.type)) {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (removableOwnerTypes.has(ancestor.type)) {\n owner = ancestor;\n ownerAncestorIndex = idx;\n break;\n }\n }\n }\n\n const parent =\n ownerAncestorIndex > 0 ? ancestors[ownerAncestorIndex - 1] : null;\n if (\n parent?.type === 'ExportNamedDeclaration' &&\n 'declaration' in parent &&\n parent.declaration === owner\n ) {\n return parent;\n }\n\n return owner;\n};\n\ntype ExportedBindingProtection = {\n start: number;\n end: number;\n value: string;\n};\n\nconst collectReExportedLocalNames = (program: Program): Set<string> => {\n const names = new Set<string>();\n for (const stmt of program.body) {\n if (\n stmt.type !== 'ExportNamedDeclaration' ||\n stmt.declaration ||\n stmt.source\n ) {\n continue;\n }\n for (const spec of stmt.specifiers) {\n if (spec.type === 'ExportSpecifier' && spec.local.type === 'Identifier') {\n names.add(spec.local.name);\n }\n }\n }\n return names;\n};\n\n// When an offending identifier sits inside the value of a top-level export,\n// removing the surrounding declaration would strip the export binding too.\n// ESM linker then fails on consumers' `import { name } from '...'` because the\n// named export no longer exists. To keep the binding alive, replace just the\n// value (declarator init or default-export expression) with `undefined`.\nconst findExportedBindingProtection = (\n node: Node,\n ancestors: Node[],\n reExportedLocalNames: Set<string>\n): ExportedBindingProtection | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n\n if (ancestor.type === 'ExportDefaultDeclaration') {\n const decl = ancestor.declaration;\n if (decl && decl !== node && 'start' in decl && 'end' in decl) {\n return { start: decl.start, end: decl.end, value: 'undefined' };\n }\n return null;\n }\n\n if (ancestor.type !== 'VariableDeclarator') {\n continue;\n }\n\n if (\n ancestor.id.type !== 'Identifier' ||\n !ancestor.init ||\n ancestor.init === node\n ) {\n return null;\n }\n\n const varDecl = ancestors[idx - 1];\n const wrapper = ancestors[idx - 2] ?? null;\n\n if (varDecl?.type !== 'VariableDeclaration') {\n return null;\n }\n\n const isDirectExport =\n wrapper?.type === 'ExportNamedDeclaration' &&\n wrapper.declaration === varDecl;\n const isTopLevelDeclaration =\n wrapper === null || wrapper?.type === 'Program';\n const isReExported =\n isTopLevelDeclaration && reExportedLocalNames.has(ancestor.id.name);\n\n if (!isDirectExport && !isReExported) {\n return null;\n }\n\n return {\n start: ancestor.init.start,\n end: ancestor.init.end,\n value: 'undefined',\n };\n }\n\n return null;\n};\n\nconst findPromiseCallbackOwner = (ancestors: Node[]): Node | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'NewExpression' &&\n ancestor.callee.type === 'Identifier' &&\n ancestor.callee.name === 'Promise'\n ) {\n return ancestor;\n }\n\n if (\n ancestor.type === 'CallExpression' &&\n ancestor.callee.type === 'MemberExpression' &&\n promiseCallbackMethods.has(getMemberPropertyName(ancestor.callee) ?? '')\n ) {\n return ancestor;\n }\n }\n\n return null;\n};\n\nconst containsForbiddenIdentifier = (node: Node): boolean => {\n if (node.type === 'Identifier' && alwaysForbiddenIdentifiers.has(node.name)) {\n return true;\n }\n\n return getChildren(node).some(containsForbiddenIdentifier);\n};\n\nconst collectWindowScopedNames = (program: Program): Set<string> => {\n const windowScopedNames = new Set<string>();\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'MemberExpression' ||\n node.object.type !== 'Identifier' ||\n node.object.name !== 'window' ||\n hasBinding(scope, 'window')\n ) {\n return;\n }\n\n const propertyName = getMemberPropertyName(node);\n if (propertyName) {\n windowScopedNames.add(propertyName);\n }\n });\n\n return windowScopedNames;\n};\n\nconst containsForbiddenReference = (\n node: Node,\n scope: Scope,\n windowScopedNames: Set<string>,\n derivedForbiddenBindings: Set<string> = new Set()\n): boolean => {\n let found = false;\n\n visit(node, scope, (child, childScope, parent, ancestors) => {\n if (\n found ||\n child.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isPropertyOnlyIdentifier(child, parent) ||\n isBindingPosition(child, parent)\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(childScope, child.name);\n if (\n alwaysForbiddenIdentifiers.has(child.name) ||\n (forbiddenGlobals.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (windowScopedNames.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (bindingKey !== null && derivedForbiddenBindings.has(bindingKey))\n ) {\n found = true;\n }\n });\n\n return found;\n};\n\nconst nameFromModuleExport = (node: Node): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n\n return null;\n};\n\nconst collectImportBindings = (\n code: string,\n filename: string,\n program: Program\n): ImportBinding[] => {\n const bindings = new Map<string, ImportBinding>();\n const addBinding = (binding: ImportBinding): void => {\n bindings.set(\n `${binding.local}\\0${binding.source}\\0${binding.imported}`,\n binding\n );\n };\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n const source = statement.source.value;\n statement.specifiers.forEach((specifier) => {\n if (specifier.type === 'ImportDefaultSpecifier') {\n addBinding({\n imported: 'default',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n addBinding({\n imported: '*',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n const imported = nameFromModuleExport(specifier.imported);\n if (!imported) {\n return;\n }\n\n addBinding({\n imported,\n local: specifier.local.name,\n source,\n });\n });\n });\n\n if (!requireCallRe.test(code)) {\n return [...bindings.values()];\n }\n\n collectOxcExportsAndImports(code, filename).imports.forEach((item) => {\n if (item.imported === 'side-effect') {\n return;\n }\n\n addBinding({\n imported: item.imported,\n local: item.local.code,\n source: item.source,\n });\n\n if (item.local.name && item.local.name !== item.local.code) {\n addBinding({\n imported: item.imported,\n local: item.local.name,\n source: item.source,\n });\n }\n });\n\n return [...bindings.values()];\n};\n\nconst getImportBinding = (\n imports: ImportBinding[],\n local: string\n): ImportBinding | undefined => imports.find((item) => item.local === local);\n\nfunction unwrapSequenceCallee(node: Expression): Expression {\n if (\n node.type === 'SequenceExpression' &&\n node.expressions.length === 2 &&\n node.expressions[0]?.type === 'Literal' &&\n node.expressions[0].value === 0\n ) {\n return node.expressions[1] as Expression;\n }\n\n return node;\n}\n\nconst getExpressionImportKey = (node: Expression): string | null => {\n const expression = unwrapSequenceCallee(node);\n\n if (expression.type === 'Identifier') {\n return expression.name;\n }\n\n if (expression.type !== 'MemberExpression') {\n return null;\n }\n\n if (expression.object.type !== 'Identifier') {\n return null;\n }\n\n const propertyName = getMemberPropertyName(expression);\n return propertyName ? `${expression.object.name}.${propertyName}` : null;\n};\n\nconst isHookOrCreateElement = (name: string): boolean =>\n name === 'createElement' || /use[A-Z]/.test(name);\n\nconst getInnermostCallee = (call: CallExpression): Expression => {\n let callee = unwrapSequenceCallee(call.callee);\n while (callee.type === 'CallExpression') {\n callee = unwrapSequenceCallee(callee.callee);\n }\n\n return callee;\n};\n\nconst getImportForExpression = (\n node: Expression,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n const expression = unwrapSequenceCallee(node);\n const directMatchKey = getExpressionImportKey(expression);\n if (directMatchKey) {\n const directMatch = getImportBinding(imports, directMatchKey);\n if (directMatch) {\n return [directMatch.source, directMatch.imported];\n }\n }\n\n if (expression.type === 'Identifier') {\n const matched = getImportBinding(imports, expression.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (expression.type !== 'MemberExpression') {\n return undefined;\n }\n\n if (expression.object.type !== 'Identifier') {\n return undefined;\n }\n\n const propertyName = getMemberPropertyName(expression);\n if (!propertyName) {\n return undefined;\n }\n\n const objectImport = getImportBinding(imports, expression.object.name);\n if (!objectImport) {\n return undefined;\n }\n\n if (\n objectImport.imported === 'default' ||\n objectImport.imported === '*' ||\n objectImport.source === 'react'\n ) {\n return [objectImport.source, propertyName];\n }\n\n return undefined;\n};\n\nconst isReactRuntimeCall = (\n call: CallExpression,\n imports: ImportBinding[]\n): boolean => {\n const callee = unwrapSequenceCallee(call.callee);\n const matched = getImportForExpression(callee, imports);\n if (!matched) {\n return false;\n }\n\n const [source, imported] = matched;\n if (jsxRuntimeSources.has(source)) {\n return true;\n }\n\n return source === 'react' && isHookOrCreateElement(imported);\n};\n\nconst isHocCall = (\n call: CallExpression,\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n const matched = getImportForExpression(getInnermostCallee(call), imports);\n return !!matched && hocs[matched[0]]?.includes(matched[1]);\n};\n\nconst getComponentTypes = (\n options?: CodeRemoverOptions\n): Record<string, string[]> => {\n const componentTypes = {\n ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),\n };\n const reactTypes = componentTypes.react;\n\n if (Array.isArray(reactTypes) && reactTypes.includes(defaultPlaceholder)) {\n const idx = reactTypes.indexOf(defaultPlaceholder);\n componentTypes.react = [...reactTypes];\n componentTypes.react.splice(idx, 1, ...defaultReactComponentTypes);\n }\n\n return componentTypes;\n};\n\nconst getTypeImport = (\n node: Node,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n if (node.type === 'Identifier') {\n const matched = getImportBinding(imports, node.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (node.type !== 'TSQualifiedName') {\n return undefined;\n }\n\n if (node.left.type !== 'Identifier') {\n return undefined;\n }\n\n const matched = getImportBinding(imports, node.left.name);\n return matched ? [matched.source, node.right.name] : undefined;\n};\n\nconst isComponentTypeMatch = (\n id: Node,\n componentTypes: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n if (id.type !== 'Identifier') {\n return false;\n }\n\n const annotation = id.typeAnnotation;\n if (\n !annotation ||\n annotation.type !== 'TSTypeAnnotation' ||\n annotation.typeAnnotation.type !== 'TSTypeReference'\n ) {\n return false;\n }\n\n const matched = getTypeImport(annotation.typeAnnotation.typeName, imports);\n return !!matched && componentTypes[matched[0]]?.includes(matched[1]);\n};\n\nconst getClassName = (node: Node): string | null =>\n node.type === 'ClassDeclaration' && node.id ? node.id.name : null;\n\nconst isFunctionLikeNode = (node: Node): node is OxcFunctionLikeNode =>\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst isImmediatelyInvokedFunction = (\n fnNode: Node,\n ancestors: Node[],\n fnIndex: number\n): boolean => {\n // Walk past any ParenthesizedExpression / SequenceExpression wrappers that\n // sit between the function and its enclosing CallExpression. oxc-parser\n // preserves ParenthesizedExpression nodes, so `(() => {...})()` shows up\n // as CallExpression -> ParenthesizedExpression -> ArrowFunctionExpression.\n let child: Node = fnNode;\n for (let idx = fnIndex - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'ParenthesizedExpression' &&\n 'expression' in ancestor &&\n ancestor.expression === child\n ) {\n child = ancestor;\n continue;\n }\n if (\n ancestor.type === 'SequenceExpression' &&\n Array.isArray(ancestor.expressions) &&\n ancestor.expressions[ancestor.expressions.length - 1] === child\n ) {\n child = ancestor;\n continue;\n }\n return ancestor.type === 'CallExpression' && ancestor.callee === child;\n }\n return false;\n};\n\n// A reference is \"deferred\" when it lives inside a function body that is\n// not immediately invoked. Module preeval reads exports without calling\n// them, so deferred references never run and must not be sanitized — that\n// would silently drop the binding (or remove the entire export) and break\n// importers that expect the function to be callable.\nconst isInDeferredFunctionScope = (ancestors: Node[]): boolean => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (!isFunctionLikeNode(ancestor)) {\n continue;\n }\n if (!isImmediatelyInvokedFunction(ancestor, ancestors, idx)) {\n return true;\n }\n }\n return false;\n};\n\nconst findFunctionReplacement = (ancestors: Node[]): Replacement | null => {\n const renderMethod = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'MethodDefinition' &&\n ancestor.key.type === 'Identifier' &&\n ancestor.key.name === 'render'\n );\n\n if (renderMethod) {\n const classDecl = findLastAncestor(\n ancestors,\n (ancestor) => ancestor.type === 'ClassDeclaration'\n );\n const className = classDecl ? getClassName(classDecl) : null;\n if (classDecl && className) {\n return {\n start: classDecl.start,\n end: classDecl.end,\n value: `function ${className}() { return null; }`,\n };\n }\n }\n\n const functionNode = findLastAncestor(ancestors, isFunctionLikeNode);\n\n if (!functionNode) {\n return null;\n }\n\n if (functionNode.type === 'ArrowFunctionExpression') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}() => { return null; }`,\n };\n }\n\n if (functionNode.type === 'FunctionDeclaration') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}function ${\n functionNode.id?.name ?? ''\n }() { return null; }`,\n };\n }\n\n return {\n start: functionNode.body.start,\n end: functionNode.body.end,\n value: '{ return null; }',\n };\n};\n\nconst normalizeReplacements = (replacements: Replacement[]): Replacement[] => {\n const sorted = [...replacements].sort((a, b) =>\n a.start === b.start ? b.end - a.end : a.start - b.start\n );\n const result: Replacement[] = [];\n\n sorted.forEach((replacement) => {\n const last = result[result.length - 1];\n if (\n last &&\n replacement.start >= last.start &&\n replacement.end <= last.end\n ) {\n return;\n }\n\n result.push(replacement);\n });\n\n return result;\n};\n\nexport const removeDangerousCodeWithOxc = (\n code: string,\n filename: string,\n options?: CodeRemoverOptions\n): string => {\n const replacements: Replacement[] = [];\n const derivedForbiddenBindings = new Set<string>();\n const program = parseOxc(code, filename);\n const imports = collectImportBindings(code, filename, program);\n const componentTypes = getComponentTypes(options);\n const hocs = options?.hocs ?? {};\n const hasHocs = Object.keys(hocs).length > 0;\n const windowScopedNames = windowTokenRe.test(code)\n ? collectWindowScopedNames(program)\n : new Set<string>();\n const reExportedLocalNames = collectReExportedLocalNames(program);\n\n const derivedBindingDiscovery = { found: true };\n while (derivedBindingDiscovery.found) {\n derivedBindingDiscovery.found = false;\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'VariableDeclarator' ||\n node.id.type !== 'Identifier' ||\n !node.init\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(scope, node.id.name);\n if (!bindingKey || derivedForbiddenBindings.has(bindingKey)) {\n return;\n }\n\n if (\n containsForbiddenIdentifier(node.init) ||\n containsForbiddenReference(\n node.init,\n scope,\n windowScopedNames,\n derivedForbiddenBindings\n )\n ) {\n derivedForbiddenBindings.add(bindingKey);\n derivedBindingDiscovery.found = true;\n }\n });\n }\n\n visit(\n program,\n createScope(null, 'root'),\n (node, scope, parent, ancestors) => {\n if (node.type === 'JSXElement' || node.type === 'JSXFragment') {\n replacements.push(\n findFunctionReplacement(ancestors) ?? {\n start: node.start,\n end: node.end,\n value: 'null',\n }\n );\n return;\n }\n\n if (node.type === 'CallExpression') {\n if (isReactRuntimeCall(node, imports)) {\n const replacement = findFunctionReplacement(ancestors);\n if (replacement) {\n replacements.push(replacement);\n }\n\n return;\n }\n\n if (hasHocs && isHocCall(node, hocs, imports)) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '() => null',\n });\n return;\n }\n }\n\n if (\n node.type === 'VariableDeclarator' &&\n node.id.type === 'Identifier' &&\n node.init &&\n isComponentTypeMatch(node.id, componentTypes, imports)\n ) {\n replacements.push({\n start: node.init.start,\n end: node.init.end,\n value: '() => null',\n });\n return;\n }\n\n if (\n node.type === 'UnaryExpression' &&\n node.operator === 'typeof' &&\n node.argument.type === 'Identifier' &&\n ssrCheckFields.has(node.argument.name) &&\n !hasBinding(scope, node.argument.name)\n ) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '\"undefined\"',\n });\n return;\n }\n\n if (node.type === 'MetaProperty') {\n const owner = findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n return;\n }\n\n if (\n node.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isInsideImportDeclaration(ancestors)\n ) {\n return;\n }\n\n if (isPropertyOnlyIdentifier(node, parent)) {\n return;\n }\n\n const isAlwaysForbidden = alwaysForbiddenIdentifiers.has(node.name);\n const bindingKey = getBindingKey(scope, node.name);\n const isDerivedForbidden =\n bindingKey !== null && derivedForbiddenBindings.has(bindingKey);\n const isWindowScoped =\n windowScopedNames.has(node.name) && !hasBinding(scope, node.name);\n const isForbiddenGlobal =\n forbiddenGlobals.has(node.name) && !hasBinding(scope, node.name);\n\n if (\n !isAlwaysForbidden &&\n !isDerivedForbidden &&\n !isWindowScoped &&\n !isForbiddenGlobal\n ) {\n return;\n }\n\n if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {\n return;\n }\n\n if (isBindingPosition(node, parent) && !isAlwaysForbidden) {\n return;\n }\n\n if (\n parent?.type === 'ExportDefaultDeclaration' &&\n parent.declaration === node\n ) {\n return;\n }\n\n if (\n generatedProcessorHelperNameRe.test(node.name) &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n const generatedHelperDeclarator = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'VariableDeclarator' &&\n ancestor.id.type === 'Identifier' &&\n generatedProcessorHelperNameRe.test(ancestor.id.name)\n );\n if (generatedHelperDeclarator) {\n return;\n }\n\n if (\n parent?.type === 'Property' &&\n parent.value === node &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n if (parent?.type === 'Property' && parent.value === node) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: parent.shorthand ? `${node.name}: undefined` : 'undefined',\n });\n return;\n }\n\n const grandparent = ancestors[ancestors.length - 2] ?? null;\n if (\n parent?.type === 'MemberExpression' &&\n parent.object === node &&\n grandparent?.type === 'SpreadElement' &&\n grandparent.argument === parent\n ) {\n replacements.push({\n start: grandparent.start,\n end: grandparent.end,\n value: '...{}',\n });\n return;\n }\n\n const exportProtection = findExportedBindingProtection(\n node,\n ancestors,\n reExportedLocalNames\n );\n if (exportProtection) {\n replacements.push(exportProtection);\n return;\n }\n\n const promiseOwner = findPromiseCallbackOwner(ancestors);\n const owner = promiseOwner\n ? findRemovableOwner(promiseOwner, ancestors)\n : findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n }\n );\n\n return applyReplacements(code, normalizeReplacements(replacements));\n};\n"],"file":"oxcPreevalTransforms.js"}
|
|
1
|
+
{"mappings":"AAYA,SAAS,mCAAmC;AAC5C,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAiCtC,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,mBAAmB,IAAI,IAAI;CAC/B,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAC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KAAK,EAC5B;AACA;;EAGF,MAAM,4BAA4B,iBAChC,YACC,aACC,SAAS,SAAS,wBAClB,SAAS,GAAG,SAAS,gBACrB,+BAA+B,KAAK,SAAS,GAAG,KAAK,CACxD;AACD,MAAI,2BAA2B;AAC7B;;AAGF,MACE,QAAQ,SAAS,cACjB,OAAO,UAAU,QACjB,WAAW,OAAO,KAAK,KAAK,EAC5B;AACA;;AAGF,MAAI,QAAQ,SAAS,cAAc,OAAO,UAAU,MAAM;AACxD,gBAAa,KAAK;IAChB,OAAO,KAAK;IACZ,KAAK,KAAK;IACV,OAAO,OAAO,YAAY,GAAG,KAAK,KAAK,eAAe;IACvD,CAAC;AACF;;EAGF,MAAM,cAAc,UAAU,UAAU,SAAS,MAAM;AACvD,MACE,QAAQ,SAAS,sBACjB,OAAO,WAAW,QAClB,aAAa,SAAS,mBACtB,YAAY,aAAa,QACzB;AACA,gBAAa,KAAK;IAChB,OAAO,YAAY;IACnB,KAAK,YAAY;IACjB,OAAO;IACR,CAAC;AACF;;EAGF,MAAM,mBAAmB,8BACvB,MACA,WACA,qBACD;AACD,MAAI,kBAAkB;AACpB,gBAAa,KAAK,iBAAiB;AACnC;;EAGF,MAAM,eAAe,yBAAyB,UAAU;EACxD,MAAM,QAAQ,eACV,mBAAmB,cAAc,UAAU,GAC3C,mBAAmB,MAAM,UAAU;AACvC,eAAa,KAAK;GAAE,OAAO,MAAM;GAAO,KAAK,MAAM;GAAK,OAAO;GAAI,CAAC;GAEvE;AAED,QAAO,kBAAkB,MAAM,sBAAsB,aAAa,CAAC","names":[],"sources":["../../src/utils/oxcPreevalTransforms.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type {\n CallExpression,\n Expression,\n ImportExpression,\n Node,\n Program,\n} from 'oxc-parser';\n\nimport type { CodeRemoverOptions } from '@wyw-in-js/shared';\n\nimport { collectOxcExportsAndImports } from './collectOxcExportsAndImports';\nimport { EventEmitter } from './EventEmitter';\nimport { parseOxcProgramCached } from './parseOxc';\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype Replacement = {\n end: number;\n start: number;\n value: string;\n};\n\ntype Scope = {\n bindings: Map<string, Expression | null>;\n key: string;\n names: Set<string>;\n parent: Scope | null;\n};\n\ntype ImportBinding = {\n imported: string | 'default' | '*';\n local: string;\n source: string;\n};\n\ntype OxcFunctionLikeNode = Node & {\n async: boolean;\n body: Node;\n id?: { name: string } | null;\n type:\n | 'ArrowFunctionExpression'\n | 'FunctionDeclaration'\n | 'FunctionExpression';\n};\n\nconst ssrCheckFields = new Set([\n 'document',\n 'location',\n 'navigator',\n 'sessionStorage',\n 'localStorage',\n 'window',\n]);\n\nconst forbiddenGlobals = new Set([\n ...ssrCheckFields,\n '$RefreshReg$',\n '$RefreshSig$',\n 'XMLHttpRequest',\n 'clearImmediate',\n 'clearInterval',\n 'clearTimeout',\n 'fetch',\n 'navigator',\n 'setImmediate',\n 'setInterval',\n 'setTimeout',\n]);\n\nconst alwaysForbiddenIdentifiers = new Set(['$RefreshReg$', '$RefreshSig$']);\nconst promiseCallbackMethods = new Set(['then', 'catch', 'finally']);\nconst jsxRuntimeSources = new Set([\n 'react/jsx-runtime',\n 'react/jsx-dev-runtime',\n]);\nconst defaultPlaceholder = '...';\nconst defaultReactComponentTypes = [\n 'ExoticComponent',\n 'FC',\n 'ForwardRefExoticComponent',\n 'FunctionComponent',\n 'LazyExoticComponent',\n 'MemoExoticComponent',\n 'NamedExoticComponent',\n];\nconst defaultReactHocs = ['forwardRef', 'memo'];\nconst generatedProcessorHelperNameRe = /^_exp\\d*$/;\nconst requireCallRe = /\\brequire\\s*\\(/;\nconst windowTokenRe = /\\bwindow\\b/;\nconst removableOwnerTypes = new Set([\n 'DoWhileStatement',\n 'ExpressionStatement',\n 'ForInStatement',\n 'ForOfStatement',\n 'ForStatement',\n 'FunctionDeclaration',\n 'IfStatement',\n 'PropertyDefinition',\n 'ReturnStatement',\n 'VariableDeclaration',\n 'WhileStatement',\n]);\nconst importMetaEnvRe = /\\bimport\\s*\\.\\s*meta\\s*\\.\\s*env\\b/;\n\nconst createScope = (parent: Scope | null, key: string): Scope => ({\n bindings: new Map(),\n key,\n names: new Set(),\n parent,\n});\n\nconst createsScope = (node: Node): boolean =>\n node.type === 'Program' ||\n node.type === 'BlockStatement' ||\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst hasBinding = (scope: Scope, name: string): boolean => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n};\n\nconst getBindingKey = (scope: Scope, name: string): string | null => {\n let current: Scope | null = scope;\n while (current) {\n if (current.names.has(name)) {\n return `${current.key}\\0${name}`;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst getStaticBinding = (\n scope: Scope,\n name: string\n): Expression | null | undefined => {\n let current: Scope | null = scope;\n while (current) {\n if (current.bindings.has(name)) {\n return current.bindings.get(name);\n }\n\n current = current.parent;\n }\n\n return undefined;\n};\n\nconst isFileLikeRequireSpecifier = (value: string): boolean =>\n value.startsWith('.') || value.startsWith('/') || value.startsWith('file:');\n\nconst isNode = (value: unknown): value is Node =>\n !!value &&\n typeof value === 'object' &&\n 'type' in value &&\n typeof (value as { type?: unknown }).type === 'string';\n\nconst getChildren = (node: Node): Node[] => {\n const result: Node[] = [];\n const record = node as AnyNode;\n\n Object.keys(record).forEach((key) => {\n if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {\n return;\n }\n\n const value = record[key];\n if (isNode(value)) {\n result.push(value);\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (isNode(item)) {\n result.push(item);\n }\n });\n }\n });\n\n return result;\n};\n\nconst parseOxc = (code: string, filename: string): Program => {\n return parseOxcProgramCached(filename, code, 'unambiguous');\n};\n\nconst unwrapExpression = (node: Expression): Expression => {\n if (\n node.type === 'TSAsExpression' ||\n node.type === 'TSSatisfiesExpression' ||\n node.type === 'TSNonNullExpression' ||\n node.type === 'TSTypeAssertion' ||\n node.type === 'ParenthesizedExpression'\n ) {\n return unwrapExpression(node.expression);\n }\n\n return node;\n};\n\nconst getMemberPropertyName = (node: Node): string | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst isStringLikeExpression = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (expression.type === 'TemplateLiteral') {\n return true;\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n return (\n isStringLikeExpression(expression.left) ||\n isStringLikeExpression(expression.right)\n );\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression' &&\n getMemberPropertyName(expression.callee) === 'concat'\n ) {\n return isStringLikeExpression(expression.callee.object);\n }\n\n return false;\n};\n\nconst templateLiteralToConcat = (code: string, node: Expression): string => {\n if (node.type !== 'TemplateLiteral' || node.expressions.length === 0) {\n return code.slice(node.start, node.end);\n }\n\n const parts: string[] = [];\n node.quasis.forEach((quasi, index) => {\n const cooked = quasi.value.cooked ?? quasi.value.raw;\n if (cooked !== '') {\n parts.push(JSON.stringify(cooked));\n }\n\n const expression = node.expressions[index];\n if (expression) {\n parts.push(code.slice(expression.start, expression.end));\n }\n });\n\n return parts.length > 0 ? parts.join(' + ') : '\"\"';\n};\n\nconst dynamicImportArgumentCode = (code: string, node: Expression): string => {\n if (node.type === 'TemplateLiteral') {\n return templateLiteralToConcat(code, node);\n }\n\n return code.slice(node.start, node.end);\n};\n\nconst evaluateStaticValue = (\n node: Expression,\n scope: Scope,\n seen = new Set<string>()\n): unknown | undefined => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal') {\n return expression.value;\n }\n\n if (expression.type === 'TemplateLiteral') {\n let result = '';\n\n for (let idx = 0; idx < expression.quasis.length; idx += 1) {\n result += expression.quasis[idx]?.value.cooked ?? '';\n\n const nextExpression = expression.expressions[idx];\n if (!nextExpression) {\n continue;\n }\n\n const value = evaluateStaticValue(nextExpression, scope, seen);\n if (\n value === undefined ||\n (typeof value !== 'string' && typeof value !== 'number')\n ) {\n return undefined;\n }\n\n result += String(value);\n }\n\n return result;\n }\n\n if (expression.type === 'Identifier') {\n if (seen.has(expression.name)) {\n return undefined;\n }\n\n const binding = getStaticBinding(scope, expression.name);\n if (!binding) {\n return undefined;\n }\n\n return evaluateStaticValue(\n binding,\n scope,\n new Set([...seen, expression.name])\n );\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n const left = evaluateStaticValue(expression.left, scope, seen);\n const right = evaluateStaticValue(expression.right, scope, seen);\n\n if (left === undefined || right === undefined) {\n return undefined;\n }\n\n if (typeof left === 'number' && typeof right === 'number') {\n return left + right;\n }\n\n if (\n (typeof left === 'string' || typeof left === 'number') &&\n (typeof right === 'string' || typeof right === 'number')\n ) {\n return `${left}${right}`;\n }\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression'\n ) {\n const objectValue = evaluateStaticValue(\n expression.callee.object,\n scope,\n seen\n );\n const propertyName = getMemberPropertyName(expression.callee);\n if (!propertyName) {\n return undefined;\n }\n\n if (typeof objectValue === 'string') {\n if (propertyName === 'toLowerCase' && expression.arguments.length === 0) {\n return objectValue.toLowerCase();\n }\n\n if (propertyName === 'toUpperCase' && expression.arguments.length === 0) {\n return objectValue.toUpperCase();\n }\n\n if (propertyName === 'trim' && expression.arguments.length === 0) {\n return objectValue.trim();\n }\n\n if (propertyName === 'concat') {\n const args = expression.arguments.map((argument) =>\n argument.type === 'SpreadElement'\n ? undefined\n : evaluateStaticValue(argument, scope, seen)\n );\n if (\n args.some((value) => value === undefined) ||\n args.some(\n (value) => typeof value !== 'string' && typeof value !== 'number'\n )\n ) {\n return undefined;\n }\n\n return objectValue.concat(...args.map((value) => String(value)));\n }\n }\n }\n\n return undefined;\n};\n\nconst isLiteralRequireArg = (node: Expression): boolean => {\n const expression = unwrapExpression(node);\n\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return true;\n }\n\n if (\n expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0\n ) {\n return true;\n }\n\n return false;\n};\n\nconst applyReplacements = (\n code: string,\n replacements: Replacement[]\n): string => {\n let result = code;\n replacements\n .sort((a, b) => b.start - a.start)\n .forEach((replacement) => {\n result =\n result.slice(0, replacement.start) +\n replacement.value +\n result.slice(replacement.end);\n });\n\n return result;\n};\n\nconst isIdentifierNamed = (value: unknown, name: string): boolean =>\n isNode(value) && value.type === 'Identifier' && value.name === name;\n\nconst isImportMeta = (node: unknown): boolean => {\n if (!isNode(node) || node.type !== 'MetaProperty') {\n return false;\n }\n\n const metaProperty = node as AnyNode;\n return (\n isIdentifierNamed(metaProperty.meta, 'import') &&\n isIdentifierNamed(metaProperty.property, 'meta')\n );\n};\n\nconst isImportMetaEnv = (node: Node): boolean => {\n if (node.type !== 'MemberExpression') {\n return false;\n }\n\n if (node.computed || !isIdentifierNamed(node.property, 'env')) {\n return false;\n }\n\n return isImportMeta(node.object);\n};\n\nconst collectBindingNames = (node: Node): string[] => {\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectBindingNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectBindingNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) =>\n element ? collectBindingNames(element) : []\n );\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingNames(node.parameter);\n }\n\n return [];\n};\n\nconst predeclareScopeNames = (node: Node, scope: Scope): void => {\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n if (node.type !== 'ArrowFunctionExpression' && node.id) {\n scope.names.add(node.id.name);\n }\n\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n });\n });\n }\n\n const visitScopeDescendants = (child: Node): void => {\n if (child.type === 'VariableDeclarator') {\n collectBindingNames(child.id).forEach((name) => {\n scope.names.add(name);\n });\n } else if (child.type === 'FunctionDeclaration' && child.id) {\n scope.names.add(child.id.name);\n } else if (child.type === 'ClassDeclaration' && child.id) {\n scope.names.add(child.id.name);\n } else if (\n child.type === 'ImportDefaultSpecifier' ||\n child.type === 'ImportNamespaceSpecifier' ||\n child.type === 'ImportSpecifier'\n ) {\n scope.names.add(child.local.name);\n }\n\n if (createsScope(child)) {\n return;\n }\n\n getChildren(child).forEach(visitScopeDescendants);\n };\n\n getChildren(node).forEach(visitScopeDescendants);\n};\n\nconst declareBindings = (node: Node, scope: Scope): void => {\n if (node.type === 'VariableDeclarator') {\n const names = collectBindingNames(node.id);\n names.forEach((name) => {\n scope.names.add(name);\n scope.bindings.set(name, null);\n });\n\n if (node.id.type === 'Identifier' && node.init) {\n scope.bindings.set(node.id.name, node.init);\n }\n return;\n }\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n }\n\n if (node.type === 'ClassDeclaration' && node.id) {\n scope.names.add(node.id.name);\n scope.bindings.set(node.id.name, null);\n return;\n }\n\n if (\n node.type === 'ImportDefaultSpecifier' ||\n node.type === 'ImportNamespaceSpecifier' ||\n node.type === 'ImportSpecifier'\n ) {\n scope.names.add(node.local.name);\n scope.bindings.set(node.local.name, null);\n return;\n }\n\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n scope.names.add(name);\n scope.bindings.set(name, null);\n });\n });\n }\n};\n\nconst visit = (\n node: Node,\n scope: Scope,\n enter: (\n node: Node,\n scope: Scope,\n parent: Node | null,\n ancestors: Node[]\n ) => void,\n parent: Node | null = null,\n ancestors: Node[] = []\n): void => {\n let currentScope = scope;\n if (createsScope(node)) {\n currentScope = createScope(scope, `${node.type}:${node.start}:${node.end}`);\n predeclareScopeNames(node, currentScope);\n }\n\n declareBindings(node, currentScope);\n enter(node, currentScope, parent, ancestors);\n\n getChildren(node).forEach((child) =>\n visit(child, currentScope, enter, node, [...ancestors, node])\n );\n};\n\nexport const replaceImportMetaEnvWithOxc = (\n code: string,\n filename: string\n): string => {\n if (!importMetaEnvRe.test(code)) {\n return code;\n }\n\n const replacements: Replacement[] = [];\n\n visit(parseOxc(code, filename), createScope(null, 'root'), (node) => {\n if (!isImportMetaEnv(node)) {\n return;\n }\n\n replacements.push({\n end: node.end,\n start: node.start,\n value: '__wyw_import_meta_env',\n });\n });\n\n return applyReplacements(code, replacements);\n};\n\ntype CombinedSyntaxRewriteOptions = {\n addRequireFallback: boolean;\n eventEmitter?: EventEmitter;\n rewriteDynamicImports: boolean;\n};\n\ntype RequireFallbackCandidate = {\n call: CallExpression;\n scope: Scope;\n};\n\nfunction collectDynamicImportAndRequireFallbackReplacements(\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): Replacement[] {\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const dynamicImportCandidates: ImportExpression[] = [];\n const requireFallbackCandidates: RequireFallbackCandidate[] = [];\n\n eventEmitter.perf(\n 'transform:preeval:dynamicImportRequireFallback:scan',\n () => {\n visit(\n parseOxc(code, filename),\n createScope(null, 'root'),\n (node, scope) => {\n if (\n options.rewriteDynamicImports &&\n node.type === 'ImportExpression'\n ) {\n dynamicImportCandidates.push(node as ImportExpression);\n }\n\n if (!options.addRequireFallback || node.type !== 'CallExpression') {\n return;\n }\n\n const call = node as CallExpression;\n if (\n call.callee.type !== 'Identifier' ||\n call.callee.name !== 'require' ||\n hasBinding(scope, 'require') ||\n call.arguments.length !== 1\n ) {\n return;\n }\n\n const [firstArg] = call.arguments;\n if (\n !firstArg ||\n firstArg.type === 'SpreadElement' ||\n isLiteralRequireArg(firstArg)\n ) {\n return;\n }\n\n requireFallbackCandidates.push({\n call,\n scope,\n });\n }\n );\n }\n );\n\n const replacements: Replacement[] = [];\n\n eventEmitter.perf('transform:preeval:dynamicImport', () => {\n dynamicImportCandidates.forEach((importExpression) => {\n const argument = importExpression.source;\n const nextArgument = isStringLikeExpression(argument)\n ? unwrapExpression(argument)\n : argument;\n\n replacements.push({\n end: importExpression.end,\n start: importExpression.start,\n value: `__wyw_dynamic_import(${dynamicImportArgumentCode(\n code,\n nextArgument\n )})`,\n });\n });\n });\n\n eventEmitter.perf('transform:preeval:requireFallback', () => {\n requireFallbackCandidates.forEach(({ call, scope }) => {\n const [firstArg] = call.arguments;\n if (!firstArg || firstArg.type === 'SpreadElement') {\n return;\n }\n\n const staticValue = evaluateStaticValue(firstArg, scope);\n if (\n typeof staticValue === 'string' &&\n isFileLikeRequireSpecifier(staticValue)\n ) {\n replacements.push({\n end: firstArg.end,\n start: firstArg.start,\n value: JSON.stringify(staticValue),\n });\n return;\n }\n\n replacements.push({\n end: firstArg.end,\n start: firstArg.end,\n value: ', true',\n });\n });\n });\n\n return replacements;\n}\n\nexport const rewriteDynamicImportsWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: false,\n rewriteDynamicImports: true,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const addRequireFallbackWithOxc = (\n code: string,\n filename: string\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n {\n addRequireFallback: true,\n rewriteDynamicImports: false,\n }\n );\n\n return applyReplacements(code, replacements);\n};\n\nexport const rewriteDynamicImportsAndAddRequireFallbackWithOxc = (\n code: string,\n filename: string,\n options: CombinedSyntaxRewriteOptions\n): string => {\n const replacements = collectDynamicImportAndRequireFallbackReplacements(\n code,\n filename,\n options\n );\n\n return applyReplacements(code, replacements);\n};\n\nconst isBindingPosition = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'VariableDeclarator' && parent.id === node) {\n return true;\n }\n\n if (\n (parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression' ||\n parent.type === 'ClassDeclaration' ||\n parent.type === 'ClassExpression') &&\n parent.id === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ImportSpecifier' &&\n (parent.local === node || parent.imported === node)\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ImportDefaultSpecifier' ||\n parent.type === 'ImportNamespaceSpecifier') &&\n parent.local === node\n ) {\n return true;\n }\n\n if (\n parent.type === 'ExportSpecifier' &&\n (parent.local === node || parent.exported === node)\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isPropertyOnlyIdentifier = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (\n parent.type === 'MemberExpression' &&\n !parent.computed &&\n parent.property === node\n ) {\n return true;\n }\n\n if (\n (parent.type === 'Property' ||\n parent.type === 'MethodDefinition' ||\n parent.type === 'PropertyDefinition') &&\n !parent.computed &&\n parent.key === node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isTypeContext = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type.startsWith('TS') || ancestor.type.startsWith('JSDoc')\n );\n\nconst isInsideTypeof = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type === 'UnaryExpression' && ancestor.operator === 'typeof'\n );\n\nconst isInsideImportDeclaration = (ancestors: Node[]): boolean =>\n ancestors.some((ancestor) => ancestor.type === 'ImportDeclaration');\n\nfunction findLastAncestor<T extends Node>(\n ancestors: Node[],\n predicate: (ancestor: Node) => ancestor is T\n): T | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null;\nfunction findLastAncestor(\n ancestors: Node[],\n predicate: (ancestor: Node) => boolean\n): Node | null {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (predicate(ancestor)) {\n return ancestor;\n }\n }\n\n return null;\n}\n\nconst findRemovableOwner = (node: Node, ancestors: Node[]): Node => {\n let owner: Node = node;\n let ownerAncestorIndex = -1;\n\n if (!removableOwnerTypes.has(node.type)) {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (removableOwnerTypes.has(ancestor.type)) {\n owner = ancestor;\n ownerAncestorIndex = idx;\n break;\n }\n }\n }\n\n const parent =\n ownerAncestorIndex > 0 ? ancestors[ownerAncestorIndex - 1] : null;\n if (\n parent?.type === 'ExportNamedDeclaration' &&\n 'declaration' in parent &&\n parent.declaration === owner\n ) {\n return parent;\n }\n\n return owner;\n};\n\ntype ExportedBindingProtection = {\n start: number;\n end: number;\n value: string;\n};\n\nconst collectReExportedLocalNames = (program: Program): Set<string> => {\n const names = new Set<string>();\n for (const stmt of program.body) {\n if (\n stmt.type !== 'ExportNamedDeclaration' ||\n stmt.declaration ||\n stmt.source\n ) {\n continue;\n }\n for (const spec of stmt.specifiers) {\n if (spec.type === 'ExportSpecifier' && spec.local.type === 'Identifier') {\n names.add(spec.local.name);\n }\n }\n }\n return names;\n};\n\n// When an offending identifier sits inside the value of a top-level export,\n// removing the surrounding declaration would strip the export binding too.\n// ESM linker then fails on consumers' `import { name } from '...'` because the\n// named export no longer exists. To keep the binding alive, replace just the\n// value (declarator init or default-export expression) with `undefined`.\nconst findExportedBindingProtection = (\n node: Node,\n ancestors: Node[],\n reExportedLocalNames: Set<string>\n): ExportedBindingProtection | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n\n if (ancestor.type === 'ExportDefaultDeclaration') {\n const decl = ancestor.declaration;\n if (decl && decl !== node && 'start' in decl && 'end' in decl) {\n return { start: decl.start, end: decl.end, value: 'undefined' };\n }\n return null;\n }\n\n if (ancestor.type !== 'VariableDeclarator') {\n continue;\n }\n\n if (\n ancestor.id.type !== 'Identifier' ||\n !ancestor.init ||\n ancestor.init === node\n ) {\n return null;\n }\n\n const varDecl = ancestors[idx - 1];\n const wrapper = ancestors[idx - 2] ?? null;\n\n if (varDecl?.type !== 'VariableDeclaration') {\n return null;\n }\n\n const isDirectExport =\n wrapper?.type === 'ExportNamedDeclaration' &&\n wrapper.declaration === varDecl;\n const isTopLevelDeclaration =\n wrapper === null || wrapper?.type === 'Program';\n const isReExported =\n isTopLevelDeclaration && reExportedLocalNames.has(ancestor.id.name);\n\n if (!isDirectExport && !isReExported) {\n return null;\n }\n\n return {\n start: ancestor.init.start,\n end: ancestor.init.end,\n value: 'undefined',\n };\n }\n\n return null;\n};\n\nconst findPromiseCallbackOwner = (ancestors: Node[]): Node | null => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'NewExpression' &&\n ancestor.callee.type === 'Identifier' &&\n ancestor.callee.name === 'Promise'\n ) {\n return ancestor;\n }\n\n if (\n ancestor.type === 'CallExpression' &&\n ancestor.callee.type === 'MemberExpression' &&\n promiseCallbackMethods.has(getMemberPropertyName(ancestor.callee) ?? '')\n ) {\n return ancestor;\n }\n }\n\n return null;\n};\n\nconst containsForbiddenIdentifier = (node: Node): boolean => {\n if (node.type === 'Identifier' && alwaysForbiddenIdentifiers.has(node.name)) {\n return true;\n }\n\n return getChildren(node).some(containsForbiddenIdentifier);\n};\n\nconst collectWindowScopedNames = (program: Program): Set<string> => {\n const windowScopedNames = new Set<string>();\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'MemberExpression' ||\n node.object.type !== 'Identifier' ||\n node.object.name !== 'window' ||\n hasBinding(scope, 'window')\n ) {\n return;\n }\n\n const propertyName = getMemberPropertyName(node);\n if (propertyName) {\n windowScopedNames.add(propertyName);\n }\n });\n\n return windowScopedNames;\n};\n\nconst containsForbiddenReference = (\n node: Node,\n scope: Scope,\n windowScopedNames: Set<string>,\n derivedForbiddenBindings: Set<string> = new Set()\n): boolean => {\n let found = false;\n\n visit(node, scope, (child, childScope, parent, ancestors) => {\n if (\n found ||\n child.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isPropertyOnlyIdentifier(child, parent) ||\n isBindingPosition(child, parent)\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(childScope, child.name);\n if (\n alwaysForbiddenIdentifiers.has(child.name) ||\n (forbiddenGlobals.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (windowScopedNames.has(child.name) &&\n !hasBinding(childScope, child.name)) ||\n (bindingKey !== null && derivedForbiddenBindings.has(bindingKey))\n ) {\n found = true;\n }\n });\n\n return found;\n};\n\nconst nameFromModuleExport = (node: Node): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n\n return null;\n};\n\nconst collectImportBindings = (\n code: string,\n filename: string,\n program: Program\n): ImportBinding[] => {\n const bindings = new Map<string, ImportBinding>();\n const addBinding = (binding: ImportBinding): void => {\n bindings.set(\n `${binding.local}\\0${binding.source}\\0${binding.imported}`,\n binding\n );\n };\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n const source = statement.source.value;\n statement.specifiers.forEach((specifier) => {\n if (specifier.type === 'ImportDefaultSpecifier') {\n addBinding({\n imported: 'default',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n addBinding({\n imported: '*',\n local: specifier.local.name,\n source,\n });\n return;\n }\n\n const imported = nameFromModuleExport(specifier.imported);\n if (!imported) {\n return;\n }\n\n addBinding({\n imported,\n local: specifier.local.name,\n source,\n });\n });\n });\n\n if (!requireCallRe.test(code)) {\n return [...bindings.values()];\n }\n\n collectOxcExportsAndImports(code, filename).imports.forEach((item) => {\n if (item.imported === 'side-effect') {\n return;\n }\n\n addBinding({\n imported: item.imported,\n local: item.local.code,\n source: item.source,\n });\n\n if (item.local.name && item.local.name !== item.local.code) {\n addBinding({\n imported: item.imported,\n local: item.local.name,\n source: item.source,\n });\n }\n });\n\n return [...bindings.values()];\n};\n\nconst getImportBinding = (\n imports: ImportBinding[],\n local: string\n): ImportBinding | undefined => imports.find((item) => item.local === local);\n\nfunction unwrapSequenceCallee(node: Expression): Expression {\n if (\n node.type === 'SequenceExpression' &&\n node.expressions.length === 2 &&\n node.expressions[0]?.type === 'Literal' &&\n node.expressions[0].value === 0\n ) {\n return node.expressions[1] as Expression;\n }\n\n return node;\n}\n\nconst getExpressionImportKey = (node: Expression): string | null => {\n const expression = unwrapSequenceCallee(node);\n\n if (expression.type === 'Identifier') {\n return expression.name;\n }\n\n if (expression.type !== 'MemberExpression') {\n return null;\n }\n\n if (expression.object.type !== 'Identifier') {\n return null;\n }\n\n const propertyName = getMemberPropertyName(expression);\n return propertyName ? `${expression.object.name}.${propertyName}` : null;\n};\n\nconst isHookOrCreateElement = (name: string): boolean =>\n name === 'createElement' || /use[A-Z]/.test(name);\n\nconst getInnermostCallee = (call: CallExpression): Expression => {\n let callee = unwrapSequenceCallee(call.callee);\n while (callee.type === 'CallExpression') {\n callee = unwrapSequenceCallee(callee.callee);\n }\n\n return callee;\n};\n\nconst getImportForExpression = (\n node: Expression,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n const expression = unwrapSequenceCallee(node);\n const directMatchKey = getExpressionImportKey(expression);\n if (directMatchKey) {\n const directMatch = getImportBinding(imports, directMatchKey);\n if (directMatch) {\n return [directMatch.source, directMatch.imported];\n }\n }\n\n if (expression.type === 'Identifier') {\n const matched = getImportBinding(imports, expression.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (expression.type !== 'MemberExpression') {\n return undefined;\n }\n\n if (expression.object.type !== 'Identifier') {\n return undefined;\n }\n\n const propertyName = getMemberPropertyName(expression);\n if (!propertyName) {\n return undefined;\n }\n\n const objectImport = getImportBinding(imports, expression.object.name);\n if (!objectImport) {\n return undefined;\n }\n\n if (\n objectImport.imported === 'default' ||\n objectImport.imported === '*' ||\n objectImport.source === 'react'\n ) {\n return [objectImport.source, propertyName];\n }\n\n return undefined;\n};\n\nconst isReactRuntimeCall = (\n call: CallExpression,\n imports: ImportBinding[]\n): boolean => {\n const callee = unwrapSequenceCallee(call.callee);\n const matched = getImportForExpression(callee, imports);\n if (!matched) {\n return false;\n }\n\n const [source, imported] = matched;\n if (jsxRuntimeSources.has(source)) {\n return true;\n }\n\n return source === 'react' && isHookOrCreateElement(imported);\n};\n\nconst isHocCall = (\n call: CallExpression,\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n const matched = getImportForExpression(getInnermostCallee(call), imports);\n return !!matched && hocs[matched[0]]?.includes(matched[1]);\n};\n\nconst isInsideHocCall = (\n ancestors: Node[],\n hocs: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean =>\n ancestors.some(\n (ancestor): ancestor is CallExpression =>\n ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports)\n );\n\nconst getComponentTypes = (\n options?: CodeRemoverOptions\n): Record<string, string[]> => {\n const componentTypes = {\n ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),\n };\n const reactTypes = componentTypes.react;\n\n if (Array.isArray(reactTypes) && reactTypes.includes(defaultPlaceholder)) {\n const idx = reactTypes.indexOf(defaultPlaceholder);\n componentTypes.react = [...reactTypes];\n componentTypes.react.splice(idx, 1, ...defaultReactComponentTypes);\n }\n\n return componentTypes;\n};\n\nconst getHocs = (options?: CodeRemoverOptions): Record<string, string[]> => {\n const hocs = {\n ...(options?.hocs ?? {}),\n };\n const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);\n\n hocs.react = [...reactHocs];\n return hocs;\n};\n\nconst getTypeImport = (\n node: Node,\n imports: ImportBinding[]\n): [source: string, imported: string] | undefined => {\n if (node.type === 'Identifier') {\n const matched = getImportBinding(imports, node.name);\n return matched ? [matched.source, matched.imported] : undefined;\n }\n\n if (node.type !== 'TSQualifiedName') {\n return undefined;\n }\n\n if (node.left.type !== 'Identifier') {\n return undefined;\n }\n\n const matched = getImportBinding(imports, node.left.name);\n return matched ? [matched.source, node.right.name] : undefined;\n};\n\nconst isComponentTypeMatch = (\n id: Node,\n componentTypes: Record<string, string[]>,\n imports: ImportBinding[]\n): boolean => {\n if (id.type !== 'Identifier') {\n return false;\n }\n\n const annotation = id.typeAnnotation;\n if (\n !annotation ||\n annotation.type !== 'TSTypeAnnotation' ||\n annotation.typeAnnotation.type !== 'TSTypeReference'\n ) {\n return false;\n }\n\n const matched = getTypeImport(annotation.typeAnnotation.typeName, imports);\n return !!matched && componentTypes[matched[0]]?.includes(matched[1]);\n};\n\nconst getClassName = (node: Node): string | null =>\n node.type === 'ClassDeclaration' && node.id ? node.id.name : null;\n\nconst isFunctionLikeNode = (node: Node): node is OxcFunctionLikeNode =>\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression';\n\nconst isImmediatelyInvokedFunction = (\n fnNode: Node,\n ancestors: Node[],\n fnIndex: number\n): boolean => {\n // Walk past any ParenthesizedExpression / SequenceExpression wrappers that\n // sit between the function and its enclosing CallExpression. oxc-parser\n // preserves ParenthesizedExpression nodes, so `(() => {...})()` shows up\n // as CallExpression -> ParenthesizedExpression -> ArrowFunctionExpression.\n let child: Node = fnNode;\n for (let idx = fnIndex - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'ParenthesizedExpression' &&\n 'expression' in ancestor &&\n ancestor.expression === child\n ) {\n child = ancestor;\n continue;\n }\n if (\n ancestor.type === 'SequenceExpression' &&\n Array.isArray(ancestor.expressions) &&\n ancestor.expressions[ancestor.expressions.length - 1] === child\n ) {\n child = ancestor;\n continue;\n }\n return ancestor.type === 'CallExpression' && ancestor.callee === child;\n }\n return false;\n};\n\n// A reference is \"deferred\" when it lives inside a function body that is\n// not immediately invoked. Module preeval reads exports without calling\n// them, so deferred references never run and must not be sanitized — that\n// would silently drop the binding (or remove the entire export) and break\n// importers that expect the function to be callable.\nconst isInDeferredFunctionScope = (ancestors: Node[]): boolean => {\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (!isFunctionLikeNode(ancestor)) {\n continue;\n }\n if (!isImmediatelyInvokedFunction(ancestor, ancestors, idx)) {\n return true;\n }\n }\n return false;\n};\n\nconst findFunctionReplacement = (ancestors: Node[]): Replacement | null => {\n const renderMethod = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'MethodDefinition' &&\n ancestor.key.type === 'Identifier' &&\n ancestor.key.name === 'render'\n );\n\n if (renderMethod) {\n const classDecl = findLastAncestor(\n ancestors,\n (ancestor) => ancestor.type === 'ClassDeclaration'\n );\n const className = classDecl ? getClassName(classDecl) : null;\n if (classDecl && className) {\n return {\n start: classDecl.start,\n end: classDecl.end,\n value: `function ${className}() { return null; }`,\n };\n }\n }\n\n const functionNode = findLastAncestor(ancestors, isFunctionLikeNode);\n\n if (!functionNode) {\n return null;\n }\n\n if (functionNode.type === 'ArrowFunctionExpression') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}() => { return null; }`,\n };\n }\n\n if (functionNode.type === 'FunctionDeclaration') {\n return {\n start: functionNode.start,\n end: functionNode.end,\n value: `${functionNode.async ? 'async ' : ''}function ${\n functionNode.id?.name ?? ''\n }() { return null; }`,\n };\n }\n\n return {\n start: functionNode.body.start,\n end: functionNode.body.end,\n value: '{ return null; }',\n };\n};\n\nconst normalizeReplacements = (replacements: Replacement[]): Replacement[] => {\n const sorted = [...replacements].sort((a, b) =>\n a.start === b.start ? b.end - a.end : a.start - b.start\n );\n const result: Replacement[] = [];\n\n sorted.forEach((replacement) => {\n const last = result[result.length - 1];\n if (\n last &&\n replacement.start >= last.start &&\n replacement.end <= last.end\n ) {\n return;\n }\n\n result.push(replacement);\n });\n\n return result;\n};\n\nexport const removeDangerousCodeWithOxc = (\n code: string,\n filename: string,\n options?: CodeRemoverOptions\n): string => {\n const replacements: Replacement[] = [];\n const derivedForbiddenBindings = new Set<string>();\n const program = parseOxc(code, filename);\n const imports = collectImportBindings(code, filename, program);\n const componentTypes = getComponentTypes(options);\n const hocs = getHocs(options);\n const hasHocs = Object.keys(hocs).length > 0;\n const windowScopedNames = windowTokenRe.test(code)\n ? collectWindowScopedNames(program)\n : new Set<string>();\n const reExportedLocalNames = collectReExportedLocalNames(program);\n\n const derivedBindingDiscovery = { found: true };\n while (derivedBindingDiscovery.found) {\n derivedBindingDiscovery.found = false;\n\n visit(program, createScope(null, 'root'), (node, scope) => {\n if (\n node.type !== 'VariableDeclarator' ||\n node.id.type !== 'Identifier' ||\n !node.init\n ) {\n return;\n }\n\n const bindingKey = getBindingKey(scope, node.id.name);\n if (!bindingKey || derivedForbiddenBindings.has(bindingKey)) {\n return;\n }\n\n if (\n containsForbiddenIdentifier(node.init) ||\n containsForbiddenReference(\n node.init,\n scope,\n windowScopedNames,\n derivedForbiddenBindings\n )\n ) {\n derivedForbiddenBindings.add(bindingKey);\n derivedBindingDiscovery.found = true;\n }\n });\n }\n\n visit(\n program,\n createScope(null, 'root'),\n (node, scope, parent, ancestors) => {\n if (node.type === 'JSXElement' || node.type === 'JSXFragment') {\n replacements.push(\n findFunctionReplacement(ancestors) ?? {\n start: node.start,\n end: node.end,\n value: 'null',\n }\n );\n return;\n }\n\n if (node.type === 'CallExpression') {\n if (isReactRuntimeCall(node, imports)) {\n const replacement = findFunctionReplacement(ancestors);\n if (replacement) {\n replacements.push(replacement);\n }\n\n return;\n }\n\n if (hasHocs && isHocCall(node, hocs, imports)) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '() => null',\n });\n return;\n }\n }\n\n if (\n node.type === 'VariableDeclarator' &&\n node.id.type === 'Identifier' &&\n node.init &&\n isComponentTypeMatch(node.id, componentTypes, imports)\n ) {\n replacements.push({\n start: node.init.start,\n end: node.init.end,\n value: '() => null',\n });\n return;\n }\n\n if (\n node.type === 'UnaryExpression' &&\n node.operator === 'typeof' &&\n node.argument.type === 'Identifier' &&\n ssrCheckFields.has(node.argument.name) &&\n !hasBinding(scope, node.argument.name)\n ) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: '\"undefined\"',\n });\n return;\n }\n\n if (node.type === 'MetaProperty') {\n const owner = findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n return;\n }\n\n if (\n node.type !== 'Identifier' ||\n isTypeContext(ancestors) ||\n isInsideTypeof(ancestors) ||\n isInsideImportDeclaration(ancestors)\n ) {\n return;\n }\n\n if (isPropertyOnlyIdentifier(node, parent)) {\n return;\n }\n\n const isAlwaysForbidden = alwaysForbiddenIdentifiers.has(node.name);\n const bindingKey = getBindingKey(scope, node.name);\n const isDerivedForbidden =\n bindingKey !== null && derivedForbiddenBindings.has(bindingKey);\n const isWindowScoped =\n windowScopedNames.has(node.name) && !hasBinding(scope, node.name);\n const isForbiddenGlobal =\n forbiddenGlobals.has(node.name) && !hasBinding(scope, node.name);\n\n if (\n !isAlwaysForbidden &&\n !isDerivedForbidden &&\n !isWindowScoped &&\n !isForbiddenGlobal\n ) {\n return;\n }\n\n if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {\n return;\n }\n\n if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {\n return;\n }\n\n if (isBindingPosition(node, parent) && !isAlwaysForbidden) {\n return;\n }\n\n if (\n parent?.type === 'ExportDefaultDeclaration' &&\n parent.declaration === node\n ) {\n return;\n }\n\n if (\n generatedProcessorHelperNameRe.test(node.name) &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n const generatedHelperDeclarator = findLastAncestor(\n ancestors,\n (ancestor) =>\n ancestor.type === 'VariableDeclarator' &&\n ancestor.id.type === 'Identifier' &&\n generatedProcessorHelperNameRe.test(ancestor.id.name)\n );\n if (generatedHelperDeclarator) {\n return;\n }\n\n if (\n parent?.type === 'Property' &&\n parent.value === node &&\n hasBinding(scope, node.name)\n ) {\n return;\n }\n\n if (parent?.type === 'Property' && parent.value === node) {\n replacements.push({\n start: node.start,\n end: node.end,\n value: parent.shorthand ? `${node.name}: undefined` : 'undefined',\n });\n return;\n }\n\n const grandparent = ancestors[ancestors.length - 2] ?? null;\n if (\n parent?.type === 'MemberExpression' &&\n parent.object === node &&\n grandparent?.type === 'SpreadElement' &&\n grandparent.argument === parent\n ) {\n replacements.push({\n start: grandparent.start,\n end: grandparent.end,\n value: '...{}',\n });\n return;\n }\n\n const exportProtection = findExportedBindingProtection(\n node,\n ancestors,\n reExportedLocalNames\n );\n if (exportProtection) {\n replacements.push(exportProtection);\n return;\n }\n\n const promiseOwner = findPromiseCallbackOwner(ancestors);\n const owner = promiseOwner\n ? findRemovableOwner(promiseOwner, ancestors)\n : findRemovableOwner(node, ancestors);\n replacements.push({ start: owner.start, end: owner.end, value: '' });\n }\n );\n\n return applyReplacements(code, normalizeReplacements(replacements));\n};\n"],"file":"oxcPreevalTransforms.js"}
|