@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
|
@@ -55,8 +55,11 @@ const ensureOxcPreevalResult = (services, item, originalAst) => {
|
|
|
55
55
|
dependencyNames: result.dependencyNames,
|
|
56
56
|
evalCode: result.code,
|
|
57
57
|
metadata: result.metadata,
|
|
58
|
+
processorClassNames: result.processorClassNames,
|
|
59
|
+
staticImportLocals: [],
|
|
58
60
|
staticSideEffectImportLocals: [],
|
|
59
61
|
staticDependencies: result.staticDependencies,
|
|
62
|
+
staticValuesApplied: false,
|
|
60
63
|
staticValueCache: result.staticValueCache,
|
|
61
64
|
staticValueCandidates: result.staticValueCandidates,
|
|
62
65
|
};
|
|
@@ -132,6 +135,62 @@ export const prepareCodeForEvalRuntime = (services, item, originalAst) => prepar
|
|
|
132
135
|
shortCircuitOnMissingMetadata: true,
|
|
133
136
|
stripForEvalRuntime: true,
|
|
134
137
|
});
|
|
138
|
+
function* resolveAndProcessOxcPreparedImports(action, preparedCode, imports) {
|
|
139
|
+
const { loadedAndParsed } = action.entrypoint;
|
|
140
|
+
if (imports === null || imports.size === 0) {
|
|
141
|
+
return preparedCode;
|
|
142
|
+
}
|
|
143
|
+
const resolvedImports = yield* action.getNext('resolveImports', action.entrypoint, {
|
|
144
|
+
imports,
|
|
145
|
+
phase: 'initial',
|
|
146
|
+
});
|
|
147
|
+
let nextCode = preparedCode;
|
|
148
|
+
let nextResolvedImports = [];
|
|
149
|
+
let skippedParentDependencyTracking = [];
|
|
150
|
+
if (resolvedImports.length > 0) {
|
|
151
|
+
const rewritten = yield* rewriteOptimizedOxcBarrelImports.call(action, preparedCode, loadedAndParsed.evaluator === 'ignored'
|
|
152
|
+
? action.entrypoint.name
|
|
153
|
+
: loadedAndParsed.evalConfig.filename ?? action.entrypoint.name, resolvedImports);
|
|
154
|
+
nextCode = rewritten.code;
|
|
155
|
+
if (rewritten.optimizedCount > 0) {
|
|
156
|
+
skippedParentDependencyTracking = rewritten.generatedSources;
|
|
157
|
+
const fullyRewrittenSources = new Set(rewritten.fullyRewrittenSources);
|
|
158
|
+
const partialFallbackSources = new Set(rewritten.partialFallbackSources);
|
|
159
|
+
for (const dependency of resolvedImports) {
|
|
160
|
+
if (dependency.resolved &&
|
|
161
|
+
(fullyRewrittenSources.has(dependency.source) ||
|
|
162
|
+
partialFallbackSources.has(dependency.source))) {
|
|
163
|
+
if (partialFallbackSources.has(dependency.source)) {
|
|
164
|
+
action.entrypoint.addDependency(dependency);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
action.entrypoint.addInvalidationDependency(dependency);
|
|
168
|
+
}
|
|
169
|
+
action.entrypoint.markInvalidateOnDependencyChange(dependency.resolved);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
nextResolvedImports = yield* action.getNext('resolveImports', action.entrypoint, {
|
|
173
|
+
imports: rewritten.imports,
|
|
174
|
+
phase: 'rewritten',
|
|
175
|
+
preResolved: rewritten.preResolvedImports,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
nextResolvedImports = resolvedImports;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (nextResolvedImports.length !== 0) {
|
|
183
|
+
yield [
|
|
184
|
+
'processImports',
|
|
185
|
+
action.entrypoint,
|
|
186
|
+
{
|
|
187
|
+
resolved: nextResolvedImports,
|
|
188
|
+
skipParentDependencyTracking: skippedParentDependencyTracking,
|
|
189
|
+
},
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
return nextCode;
|
|
193
|
+
}
|
|
135
194
|
export function* internalTransform(prepareFn) {
|
|
136
195
|
const { only, loadedAndParsed, log } = this.entrypoint;
|
|
137
196
|
if (loadedAndParsed.evaluator === 'ignored') {
|
|
@@ -149,7 +208,7 @@ export function* internalTransform(prepareFn) {
|
|
|
149
208
|
ensureOxcPreevalResult(this.services, this.entrypoint, null);
|
|
150
209
|
yield* resolveStaticOxcPreevalValues.call(this);
|
|
151
210
|
}
|
|
152
|
-
|
|
211
|
+
let [preparedCode, imports, metadata] = prepareFn(this.services, this.entrypoint, null);
|
|
153
212
|
let finalPreparedCode = preparedCode;
|
|
154
213
|
if (loadedAndParsed.evaluator === oxcShaker) {
|
|
155
214
|
if (metadata === null && isPrevalOnly(only)) {
|
|
@@ -159,54 +218,10 @@ export function* internalTransform(prepareFn) {
|
|
|
159
218
|
metadata: null,
|
|
160
219
|
};
|
|
161
220
|
}
|
|
162
|
-
let nextCode = preparedCode;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const resolvedImports = yield* this.getNext('resolveImports', this.entrypoint, {
|
|
167
|
-
imports,
|
|
168
|
-
phase: 'initial',
|
|
169
|
-
});
|
|
170
|
-
if (resolvedImports.length > 0) {
|
|
171
|
-
const rewritten = yield* rewriteOptimizedOxcBarrelImports.call(this, preparedCode, loadedAndParsed.evalConfig.filename ?? this.entrypoint.name, resolvedImports);
|
|
172
|
-
nextCode = rewritten.code;
|
|
173
|
-
if (rewritten.optimizedCount > 0) {
|
|
174
|
-
skippedParentDependencyTracking = rewritten.generatedSources;
|
|
175
|
-
const fullyRewrittenSources = new Set(rewritten.fullyRewrittenSources);
|
|
176
|
-
const partialFallbackSources = new Set(rewritten.partialFallbackSources);
|
|
177
|
-
for (const dependency of resolvedImports) {
|
|
178
|
-
if (dependency.resolved &&
|
|
179
|
-
(fullyRewrittenSources.has(dependency.source) ||
|
|
180
|
-
partialFallbackSources.has(dependency.source))) {
|
|
181
|
-
if (partialFallbackSources.has(dependency.source)) {
|
|
182
|
-
this.entrypoint.addDependency(dependency);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
this.entrypoint.addInvalidationDependency(dependency);
|
|
186
|
-
}
|
|
187
|
-
this.entrypoint.markInvalidateOnDependencyChange(dependency.resolved);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
nextResolvedImports = yield* this.getNext('resolveImports', this.entrypoint, {
|
|
191
|
-
imports: rewritten.imports,
|
|
192
|
-
phase: 'rewritten',
|
|
193
|
-
preResolved: rewritten.preResolvedImports,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
nextResolvedImports = resolvedImports;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if (nextResolvedImports.length !== 0) {
|
|
202
|
-
yield [
|
|
203
|
-
'processImports',
|
|
204
|
-
this.entrypoint,
|
|
205
|
-
{
|
|
206
|
-
resolved: nextResolvedImports,
|
|
207
|
-
skipParentDependencyTracking: skippedParentDependencyTracking,
|
|
208
|
-
},
|
|
209
|
-
];
|
|
221
|
+
let nextCode = yield* resolveAndProcessOxcPreparedImports(this, preparedCode, imports);
|
|
222
|
+
if (yield* resolveStaticOxcPreevalValues.call(this)) {
|
|
223
|
+
[preparedCode, imports, metadata] = prepareFn(this.services, this.entrypoint, null);
|
|
224
|
+
nextCode = yield* resolveAndProcessOxcPreparedImports(this, preparedCode, imports);
|
|
210
225
|
}
|
|
211
226
|
finalPreparedCode = this.services.eventEmitter.perf('transform:emitCommonJS', () => emitOxcCommonJS(nextCode, loadedAndParsed.evalConfig.filename ?? this.entrypoint.name).code);
|
|
212
227
|
}
|
|
@@ -28,6 +28,10 @@ const explorerSync = cosmiconfigSync('wyw-in-js', {
|
|
|
28
28
|
const cache = new WeakMap();
|
|
29
29
|
const defaultOverrides = {};
|
|
30
30
|
const nodeModulesRegExp = /[\\/]node_modules[\\/]/;
|
|
31
|
+
const evalResolverModes = new Set(['bundler', 'hybrid', 'native', 'custom']);
|
|
32
|
+
const evalStrategies = new Set(['execute', 'hybrid', 'static']);
|
|
33
|
+
const evalRuntimes = new Set(['nodejs']);
|
|
34
|
+
const evalErrorModes = new Set(['strict', 'loose']);
|
|
31
35
|
const defaultImportLoaders = {
|
|
32
36
|
raw: 'raw',
|
|
33
37
|
url: 'url',
|
|
@@ -98,13 +102,14 @@ export function loadWywOptions(overrides = defaultOverrides) {
|
|
|
98
102
|
globalCache: true,
|
|
99
103
|
happyDOM: true,
|
|
100
104
|
softErrors: false,
|
|
101
|
-
staticImportValues: false,
|
|
102
105
|
useWeakRefInEval: true,
|
|
103
106
|
};
|
|
104
107
|
const defaultEval = {
|
|
105
|
-
|
|
108
|
+
errors: 'strict',
|
|
106
109
|
require: 'warn-and-run',
|
|
107
110
|
resolver: 'bundler',
|
|
111
|
+
runtime: 'nodejs',
|
|
112
|
+
strategy: 'hybrid',
|
|
108
113
|
};
|
|
109
114
|
const config = (() => {
|
|
110
115
|
if (configFile === false) {
|
|
@@ -120,7 +125,6 @@ export function loadWywOptions(overrides = defaultOverrides) {
|
|
|
120
125
|
const configEval = config.eval;
|
|
121
126
|
const options = {
|
|
122
127
|
displayName: false,
|
|
123
|
-
evaluate: true,
|
|
124
128
|
evalConsole: 'pipe',
|
|
125
129
|
extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],
|
|
126
130
|
outputMetadata: false,
|
|
@@ -165,6 +169,22 @@ export function loadWywOptions(overrides = defaultOverrides) {
|
|
|
165
169
|
...rest.features,
|
|
166
170
|
},
|
|
167
171
|
};
|
|
172
|
+
const evalResolver = options.eval?.resolver;
|
|
173
|
+
if (evalResolver && !evalResolverModes.has(evalResolver)) {
|
|
174
|
+
throw new Error(`[wyw-in-js] Unsupported eval.resolver "${evalResolver}". Use "bundler", "hybrid", "native", or "custom".`);
|
|
175
|
+
}
|
|
176
|
+
const evalStrategy = options.eval?.strategy;
|
|
177
|
+
if (evalStrategy && !evalStrategies.has(evalStrategy)) {
|
|
178
|
+
throw new Error(`[wyw-in-js] Unsupported eval.strategy "${evalStrategy}". Use "execute", "hybrid", or "static".`);
|
|
179
|
+
}
|
|
180
|
+
const evalRuntime = options.eval?.runtime;
|
|
181
|
+
if (evalRuntime && !evalRuntimes.has(evalRuntime)) {
|
|
182
|
+
throw new Error(`[wyw-in-js] Unsupported eval.runtime "${evalRuntime}". Use "nodejs".`);
|
|
183
|
+
}
|
|
184
|
+
const evalErrors = options.eval?.errors;
|
|
185
|
+
if (evalErrors && !evalErrorModes.has(evalErrors)) {
|
|
186
|
+
throw new Error(`[wyw-in-js] Unsupported eval.errors "${evalErrors}". Use "strict" or "loose".`);
|
|
187
|
+
}
|
|
168
188
|
cache.set(overrides, options);
|
|
169
189
|
return options;
|
|
170
190
|
}
|
package/types/transform.js
CHANGED
|
@@ -47,9 +47,11 @@ const canonicalizeForHash = (value) => {
|
|
|
47
47
|
const getEvalCacheKey = (pluginOptions, asyncResolveKey, asyncResolve) => {
|
|
48
48
|
const evalOptions = pluginOptions.eval ?? {};
|
|
49
49
|
const payload = JSON.stringify({
|
|
50
|
-
|
|
50
|
+
errors: evalOptions.errors,
|
|
51
51
|
resolver: evalOptions.resolver,
|
|
52
52
|
require: evalOptions.require,
|
|
53
|
+
runtime: evalOptions.runtime,
|
|
54
|
+
strategy: evalOptions.strategy,
|
|
53
55
|
globals: canonicalizeForHash(encodeGlobals(evalOptions.globals ?? {})),
|
|
54
56
|
customResolver: getResolverId(evalOptions.customResolver),
|
|
55
57
|
customLoader: getResolverId(evalOptions.customLoader),
|
|
@@ -45,14 +45,29 @@ export interface OnAction {
|
|
|
45
45
|
(...args: OnActionStartArgs): number;
|
|
46
46
|
(...args: OnActionFinishArgs): void;
|
|
47
47
|
}
|
|
48
|
+
type PerfStatus = 'failed' | 'finished';
|
|
49
|
+
export type PerfFinishEvent = {
|
|
50
|
+
durationMs: number;
|
|
51
|
+
error?: unknown;
|
|
52
|
+
finishedAt: number;
|
|
53
|
+
isAsync: boolean;
|
|
54
|
+
method: string;
|
|
55
|
+
spanId: number;
|
|
56
|
+
startedAt: number;
|
|
57
|
+
status: PerfStatus;
|
|
58
|
+
type: 'perf-span';
|
|
59
|
+
};
|
|
48
60
|
export declare class EventEmitter {
|
|
49
61
|
protected onEvent: OnEvent;
|
|
50
62
|
protected onAction: OnAction;
|
|
51
63
|
protected onEntrypointEvent: OnEntrypointEvent;
|
|
64
|
+
readonly enabled: boolean;
|
|
52
65
|
static dummy: EventEmitter;
|
|
53
|
-
|
|
66
|
+
private perfSpanId;
|
|
67
|
+
constructor(onEvent: OnEvent, onAction: OnAction, onEntrypointEvent: OnEntrypointEvent, enabled?: boolean);
|
|
54
68
|
action<TRes>(actonType: string, idx: string, entrypointRef: string, fn: () => TRes): TRes;
|
|
55
69
|
entrypointEvent(sequenceId: number, event: EntrypointEvent): void;
|
|
56
70
|
perf<TRes>(method: string, fn: () => TRes): TRes;
|
|
57
71
|
single(labels: Record<string, unknown>): void;
|
|
58
72
|
}
|
|
73
|
+
export {};
|
|
@@ -8,13 +8,23 @@ export class EventEmitter {
|
|
|
8
8
|
onEvent;
|
|
9
9
|
onAction;
|
|
10
10
|
onEntrypointEvent;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
enabled;
|
|
12
|
+
static dummy = new EventEmitter(() => { }, () => 0, () => { }, false);
|
|
13
|
+
perfSpanId = 0;
|
|
14
|
+
constructor(onEvent, onAction, onEntrypointEvent, enabled = true) {
|
|
13
15
|
this.onEvent = onEvent;
|
|
14
16
|
this.onAction = onAction;
|
|
15
17
|
this.onEntrypointEvent = onEntrypointEvent;
|
|
18
|
+
this.enabled = enabled;
|
|
16
19
|
}
|
|
17
20
|
action(actonType, idx, entrypointRef, fn) {
|
|
21
|
+
// Fast path: when the emitter is disabled (the dummy used by the
|
|
22
|
+
// production transform path) skip start/finish bookkeeping and the
|
|
23
|
+
// Promise hookup. action() is on the hot path for every step of every
|
|
24
|
+
// action — its per-call overhead is small but ubiquitous.
|
|
25
|
+
if (!this.enabled) {
|
|
26
|
+
return fn();
|
|
27
|
+
}
|
|
18
28
|
const id = this.onAction('start', performance.now(), actonType, idx, entrypointRef);
|
|
19
29
|
try {
|
|
20
30
|
const result = fn();
|
|
@@ -35,16 +45,54 @@ export class EventEmitter {
|
|
|
35
45
|
this.onEntrypointEvent(sequenceId, performance.now(), event);
|
|
36
46
|
}
|
|
37
47
|
perf(method, fn) {
|
|
48
|
+
// Fast path: see action() above. perf() wraps ~28s of cumulative time
|
|
49
|
+
// in the production-path CPU profile; the wrapper overhead per call is
|
|
50
|
+
// small but everywhere.
|
|
51
|
+
if (!this.enabled) {
|
|
52
|
+
return fn();
|
|
53
|
+
}
|
|
54
|
+
const spanId = this.perfSpanId;
|
|
55
|
+
this.perfSpanId += 1;
|
|
56
|
+
const startedAt = performance.now();
|
|
38
57
|
const labels = { method };
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
const startEvent = {
|
|
59
|
+
method,
|
|
60
|
+
spanId,
|
|
61
|
+
startedAt,
|
|
62
|
+
type: 'perf-span-start',
|
|
63
|
+
};
|
|
64
|
+
this.onEvent(labels, 'start', startEvent);
|
|
65
|
+
const finish = (status, isAsync, error) => {
|
|
66
|
+
const finishedAt = performance.now();
|
|
67
|
+
const finishEvent = {
|
|
68
|
+
durationMs: finishedAt - startedAt,
|
|
69
|
+
finishedAt,
|
|
70
|
+
isAsync,
|
|
71
|
+
method,
|
|
72
|
+
spanId,
|
|
73
|
+
startedAt,
|
|
74
|
+
status,
|
|
75
|
+
type: 'perf-span',
|
|
76
|
+
};
|
|
77
|
+
if (error !== undefined) {
|
|
78
|
+
finishEvent.error = error;
|
|
79
|
+
}
|
|
80
|
+
this.onEvent(labels, 'finish', finishEvent);
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
const result = fn();
|
|
84
|
+
if (result instanceof Promise) {
|
|
85
|
+
result.then(() => finish('finished', true), (error) => finish('failed', true, error));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
finish('finished', false);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
43
91
|
}
|
|
44
|
-
|
|
45
|
-
|
|
92
|
+
catch (error) {
|
|
93
|
+
finish('failed', false, error);
|
|
94
|
+
throw error;
|
|
46
95
|
}
|
|
47
|
-
return result;
|
|
48
96
|
}
|
|
49
97
|
single(labels) {
|
|
50
98
|
this.onEvent({
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BaseProcessor, IFileContext } from '@wyw-in-js/processor-utils';
|
|
2
|
+
import type { StrictOptions } from '@wyw-in-js/shared';
|
|
3
|
+
import { EventEmitter } from '../EventEmitter';
|
|
4
|
+
import type { ApplyOxcProcessorsResult } from './types';
|
|
5
|
+
export declare const applyOxcProcessors: (code: string, fileContext: IFileContext, options: Pick<StrictOptions, "classNameSlug" | "displayName" | "eval" | "extensions" | "staticBindings" | "tagResolver"> & {
|
|
6
|
+
eventEmitter?: EventEmitter;
|
|
7
|
+
preserveSideEffectImportOrderLocals?: Set<string>;
|
|
8
|
+
preserveSideEffectImportLocals?: Set<string>;
|
|
9
|
+
}, callback: (processor: BaseProcessor) => void, cleanupUnused?: boolean) => ApplyOxcProcessorsResult;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { collectOxcProcessorImportsFromProgram } from '../collectOxcExportsAndImports';
|
|
2
|
+
import { collectOxcExpressionDependencies } from '../collectOxcTemplateDependencies';
|
|
3
|
+
import { EventEmitter } from '../EventEmitter';
|
|
4
|
+
import { isOxcNode } from '../oxc/ast';
|
|
5
|
+
import { applyOxcReplacements } from '../oxc/replacements';
|
|
6
|
+
import { buildOxcCodeFrameError, createOxcLocationLookup, } from '../oxc/sourceLocations';
|
|
7
|
+
import { getProcessorForImport } from '../processorLookup';
|
|
8
|
+
import { resolveProcessorStaticClassName } from '../processorStaticSemantics';
|
|
9
|
+
import { collectUsedNames } from './cleanupBindings';
|
|
10
|
+
import { addCandidateInlineConstants, collectSameFileProcessorObjectStaticValuesByLocal, collectSameFileProcessorStaticValuesByLocal, collectWYWMetaExtendsHelperNames, getSameFileProcessorObjectProperty, } from './sameFileStaticValues';
|
|
11
|
+
import { collectSameFileProcessorStaticValues, getTagOwner, isTagReferenced, } from './displayName';
|
|
12
|
+
import { buildParams } from './expressionValues';
|
|
13
|
+
import { createProcessor, shouldCollectStaticExpressionValues, } from './processorFactory';
|
|
14
|
+
import { collectProcessorUsages, collectUsageExpressionSpans, } from './processorUsages';
|
|
15
|
+
import { removeUnusedAfterReplacement } from './cleanupRemovals';
|
|
16
|
+
import { insertAddedImports, parseOxc } from './shared';
|
|
17
|
+
export const applyOxcProcessors = (code, fileContext, options, callback, cleanupUnused = false) => {
|
|
18
|
+
const filename = fileContext.filename ?? 'unknown.js';
|
|
19
|
+
const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;
|
|
20
|
+
const collectStaticExpressionValues = shouldCollectStaticExpressionValues(options);
|
|
21
|
+
let workingCode = code;
|
|
22
|
+
let program = parseOxc(workingCode, filename);
|
|
23
|
+
const definedProcessors = new Map();
|
|
24
|
+
const removableImportLocals = new Set();
|
|
25
|
+
const removableExpressionRefs = new Set();
|
|
26
|
+
eventEmitter.perf('transform:preeval:processTemplate:imports', () => {
|
|
27
|
+
const imports = eventEmitter.perf('transform:preeval:processTemplate:imports:analysis', () => collectOxcProcessorImportsFromProgram(program, workingCode));
|
|
28
|
+
eventEmitter.perf('transform:preeval:processTemplate:imports:lookup', () => {
|
|
29
|
+
imports.forEach((item) => {
|
|
30
|
+
const localName = item.local.name ?? item.local.code;
|
|
31
|
+
if (item.imported === 'side-effect' || !localName) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const [processor, tagSource] = getProcessorForImport({
|
|
35
|
+
imported: item.imported,
|
|
36
|
+
source: item.source,
|
|
37
|
+
}, filename, options);
|
|
38
|
+
if (processor) {
|
|
39
|
+
definedProcessors.set(localName, [processor, tagSource]);
|
|
40
|
+
removableImportLocals.add(localName);
|
|
41
|
+
const rootLocalName = localName.split('.')[0];
|
|
42
|
+
if (rootLocalName) {
|
|
43
|
+
removableImportLocals.add(rootLocalName);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
if (definedProcessors.size === 0) {
|
|
50
|
+
return {
|
|
51
|
+
code: workingCode,
|
|
52
|
+
processorClassNamesByLocal: new Map(),
|
|
53
|
+
processors: [],
|
|
54
|
+
staticValueCandidates: [],
|
|
55
|
+
staticValues: [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
let processorUsages = eventEmitter.perf('transform:preeval:processTemplate:usages', () => collectProcessorUsages(program, definedProcessors));
|
|
59
|
+
if (processorUsages.length === 0) {
|
|
60
|
+
return {
|
|
61
|
+
code: workingCode,
|
|
62
|
+
processorClassNamesByLocal: new Map(),
|
|
63
|
+
processors: [],
|
|
64
|
+
staticValueCandidates: [],
|
|
65
|
+
staticValues: [],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const targetExpressionSpans = processorUsages.flatMap(collectUsageExpressionSpans);
|
|
69
|
+
const extracted = targetExpressionSpans.length > 0
|
|
70
|
+
? eventEmitter.perf('transform:preeval:processTemplate:deps', () => collectOxcExpressionDependencies(workingCode, filename, collectStaticExpressionValues, targetExpressionSpans, options.staticBindings))
|
|
71
|
+
: {
|
|
72
|
+
code: workingCode,
|
|
73
|
+
dependencyNames: [],
|
|
74
|
+
expressionValues: [],
|
|
75
|
+
staticValueCandidates: [],
|
|
76
|
+
staticValues: [],
|
|
77
|
+
};
|
|
78
|
+
if (extracted.code !== workingCode) {
|
|
79
|
+
workingCode = extracted.code;
|
|
80
|
+
program = eventEmitter.perf('transform:preeval:processTemplate:reparse', () => parseOxc(workingCode, filename));
|
|
81
|
+
processorUsages = eventEmitter.perf('transform:preeval:processTemplate:usages', () => collectProcessorUsages(program, definedProcessors));
|
|
82
|
+
}
|
|
83
|
+
const templateExpressionValues = extracted.expressionValues.map((value) => ({
|
|
84
|
+
...value,
|
|
85
|
+
buildCodeFrameError: (message) => buildOxcCodeFrameError(code, value.ex.loc, message),
|
|
86
|
+
}));
|
|
87
|
+
const loc = createOxcLocationLookup(workingCode);
|
|
88
|
+
const usedNames = eventEmitter.perf('transform:preeval:processTemplate:usedNames', () => collectUsedNames(program));
|
|
89
|
+
const addedImports = [];
|
|
90
|
+
const replacements = [];
|
|
91
|
+
const processors = [];
|
|
92
|
+
const processorClassNamesByLocal = new Map();
|
|
93
|
+
const sameFileProcessorsByLocal = new Map();
|
|
94
|
+
const sameFileProcessorObjectsByLocal = new Map();
|
|
95
|
+
extracted.dependencyNames.forEach((name) => removableImportLocals.add(name));
|
|
96
|
+
eventEmitter.perf('transform:preeval:processTemplate:processors', () => {
|
|
97
|
+
processorUsages.forEach((usage, idx) => {
|
|
98
|
+
const params = buildParams(usage, workingCode, loc, filename, templateExpressionValues, usage.collapseQualifiedCallee);
|
|
99
|
+
if (!params) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const created = createProcessor(usage.definedProcessor, params, usage.target, usage.replacementTarget, usage.ancestors, fileContext, options, workingCode, loc, idx, isTagReferenced(program, usage.ancestors), usedNames, replacements);
|
|
103
|
+
if (!created) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const { astService, processor } = created;
|
|
107
|
+
const owner = getTagOwner(usage.ancestors);
|
|
108
|
+
if (owner?.type === 'VariableDeclarator') {
|
|
109
|
+
const { id } = owner;
|
|
110
|
+
if (isOxcNode(id) && id.type === 'Identifier') {
|
|
111
|
+
removableExpressionRefs.add(id.name);
|
|
112
|
+
sameFileProcessorsByLocal.set(id.name, processor);
|
|
113
|
+
// Cross-file map (used as a className-only fallback in
|
|
114
|
+
// resolveStaticExport) is restricted to processors whose
|
|
115
|
+
// runtime value IS the className string. Styled-component
|
|
116
|
+
// bindings emit a richer value and must reach consumers via
|
|
117
|
+
// resolveProcessorStaticExport so composition still works.
|
|
118
|
+
const staticClassName = resolveProcessorStaticClassName(processor);
|
|
119
|
+
if (staticClassName) {
|
|
120
|
+
processorClassNamesByLocal.set(id.name, staticClassName);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const replacement = processor.value;
|
|
124
|
+
if ((replacement?.type === 'StringLiteral' ||
|
|
125
|
+
replacement?.type === 'Literal') &&
|
|
126
|
+
typeof replacement.value === 'string') {
|
|
127
|
+
processorClassNamesByLocal.set(id.name, processor.className);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const objectProperty = getSameFileProcessorObjectProperty(usage.ancestors);
|
|
133
|
+
if (objectProperty) {
|
|
134
|
+
const existing = sameFileProcessorObjectsByLocal.get(objectProperty.localName);
|
|
135
|
+
const object = existing ?? {
|
|
136
|
+
properties: new Map(),
|
|
137
|
+
propertyNames: objectProperty.propertyNames,
|
|
138
|
+
};
|
|
139
|
+
object.properties.set(objectProperty.propertyName, processor);
|
|
140
|
+
sameFileProcessorObjectsByLocal.set(objectProperty.localName, object);
|
|
141
|
+
}
|
|
142
|
+
processors.push(processor);
|
|
143
|
+
callback(processor);
|
|
144
|
+
addedImports.push(...astService.getAddedImports());
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
const sameFileProcessorStaticValuesByLocal = collectSameFileProcessorStaticValuesByLocal(sameFileProcessorsByLocal, extracted.expressionValues);
|
|
148
|
+
const sameFileProcessorObjectStaticValuesByLocal = collectSameFileProcessorObjectStaticValuesByLocal(sameFileProcessorObjectsByLocal, sameFileProcessorsByLocal, extracted.expressionValues);
|
|
149
|
+
sameFileProcessorObjectStaticValuesByLocal.forEach((value, local) => {
|
|
150
|
+
sameFileProcessorStaticValuesByLocal.set(local, value);
|
|
151
|
+
});
|
|
152
|
+
const replacedCode = applyOxcReplacements(workingCode, replacements);
|
|
153
|
+
const metadataExtendsHelperNames = collectWYWMetaExtendsHelperNames(replacedCode);
|
|
154
|
+
const staticValueCandidates = extracted.staticValueCandidates.filter((candidate) => candidate.imports.length > 0 ||
|
|
155
|
+
!metadataExtendsHelperNames.has(candidate.name));
|
|
156
|
+
const sameFileProcessorStaticValues = collectSameFileProcessorStaticValues(extracted.expressionValues, sameFileProcessorStaticValuesByLocal);
|
|
157
|
+
const codeWithAddedImports = insertAddedImports(replacedCode, program, addedImports);
|
|
158
|
+
return {
|
|
159
|
+
code: cleanupUnused
|
|
160
|
+
? eventEmitter.perf('transform:preeval:processTemplate:cleanup', () => removeUnusedAfterReplacement(codeWithAddedImports, filename, removableImportLocals, new Set([...removableExpressionRefs, ...extracted.dependencyNames]), options.preserveSideEffectImportLocals ?? new Set(), options.preserveSideEffectImportOrderLocals ??
|
|
161
|
+
options.preserveSideEffectImportLocals ??
|
|
162
|
+
new Set()))
|
|
163
|
+
: codeWithAddedImports,
|
|
164
|
+
processorClassNamesByLocal,
|
|
165
|
+
processors,
|
|
166
|
+
staticValueCandidates: addCandidateInlineConstants(staticValueCandidates, sameFileProcessorStaticValuesByLocal),
|
|
167
|
+
staticValues: [...extracted.staticValues, ...sameFileProcessorStaticValues],
|
|
168
|
+
};
|
|
169
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node, Program } from 'oxc-parser';
|
|
2
|
+
import type { TopLevelStatementInfo } from './types';
|
|
3
|
+
export declare const collectUsedNames: (program: Program) => Set<string>;
|
|
4
|
+
export declare const isNodeReference: (node: Node, parent: Node | null) => boolean;
|
|
5
|
+
export declare const collectReferencedNames: (root: Node) => Set<string>;
|
|
6
|
+
export declare const collectImportLocalNames: (node: Node) => string[];
|
|
7
|
+
export declare const getImportSpecifierLocalName: (node: Node) => string | null;
|
|
8
|
+
export declare const collectDeclaredNames: (node: Node) => string[];
|
|
9
|
+
export declare const collectTopLevelBindings: (statement: Node) => Set<string>;
|
|
10
|
+
export declare const collectTopLevelStatementInfos: (program: Program) => TopLevelStatementInfo[];
|
|
11
|
+
export declare const collectTopLevelBindingsFromStatements: (statements: TopLevelStatementInfo[]) => Set<string>;
|
|
12
|
+
export declare const collectRemovableNamesFromStatements: (statements: TopLevelStatementInfo[], initialNames: Set<string>) => Set<string>;
|