@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/collect.js +1 -0
- package/esm/transform/generators/collect.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 +272 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +184 -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 +58 -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 +55 -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 +517 -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/collectOxcExportsAndImports.js +8 -0
- package/esm/utils/collectOxcExportsAndImports.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 +58 -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 +106 -66
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/parseOxc.js +6 -1
- package/esm/utils/parseOxc.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 +6 -5
- 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 +4 -0
- package/types/transform/generators/collect.js +1 -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 +312 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +198 -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 +64 -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 +57 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +9 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +169 -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 +567 -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/collectOxcExportsAndImports.js +8 -0
- 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 +17 -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 +61 -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 +111 -75
- package/types/utils/parseOxc.js +6 -1
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.js +3 -3
- package/esm/eval/resolverStrategy.js +0 -51
- package/esm/eval/resolverStrategy.js.map +0 -1
- package/types/eval/resolverStrategy.d.ts +0 -13
- package/types/eval/resolverStrategy.js +0 -46
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { usesStaticEvaluation } from "./evalStrategy.js";
|
|
2
|
+
export const createStaticPreevalOverlay = (processed, dependencyNames, options) => {
|
|
3
|
+
const staticValuesEnabled = usesStaticEvaluation(options);
|
|
4
|
+
const staticValueNames = staticValuesEnabled ? new Set(processed.staticValues.map((item) => item.name)) : null;
|
|
5
|
+
const evalDependencyNames = staticValuesEnabled ? dependencyNames.filter((name) => !staticValueNames.has(name)) : dependencyNames;
|
|
6
|
+
const staticValueCache = new Map();
|
|
7
|
+
if (staticValuesEnabled) {
|
|
8
|
+
processed.staticValues.forEach(({ name, value }) => {
|
|
9
|
+
staticValueCache.set(name, value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
evalDependencyNames,
|
|
14
|
+
staticValueCache,
|
|
15
|
+
staticValueCandidates: staticValuesEnabled ? processed.staticValueCandidates : []
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=staticOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AACA,SAAS,4BAA4B;AAGrC,OAAO,MAAM,8BACX,WACA,iBACA,YACyB;CACzB,MAAM,sBAAsB,qBAAqB,QAAQ;CACzD,MAAM,mBAAmB,sBACrB,IAAI,IAAI,UAAU,aAAa,KAAK,SAAS,KAAK,KAAK,CAAC,GACxD;CACJ,MAAM,sBAAsB,sBACxB,gBAAgB,QAAQ,SAAS,CAAC,iBAAkB,IAAI,KAAK,CAAC,GAC9D;CACJ,MAAM,mBAAmB,IAAI,KAAsB;AAEnD,KAAI,qBAAqB;AACvB,YAAU,aAAa,SAAS,EAAE,MAAM,YAAY;AAClD,oBAAiB,IAAI,MAAM,MAAM;IACjC;;AAGJ,QAAO;EACL;EACA;EACA,uBAAuB,sBACnB,UAAU,wBACV,EAAE;EACP","names":[],"sources":["../../../src/utils/oxcPreevalStage/staticOverlay.ts"],"version":3,"sourcesContent":["import type { ApplyOxcProcessorsResult } from '../applyOxcProcessors/types';\nimport { usesStaticEvaluation } from './evalStrategy';\nimport type { OxcPreevalOptions, StaticPreevalOverlay } from './types';\n\nexport const createStaticPreevalOverlay = (\n processed: ApplyOxcProcessorsResult,\n dependencyNames: string[],\n options: OxcPreevalOptions\n): StaticPreevalOverlay => {\n const staticValuesEnabled = usesStaticEvaluation(options);\n const staticValueNames = staticValuesEnabled\n ? new Set(processed.staticValues.map((item) => item.name))\n : null;\n const evalDependencyNames = staticValuesEnabled\n ? dependencyNames.filter((name) => !staticValueNames!.has(name))\n : dependencyNames;\n const staticValueCache = new Map<string, unknown>();\n\n if (staticValuesEnabled) {\n processed.staticValues.forEach(({ name, value }) => {\n staticValueCache.set(name, value);\n });\n }\n\n return {\n evalDependencyNames,\n staticValueCache,\n staticValueCandidates: staticValuesEnabled\n ? processed.staticValueCandidates\n : [],\n };\n};\n"],"file":"staticOverlay.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/utils/oxcPreevalStage/types.ts"],"version":3,"sourcesContent":["import type { StrictOptions } from '@wyw-in-js/shared';\n\nimport type { EventEmitter } from '../EventEmitter';\nimport type { WYWTransformMetadata } from '../TransformMetadata';\nimport type { OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';\n\nexport type OxcPreevalOptions = Pick<\n StrictOptions,\n | 'classNameSlug'\n | 'codeRemover'\n | 'displayName'\n | 'eval'\n | 'extensions'\n | 'features'\n | 'staticBindings'\n | 'tagResolver'\n> & { eventEmitter?: EventEmitter };\n\nexport type OxcPreevalResult = {\n baseCode: string;\n code: string;\n dependencyNames: string[];\n metadata: WYWTransformMetadata | null;\n processorClassNames: Record<string, string>;\n staticDependencies: string[];\n staticValueCache: Map<string, unknown>;\n staticValueCandidates: OxcStaticValueCandidate[];\n};\n\nexport type StaticPreevalOverlay = {\n evalDependencyNames: string[];\n staticValueCache: Map<string, unknown>;\n staticValueCandidates: OxcStaticValueCandidate[];\n};\n"],"file":"types.js"}
|
|
@@ -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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { collectOxcExportsAndImports } from "./collectOxcExportsAndImports.js";
|
|
2
2
|
import { EventEmitter } from "./EventEmitter.js";
|
|
3
|
+
import { getOxcNodeChildren } from "./oxc/ast.js";
|
|
3
4
|
import { parseOxcProgramCached } from "./parseOxc.js";
|
|
4
5
|
const ssrCheckFields = new Set([
|
|
5
6
|
"document",
|
|
@@ -40,6 +41,7 @@ const defaultReactComponentTypes = [
|
|
|
40
41
|
"MemoExoticComponent",
|
|
41
42
|
"NamedExoticComponent"
|
|
42
43
|
];
|
|
44
|
+
const defaultReactHocs = ["forwardRef", "memo"];
|
|
43
45
|
const generatedProcessorHelperNameRe = /^_exp\d*$/;
|
|
44
46
|
const requireCallRe = /\brequire\s*\(/;
|
|
45
47
|
const windowTokenRe = /\bwindow\b/;
|
|
@@ -96,28 +98,11 @@ const getStaticBinding = (scope, name) => {
|
|
|
96
98
|
};
|
|
97
99
|
const isFileLikeRequireSpecifier = (value) => value.startsWith(".") || value.startsWith("/") || value.startsWith("file:");
|
|
98
100
|
const isNode = (value) => !!value && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const value = record[key];
|
|
107
|
-
if (isNode(value)) {
|
|
108
|
-
result.push(value);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (Array.isArray(value)) {
|
|
112
|
-
value.forEach((item) => {
|
|
113
|
-
if (isNode(item)) {
|
|
114
|
-
result.push(item);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
return result;
|
|
120
|
-
};
|
|
101
|
+
// Reuses the per-node.type visitor-key cache in utils/oxc/ast.ts. This file's
|
|
102
|
+
// getChildren shape historically diverged from the canonical one (a smaller
|
|
103
|
+
// metadata-key skip set), but the produced children list is identical in
|
|
104
|
+
// practice because oxc-parser nodes don't carry the extra metadata fields.
|
|
105
|
+
const getChildren = getOxcNodeChildren;
|
|
121
106
|
const parseOxc = (code, filename) => {
|
|
122
107
|
return parseOxcProgramCached(filename, code, "unambiguous");
|
|
123
108
|
};
|
|
@@ -313,57 +298,92 @@ const predeclareScopeNames = (node, scope) => {
|
|
|
313
298
|
});
|
|
314
299
|
}
|
|
315
300
|
const visitScopeDescendants = (child) => {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
301
|
+
switch (child.type) {
|
|
302
|
+
case "VariableDeclarator": {
|
|
303
|
+
const names = collectBindingNames(child.id);
|
|
304
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
305
|
+
scope.names.add(names[i]);
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
case "FunctionDeclaration":
|
|
310
|
+
case "ClassDeclaration":
|
|
311
|
+
if (child.id) {
|
|
312
|
+
scope.names.add(child.id.name);
|
|
313
|
+
}
|
|
314
|
+
break;
|
|
315
|
+
case "ImportDefaultSpecifier":
|
|
316
|
+
case "ImportNamespaceSpecifier":
|
|
317
|
+
case "ImportSpecifier":
|
|
318
|
+
scope.names.add(child.local.name);
|
|
319
|
+
break;
|
|
320
|
+
default: break;
|
|
326
321
|
}
|
|
327
322
|
if (createsScope(child)) {
|
|
328
323
|
return;
|
|
329
324
|
}
|
|
330
|
-
getChildren(child)
|
|
325
|
+
const children = getChildren(child);
|
|
326
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
327
|
+
visitScopeDescendants(children[i]);
|
|
328
|
+
}
|
|
331
329
|
};
|
|
332
|
-
getChildren(node)
|
|
330
|
+
const rootChildren = getChildren(node);
|
|
331
|
+
for (let i = 0; i < rootChildren.length; i += 1) {
|
|
332
|
+
visitScopeDescendants(rootChildren[i]);
|
|
333
|
+
}
|
|
333
334
|
};
|
|
334
335
|
const declareBindings = (node, scope) => {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (node.type === "FunctionDeclaration" && node.id) {
|
|
347
|
-
scope.names.add(node.id.name);
|
|
348
|
-
scope.bindings.set(node.id.name, null);
|
|
349
|
-
}
|
|
350
|
-
if (node.type === "ClassDeclaration" && node.id) {
|
|
351
|
-
scope.names.add(node.id.name);
|
|
352
|
-
scope.bindings.set(node.id.name, null);
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
if (node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier" || node.type === "ImportSpecifier") {
|
|
356
|
-
scope.names.add(node.local.name);
|
|
357
|
-
scope.bindings.set(node.local.name, null);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
361
|
-
node.params.forEach((param) => {
|
|
362
|
-
collectBindingNames(param).forEach((name) => {
|
|
336
|
+
// Called for every visited AST node, so the dispatch is hot. A switch lets
|
|
337
|
+
// V8 generate a jump table on node.type; the previous chained `if`s walked
|
|
338
|
+
// each branch's string-compare for every non-matching node.
|
|
339
|
+
switch (node.type) {
|
|
340
|
+
case "VariableDeclarator": {
|
|
341
|
+
const names = collectBindingNames(node.id);
|
|
342
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
343
|
+
const name = names[i];
|
|
363
344
|
scope.names.add(name);
|
|
364
345
|
scope.bindings.set(name, null);
|
|
365
|
-
}
|
|
366
|
-
|
|
346
|
+
}
|
|
347
|
+
if (node.id.type === "Identifier" && node.init) {
|
|
348
|
+
scope.bindings.set(node.id.name, node.init);
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
case "ClassDeclaration": {
|
|
353
|
+
if (node.id) {
|
|
354
|
+
scope.names.add(node.id.name);
|
|
355
|
+
scope.bindings.set(node.id.name, null);
|
|
356
|
+
}
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
case "ImportDefaultSpecifier":
|
|
360
|
+
case "ImportNamespaceSpecifier":
|
|
361
|
+
case "ImportSpecifier": {
|
|
362
|
+
scope.names.add(node.local.name);
|
|
363
|
+
scope.bindings.set(node.local.name, null);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
case "FunctionDeclaration": {
|
|
367
|
+
if (node.id) {
|
|
368
|
+
scope.names.add(node.id.name);
|
|
369
|
+
scope.bindings.set(node.id.name, null);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// eslint-disable-next-line no-fallthrough
|
|
373
|
+
case "FunctionExpression":
|
|
374
|
+
case "ArrowFunctionExpression": {
|
|
375
|
+
const { params } = node;
|
|
376
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
377
|
+
const names = collectBindingNames(params[i]);
|
|
378
|
+
for (let j = 0; j < names.length; j += 1) {
|
|
379
|
+
const name = names[j];
|
|
380
|
+
scope.names.add(name);
|
|
381
|
+
scope.bindings.set(name, null);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
default: break;
|
|
367
387
|
}
|
|
368
388
|
};
|
|
369
389
|
const visit = (node, scope, enter, parent = null, ancestors = []) => {
|
|
@@ -374,7 +394,17 @@ const visit = (node, scope, enter, parent = null, ancestors = []) => {
|
|
|
374
394
|
}
|
|
375
395
|
declareBindings(node, currentScope);
|
|
376
396
|
enter(node, currentScope, parent, ancestors);
|
|
377
|
-
|
|
397
|
+
// Push onto a shared ancestors stack instead of allocating `[...ancestors,
|
|
398
|
+
// node]` per child step (O(n × depth) extra allocation on deep ASTs).
|
|
399
|
+
// Every consumer of `ancestors` in this file reads it synchronously inside
|
|
400
|
+
// the enter callback; future callers that need to retain the reference
|
|
401
|
+
// must .slice() it themselves.
|
|
402
|
+
ancestors.push(node);
|
|
403
|
+
const children = getChildren(node);
|
|
404
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
405
|
+
visit(children[i], currentScope, enter, node, ancestors);
|
|
406
|
+
}
|
|
407
|
+
ancestors.pop();
|
|
378
408
|
};
|
|
379
409
|
export const replaceImportMetaEnvWithOxc = (code, filename) => {
|
|
380
410
|
if (!importMetaEnvRe.test(code)) {
|
|
@@ -785,6 +815,7 @@ const isHocCall = (call, hocs, imports) => {
|
|
|
785
815
|
const matched = getImportForExpression(getInnermostCallee(call), imports);
|
|
786
816
|
return !!matched && hocs[matched[0]]?.includes(matched[1]);
|
|
787
817
|
};
|
|
818
|
+
const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === "CallExpression" && isHocCall(ancestor, hocs, imports));
|
|
788
819
|
const getComponentTypes = (options) => {
|
|
789
820
|
const componentTypes = { ...options?.componentTypes ?? { react: [defaultPlaceholder] } };
|
|
790
821
|
const reactTypes = componentTypes.react;
|
|
@@ -795,6 +826,12 @@ const getComponentTypes = (options) => {
|
|
|
795
826
|
}
|
|
796
827
|
return componentTypes;
|
|
797
828
|
};
|
|
829
|
+
const getHocs = (options) => {
|
|
830
|
+
const hocs = { ...options?.hocs ?? {} };
|
|
831
|
+
const reactHocs = new Set([...defaultReactHocs, ...hocs.react ?? []]);
|
|
832
|
+
hocs.react = [...reactHocs];
|
|
833
|
+
return hocs;
|
|
834
|
+
};
|
|
798
835
|
const getTypeImport = (node, imports) => {
|
|
799
836
|
if (node.type === "Identifier") {
|
|
800
837
|
const matched = getImportBinding(imports, node.name);
|
|
@@ -914,7 +951,7 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
|
|
|
914
951
|
const program = parseOxc(code, filename);
|
|
915
952
|
const imports = collectImportBindings(code, filename, program);
|
|
916
953
|
const componentTypes = getComponentTypes(options);
|
|
917
|
-
const hocs = options
|
|
954
|
+
const hocs = getHocs(options);
|
|
918
955
|
const hasHocs = Object.keys(hocs).length > 0;
|
|
919
956
|
const windowScopedNames = windowTokenRe.test(code) ? collectWindowScopedNames(program) : new Set();
|
|
920
957
|
const reExportedLocalNames = collectReExportedLocalNames(program);
|
|
@@ -1003,6 +1040,9 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
|
|
|
1003
1040
|
if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
|
|
1004
1041
|
return;
|
|
1005
1042
|
}
|
|
1043
|
+
if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1006
1046
|
if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
|
|
1007
1047
|
return;
|
|
1008
1048
|
}
|