@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/cache.js +7 -0
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +35 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +230 -89
- package/esm/eval/broker.js.map +1 -1
- package/esm/eval/protocol.js.map +1 -1
- package/esm/eval/runner.js +143 -24
- package/esm/eval/runner.js.map +1 -1
- package/esm/module.js +70 -43
- package/esm/module.js.map +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +35 -20
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +48 -2
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
- package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
- package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
- package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
- package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
- package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
- package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
- package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
- package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
- package/esm/transform/generators/transform.js +57 -45
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +33 -4
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform.js +3 -1
- package/esm/transform.js.map +1 -1
- package/esm/utils/EventEmitter.js +42 -9
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
- package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
- package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
- package/esm/utils/applyOxcProcessors/displayName.js +93 -0
- package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/shared.js +29 -0
- package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
- package/esm/utils/applyOxcProcessors/types.js +2 -0
- package/esm/utils/applyOxcProcessors/types.js.map +1 -0
- package/esm/utils/applyOxcProcessors.js +1 -1216
- package/esm/utils/applyOxcProcessors.js.map +1 -1
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
- package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
- package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
- package/esm/utils/collectOxcRuntime/types.js +2 -0
- package/esm/utils/collectOxcRuntime/types.js.map +1 -0
- package/esm/utils/collectOxcRuntime.js +5 -193
- package/esm/utils/collectOxcRuntime.js.map +1 -1
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
- package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
- package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
- package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
- package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
- package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
- package/esm/utils/nativeResolver.js +93 -0
- package/esm/utils/nativeResolver.js.map +1 -0
- package/esm/utils/oxc/ast.js +28 -0
- package/esm/utils/oxc/ast.js.map +1 -0
- package/esm/utils/oxc/parse.js +3 -0
- package/esm/utils/oxc/parse.js.map +1 -0
- package/esm/utils/oxc/replacements.js +14 -0
- package/esm/utils/oxc/replacements.js.map +1 -0
- package/esm/utils/oxc/sourceLocations.js +59 -0
- package/esm/utils/oxc/sourceLocations.js.map +1 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
- package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
- package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
- package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
- package/esm/utils/oxcPreevalStage/processors.js +17 -0
- package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
- package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
- package/esm/utils/oxcPreevalStage/types.js +2 -0
- package/esm/utils/oxcPreevalStage/types.js.map +1 -0
- package/esm/utils/oxcPreevalStage.js +17 -73
- package/esm/utils/oxcPreevalStage.js.map +1 -1
- package/esm/utils/oxcPreevalTransforms.js +12 -1
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +3 -3
- package/esm/utils/resolveWithConditions.js.map +1 -1
- package/package.json +4 -3
- package/types/cache.js +8 -0
- package/types/debug/fileReporter.js +46 -1
- package/types/eval/broker.d.ts +6 -2
- package/types/eval/broker.js +244 -95
- package/types/eval/protocol.d.ts +15 -1
- package/types/module.d.ts +4 -1
- package/types/module.js +97 -48
- package/types/transform/Entrypoint.types.d.ts +3 -0
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +49 -2
- package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
- package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
- package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
- package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
- package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
- package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
- package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
- package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
- package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
- package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
- package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
- package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
- package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
- package/types/transform/generators/transform.js +63 -49
- package/types/transform/helpers/loadWywOptions.js +23 -3
- package/types/transform.js +3 -1
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +44 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
- package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
- package/types/utils/applyOxcProcessors/displayName.js +113 -0
- package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
- package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
- package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
- package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
- package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
- package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
- package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
- package/types/utils/applyOxcProcessors/shared.js +37 -0
- package/types/utils/applyOxcProcessors/types.d.ts +88 -0
- package/types/utils/applyOxcProcessors/types.js +1 -0
- package/types/utils/applyOxcProcessors.d.ts +1 -16
- package/types/utils/applyOxcProcessors.js +1 -1391
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
- package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
- package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
- package/types/utils/collectOxcRuntime/types.d.ts +16 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +2 -12
- package/types/utils/collectOxcRuntime.js +5 -224
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
- package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
- package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
- package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
- package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
- package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
- package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
- package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
- package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
- package/types/utils/collectOxcTemplateDependencies.js +3 -1580
- package/types/utils/nativeResolver.d.ts +13 -0
- package/types/utils/nativeResolver.js +91 -0
- package/types/utils/oxc/ast.d.ts +4 -0
- package/types/utils/oxc/ast.js +37 -0
- package/types/utils/oxc/parse.d.ts +3 -0
- package/types/utils/oxc/parse.js +2 -0
- package/types/utils/oxc/replacements.d.ts +12 -0
- package/types/utils/oxc/replacements.js +18 -0
- package/types/utils/oxc/sourceLocations.d.ts +5 -0
- package/types/utils/oxc/sourceLocations.js +63 -0
- package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
- package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
- package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
- package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
- package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
- package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
- package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
- package/types/utils/oxcPreevalStage/processors.js +16 -0
- package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
- package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
- package/types/utils/oxcPreevalStage/types.d.ts +22 -0
- package/types/utils/oxcPreevalStage/types.js +1 -0
- package/types/utils/oxcPreevalStage.d.ts +2 -18
- package/types/utils/oxcPreevalStage.js +17 -79
- package/types/utils/oxcPreevalTransforms.js +14 -1
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.js +3 -3
- package/esm/eval/resolverStrategy.js +0 -51
- package/esm/eval/resolverStrategy.js.map +0 -1
- package/types/eval/resolverStrategy.d.ts +0 -13
- package/types/eval/resolverStrategy.js +0 -46
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { evaluateOxcStaticExpression, isOxcStaticSerializableValue, lookupStaticBinding, } from '../../../utils/collectOxcTemplateDependencies';
|
|
3
|
+
import { resolveDependency } from './dependencies';
|
|
4
|
+
import { debugStaticResolve, getStaticBindings } from './environment';
|
|
5
|
+
import { resolveImportValue } from './exportResolver';
|
|
6
|
+
import { resolveImportAsOpaqueRuntime } from './opaqueRuntime';
|
|
7
|
+
import { bindStaticResolvedValue, isRuntimeCallbackExpression, parseStaticExpressionSource, } from './staticExpression';
|
|
8
|
+
export function* resolveCandidateValue(action, candidate, filename, memo) {
|
|
9
|
+
const env = new Map();
|
|
10
|
+
const dependencies = new Set();
|
|
11
|
+
const sideEffectDependencies = new Set();
|
|
12
|
+
const sideEffectImportLocals = new Set();
|
|
13
|
+
let candidateExpression;
|
|
14
|
+
if (candidate.inlineConstants) {
|
|
15
|
+
for (const [name, value] of Object.entries(candidate.inlineConstants)) {
|
|
16
|
+
env.set(name, value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const staticBindingsForCandidate = getStaticBindings(action);
|
|
20
|
+
for (const item of candidate.imports) {
|
|
21
|
+
// staticBindings overrides take precedence over actual import
|
|
22
|
+
// resolution: a registered value (or function) replaces whatever
|
|
23
|
+
// the source module would otherwise provide. Useful for prototyping
|
|
24
|
+
// / SSR theming and for opaque utilities like `cx`.
|
|
25
|
+
//
|
|
26
|
+
// Match the override map first by the raw specifier as written
|
|
27
|
+
// (`@linaria/core`, `./flags`, …). If that misses, resolve to an
|
|
28
|
+
// absolute path and try again — this lets the host key by
|
|
29
|
+
// absolute file path so a single entry covers every relative
|
|
30
|
+
// variant of the same module.
|
|
31
|
+
let override = lookupStaticBinding(staticBindingsForCandidate, item.source, item.imported);
|
|
32
|
+
if (!override.found && staticBindingsForCandidate) {
|
|
33
|
+
const dep = yield* resolveDependency(action, filename, item.source, item.imported);
|
|
34
|
+
if (dep?.resolved) {
|
|
35
|
+
override = lookupStaticBinding(staticBindingsForCandidate, dep.resolved, item.imported);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (override.found) {
|
|
39
|
+
env.set(item.local, override.value);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const resolved = yield* resolveImportValue(action, filename, item, new Set(), memo);
|
|
43
|
+
if (!resolved) {
|
|
44
|
+
debugStaticResolve(action, {
|
|
45
|
+
candidate: candidate.name,
|
|
46
|
+
filename,
|
|
47
|
+
imported: item.imported,
|
|
48
|
+
phase: 'candidate',
|
|
49
|
+
reason: 'candidate-import-unresolved',
|
|
50
|
+
source: item.source,
|
|
51
|
+
status: 'rejected',
|
|
52
|
+
});
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (resolved.callable === 'zero-arg' && candidateExpression === undefined) {
|
|
56
|
+
candidateExpression = parseStaticExpressionSource(candidate.source, filename);
|
|
57
|
+
}
|
|
58
|
+
const expressionForBinding = resolved.callable === 'zero-arg' ? candidateExpression : null;
|
|
59
|
+
if ((resolved.callable === 'zero-arg' && !expressionForBinding) ||
|
|
60
|
+
(expressionForBinding &&
|
|
61
|
+
!bindStaticResolvedValue(env, expressionForBinding, item.local, resolved))) {
|
|
62
|
+
debugStaticResolve(action, {
|
|
63
|
+
candidate: candidate.name,
|
|
64
|
+
filename,
|
|
65
|
+
imported: item.imported,
|
|
66
|
+
phase: 'candidate',
|
|
67
|
+
reason: 'candidate-callable-usage-unsupported',
|
|
68
|
+
source: item.source,
|
|
69
|
+
status: 'rejected',
|
|
70
|
+
});
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
if (!expressionForBinding) {
|
|
74
|
+
env.set(item.local, resolved.value);
|
|
75
|
+
}
|
|
76
|
+
resolved.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
77
|
+
resolved.sideEffectDependencies?.forEach((dependency) => {
|
|
78
|
+
sideEffectDependencies.add(dependency);
|
|
79
|
+
sideEffectImportLocals.add(item.importLocal ?? item.local);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (candidateExpression === undefined) {
|
|
83
|
+
candidateExpression = parseStaticExpressionSource(candidate.source, filename);
|
|
84
|
+
}
|
|
85
|
+
const value = evaluateOxcStaticExpression(candidate.source, filename, env, getStaticBindings(action));
|
|
86
|
+
// Function-valued candidates are runtime callbacks (e.g. styled-
|
|
87
|
+
// component dynamic prop interpolations like `${props => ...}`). The
|
|
88
|
+
// value isn't serializable, but the candidate IS resolved — the
|
|
89
|
+
// local `_exp = () => target` arrow already lives in the bundle, so
|
|
90
|
+
// the file does not need evalFile to compute it. Mark the result as
|
|
91
|
+
// runtimeOnly so the helper declaration survives pruning.
|
|
92
|
+
if (typeof value === 'function' ||
|
|
93
|
+
(value === undefined && isRuntimeCallbackExpression(candidateExpression))) {
|
|
94
|
+
debugStaticResolve(action, {
|
|
95
|
+
candidate: candidate.name,
|
|
96
|
+
filename,
|
|
97
|
+
phase: 'candidate',
|
|
98
|
+
reason: 'runtime-callback',
|
|
99
|
+
status: 'resolved',
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
dependencies: [...dependencies],
|
|
103
|
+
runtimeOnly: true,
|
|
104
|
+
sideEffectDependencies: [...sideEffectDependencies],
|
|
105
|
+
sideEffectImportLocals: [...sideEffectImportLocals],
|
|
106
|
+
value,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (!isOxcStaticSerializableValue(value)) {
|
|
110
|
+
debugStaticResolve(action, {
|
|
111
|
+
candidate: candidate.name,
|
|
112
|
+
filename,
|
|
113
|
+
phase: 'candidate',
|
|
114
|
+
reason: 'candidate-expression-non-serializable',
|
|
115
|
+
status: 'rejected',
|
|
116
|
+
});
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
debugStaticResolve(action, {
|
|
120
|
+
candidate: candidate.name,
|
|
121
|
+
filename,
|
|
122
|
+
phase: 'candidate',
|
|
123
|
+
status: 'resolved',
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
dependencies: [...dependencies],
|
|
127
|
+
sideEffectDependencies: [...sideEffectDependencies],
|
|
128
|
+
sideEffectImportLocals: [...sideEffectImportLocals],
|
|
129
|
+
value,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export function* resolveOpaqueRuntimeCandidateValue(action, candidate, filename) {
|
|
133
|
+
if (candidate.imports.length === 0) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const dependencies = new Set();
|
|
137
|
+
const memo = new Map();
|
|
138
|
+
for (const item of candidate.imports) {
|
|
139
|
+
const proof = yield* resolveImportAsOpaqueRuntime(action, filename, item, new Set(), memo);
|
|
140
|
+
if (!proof) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
proof.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
dependencies: [...dependencies],
|
|
147
|
+
value: null,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IEntrypointDependency } from '../../Entrypoint.types';
|
|
2
|
+
import type { ITransformAction, SyncScenarioFor } from '../../types';
|
|
3
|
+
export declare const isRelativeSource: (source: string) => boolean;
|
|
4
|
+
export declare const dependencyResolutionCaches: WeakMap<object, Map<string, IEntrypointDependency>>;
|
|
5
|
+
export declare const dependencyResolutionCacheKey: (importer: string, source: string, imported: string) => string;
|
|
6
|
+
export declare function resolveDependency(action: ITransformAction, importer: string, source: string, imported: string): SyncScenarioFor<IEntrypointDependency | null>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { Entrypoint } from '../../Entrypoint';
|
|
3
|
+
import { getWeakCacheMap } from './cache';
|
|
4
|
+
export const isRelativeSource = (source) => source.startsWith('./') ||
|
|
5
|
+
source.startsWith('../') ||
|
|
6
|
+
source === '.' ||
|
|
7
|
+
source === '..';
|
|
8
|
+
export const dependencyResolutionCaches = new WeakMap();
|
|
9
|
+
// Bare package and alias resolution can depend on the importer through nested
|
|
10
|
+
// packages, package boundaries, tsconfig paths, or bundler aliases.
|
|
11
|
+
export const dependencyResolutionCacheKey = (importer, source, imported) => `${importer}\0${source}\0${imported}`;
|
|
12
|
+
export function* resolveDependency(action, importer, source, imported) {
|
|
13
|
+
const entrypoint = importer === action.entrypoint.name
|
|
14
|
+
? action.entrypoint
|
|
15
|
+
: Entrypoint.createRoot(action.services, importer, [imported], undefined);
|
|
16
|
+
const imports = new Map([[source, [imported]]]);
|
|
17
|
+
const [resolved] = yield* action.getNext('resolveImports', entrypoint, {
|
|
18
|
+
imports,
|
|
19
|
+
phase: 'initial',
|
|
20
|
+
});
|
|
21
|
+
// Non-relative sources (package names, aliases) can still be importer-
|
|
22
|
+
// dependent because of nested packages, tsconfig boundaries, and bundler
|
|
23
|
+
// aliases. Cache only within the same importer context.
|
|
24
|
+
if (!isRelativeSource(source)) {
|
|
25
|
+
const cache = getWeakCacheMap(dependencyResolutionCaches, action.services.cache);
|
|
26
|
+
const cacheKey = dependencyResolutionCacheKey(importer, source, imported);
|
|
27
|
+
if (resolved?.resolved) {
|
|
28
|
+
cache.set(cacheKey, resolved);
|
|
29
|
+
return resolved;
|
|
30
|
+
}
|
|
31
|
+
const cached = cache.get(cacheKey);
|
|
32
|
+
if (cached?.resolved) {
|
|
33
|
+
return cached;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return resolved ?? null;
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Program } from 'oxc-parser';
|
|
2
|
+
import type { ITransformAction } from '../../types';
|
|
3
|
+
import type { StaticResolveDebugEvent } from './types';
|
|
4
|
+
export declare const isInsideRoot: (filename: string, root: string) => boolean;
|
|
5
|
+
export declare const nodeModulesPattern: RegExp;
|
|
6
|
+
export declare const isLocalStaticMetadataFile: (filename: string, root: string) => boolean;
|
|
7
|
+
export declare const isEnvDisabled: (value: string) => boolean;
|
|
8
|
+
export declare const getEvalStrategy: (action: ITransformAction) => import("@wyw-in-js/shared").EvalStrategy;
|
|
9
|
+
export declare const getStaticStrategyFailure: (filename: string, dependencyNames: Iterable<string>) => Error;
|
|
10
|
+
export declare const debugStaticResolve: (action: ITransformAction, event: StaticResolveDebugEvent) => void;
|
|
11
|
+
export declare const parseProgram: (code: string, filename: string) => Program;
|
|
12
|
+
export declare const getStaticBindings: (action: ITransformAction) => Record<string, Record<string, unknown>> | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { isAbsolute, relative } from 'path';
|
|
3
|
+
import { parseOxcProgram } from '../../../utils/oxc/parse';
|
|
4
|
+
import { stripQueryAndHash } from '../../../utils/parseRequest';
|
|
5
|
+
export const isInsideRoot = (filename, root) => {
|
|
6
|
+
const relativePath = relative(root, filename);
|
|
7
|
+
return (relativePath === '' ||
|
|
8
|
+
(!!relativePath &&
|
|
9
|
+
!relativePath.startsWith('..') &&
|
|
10
|
+
!isAbsolute(relativePath)));
|
|
11
|
+
};
|
|
12
|
+
export const nodeModulesPattern = /[\\/]node_modules[\\/]/;
|
|
13
|
+
export const isLocalStaticMetadataFile = (filename, root) => {
|
|
14
|
+
const strippedFilename = stripQueryAndHash(filename);
|
|
15
|
+
if (isInsideRoot(strippedFilename, root)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return (isAbsolute(strippedFilename) && !nodeModulesPattern.test(strippedFilename));
|
|
19
|
+
};
|
|
20
|
+
export const isEnvDisabled = (value) => value === '0' || value === 'false' || value === 'no' || value === 'off';
|
|
21
|
+
export const getEvalStrategy = (action) => action.services.options.pluginOptions.eval?.strategy ?? 'execute';
|
|
22
|
+
export const getStaticStrategyFailure = (filename, dependencyNames) => new Error(`[wyw-in-js] eval.strategy: "static" cannot fall back to the build-time evaluator for ${filename}. ` +
|
|
23
|
+
`Unresolved values: ${[...dependencyNames].join(', ')}.`);
|
|
24
|
+
export const debugStaticResolve = (action, event) => {
|
|
25
|
+
const labels = Object.fromEntries(Object.entries({
|
|
26
|
+
...event,
|
|
27
|
+
type: 'staticResolve',
|
|
28
|
+
}).filter(([, value]) => value !== undefined));
|
|
29
|
+
action.services.eventEmitter.single(labels);
|
|
30
|
+
};
|
|
31
|
+
export const parseProgram = (code, filename) => parseOxcProgram(code, filename, 'unambiguous');
|
|
32
|
+
export const getStaticBindings = (action) => action.services.options.pluginOptions?.staticBindings;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ITransformAction, SyncScenarioFor } from '../../types';
|
|
2
|
+
import type { ImportBinding, StaticExportResult } from './types';
|
|
3
|
+
export declare function resolveImportValue(action: ITransformAction, importer: string, binding: Pick<ImportBinding, 'imported' | 'source'>, stack: Set<string>, memo: Map<string, StaticExportResult | null>): SyncScenarioFor<StaticExportResult | null>;
|
|
4
|
+
export declare function resolveStaticExport(action: ITransformAction, filename: string, exportedName: string, stack: Set<string>, memo: Map<string, StaticExportResult | null>): SyncScenarioFor<StaticExportResult | null>;
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { evaluateOxcStaticExpressionAt, isOxcStaticSerializableValue, lookupStaticBinding, } from '../../../utils/collectOxcTemplateDependencies';
|
|
3
|
+
import { getStaticExportCachedResult, getStaticFileAnalysis, getStaticMetadataPreevalResult, setStaticExportCachedResult, } from './cache';
|
|
4
|
+
import { resolveDependency } from './dependencies';
|
|
5
|
+
import { debugStaticResolve, getStaticBindings } from './environment';
|
|
6
|
+
import { findExportTarget, typeScriptEnumStaticExportValue, } from './exportTargets';
|
|
7
|
+
import { resolveObjectAssignStaticExport } from './objectAssignStaticExport';
|
|
8
|
+
import { resolveProcessorStaticExport } from './processorStaticExport';
|
|
9
|
+
import { bindStaticResolvedValue, collectImportBindings, } from './staticExpression';
|
|
10
|
+
import { collectStaticExpressionDependencies } from './staticExpressionDependencies';
|
|
11
|
+
import { resolveZeroArgFunctionStaticExport } from './zeroArgFunctionStaticExport';
|
|
12
|
+
export function* resolveImportValue(action, importer, binding, stack, memo) {
|
|
13
|
+
const dependency = yield* resolveDependency(action, importer, binding.source, binding.imported);
|
|
14
|
+
if (!dependency?.resolved) {
|
|
15
|
+
debugStaticResolve(action, {
|
|
16
|
+
filename: importer,
|
|
17
|
+
imported: binding.imported,
|
|
18
|
+
phase: 'import',
|
|
19
|
+
reason: 'dependency-unresolved',
|
|
20
|
+
source: binding.source,
|
|
21
|
+
status: 'rejected',
|
|
22
|
+
});
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const resolved = yield* resolveStaticExport(action, dependency.resolved, binding.imported, stack, memo);
|
|
26
|
+
if (!resolved) {
|
|
27
|
+
debugStaticResolve(action, {
|
|
28
|
+
dependency: dependency.resolved,
|
|
29
|
+
filename: importer,
|
|
30
|
+
imported: binding.imported,
|
|
31
|
+
phase: 'import',
|
|
32
|
+
reason: 'resolve-failed',
|
|
33
|
+
source: binding.source,
|
|
34
|
+
status: 'rejected',
|
|
35
|
+
});
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
debugStaticResolve(action, {
|
|
39
|
+
dependency: dependency.resolved,
|
|
40
|
+
filename: importer,
|
|
41
|
+
imported: binding.imported,
|
|
42
|
+
phase: 'import',
|
|
43
|
+
source: binding.source,
|
|
44
|
+
status: 'resolved',
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
callable: resolved.callable,
|
|
48
|
+
dependencies: [
|
|
49
|
+
dependency.resolved,
|
|
50
|
+
...resolved.dependencies.filter((item) => item !== dependency.resolved),
|
|
51
|
+
],
|
|
52
|
+
sideEffectDependencies: resolved.sideEffectDependencies,
|
|
53
|
+
value: resolved.value,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function* resolveStaticExport(action, filename, exportedName, stack, memo) {
|
|
57
|
+
const memoKey = `${filename}\0${exportedName}`;
|
|
58
|
+
if (memo.has(memoKey)) {
|
|
59
|
+
return memo.get(memoKey) ?? null;
|
|
60
|
+
}
|
|
61
|
+
if (stack.has(memoKey)) {
|
|
62
|
+
memo.set(memoKey, null);
|
|
63
|
+
debugStaticResolve(action, {
|
|
64
|
+
exported: exportedName,
|
|
65
|
+
filename,
|
|
66
|
+
phase: 'export',
|
|
67
|
+
reason: 'cyclic-export',
|
|
68
|
+
status: 'rejected',
|
|
69
|
+
});
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
stack.add(memoKey);
|
|
73
|
+
const analysis = getStaticFileAnalysis(action, filename);
|
|
74
|
+
if (!analysis) {
|
|
75
|
+
memo.set(memoKey, null);
|
|
76
|
+
stack.delete(memoKey);
|
|
77
|
+
debugStaticResolve(action, {
|
|
78
|
+
exported: exportedName,
|
|
79
|
+
filename,
|
|
80
|
+
phase: 'export',
|
|
81
|
+
reason: 'ignored-or-non-oxc',
|
|
82
|
+
status: 'rejected',
|
|
83
|
+
});
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const { code, codeHash, program } = analysis;
|
|
87
|
+
const finish = (result) => {
|
|
88
|
+
memo.set(memoKey, result);
|
|
89
|
+
stack.delete(memoKey);
|
|
90
|
+
setStaticExportCachedResult(action, filename, exportedName, codeHash, result);
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
93
|
+
const cachedResult = getStaticExportCachedResult(action, filename, exportedName, codeHash);
|
|
94
|
+
if (cachedResult !== undefined) {
|
|
95
|
+
memo.set(memoKey, cachedResult);
|
|
96
|
+
stack.delete(memoKey);
|
|
97
|
+
return cachedResult;
|
|
98
|
+
}
|
|
99
|
+
const enumValue = typeScriptEnumStaticExportValue(program, exportedName);
|
|
100
|
+
if (enumValue) {
|
|
101
|
+
debugStaticResolve(action, {
|
|
102
|
+
exported: exportedName,
|
|
103
|
+
filename,
|
|
104
|
+
phase: 'export',
|
|
105
|
+
reason: 'typescript-enum',
|
|
106
|
+
status: 'resolved',
|
|
107
|
+
});
|
|
108
|
+
return finish({
|
|
109
|
+
dependencies: [filename],
|
|
110
|
+
value: enumValue,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const target = findExportTarget(program, exportedName);
|
|
114
|
+
if (!target) {
|
|
115
|
+
debugStaticResolve(action, {
|
|
116
|
+
exported: exportedName,
|
|
117
|
+
filename,
|
|
118
|
+
phase: 'export',
|
|
119
|
+
reason: 'no-export-target',
|
|
120
|
+
status: 'rejected',
|
|
121
|
+
});
|
|
122
|
+
return finish(null);
|
|
123
|
+
}
|
|
124
|
+
if (target.kind === 'import') {
|
|
125
|
+
const resolved = yield* resolveImportValue(action, filename, target, stack, memo);
|
|
126
|
+
debugStaticResolve(action, {
|
|
127
|
+
exported: exportedName,
|
|
128
|
+
filename,
|
|
129
|
+
imported: target.imported,
|
|
130
|
+
phase: 'export',
|
|
131
|
+
reason: resolved ? undefined : 'resolve-failed',
|
|
132
|
+
source: target.source,
|
|
133
|
+
status: resolved ? 'resolved' : 'rejected',
|
|
134
|
+
});
|
|
135
|
+
return finish(resolved);
|
|
136
|
+
}
|
|
137
|
+
const resolvers = {
|
|
138
|
+
resolveImportValue,
|
|
139
|
+
resolveStaticExport,
|
|
140
|
+
};
|
|
141
|
+
const objectAssignResult = yield* resolveObjectAssignStaticExport(action, filename, code, program, target, stack, memo, resolvers);
|
|
142
|
+
if (objectAssignResult) {
|
|
143
|
+
debugStaticResolve(action, {
|
|
144
|
+
exported: exportedName,
|
|
145
|
+
filename,
|
|
146
|
+
phase: 'export',
|
|
147
|
+
reason: 'object-assign',
|
|
148
|
+
status: 'resolved',
|
|
149
|
+
});
|
|
150
|
+
return finish(objectAssignResult);
|
|
151
|
+
}
|
|
152
|
+
const zeroArgFunctionResult = yield* resolveZeroArgFunctionStaticExport(action, filename, code, program, target, stack, memo, resolveImportValue);
|
|
153
|
+
if (zeroArgFunctionResult) {
|
|
154
|
+
debugStaticResolve(action, {
|
|
155
|
+
exported: exportedName,
|
|
156
|
+
filename,
|
|
157
|
+
phase: 'export',
|
|
158
|
+
reason: 'zero-arg-function',
|
|
159
|
+
status: 'resolved',
|
|
160
|
+
});
|
|
161
|
+
return finish(zeroArgFunctionResult);
|
|
162
|
+
}
|
|
163
|
+
// Pre-fetch the source file's preeval result so processor className
|
|
164
|
+
// bindings (`const x = css\`\``) can short-circuit dependency walks
|
|
165
|
+
// and seed the evaluator's env. The TaggedTemplateExpression init
|
|
166
|
+
// isn't safe-static by itself; the className IS.
|
|
167
|
+
const sourcePreevalForExpression = getStaticMetadataPreevalResult(action, filename, code, codeHash);
|
|
168
|
+
const preResolvedLocals = sourcePreevalForExpression?.processorClassNames
|
|
169
|
+
? new Set(Object.keys(sourcePreevalForExpression.processorClassNames))
|
|
170
|
+
: undefined;
|
|
171
|
+
// Build the set of import-local names registered as pure helpers via
|
|
172
|
+
// pluginOptions.staticBindings. The dependency walker admits
|
|
173
|
+
// CallExpressions whose callee is one of these so `cx(a, b)` and
|
|
174
|
+
// `isFlagPresent('x')` stop tripping isSafeStaticExpression.
|
|
175
|
+
const staticBindingsForExportShape = getStaticBindings(action);
|
|
176
|
+
const staticHelperLocals = new Set();
|
|
177
|
+
if (staticBindingsForExportShape) {
|
|
178
|
+
const fileImports = collectImportBindings(program);
|
|
179
|
+
for (const [local, binding] of fileImports) {
|
|
180
|
+
if (!binding.imported ||
|
|
181
|
+
binding.imported === '*' ||
|
|
182
|
+
binding.imported === 'default') {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
let override = lookupStaticBinding(staticBindingsForExportShape, binding.source, binding.imported);
|
|
186
|
+
if (!override.found) {
|
|
187
|
+
const dep = yield* resolveDependency(action, filename, binding.source, binding.imported);
|
|
188
|
+
if (dep?.resolved) {
|
|
189
|
+
override = lookupStaticBinding(staticBindingsForExportShape, dep.resolved, binding.imported);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (override.found && typeof override.value === 'function') {
|
|
193
|
+
staticHelperLocals.add(local);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const staticDependencies = collectStaticExpressionDependencies(program, target, {
|
|
198
|
+
...(preResolvedLocals ? { preResolvedLocals } : {}),
|
|
199
|
+
...(staticHelperLocals.size > 0 ? { staticHelperLocals } : {}),
|
|
200
|
+
});
|
|
201
|
+
if (!staticDependencies) {
|
|
202
|
+
debugStaticResolve(action, {
|
|
203
|
+
exported: exportedName,
|
|
204
|
+
filename,
|
|
205
|
+
phase: 'export',
|
|
206
|
+
reason: 'unsupported-expression',
|
|
207
|
+
status: 'rejected',
|
|
208
|
+
});
|
|
209
|
+
const metadataResult = yield* resolveProcessorStaticExport(action, filename, code, codeHash, program, exportedName, stack, memo, resolvers);
|
|
210
|
+
if (metadataResult) {
|
|
211
|
+
debugStaticResolve(action, {
|
|
212
|
+
exported: exportedName,
|
|
213
|
+
filename,
|
|
214
|
+
phase: 'export',
|
|
215
|
+
status: 'resolved',
|
|
216
|
+
});
|
|
217
|
+
return finish(metadataResult);
|
|
218
|
+
}
|
|
219
|
+
// Fallback: the metadata path rejected (e.g. non-empty-css-artifact
|
|
220
|
+
// when the css\`\` template has interpolations the source-preeval
|
|
221
|
+
// can't fold). The processor still computed a className for this
|
|
222
|
+
// binding during applyOxcProcessors; surface it as the export's
|
|
223
|
+
// value. Keep the source file in sideEffectDependencies so its CSS
|
|
224
|
+
// registers at runtime.
|
|
225
|
+
//
|
|
226
|
+
// Two shapes resolve here:
|
|
227
|
+
// export const x = css\`...\` (TaggedTemplateExpression init)
|
|
228
|
+
// export const x = sameFileCssConst (Identifier alias)
|
|
229
|
+
let lookupName = null;
|
|
230
|
+
if (target.expression.type === 'TaggedTemplateExpression') {
|
|
231
|
+
lookupName = target.localName ?? null;
|
|
232
|
+
}
|
|
233
|
+
else if (target.expression.type === 'Identifier') {
|
|
234
|
+
lookupName = target.expression.name;
|
|
235
|
+
}
|
|
236
|
+
if (lookupName) {
|
|
237
|
+
const sourcePreeval = getStaticMetadataPreevalResult(action, filename, code, codeHash);
|
|
238
|
+
const className = sourcePreeval?.processorClassNames[lookupName];
|
|
239
|
+
if (className) {
|
|
240
|
+
debugStaticResolve(action, {
|
|
241
|
+
exported: exportedName,
|
|
242
|
+
filename,
|
|
243
|
+
phase: 'export',
|
|
244
|
+
reason: 'processor-class-name',
|
|
245
|
+
status: 'resolved',
|
|
246
|
+
});
|
|
247
|
+
return finish({
|
|
248
|
+
dependencies: [filename],
|
|
249
|
+
sideEffectDependencies: [filename],
|
|
250
|
+
value: className,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
debugStaticResolve(action, {
|
|
255
|
+
exported: exportedName,
|
|
256
|
+
filename,
|
|
257
|
+
phase: 'export',
|
|
258
|
+
reason: 'resolve-failed',
|
|
259
|
+
status: 'rejected',
|
|
260
|
+
});
|
|
261
|
+
return finish(null);
|
|
262
|
+
}
|
|
263
|
+
const env = new Map();
|
|
264
|
+
const dependencies = new Set([filename]);
|
|
265
|
+
const sideEffectDependencies = new Set();
|
|
266
|
+
const staticBindingsForExport = getStaticBindings(action);
|
|
267
|
+
for (const binding of staticDependencies.imports) {
|
|
268
|
+
// staticBindings overrides take precedence here too — same shape as
|
|
269
|
+
// the candidate path. Try the raw specifier first, then the
|
|
270
|
+
// resolved absolute path on miss.
|
|
271
|
+
let override = lookupStaticBinding(staticBindingsForExport, binding.source, binding.imported);
|
|
272
|
+
if (!override.found && staticBindingsForExport) {
|
|
273
|
+
const dep = yield* resolveDependency(action, filename, binding.source, binding.imported);
|
|
274
|
+
if (dep?.resolved) {
|
|
275
|
+
override = lookupStaticBinding(staticBindingsForExport, dep.resolved, binding.imported);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (override.found) {
|
|
279
|
+
env.set(binding.local, override.value);
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
const resolved = yield* resolveImportValue(action, filename, binding, stack, memo);
|
|
283
|
+
if (!resolved) {
|
|
284
|
+
debugStaticResolve(action, {
|
|
285
|
+
exported: exportedName,
|
|
286
|
+
filename,
|
|
287
|
+
imported: binding.imported,
|
|
288
|
+
phase: 'export',
|
|
289
|
+
reason: 'resolve-failed',
|
|
290
|
+
source: binding.source,
|
|
291
|
+
status: 'rejected',
|
|
292
|
+
});
|
|
293
|
+
return finish(null);
|
|
294
|
+
}
|
|
295
|
+
if (!bindStaticResolvedValue(env, target.expression, binding.local, resolved)) {
|
|
296
|
+
debugStaticResolve(action, {
|
|
297
|
+
exported: exportedName,
|
|
298
|
+
filename,
|
|
299
|
+
imported: binding.imported,
|
|
300
|
+
phase: 'export',
|
|
301
|
+
reason: 'callable-usage-unsupported',
|
|
302
|
+
source: binding.source,
|
|
303
|
+
status: 'rejected',
|
|
304
|
+
});
|
|
305
|
+
return finish(null);
|
|
306
|
+
}
|
|
307
|
+
resolved.dependencies.forEach((item) => dependencies.add(item));
|
|
308
|
+
resolved.sideEffectDependencies?.forEach((item) => sideEffectDependencies.add(item));
|
|
309
|
+
}
|
|
310
|
+
// Seed env with the source file's selector-only processor class names
|
|
311
|
+
// so expressions like `baseClassName + ' ' + hoverClassName` can fold
|
|
312
|
+
// — `baseClassName`'s init is a TaggedTemplateExpression the evaluator
|
|
313
|
+
// can't unfold by walking the AST, but its className is already known
|
|
314
|
+
// from applyOxcProcessors.
|
|
315
|
+
if (sourcePreevalForExpression?.processorClassNames) {
|
|
316
|
+
for (const [name, className] of Object.entries(sourcePreevalForExpression.processorClassNames)) {
|
|
317
|
+
if (!env.has(name)) {
|
|
318
|
+
env.set(name, className);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const value = evaluateOxcStaticExpressionAt(code, filename, {
|
|
323
|
+
end: target.expression.end,
|
|
324
|
+
start: target.expression.start,
|
|
325
|
+
}, env, getStaticBindings(action));
|
|
326
|
+
if (!isOxcStaticSerializableValue(value)) {
|
|
327
|
+
const metadataResult = yield* resolveProcessorStaticExport(action, filename, code, codeHash, program, exportedName, stack, memo, resolvers);
|
|
328
|
+
if (metadataResult) {
|
|
329
|
+
debugStaticResolve(action, {
|
|
330
|
+
exported: exportedName,
|
|
331
|
+
filename,
|
|
332
|
+
phase: 'export',
|
|
333
|
+
status: 'resolved',
|
|
334
|
+
});
|
|
335
|
+
return finish(metadataResult);
|
|
336
|
+
}
|
|
337
|
+
debugStaticResolve(action, {
|
|
338
|
+
exported: exportedName,
|
|
339
|
+
filename,
|
|
340
|
+
phase: 'export',
|
|
341
|
+
reason: 'non-serializable',
|
|
342
|
+
status: 'rejected',
|
|
343
|
+
});
|
|
344
|
+
return finish(null);
|
|
345
|
+
}
|
|
346
|
+
const result = {
|
|
347
|
+
dependencies: [...dependencies],
|
|
348
|
+
sideEffectDependencies: [...sideEffectDependencies],
|
|
349
|
+
value,
|
|
350
|
+
};
|
|
351
|
+
debugStaticResolve(action, {
|
|
352
|
+
exported: exportedName,
|
|
353
|
+
filename,
|
|
354
|
+
phase: 'export',
|
|
355
|
+
status: 'resolved',
|
|
356
|
+
});
|
|
357
|
+
return finish(result);
|
|
358
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExportSpecifier, Node, Program, VariableDeclaration } from 'oxc-parser';
|
|
2
|
+
import type { ExportTarget } from './types';
|
|
3
|
+
export declare const getExportSpecifierNames: (specifier: ExportSpecifier) => {
|
|
4
|
+
exported: string;
|
|
5
|
+
local: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const findExportTarget: (program: Program, exportedName: string) => ExportTarget | null;
|
|
8
|
+
export declare const exportedLocalName: (program: Program, exportedName: string) => string | null;
|
|
9
|
+
export declare const isIdentifierNamed: (node: Node, name: string) => boolean;
|
|
10
|
+
export declare const enumLiteralValue: (node: Node) => number | string | null;
|
|
11
|
+
export declare const enumMemberKey: (node: Node, computed: boolean) => string | null;
|
|
12
|
+
export declare const enumSimpleAssignment: (node: Node, enumParamName: string) => {
|
|
13
|
+
key: string;
|
|
14
|
+
value: number | string;
|
|
15
|
+
} | null;
|
|
16
|
+
export declare const collectEnumIifeAssignments: (call: Node, localName: string) => Record<string, number | string> | null;
|
|
17
|
+
export declare const enumIifeLocalName: (statement: Node) => string | null;
|
|
18
|
+
export declare const isEnumVarDeclaration: (statement: Node) => statement is VariableDeclaration;
|
|
19
|
+
export declare const isTypeScriptEnumOnlyModule: (program: Program) => boolean;
|
|
20
|
+
export declare const typeScriptEnumStaticExportValue: (program: Program, exportedName: string) => Record<string, number | string> | null;
|