@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-syntax,no-continue */
|
|
2
2
|
import { collectOxcExportsAndImports } from './collectOxcExportsAndImports';
|
|
3
3
|
import { EventEmitter } from './EventEmitter';
|
|
4
|
+
import { getOxcNodeChildren } from './oxc/ast';
|
|
4
5
|
import { parseOxcProgramCached } from './parseOxc';
|
|
5
6
|
const ssrCheckFields = new Set([
|
|
6
7
|
'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/;
|
|
@@ -103,28 +105,11 @@ const isNode = (value) => !!value &&
|
|
|
103
105
|
typeof value === 'object' &&
|
|
104
106
|
'type' in value &&
|
|
105
107
|
typeof value.type === 'string';
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const value = record[key];
|
|
114
|
-
if (isNode(value)) {
|
|
115
|
-
result.push(value);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (Array.isArray(value)) {
|
|
119
|
-
value.forEach((item) => {
|
|
120
|
-
if (isNode(item)) {
|
|
121
|
-
result.push(item);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return result;
|
|
127
|
-
};
|
|
108
|
+
// Reuses the per-node.type visitor-key cache in utils/oxc/ast.ts. This file's
|
|
109
|
+
// getChildren shape historically diverged from the canonical one (a smaller
|
|
110
|
+
// metadata-key skip set), but the produced children list is identical in
|
|
111
|
+
// practice because oxc-parser nodes don't carry the extra metadata fields.
|
|
112
|
+
const getChildren = getOxcNodeChildren;
|
|
128
113
|
const parseOxc = (code, filename) => {
|
|
129
114
|
return parseOxcProgramCached(filename, code, 'unambiguous');
|
|
130
115
|
};
|
|
@@ -347,66 +332,95 @@ const predeclareScopeNames = (node, scope) => {
|
|
|
347
332
|
});
|
|
348
333
|
}
|
|
349
334
|
const visitScopeDescendants = (child) => {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
335
|
+
switch (child.type) {
|
|
336
|
+
case 'VariableDeclarator': {
|
|
337
|
+
const names = collectBindingNames(child.id);
|
|
338
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
339
|
+
scope.names.add(names[i]);
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
case 'FunctionDeclaration':
|
|
344
|
+
case 'ClassDeclaration':
|
|
345
|
+
if (child.id) {
|
|
346
|
+
scope.names.add(child.id.name);
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
case 'ImportDefaultSpecifier':
|
|
350
|
+
case 'ImportNamespaceSpecifier':
|
|
351
|
+
case 'ImportSpecifier':
|
|
352
|
+
scope.names.add(child.local.name);
|
|
353
|
+
break;
|
|
354
|
+
default:
|
|
355
|
+
break;
|
|
365
356
|
}
|
|
366
357
|
if (createsScope(child)) {
|
|
367
358
|
return;
|
|
368
359
|
}
|
|
369
|
-
getChildren(child)
|
|
360
|
+
const children = getChildren(child);
|
|
361
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
362
|
+
visitScopeDescendants(children[i]);
|
|
363
|
+
}
|
|
370
364
|
};
|
|
371
|
-
getChildren(node)
|
|
365
|
+
const rootChildren = getChildren(node);
|
|
366
|
+
for (let i = 0; i < rootChildren.length; i += 1) {
|
|
367
|
+
visitScopeDescendants(rootChildren[i]);
|
|
368
|
+
}
|
|
372
369
|
};
|
|
373
370
|
const declareBindings = (node, scope) => {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
if (node.type === 'FunctionDeclaration' && node.id) {
|
|
386
|
-
scope.names.add(node.id.name);
|
|
387
|
-
scope.bindings.set(node.id.name, null);
|
|
388
|
-
}
|
|
389
|
-
if (node.type === 'ClassDeclaration' && node.id) {
|
|
390
|
-
scope.names.add(node.id.name);
|
|
391
|
-
scope.bindings.set(node.id.name, null);
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (node.type === 'ImportDefaultSpecifier' ||
|
|
395
|
-
node.type === 'ImportNamespaceSpecifier' ||
|
|
396
|
-
node.type === 'ImportSpecifier') {
|
|
397
|
-
scope.names.add(node.local.name);
|
|
398
|
-
scope.bindings.set(node.local.name, null);
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
if (node.type === 'FunctionDeclaration' ||
|
|
402
|
-
node.type === 'FunctionExpression' ||
|
|
403
|
-
node.type === 'ArrowFunctionExpression') {
|
|
404
|
-
node.params.forEach((param) => {
|
|
405
|
-
collectBindingNames(param).forEach((name) => {
|
|
371
|
+
// Called for every visited AST node, so the dispatch is hot. A switch lets
|
|
372
|
+
// V8 generate a jump table on node.type; the previous chained `if`s walked
|
|
373
|
+
// each branch's string-compare for every non-matching node.
|
|
374
|
+
switch (node.type) {
|
|
375
|
+
case 'VariableDeclarator': {
|
|
376
|
+
const names = collectBindingNames(node.id);
|
|
377
|
+
for (let i = 0; i < names.length; i += 1) {
|
|
378
|
+
const name = names[i];
|
|
406
379
|
scope.names.add(name);
|
|
407
380
|
scope.bindings.set(name, null);
|
|
408
|
-
}
|
|
409
|
-
|
|
381
|
+
}
|
|
382
|
+
if (node.id.type === 'Identifier' && node.init) {
|
|
383
|
+
scope.bindings.set(node.id.name, node.init);
|
|
384
|
+
}
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
case 'ClassDeclaration': {
|
|
388
|
+
if (node.id) {
|
|
389
|
+
scope.names.add(node.id.name);
|
|
390
|
+
scope.bindings.set(node.id.name, null);
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
case 'ImportDefaultSpecifier':
|
|
395
|
+
case 'ImportNamespaceSpecifier':
|
|
396
|
+
case 'ImportSpecifier': {
|
|
397
|
+
scope.names.add(node.local.name);
|
|
398
|
+
scope.bindings.set(node.local.name, null);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
case 'FunctionDeclaration': {
|
|
402
|
+
if (node.id) {
|
|
403
|
+
scope.names.add(node.id.name);
|
|
404
|
+
scope.bindings.set(node.id.name, null);
|
|
405
|
+
}
|
|
406
|
+
// Fall through to declare params.
|
|
407
|
+
}
|
|
408
|
+
// eslint-disable-next-line no-fallthrough
|
|
409
|
+
case 'FunctionExpression':
|
|
410
|
+
case 'ArrowFunctionExpression': {
|
|
411
|
+
const { params } = node;
|
|
412
|
+
for (let i = 0; i < params.length; i += 1) {
|
|
413
|
+
const names = collectBindingNames(params[i]);
|
|
414
|
+
for (let j = 0; j < names.length; j += 1) {
|
|
415
|
+
const name = names[j];
|
|
416
|
+
scope.names.add(name);
|
|
417
|
+
scope.bindings.set(name, null);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
default:
|
|
423
|
+
break;
|
|
410
424
|
}
|
|
411
425
|
};
|
|
412
426
|
const visit = (node, scope, enter, parent = null, ancestors = []) => {
|
|
@@ -417,7 +431,17 @@ const visit = (node, scope, enter, parent = null, ancestors = []) => {
|
|
|
417
431
|
}
|
|
418
432
|
declareBindings(node, currentScope);
|
|
419
433
|
enter(node, currentScope, parent, ancestors);
|
|
420
|
-
|
|
434
|
+
// Push onto a shared ancestors stack instead of allocating `[...ancestors,
|
|
435
|
+
// node]` per child step (O(n × depth) extra allocation on deep ASTs).
|
|
436
|
+
// Every consumer of `ancestors` in this file reads it synchronously inside
|
|
437
|
+
// the enter callback; future callers that need to retain the reference
|
|
438
|
+
// must .slice() it themselves.
|
|
439
|
+
ancestors.push(node);
|
|
440
|
+
const children = getChildren(node);
|
|
441
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
442
|
+
visit(children[i], currentScope, enter, node, ancestors);
|
|
443
|
+
}
|
|
444
|
+
ancestors.pop();
|
|
421
445
|
};
|
|
422
446
|
export const replaceImportMetaEnvWithOxc = (code, filename) => {
|
|
423
447
|
if (!importMetaEnvRe.test(code)) {
|
|
@@ -876,6 +900,7 @@ const isHocCall = (call, hocs, imports) => {
|
|
|
876
900
|
const matched = getImportForExpression(getInnermostCallee(call), imports);
|
|
877
901
|
return !!matched && hocs[matched[0]]?.includes(matched[1]);
|
|
878
902
|
};
|
|
903
|
+
const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports));
|
|
879
904
|
const getComponentTypes = (options) => {
|
|
880
905
|
const componentTypes = {
|
|
881
906
|
...(options?.componentTypes ?? { react: [defaultPlaceholder] }),
|
|
@@ -888,6 +913,14 @@ const getComponentTypes = (options) => {
|
|
|
888
913
|
}
|
|
889
914
|
return componentTypes;
|
|
890
915
|
};
|
|
916
|
+
const getHocs = (options) => {
|
|
917
|
+
const hocs = {
|
|
918
|
+
...(options?.hocs ?? {}),
|
|
919
|
+
};
|
|
920
|
+
const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);
|
|
921
|
+
hocs.react = [...reactHocs];
|
|
922
|
+
return hocs;
|
|
923
|
+
};
|
|
891
924
|
const getTypeImport = (node, imports) => {
|
|
892
925
|
if (node.type === 'Identifier') {
|
|
893
926
|
const matched = getImportBinding(imports, node.name);
|
|
@@ -1019,7 +1052,7 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
|
|
|
1019
1052
|
const program = parseOxc(code, filename);
|
|
1020
1053
|
const imports = collectImportBindings(code, filename, program);
|
|
1021
1054
|
const componentTypes = getComponentTypes(options);
|
|
1022
|
-
const hocs = options
|
|
1055
|
+
const hocs = getHocs(options);
|
|
1023
1056
|
const hasHocs = Object.keys(hocs).length > 0;
|
|
1024
1057
|
const windowScopedNames = windowTokenRe.test(code)
|
|
1025
1058
|
? collectWindowScopedNames(program)
|
|
@@ -1122,6 +1155,9 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
|
|
|
1122
1155
|
if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
|
|
1123
1156
|
return;
|
|
1124
1157
|
}
|
|
1158
|
+
if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1125
1161
|
if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
|
|
1126
1162
|
return;
|
|
1127
1163
|
}
|
package/types/utils/parseOxc.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { parseSync } from 'oxc-parser';
|
|
2
|
-
|
|
2
|
+
// 200 evicts under sustained pressure on large monorepos — the
|
|
3
|
+
// removeUnusedAfterReplacement cleanup loop reparses on every iteration
|
|
4
|
+
// (new content -> new key) and applyOxcProcessors reparses after extraction.
|
|
5
|
+
// 1000 is still bounded (~50-100 MB worst case for an enormous build) and
|
|
6
|
+
// keeps every entry hot across the actions for a single file.
|
|
7
|
+
const MAX_PARSE_CACHE_ENTRIES = 1000;
|
|
3
8
|
const parseCache = new Map();
|
|
4
9
|
const getAstType = (filename) => filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js';
|
|
5
10
|
const makeCacheKey = (filename, code, sourceType) => `${sourceType}\0${filename}\0${code}`;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BaseProcessor, Expression as ProcessorExpression, ProcessorStaticContext, ProcessorStaticValue } from '@wyw-in-js/processor-utils';
|
|
2
|
+
export declare const unknownProcessorStaticValue: unique symbol;
|
|
3
|
+
export type UnknownProcessorStaticValue = typeof unknownProcessorStaticValue;
|
|
4
|
+
export declare const createProcessorStaticContext: (processor: BaseProcessor) => ProcessorStaticContext;
|
|
5
|
+
export declare const isProcessorStaticValue: (value: unknown) => value is ProcessorStaticValue;
|
|
6
|
+
export declare const getProcessorStaticValue: (processor: BaseProcessor) => ProcessorStaticValue | null;
|
|
7
|
+
export declare const processorStaticValueToRuntimeValue: (value: ProcessorStaticValue) => unknown | UnknownProcessorStaticValue;
|
|
8
|
+
export declare const resolveProcessorStaticRuntimeValue: (processor: BaseProcessor) => unknown | UnknownProcessorStaticValue;
|
|
9
|
+
export declare const resolveProcessorStaticClassName: (processor: BaseProcessor) => string | null;
|
|
10
|
+
export declare const processorLiteralValue: (expression: ProcessorExpression) => unknown | UnknownProcessorStaticValue;
|
|
11
|
+
export declare const processorPropertyKeyName: (key: ProcessorExpression) => string | null;
|
|
12
|
+
export declare const processorObjectPropertyValue: (expression: ProcessorExpression, name: string) => ProcessorExpression | null;
|
|
13
|
+
export declare const processorExpressionToStaticValue: (expression: ProcessorExpression, resolveHelperCall: (name: string) => unknown | UnknownProcessorStaticValue) => unknown | UnknownProcessorStaticValue;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
export const unknownProcessorStaticValue = Symbol('unknownProcessorStaticValue');
|
|
2
|
+
export const createProcessorStaticContext = (processor) => {
|
|
3
|
+
const processorWithInternals = processor;
|
|
4
|
+
return {
|
|
5
|
+
addDependency: () => { },
|
|
6
|
+
debug: () => { },
|
|
7
|
+
fileContext: processorWithInternals.context ??
|
|
8
|
+
{},
|
|
9
|
+
metadata: {
|
|
10
|
+
className: processor.className,
|
|
11
|
+
displayName: processor.displayName,
|
|
12
|
+
isReferenced: processor.isReferenced,
|
|
13
|
+
location: processor.location,
|
|
14
|
+
slug: processor.slug,
|
|
15
|
+
tagSource: processor.tagSource,
|
|
16
|
+
},
|
|
17
|
+
options: processorWithInternals.options ??
|
|
18
|
+
{},
|
|
19
|
+
unresolved: (reason, details) => ({
|
|
20
|
+
...(details ? { details } : {}),
|
|
21
|
+
kind: 'unresolved',
|
|
22
|
+
reason,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export const isProcessorStaticValue = (value) => {
|
|
27
|
+
if (typeof value !== 'object' || value === null || !('kind' in value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const candidate = value;
|
|
31
|
+
switch (candidate.kind) {
|
|
32
|
+
case 'class-name':
|
|
33
|
+
return typeof candidate.className === 'string';
|
|
34
|
+
case 'opaque-component':
|
|
35
|
+
return (candidate.className === undefined ||
|
|
36
|
+
typeof candidate.className === 'string');
|
|
37
|
+
case 'runtime-callback':
|
|
38
|
+
case 'serializable':
|
|
39
|
+
return true;
|
|
40
|
+
case 'selector-chain':
|
|
41
|
+
return (typeof candidate.className === 'string' &&
|
|
42
|
+
Array.isArray(candidate.selectors) &&
|
|
43
|
+
candidate.selectors.every((selector) => typeof selector === 'string'));
|
|
44
|
+
case 'unresolved':
|
|
45
|
+
return typeof candidate.reason === 'string';
|
|
46
|
+
default:
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export const getProcessorStaticValue = (processor) => {
|
|
51
|
+
if (!processor.getStaticValue) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const value = processor.getStaticValue(createProcessorStaticContext(processor));
|
|
56
|
+
return isProcessorStaticValue(value) ? value : null;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const processorStaticValueToRuntimeValue = (value) => {
|
|
63
|
+
switch (value.kind) {
|
|
64
|
+
case 'class-name':
|
|
65
|
+
return value.value === undefined ? value.className : value.value;
|
|
66
|
+
case 'opaque-component':
|
|
67
|
+
case 'runtime-callback':
|
|
68
|
+
return value.value === undefined
|
|
69
|
+
? unknownProcessorStaticValue
|
|
70
|
+
: value.value;
|
|
71
|
+
case 'selector-chain':
|
|
72
|
+
case 'serializable':
|
|
73
|
+
return value.value;
|
|
74
|
+
case 'unresolved':
|
|
75
|
+
return unknownProcessorStaticValue;
|
|
76
|
+
default:
|
|
77
|
+
return unknownProcessorStaticValue;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export const resolveProcessorStaticRuntimeValue = (processor) => {
|
|
81
|
+
const staticValue = getProcessorStaticValue(processor);
|
|
82
|
+
return staticValue
|
|
83
|
+
? processorStaticValueToRuntimeValue(staticValue)
|
|
84
|
+
: unknownProcessorStaticValue;
|
|
85
|
+
};
|
|
86
|
+
export const resolveProcessorStaticClassName = (processor) => {
|
|
87
|
+
const staticValue = getProcessorStaticValue(processor);
|
|
88
|
+
if (staticValue?.kind !== 'class-name') {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const runtimeValue = processorStaticValueToRuntimeValue(staticValue);
|
|
92
|
+
return typeof runtimeValue === 'string'
|
|
93
|
+
? runtimeValue
|
|
94
|
+
: staticValue.className;
|
|
95
|
+
};
|
|
96
|
+
export const processorLiteralValue = (expression) => {
|
|
97
|
+
const expressionWithValue = expression;
|
|
98
|
+
if (expression.type === 'StringLiteral' ||
|
|
99
|
+
expression.type === 'NumericLiteral' ||
|
|
100
|
+
expression.type === 'BooleanLiteral' ||
|
|
101
|
+
expression.type === 'Literal') {
|
|
102
|
+
return expressionWithValue.value;
|
|
103
|
+
}
|
|
104
|
+
if (expression.type === 'NullLiteral') {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return unknownProcessorStaticValue;
|
|
108
|
+
};
|
|
109
|
+
export const processorPropertyKeyName = (key) => {
|
|
110
|
+
if (key.type === 'Identifier') {
|
|
111
|
+
return key.name;
|
|
112
|
+
}
|
|
113
|
+
const value = processorLiteralValue(key);
|
|
114
|
+
return typeof value === 'string' ? value : null;
|
|
115
|
+
};
|
|
116
|
+
export const processorObjectPropertyValue = (expression, name) => {
|
|
117
|
+
if (expression.type !== 'ObjectExpression') {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
const { properties } = expression;
|
|
121
|
+
if (!properties) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
for (const property of properties) {
|
|
125
|
+
if ((property.type === 'ObjectProperty' || property.type === 'Property') &&
|
|
126
|
+
property.key &&
|
|
127
|
+
processorPropertyKeyName(property.key) === name) {
|
|
128
|
+
return property.value ?? null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
};
|
|
133
|
+
export const processorExpressionToStaticValue = (expression, resolveHelperCall) => {
|
|
134
|
+
const literal = processorLiteralValue(expression);
|
|
135
|
+
if (literal !== unknownProcessorStaticValue) {
|
|
136
|
+
return literal;
|
|
137
|
+
}
|
|
138
|
+
if (expression.type === 'ArrayExpression') {
|
|
139
|
+
const { elements } = expression;
|
|
140
|
+
if (!elements) {
|
|
141
|
+
return unknownProcessorStaticValue;
|
|
142
|
+
}
|
|
143
|
+
const result = [];
|
|
144
|
+
for (const element of elements) {
|
|
145
|
+
if (element === null) {
|
|
146
|
+
result.push(null);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const value = processorExpressionToStaticValue(element, resolveHelperCall);
|
|
150
|
+
if (value === unknownProcessorStaticValue) {
|
|
151
|
+
return unknownProcessorStaticValue;
|
|
152
|
+
}
|
|
153
|
+
result.push(value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
if (expression.type === 'ObjectExpression') {
|
|
159
|
+
const metaExpression = processorObjectPropertyValue(expression, '__wyw_meta');
|
|
160
|
+
if (!metaExpression || metaExpression.type !== 'ObjectExpression') {
|
|
161
|
+
return unknownProcessorStaticValue;
|
|
162
|
+
}
|
|
163
|
+
const classNameExpression = processorObjectPropertyValue(metaExpression, 'className');
|
|
164
|
+
const className = classNameExpression
|
|
165
|
+
? processorLiteralValue(classNameExpression)
|
|
166
|
+
: unknownProcessorStaticValue;
|
|
167
|
+
if (typeof className !== 'string') {
|
|
168
|
+
return unknownProcessorStaticValue;
|
|
169
|
+
}
|
|
170
|
+
const extendsExpression = processorObjectPropertyValue(metaExpression, 'extends');
|
|
171
|
+
const extended = extendsExpression
|
|
172
|
+
? processorExpressionToStaticValue(extendsExpression, resolveHelperCall)
|
|
173
|
+
: null;
|
|
174
|
+
if (extended === unknownProcessorStaticValue) {
|
|
175
|
+
return unknownProcessorStaticValue;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
__wyw_meta: {
|
|
179
|
+
className,
|
|
180
|
+
extends: extended,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (expression.type === 'CallExpression') {
|
|
185
|
+
const call = expression;
|
|
186
|
+
if (call.arguments?.length === 0 && call.callee?.type === 'Identifier') {
|
|
187
|
+
return resolveHelperCall(call.callee.name);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return unknownProcessorStaticValue;
|
|
191
|
+
};
|
|
@@ -54,7 +54,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
|
|
|
54
54
|
}
|
|
55
55
|
catch {
|
|
56
56
|
throw new Error([
|
|
57
|
-
'[wyw-in-js] Failed to parse
|
|
57
|
+
'[wyw-in-js] Failed to parse custom module resolver output.',
|
|
58
58
|
`stdout: ${stdout}`,
|
|
59
59
|
result.stderr ? `stderr: ${result.stderr.trim()}` : '',
|
|
60
60
|
]
|
|
@@ -69,7 +69,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
|
|
|
69
69
|
}
|
|
70
70
|
if (result.status !== 0 || !parsed?.resolved) {
|
|
71
71
|
throw new Error([
|
|
72
|
-
'[wyw-in-js]
|
|
72
|
+
'[wyw-in-js] Custom module resolver fallback failed.',
|
|
73
73
|
`status: ${result.status ?? 'null'}`,
|
|
74
74
|
result.stderr ? `stderr: ${result.stderr.trim()}` : '',
|
|
75
75
|
]
|
|
@@ -87,7 +87,7 @@ export const resolveFilenameWithConditions = (moduleImpl, id, parent, conditions
|
|
|
87
87
|
// Bun crashes on macOS/Silicon in this exact path:
|
|
88
88
|
// Module._resolveFilename(specifier, parent, false, { conditions })
|
|
89
89
|
// We reproduced it both with a tiny standalone script and through the
|
|
90
|
-
// `EvalBroker > passes conditionNames to
|
|
90
|
+
// `EvalBroker > passes conditionNames to native fallback resolution` test,
|
|
91
91
|
// including on Bun 1.3.13. Keep this fallback narrow: only conditioned
|
|
92
92
|
// resolution under Bun goes through a short-lived Node subprocess.
|
|
93
93
|
//
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export const defaultBundlerOwnedSpecifierPrefixes = [
|
|
2
|
-
"\0",
|
|
3
|
-
"/@",
|
|
4
|
-
"virtual:"
|
|
5
|
-
];
|
|
6
|
-
export const getResolverPrecedence = (mode) => {
|
|
7
|
-
if (mode === "hybrid") {
|
|
8
|
-
return [
|
|
9
|
-
"customResolver",
|
|
10
|
-
"safeOxcResolver",
|
|
11
|
-
"bundlerResolver",
|
|
12
|
-
"nodeFallback"
|
|
13
|
-
];
|
|
14
|
-
}
|
|
15
|
-
if (mode === "bundler") {
|
|
16
|
-
return [
|
|
17
|
-
"customResolver",
|
|
18
|
-
"bundlerResolver",
|
|
19
|
-
"nodeFallback"
|
|
20
|
-
];
|
|
21
|
-
}
|
|
22
|
-
if (mode === "custom") {
|
|
23
|
-
return ["customResolver"];
|
|
24
|
-
}
|
|
25
|
-
return ["nodeFallback"];
|
|
26
|
-
};
|
|
27
|
-
export const classifyHybridResolverSpecifier = (specifier, { bundlerOwnedPrefixes = defaultBundlerOwnedSpecifierPrefixes } = {}) => {
|
|
28
|
-
if (bundlerOwnedPrefixes.some((prefix) => specifier.startsWith(prefix))) {
|
|
29
|
-
return {
|
|
30
|
-
reason: "bundler-owned-prefix",
|
|
31
|
-
route: "bundler"
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (!specifier.startsWith("./") && !specifier.startsWith("../")) {
|
|
35
|
-
return {
|
|
36
|
-
reason: "ambiguous-specifier",
|
|
37
|
-
route: "bundler"
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (/[?#]/.test(specifier)) {
|
|
41
|
-
return {
|
|
42
|
-
reason: "query-or-hash",
|
|
43
|
-
route: "bundler"
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
reason: "safe-relative-specifier",
|
|
48
|
-
route: "oxc"
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
//# sourceMappingURL=resolverStrategy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAmBA,OAAO,MAAM,uCAAuC;CAClD;CACA;CACA;CACD;AAED,OAAO,MAAM,yBACX,SACsB;AACtB,KAAI,SAAS,UAAU;AACrB,SAAO;GACL;GACA;GACA;GACA;GACD;;AAGH,KAAI,SAAS,WAAW;AACtB,SAAO;GAAC;GAAkB;GAAmB;GAAe;;AAG9D,KAAI,SAAS,UAAU;AACrB,SAAO,CAAC,iBAAiB;;AAG3B,QAAO,CAAC,eAAe;;AAGzB,OAAO,MAAM,mCACX,WACA,EACE,uBAAuB,yCACY,EAAE,KACZ;AAC3B,KAAI,qBAAqB,MAAM,WAAW,UAAU,WAAW,OAAO,CAAC,EAAE;AACvE,SAAO;GACL,QAAQ;GACR,OAAO;GACR;;AAGH,KAAI,CAAC,UAAU,WAAW,KAAK,IAAI,CAAC,UAAU,WAAW,MAAM,EAAE;AAC/D,SAAO;GACL,QAAQ;GACR,OAAO;GACR;;AAGH,KAAI,OAAO,KAAK,UAAU,EAAE;AAC1B,SAAO;GACL,QAAQ;GACR,OAAO;GACR;;AAGH,QAAO;EACL,QAAQ;EACR,OAAO;EACR","names":[],"sources":["../../src/eval/resolverStrategy.ts"],"version":3,"sourcesContent":["import type { EvalResolverMode } from '@wyw-in-js/shared';\n\nexport type HybridResolverRoute = 'bundler' | 'oxc';\n\nexport type HybridResolverReason =\n | 'ambiguous-specifier'\n | 'bundler-owned-prefix'\n | 'query-or-hash'\n | 'safe-relative-specifier';\n\nexport type HybridResolverDecision = {\n reason: HybridResolverReason;\n route: HybridResolverRoute;\n};\n\nexport type HybridResolverClassifierOptions = {\n bundlerOwnedPrefixes?: readonly string[];\n};\n\nexport const defaultBundlerOwnedSpecifierPrefixes = [\n '\\0',\n '/@',\n 'virtual:',\n] as const;\n\nexport const getResolverPrecedence = (\n mode: EvalResolverMode\n): readonly string[] => {\n if (mode === 'hybrid') {\n return [\n 'customResolver',\n 'safeOxcResolver',\n 'bundlerResolver',\n 'nodeFallback',\n ];\n }\n\n if (mode === 'bundler') {\n return ['customResolver', 'bundlerResolver', 'nodeFallback'];\n }\n\n if (mode === 'custom') {\n return ['customResolver'];\n }\n\n return ['nodeFallback'];\n};\n\nexport const classifyHybridResolverSpecifier = (\n specifier: string,\n {\n bundlerOwnedPrefixes = defaultBundlerOwnedSpecifierPrefixes,\n }: HybridResolverClassifierOptions = {}\n): HybridResolverDecision => {\n if (bundlerOwnedPrefixes.some((prefix) => specifier.startsWith(prefix))) {\n return {\n reason: 'bundler-owned-prefix',\n route: 'bundler',\n };\n }\n\n if (!specifier.startsWith('./') && !specifier.startsWith('../')) {\n return {\n reason: 'ambiguous-specifier',\n route: 'bundler',\n };\n }\n\n if (/[?#]/.test(specifier)) {\n return {\n reason: 'query-or-hash',\n route: 'bundler',\n };\n }\n\n return {\n reason: 'safe-relative-specifier',\n route: 'oxc',\n };\n};\n"],"file":"resolverStrategy.js"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { EvalResolverMode } from '@wyw-in-js/shared';
|
|
2
|
-
export type HybridResolverRoute = 'bundler' | 'oxc';
|
|
3
|
-
export type HybridResolverReason = 'ambiguous-specifier' | 'bundler-owned-prefix' | 'query-or-hash' | 'safe-relative-specifier';
|
|
4
|
-
export type HybridResolverDecision = {
|
|
5
|
-
reason: HybridResolverReason;
|
|
6
|
-
route: HybridResolverRoute;
|
|
7
|
-
};
|
|
8
|
-
export type HybridResolverClassifierOptions = {
|
|
9
|
-
bundlerOwnedPrefixes?: readonly string[];
|
|
10
|
-
};
|
|
11
|
-
export declare const defaultBundlerOwnedSpecifierPrefixes: readonly ["\0", "/@", "virtual:"];
|
|
12
|
-
export declare const getResolverPrecedence: (mode: EvalResolverMode) => readonly string[];
|
|
13
|
-
export declare const classifyHybridResolverSpecifier: (specifier: string, { bundlerOwnedPrefixes, }?: HybridResolverClassifierOptions) => HybridResolverDecision;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export const defaultBundlerOwnedSpecifierPrefixes = [
|
|
2
|
-
'\0',
|
|
3
|
-
'/@',
|
|
4
|
-
'virtual:',
|
|
5
|
-
];
|
|
6
|
-
export const getResolverPrecedence = (mode) => {
|
|
7
|
-
if (mode === 'hybrid') {
|
|
8
|
-
return [
|
|
9
|
-
'customResolver',
|
|
10
|
-
'safeOxcResolver',
|
|
11
|
-
'bundlerResolver',
|
|
12
|
-
'nodeFallback',
|
|
13
|
-
];
|
|
14
|
-
}
|
|
15
|
-
if (mode === 'bundler') {
|
|
16
|
-
return ['customResolver', 'bundlerResolver', 'nodeFallback'];
|
|
17
|
-
}
|
|
18
|
-
if (mode === 'custom') {
|
|
19
|
-
return ['customResolver'];
|
|
20
|
-
}
|
|
21
|
-
return ['nodeFallback'];
|
|
22
|
-
};
|
|
23
|
-
export const classifyHybridResolverSpecifier = (specifier, { bundlerOwnedPrefixes = defaultBundlerOwnedSpecifierPrefixes, } = {}) => {
|
|
24
|
-
if (bundlerOwnedPrefixes.some((prefix) => specifier.startsWith(prefix))) {
|
|
25
|
-
return {
|
|
26
|
-
reason: 'bundler-owned-prefix',
|
|
27
|
-
route: 'bundler',
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (!specifier.startsWith('./') && !specifier.startsWith('../')) {
|
|
31
|
-
return {
|
|
32
|
-
reason: 'ambiguous-specifier',
|
|
33
|
-
route: 'bundler',
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (/[?#]/.test(specifier)) {
|
|
37
|
-
return {
|
|
38
|
-
reason: 'query-or-hash',
|
|
39
|
-
route: 'bundler',
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
reason: 'safe-relative-specifier',
|
|
44
|
-
route: 'oxc',
|
|
45
|
-
};
|
|
46
|
-
};
|