@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
|
@@ -55,8 +55,10 @@ const ensureOxcPreevalResult = (services, item, originalAst) => {
|
|
|
55
55
|
dependencyNames: result.dependencyNames,
|
|
56
56
|
evalCode: result.code,
|
|
57
57
|
metadata: result.metadata,
|
|
58
|
+
processorClassNames: result.processorClassNames,
|
|
58
59
|
staticSideEffectImportLocals: [],
|
|
59
60
|
staticDependencies: result.staticDependencies,
|
|
61
|
+
staticValuesApplied: false,
|
|
60
62
|
staticValueCache: result.staticValueCache,
|
|
61
63
|
staticValueCandidates: result.staticValueCandidates,
|
|
62
64
|
};
|
|
@@ -132,6 +134,62 @@ export const prepareCodeForEvalRuntime = (services, item, originalAst) => prepar
|
|
|
132
134
|
shortCircuitOnMissingMetadata: true,
|
|
133
135
|
stripForEvalRuntime: true,
|
|
134
136
|
});
|
|
137
|
+
function* resolveAndProcessOxcPreparedImports(action, preparedCode, imports) {
|
|
138
|
+
const { loadedAndParsed } = action.entrypoint;
|
|
139
|
+
if (imports === null || imports.size === 0) {
|
|
140
|
+
return preparedCode;
|
|
141
|
+
}
|
|
142
|
+
const resolvedImports = yield* action.getNext('resolveImports', action.entrypoint, {
|
|
143
|
+
imports,
|
|
144
|
+
phase: 'initial',
|
|
145
|
+
});
|
|
146
|
+
let nextCode = preparedCode;
|
|
147
|
+
let nextResolvedImports = [];
|
|
148
|
+
let skippedParentDependencyTracking = [];
|
|
149
|
+
if (resolvedImports.length > 0) {
|
|
150
|
+
const rewritten = yield* rewriteOptimizedOxcBarrelImports.call(action, preparedCode, loadedAndParsed.evaluator === 'ignored'
|
|
151
|
+
? action.entrypoint.name
|
|
152
|
+
: loadedAndParsed.evalConfig.filename ?? action.entrypoint.name, resolvedImports);
|
|
153
|
+
nextCode = rewritten.code;
|
|
154
|
+
if (rewritten.optimizedCount > 0) {
|
|
155
|
+
skippedParentDependencyTracking = rewritten.generatedSources;
|
|
156
|
+
const fullyRewrittenSources = new Set(rewritten.fullyRewrittenSources);
|
|
157
|
+
const partialFallbackSources = new Set(rewritten.partialFallbackSources);
|
|
158
|
+
for (const dependency of resolvedImports) {
|
|
159
|
+
if (dependency.resolved &&
|
|
160
|
+
(fullyRewrittenSources.has(dependency.source) ||
|
|
161
|
+
partialFallbackSources.has(dependency.source))) {
|
|
162
|
+
if (partialFallbackSources.has(dependency.source)) {
|
|
163
|
+
action.entrypoint.addDependency(dependency);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
action.entrypoint.addInvalidationDependency(dependency);
|
|
167
|
+
}
|
|
168
|
+
action.entrypoint.markInvalidateOnDependencyChange(dependency.resolved);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
nextResolvedImports = yield* action.getNext('resolveImports', action.entrypoint, {
|
|
172
|
+
imports: rewritten.imports,
|
|
173
|
+
phase: 'rewritten',
|
|
174
|
+
preResolved: rewritten.preResolvedImports,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
nextResolvedImports = resolvedImports;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (nextResolvedImports.length !== 0) {
|
|
182
|
+
yield [
|
|
183
|
+
'processImports',
|
|
184
|
+
action.entrypoint,
|
|
185
|
+
{
|
|
186
|
+
resolved: nextResolvedImports,
|
|
187
|
+
skipParentDependencyTracking: skippedParentDependencyTracking,
|
|
188
|
+
},
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
return nextCode;
|
|
192
|
+
}
|
|
135
193
|
export function* internalTransform(prepareFn) {
|
|
136
194
|
const { only, loadedAndParsed, log } = this.entrypoint;
|
|
137
195
|
if (loadedAndParsed.evaluator === 'ignored') {
|
|
@@ -149,7 +207,7 @@ export function* internalTransform(prepareFn) {
|
|
|
149
207
|
ensureOxcPreevalResult(this.services, this.entrypoint, null);
|
|
150
208
|
yield* resolveStaticOxcPreevalValues.call(this);
|
|
151
209
|
}
|
|
152
|
-
|
|
210
|
+
let [preparedCode, imports, metadata] = prepareFn(this.services, this.entrypoint, null);
|
|
153
211
|
let finalPreparedCode = preparedCode;
|
|
154
212
|
if (loadedAndParsed.evaluator === oxcShaker) {
|
|
155
213
|
if (metadata === null && isPrevalOnly(only)) {
|
|
@@ -159,54 +217,10 @@ export function* internalTransform(prepareFn) {
|
|
|
159
217
|
metadata: null,
|
|
160
218
|
};
|
|
161
219
|
}
|
|
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
|
-
];
|
|
220
|
+
let nextCode = yield* resolveAndProcessOxcPreparedImports(this, preparedCode, imports);
|
|
221
|
+
if (yield* resolveStaticOxcPreevalValues.call(this)) {
|
|
222
|
+
[preparedCode, imports, metadata] = prepareFn(this.services, this.entrypoint, null);
|
|
223
|
+
nextCode = yield* resolveAndProcessOxcPreparedImports(this, preparedCode, imports);
|
|
210
224
|
}
|
|
211
225
|
finalPreparedCode = this.services.eventEmitter.perf('transform:emitCommonJS', () => emitOxcCommonJS(nextCode, loadedAndParsed.evalConfig.filename ?? this.entrypoint.name).code);
|
|
212
226
|
}
|
|
@@ -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,11 +8,14 @@ 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) {
|
|
18
21
|
const id = this.onAction('start', performance.now(), actonType, idx, entrypointRef);
|
|
@@ -35,16 +38,48 @@ export class EventEmitter {
|
|
|
35
38
|
this.onEntrypointEvent(sequenceId, performance.now(), event);
|
|
36
39
|
}
|
|
37
40
|
perf(method, fn) {
|
|
41
|
+
const spanId = this.perfSpanId;
|
|
42
|
+
this.perfSpanId += 1;
|
|
43
|
+
const startedAt = performance.now();
|
|
38
44
|
const labels = { method };
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const startEvent = {
|
|
46
|
+
method,
|
|
47
|
+
spanId,
|
|
48
|
+
startedAt,
|
|
49
|
+
type: 'perf-span-start',
|
|
50
|
+
};
|
|
51
|
+
this.onEvent(labels, 'start', startEvent);
|
|
52
|
+
const finish = (status, isAsync, error) => {
|
|
53
|
+
const finishedAt = performance.now();
|
|
54
|
+
const finishEvent = {
|
|
55
|
+
durationMs: finishedAt - startedAt,
|
|
56
|
+
finishedAt,
|
|
57
|
+
isAsync,
|
|
58
|
+
method,
|
|
59
|
+
spanId,
|
|
60
|
+
startedAt,
|
|
61
|
+
status,
|
|
62
|
+
type: 'perf-span',
|
|
63
|
+
};
|
|
64
|
+
if (error !== undefined) {
|
|
65
|
+
finishEvent.error = error;
|
|
66
|
+
}
|
|
67
|
+
this.onEvent(labels, 'finish', finishEvent);
|
|
68
|
+
};
|
|
69
|
+
try {
|
|
70
|
+
const result = fn();
|
|
71
|
+
if (result instanceof Promise) {
|
|
72
|
+
result.then(() => finish('finished', true), (error) => finish('failed', true, error));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
finish('finished', false);
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
43
78
|
}
|
|
44
|
-
|
|
45
|
-
|
|
79
|
+
catch (error) {
|
|
80
|
+
finish('failed', false, error);
|
|
81
|
+
throw error;
|
|
46
82
|
}
|
|
47
|
-
return result;
|
|
48
83
|
}
|
|
49
84
|
single(labels) {
|
|
50
85
|
this.onEvent({
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
preserveSideEffectImportLocals?: Set<string>;
|
|
8
|
+
}, callback: (processor: BaseProcessor) => void, cleanupUnused?: boolean) => ApplyOxcProcessorsResult;
|
|
@@ -0,0 +1,167 @@
|
|
|
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()))
|
|
161
|
+
: codeWithAddedImports,
|
|
162
|
+
processorClassNamesByLocal,
|
|
163
|
+
processors,
|
|
164
|
+
staticValueCandidates: addCandidateInlineConstants(staticValueCandidates, sameFileProcessorStaticValuesByLocal),
|
|
165
|
+
staticValues: [...extracted.staticValues, ...sameFileProcessorStaticValues],
|
|
166
|
+
};
|
|
167
|
+
};
|
|
@@ -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>;
|