@wyw-in-js/transform 1.1.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 +433 -289
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +171 -134
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +2275 -0
- package/esm/eval/broker.js.map +1 -0
- package/esm/eval/lru.js +36 -0
- package/esm/eval/lru.js.map +1 -0
- package/esm/eval/prepareModuleOnDemand.js +21 -0
- package/esm/eval/prepareModuleOnDemand.js.map +1 -0
- package/esm/eval/protocol.js +2 -0
- package/esm/eval/protocol.js.map +1 -0
- package/esm/eval/runner.js +1878 -0
- package/esm/eval/runner.js.map +1 -0
- package/esm/eval/serialize.js +333 -0
- package/esm/eval/serialize.js.map +1 -0
- package/esm/eval/writeQueue.js +81 -0
- package/esm/eval/writeQueue.js.map +1 -0
- package/esm/evaluators/index.js +11 -12
- package/esm/evaluators/index.js.map +1 -1
- package/esm/index.js +25 -29
- package/esm/index.js.map +1 -1
- package/esm/module.js +923 -520
- package/esm/module.js.map +1 -1
- package/esm/shaker.js +14 -80
- package/esm/shaker.js.map +1 -1
- package/esm/transform/BaseEntrypoint.js +162 -164
- package/esm/transform/BaseEntrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +96 -253
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +336 -270
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.types.js +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/EvaluatedEntrypoint.js +10 -4
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
- package/esm/transform/actions/AbortError.js +6 -6
- package/esm/transform/actions/AbortError.js.map +1 -1
- package/esm/transform/actions/BaseAction.js +140 -136
- package/esm/transform/actions/BaseAction.js.map +1 -1
- package/esm/transform/actions/UnprocessedEntrypointError.js +6 -6
- package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
- package/esm/transform/actions/actionRunner.js +63 -66
- package/esm/transform/actions/actionRunner.js.map +1 -1
- package/esm/transform/actions/types.js +1 -1
- package/esm/transform/actions/types.js.map +1 -1
- package/esm/transform/barrelManifest.types.js +2 -0
- package/esm/transform/barrelManifest.types.js.map +1 -0
- package/esm/transform/generators/baseProcessingHandlers.js +15 -17
- package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
- package/esm/transform/generators/collect.js +27 -55
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +353 -321
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/esm/transform/generators/evalFile.js +48 -47
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/extract.js +78 -90
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/getExports.js +57 -74
- package/esm/transform/generators/getExports.js.map +1 -1
- package/esm/transform/generators/index.js +11 -11
- package/esm/transform/generators/index.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +93 -67
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/processImports.js +102 -67
- package/esm/transform/generators/processImports.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +212 -197
- 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 +2 -0
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -0
- package/esm/transform/generators/rewriteOxcBarrelImports.js +822 -0
- package/esm/transform/generators/rewriteOxcBarrelImports.js.map +1 -0
- package/esm/transform/generators/transform.js +251 -248
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js +87 -90
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +183 -74
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform/helpers/withDefaultServices.js +13 -22
- package/esm/transform/helpers/withDefaultServices.js.map +1 -1
- package/esm/transform/isStaticallyEvaluatableModule.js +140 -152
- package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -1
- package/esm/transform/oxcBarrelManifest.js +349 -0
- package/esm/transform/oxcBarrelManifest.js.map +1 -0
- package/esm/transform/rootLog.js +3 -3
- package/esm/transform/rootLog.js.map +1 -1
- package/esm/transform/syntax.js +2 -0
- package/esm/transform/syntax.js.map +1 -0
- package/esm/transform/types.js +2 -2
- package/esm/transform/types.js.map +1 -1
- package/esm/transform.js +125 -147
- package/esm/transform.js.map +1 -1
- package/esm/types.js +4 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/EventEmitter.js +79 -48
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/ShakerMetadata.js +2 -2
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/TransformDiagnostics.js +9 -9
- package/esm/utils/TransformDiagnostics.js.map +1 -1
- package/esm/utils/TransformMetadata.js +24 -26
- package/esm/utils/TransformMetadata.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 +2 -0
- package/esm/utils/applyOxcProcessors.js.map +1 -0
- package/esm/utils/collectOxcExportsAndImports.js +934 -0
- package/esm/utils/collectOxcExportsAndImports.js.map +1 -0
- 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 +32 -0
- package/esm/utils/collectOxcRuntime.js.map +1 -0
- 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 +4 -0
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -0
- package/esm/utils/dispose-polyfill.js +3 -4
- package/esm/utils/dispose-polyfill.js.map +1 -1
- package/esm/utils/getFileIdx.js +6 -6
- package/esm/utils/getFileIdx.js.map +1 -1
- package/esm/utils/getPluginKey.js +12 -12
- package/esm/utils/getPluginKey.js.map +1 -1
- package/esm/utils/getVisitorKeys.js +9 -3
- package/esm/utils/getVisitorKeys.js.map +1 -1
- package/esm/utils/hasCachedWywPrevalExport.js +23 -0
- package/esm/utils/hasCachedWywPrevalExport.js.map +1 -0
- package/esm/utils/hasWywPreval.js +5 -5
- package/esm/utils/hasWywPreval.js.map +1 -1
- package/esm/utils/importOverrides.js +75 -90
- package/esm/utils/importOverrides.js.map +1 -1
- package/esm/utils/isNode.js +2 -2
- package/esm/utils/isNode.js.map +1 -1
- package/esm/utils/isNotNull.js +2 -2
- package/esm/utils/isNotNull.js.map +1 -1
- package/esm/utils/isSerializable.js +11 -11
- package/esm/utils/isSerializable.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/oxcAstService.js +121 -0
- package/esm/utils/oxcAstService.js.map +1 -0
- package/esm/utils/oxcEmit.js +447 -0
- package/esm/utils/oxcEmit.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 +41 -0
- package/esm/utils/oxcPreevalStage.js.map +1 -0
- package/esm/utils/oxcPreevalTransforms.js +1065 -0
- package/esm/utils/oxcPreevalTransforms.js.map +1 -0
- package/esm/utils/oxcShaker.js +662 -0
- package/esm/utils/oxcShaker.js.map +1 -0
- package/esm/utils/parseOxc.js +37 -0
- package/esm/utils/parseOxc.js.map +1 -0
- package/esm/utils/parseRequest.js +27 -27
- package/esm/utils/parseRequest.js.map +1 -1
- package/esm/utils/peek.js +1 -1
- package/esm/utils/peek.js.map +1 -1
- package/esm/utils/processorLookup.js +125 -0
- package/esm/utils/processorLookup.js.map +1 -0
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +99 -0
- package/esm/utils/resolveWithConditions.js.map +1 -0
- package/esm/vm/createVmContext.js +140 -141
- package/esm/vm/createVmContext.js.map +1 -1
- package/esm/vm/process.js +11 -13
- package/esm/vm/process.js.map +1 -1
- package/package.json +19 -26
- package/types/cache.d.ts +17 -8
- package/types/cache.js +245 -95
- package/types/debug/fileReporter.js +68 -23
- package/types/eval/broker.d.ts +92 -0
- package/types/eval/broker.js +2411 -0
- package/types/eval/lru.d.ts +10 -0
- package/types/eval/lru.js +36 -0
- package/types/eval/prepareModuleOnDemand.d.ts +7 -0
- package/types/eval/prepareModuleOnDemand.js +24 -0
- package/types/eval/protocol.d.ts +111 -0
- package/types/eval/protocol.js +1 -0
- package/types/eval/serialize.d.ts +78 -0
- package/types/eval/serialize.js +357 -0
- package/types/eval/writeQueue.d.ts +13 -0
- package/types/eval/writeQueue.js +80 -0
- package/types/evaluators/index.d.ts +2 -2
- package/types/evaluators/index.js +6 -9
- package/types/index.d.ts +3 -6
- package/types/index.js +24 -82
- package/types/module.d.ts +38 -7
- package/types/module.js +613 -192
- package/types/shaker.d.ts +2 -10
- package/types/shaker.js +10 -100
- package/types/transform/BaseEntrypoint.js +6 -11
- package/types/transform/Entrypoint.d.ts +15 -15
- package/types/transform/Entrypoint.helpers.d.ts +2 -5
- package/types/transform/Entrypoint.helpers.js +43 -203
- package/types/transform/Entrypoint.js +130 -53
- package/types/transform/Entrypoint.types.d.ts +31 -6
- package/types/transform/Entrypoint.types.js +1 -2
- package/types/transform/EvaluatedEntrypoint.d.ts +13 -2
- package/types/transform/EvaluatedEntrypoint.js +7 -6
- package/types/transform/actions/AbortError.js +2 -7
- package/types/transform/actions/BaseAction.js +4 -8
- package/types/transform/actions/UnprocessedEntrypointError.js +2 -7
- package/types/transform/actions/actionRunner.js +8 -12
- package/types/transform/actions/types.d.ts +2 -2
- package/types/transform/actions/types.js +1 -2
- package/types/transform/{barrelManifest.d.ts → barrelManifest.types.d.ts} +0 -2
- package/types/transform/barrelManifest.types.js +1 -0
- package/types/transform/generators/baseProcessingHandlers.d.ts +4 -5
- package/types/transform/generators/baseProcessingHandlers.js +10 -14
- package/types/transform/generators/collect.js +13 -39
- package/types/transform/generators/createStylisPreprocessor.js +19 -60
- package/types/transform/generators/evalFile.d.ts +2 -2
- package/types/transform/generators/evalFile.js +26 -28
- package/types/transform/generators/extract.js +5 -8
- package/types/transform/generators/getExports.js +23 -30
- package/types/transform/generators/index.d.ts +2 -2
- package/types/transform/generators/index.js +11 -14
- package/types/transform/generators/processEntrypoint.d.ts +2 -2
- package/types/transform/generators/processEntrypoint.js +60 -26
- package/types/transform/generators/processImports.d.ts +0 -3
- package/types/transform/generators/processImports.js +60 -20
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +66 -23
- 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 -0
- package/types/transform/generators/resolveStaticOxcValues.js +1 -0
- package/types/transform/generators/{rewriteBarrelImports.d.ts → rewriteOxcBarrelImports.d.ts} +2 -3
- package/types/transform/generators/{rewriteBarrelImports.js → rewriteOxcBarrelImports.js} +282 -225
- package/types/transform/generators/transform.d.ts +3 -7
- package/types/transform/generators/transform.js +217 -199
- package/types/transform/generators/workflow.js +62 -45
- package/types/transform/helpers/loadWywOptions.js +115 -21
- package/types/transform/helpers/withDefaultServices.d.ts +1 -1
- package/types/transform/helpers/withDefaultServices.js +6 -44
- package/types/transform/isStaticallyEvaluatableModule.d.ts +1 -2
- package/types/transform/isStaticallyEvaluatableModule.js +125 -126
- package/types/transform/oxcBarrelManifest.d.ts +2 -0
- package/types/transform/{barrelManifest.js → oxcBarrelManifest.js} +156 -97
- package/types/transform/rootLog.js +2 -5
- package/types/transform/syntax.d.ts +38 -0
- package/types/transform/syntax.js +1 -0
- package/types/transform/types.d.ts +9 -6
- package/types/transform/types.js +1 -4
- package/types/transform.d.ts +2 -2
- package/types/transform.js +90 -101
- package/types/types.d.ts +0 -23
- package/types/types.js +1 -2
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +47 -18
- package/types/utils/ShakerMetadata.js +1 -5
- package/types/utils/TransformDiagnostics.js +3 -7
- package/types/utils/TransformMetadata.js +8 -16
- 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 -0
- package/types/utils/applyOxcProcessors.js +1 -0
- package/types/utils/collectOxcExportsAndImports.d.ts +35 -0
- package/types/utils/collectOxcExportsAndImports.js +957 -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 +16 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +4 -0
- package/types/utils/collectOxcRuntime.js +31 -0
- 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 -0
- package/types/utils/collectOxcTemplateDependencies.js +3 -0
- package/types/utils/getFileIdx.js +1 -4
- package/types/utils/getPluginKey.d.ts +5 -2
- package/types/utils/getPluginKey.js +2 -6
- package/types/utils/getVisitorKeys.d.ts +4 -4
- package/types/utils/getVisitorKeys.js +9 -6
- package/types/utils/hasCachedWywPrevalExport.d.ts +14 -0
- package/types/utils/hasCachedWywPrevalExport.js +30 -0
- package/types/utils/hasWywPreval.js +1 -4
- package/types/utils/importOverrides.js +17 -27
- package/types/utils/isNode.d.ts +2 -2
- package/types/utils/isNode.js +2 -6
- package/types/utils/isNotNull.js +1 -4
- package/types/utils/isSerializable.js +3 -6
- 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/oxcAstService.d.ts +11 -0
- package/types/utils/oxcAstService.js +79 -0
- package/types/utils/oxcEmit.d.ts +19 -0
- package/types/utils/oxcEmit.js +506 -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 +4 -0
- package/types/utils/oxcPreevalStage.js +40 -0
- package/types/utils/oxcPreevalTransforms.d.ts +13 -0
- package/types/utils/oxcPreevalTransforms.js +1192 -0
- package/types/utils/oxcShaker.d.ts +13 -0
- package/types/utils/oxcShaker.js +751 -0
- package/types/utils/parseOxc.d.ts +11 -0
- package/types/utils/parseOxc.js +38 -0
- package/types/utils/parseRequest.js +2 -7
- package/types/utils/peek.js +1 -5
- package/types/utils/processorLookup.d.ts +8 -0
- package/types/utils/processorLookup.js +135 -0
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.d.ts +12 -0
- package/types/utils/resolveWithConditions.js +103 -0
- package/types/vm/createVmContext.d.ts +2 -2
- package/types/vm/createVmContext.js +25 -62
- package/types/vm/process.js +20 -26
- package/esm/babel.js +0 -2
- package/esm/babel.js.map +0 -1
- package/esm/options/buildOptions.js +0 -168
- package/esm/options/buildOptions.js.map +0 -1
- package/esm/options/buildOptions.test.js +0 -138
- package/esm/options/buildOptions.test.js.map +0 -1
- package/esm/options/loadBabelOptions.js +0 -24
- package/esm/options/loadBabelOptions.js.map +0 -1
- package/esm/plugins/babel-transform.js +0 -53
- package/esm/plugins/babel-transform.js.map +0 -1
- package/esm/plugins/collector.js +0 -60
- package/esm/plugins/collector.js.map +0 -1
- package/esm/plugins/dynamic-import.js +0 -56
- package/esm/plugins/dynamic-import.js.map +0 -1
- package/esm/plugins/preeval.js +0 -73
- package/esm/plugins/preeval.js.map +0 -1
- package/esm/plugins/shaker.js +0 -680
- package/esm/plugins/shaker.js.map +0 -1
- package/esm/transform/barrelManifest.js +0 -291
- package/esm/transform/barrelManifest.js.map +0 -1
- package/esm/transform/generators/explodeReexports.js +0 -64
- package/esm/transform/generators/explodeReexports.js.map +0 -1
- package/esm/transform/generators/rewriteBarrelImports.js +0 -733
- package/esm/transform/generators/rewriteBarrelImports.js.map +0 -1
- package/esm/utils/addIdentifierToWywPreval.js +0 -68
- package/esm/utils/addIdentifierToWywPreval.js.map +0 -1
- package/esm/utils/collectExportsAndImports.js +0 -1157
- package/esm/utils/collectExportsAndImports.js.map +0 -1
- package/esm/utils/collectTemplateDependencies.js +0 -228
- package/esm/utils/collectTemplateDependencies.js.map +0 -1
- package/esm/utils/createId.js +0 -6
- package/esm/utils/createId.js.map +0 -1
- package/esm/utils/findIdentifiers.js +0 -62
- package/esm/utils/findIdentifiers.js.map +0 -1
- package/esm/utils/getConstantStringValue.js +0 -58
- package/esm/utils/getConstantStringValue.js.map +0 -1
- package/esm/utils/getMemberExpressionPropertyName.js +0 -11
- package/esm/utils/getMemberExpressionPropertyName.js.map +0 -1
- package/esm/utils/getScope.js +0 -6
- package/esm/utils/getScope.js.map +0 -1
- package/esm/utils/getSource.js +0 -15
- package/esm/utils/getSource.js.map +0 -1
- package/esm/utils/getTagProcessor.js +0 -404
- package/esm/utils/getTagProcessor.js.map +0 -1
- package/esm/utils/isExports.js +0 -22
- package/esm/utils/isExports.js.map +0 -1
- package/esm/utils/isGlobal.js +0 -6
- package/esm/utils/isGlobal.js.map +0 -1
- package/esm/utils/isNodePath.js +0 -4
- package/esm/utils/isNodePath.js.map +0 -1
- package/esm/utils/isRemoved.js +0 -46
- package/esm/utils/isRemoved.js.map +0 -1
- package/esm/utils/isRequire.js +0 -13
- package/esm/utils/isRequire.js.map +0 -1
- package/esm/utils/isTypedNode.js +0 -6
- package/esm/utils/isTypedNode.js.map +0 -1
- package/esm/utils/isUnnecessaryReactCall.js +0 -72
- package/esm/utils/isUnnecessaryReactCall.js.map +0 -1
- package/esm/utils/removeDangerousCode.js +0 -276
- package/esm/utils/removeDangerousCode.js.map +0 -1
- package/esm/utils/replaceImportMetaEnv.js +0 -44
- package/esm/utils/replaceImportMetaEnv.js.map +0 -1
- package/esm/utils/scopeHelpers.js +0 -527
- package/esm/utils/scopeHelpers.js.map +0 -1
- package/esm/utils/traversalCache.js +0 -23
- package/esm/utils/traversalCache.js.map +0 -1
- package/esm/utils/unwrapExpression.js +0 -18
- package/esm/utils/unwrapExpression.js.map +0 -1
- package/esm/utils/unwrapSequence.js +0 -14
- package/esm/utils/unwrapSequence.js.map +0 -1
- package/esm/utils/valueToLiteral.js +0 -59
- package/esm/utils/valueToLiteral.js.map +0 -1
- package/esm/utils/visitors/JSXElementsRemover.js +0 -51
- package/esm/utils/visitors/JSXElementsRemover.js.map +0 -1
- package/lib/babel.js +0 -2
- package/lib/babel.js.map +0 -1
- package/lib/cache.js +0 -308
- package/lib/cache.js.map +0 -1
- package/lib/debug/fileReporter.js +0 -153
- package/lib/debug/fileReporter.js.map +0 -1
- package/lib/evaluators/index.js +0 -20
- package/lib/evaluators/index.js.map +0 -1
- package/lib/index.js +0 -286
- package/lib/index.js.map +0 -1
- package/lib/module.js +0 -552
- package/lib/module.js.map +0 -1
- package/lib/options/buildOptions.js +0 -176
- package/lib/options/buildOptions.js.map +0 -1
- package/lib/options/buildOptions.test.js +0 -141
- package/lib/options/buildOptions.test.js.map +0 -1
- package/lib/options/loadBabelOptions.js +0 -31
- package/lib/options/loadBabelOptions.js.map +0 -1
- package/lib/plugins/babel-transform.js +0 -60
- package/lib/plugins/babel-transform.js.map +0 -1
- package/lib/plugins/collector.js +0 -70
- package/lib/plugins/collector.js.map +0 -1
- package/lib/plugins/dynamic-import.js +0 -61
- package/lib/plugins/dynamic-import.js.map +0 -1
- package/lib/plugins/preeval.js +0 -81
- package/lib/plugins/preeval.js.map +0 -1
- package/lib/plugins/shaker.js +0 -691
- package/lib/plugins/shaker.js.map +0 -1
- package/lib/shaker.js +0 -95
- package/lib/shaker.js.map +0 -1
- package/lib/transform/BaseEntrypoint.js +0 -179
- package/lib/transform/BaseEntrypoint.js.map +0 -1
- package/lib/transform/Entrypoint.helpers.js +0 -279
- package/lib/transform/Entrypoint.helpers.js.map +0 -1
- package/lib/transform/Entrypoint.js +0 -289
- package/lib/transform/Entrypoint.js.map +0 -1
- package/lib/transform/Entrypoint.types.js +0 -2
- package/lib/transform/Entrypoint.types.js.map +0 -1
- package/lib/transform/EvaluatedEntrypoint.js +0 -13
- package/lib/transform/EvaluatedEntrypoint.js.map +0 -1
- package/lib/transform/actions/AbortError.js +0 -16
- package/lib/transform/actions/AbortError.js.map +0 -1
- package/lib/transform/actions/BaseAction.js +0 -150
- package/lib/transform/actions/BaseAction.js.map +0 -1
- package/lib/transform/actions/UnprocessedEntrypointError.js +0 -16
- package/lib/transform/actions/UnprocessedEntrypointError.js.map +0 -1
- package/lib/transform/actions/actionRunner.js +0 -82
- package/lib/transform/actions/actionRunner.js.map +0 -1
- package/lib/transform/actions/types.js +0 -2
- package/lib/transform/actions/types.js.map +0 -1
- package/lib/transform/barrelManifest.js +0 -300
- package/lib/transform/barrelManifest.js.map +0 -1
- package/lib/transform/generators/baseProcessingHandlers.js +0 -27
- package/lib/transform/generators/baseProcessingHandlers.js.map +0 -1
- package/lib/transform/generators/collect.js +0 -66
- package/lib/transform/generators/collect.js.map +0 -1
- package/lib/transform/generators/createStylisPreprocessor.js +0 -372
- package/lib/transform/generators/createStylisPreprocessor.js.map +0 -1
- package/lib/transform/generators/evalFile.js +0 -57
- package/lib/transform/generators/evalFile.js.map +0 -1
- package/lib/transform/generators/explodeReexports.js +0 -71
- package/lib/transform/generators/explodeReexports.js.map +0 -1
- package/lib/transform/generators/extract.js +0 -102
- package/lib/transform/generators/extract.js.map +0 -1
- package/lib/transform/generators/getExports.js +0 -85
- package/lib/transform/generators/getExports.js.map +0 -1
- package/lib/transform/generators/index.js +0 -19
- package/lib/transform/generators/index.js.map +0 -1
- package/lib/transform/generators/processEntrypoint.js +0 -76
- package/lib/transform/generators/processEntrypoint.js.map +0 -1
- package/lib/transform/generators/processImports.js +0 -82
- package/lib/transform/generators/processImports.js.map +0 -1
- package/lib/transform/generators/resolveImports.js +0 -221
- package/lib/transform/generators/resolveImports.js.map +0 -1
- package/lib/transform/generators/rewriteBarrelImports.js +0 -743
- package/lib/transform/generators/rewriteBarrelImports.js.map +0 -1
- package/lib/transform/generators/transform.js +0 -272
- package/lib/transform/generators/transform.js.map +0 -1
- package/lib/transform/generators/workflow.js +0 -100
- package/lib/transform/generators/workflow.js.map +0 -1
- package/lib/transform/helpers/loadWywOptions.js +0 -88
- package/lib/transform/helpers/loadWywOptions.js.map +0 -1
- package/lib/transform/helpers/withDefaultServices.js +0 -31
- package/lib/transform/helpers/withDefaultServices.js.map +0 -1
- package/lib/transform/isStaticallyEvaluatableModule.js +0 -159
- package/lib/transform/isStaticallyEvaluatableModule.js.map +0 -1
- package/lib/transform/rootLog.js +0 -9
- package/lib/transform/rootLog.js.map +0 -1
- package/lib/transform/types.js +0 -8
- package/lib/transform/types.js.map +0 -1
- package/lib/transform.js +0 -160
- package/lib/transform.js.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/utils/EventEmitter.js +0 -61
- package/lib/utils/EventEmitter.js.map +0 -1
- package/lib/utils/ShakerMetadata.js +0 -9
- package/lib/utils/ShakerMetadata.js.map +0 -1
- package/lib/utils/TransformDiagnostics.js +0 -20
- package/lib/utils/TransformDiagnostics.js.map +0 -1
- package/lib/utils/TransformMetadata.js +0 -45
- package/lib/utils/TransformMetadata.js.map +0 -1
- package/lib/utils/addIdentifierToWywPreval.js +0 -75
- package/lib/utils/addIdentifierToWywPreval.js.map +0 -1
- package/lib/utils/collectExportsAndImports.js +0 -1173
- package/lib/utils/collectExportsAndImports.js.map +0 -1
- package/lib/utils/collectTemplateDependencies.js +0 -242
- package/lib/utils/collectTemplateDependencies.js.map +0 -1
- package/lib/utils/createId.js +0 -13
- package/lib/utils/createId.js.map +0 -1
- package/lib/utils/dispose-polyfill.js +0 -9
- package/lib/utils/dispose-polyfill.js.map +0 -1
- package/lib/utils/findIdentifiers.js +0 -73
- package/lib/utils/findIdentifiers.js.map +0 -1
- package/lib/utils/getConstantStringValue.js +0 -66
- package/lib/utils/getConstantStringValue.js.map +0 -1
- package/lib/utils/getFileIdx.js +0 -16
- package/lib/utils/getFileIdx.js.map +0 -1
- package/lib/utils/getMemberExpressionPropertyName.js +0 -18
- package/lib/utils/getMemberExpressionPropertyName.js.map +0 -1
- package/lib/utils/getPluginKey.js +0 -21
- package/lib/utils/getPluginKey.js.map +0 -1
- package/lib/utils/getScope.js +0 -12
- package/lib/utils/getScope.js.map +0 -1
- package/lib/utils/getSource.js +0 -24
- package/lib/utils/getSource.js.map +0 -1
- package/lib/utils/getTagProcessor.js +0 -424
- package/lib/utils/getTagProcessor.js.map +0 -1
- package/lib/utils/getVisitorKeys.js +0 -11
- package/lib/utils/getVisitorKeys.js.map +0 -1
- package/lib/utils/hasWywPreval.js +0 -13
- package/lib/utils/hasWywPreval.js.map +0 -1
- package/lib/utils/importOverrides.js +0 -119
- package/lib/utils/importOverrides.js.map +0 -1
- package/lib/utils/isExports.js +0 -27
- package/lib/utils/isExports.js.map +0 -1
- package/lib/utils/isGlobal.js +0 -13
- package/lib/utils/isGlobal.js.map +0 -1
- package/lib/utils/isNode.js +0 -9
- package/lib/utils/isNode.js.map +0 -1
- package/lib/utils/isNodePath.js +0 -10
- package/lib/utils/isNodePath.js.map +0 -1
- package/lib/utils/isNotNull.js +0 -10
- package/lib/utils/isNotNull.js.map +0 -1
- package/lib/utils/isRemoved.js +0 -52
- package/lib/utils/isRemoved.js.map +0 -1
- package/lib/utils/isRequire.js +0 -18
- package/lib/utils/isRequire.js.map +0 -1
- package/lib/utils/isSerializable.js +0 -19
- package/lib/utils/isSerializable.js.map +0 -1
- package/lib/utils/isTypedNode.js +0 -13
- package/lib/utils/isTypedNode.js.map +0 -1
- package/lib/utils/isUnnecessaryReactCall.js +0 -81
- package/lib/utils/isUnnecessaryReactCall.js.map +0 -1
- package/lib/utils/parseRequest.js +0 -37
- package/lib/utils/parseRequest.js.map +0 -1
- package/lib/utils/peek.js +0 -9
- package/lib/utils/peek.js.map +0 -1
- package/lib/utils/removeDangerousCode.js +0 -284
- package/lib/utils/removeDangerousCode.js.map +0 -1
- package/lib/utils/replaceImportMetaEnv.js +0 -50
- package/lib/utils/replaceImportMetaEnv.js.map +0 -1
- package/lib/utils/scopeHelpers.js +0 -557
- package/lib/utils/scopeHelpers.js.map +0 -1
- package/lib/utils/traversalCache.js +0 -31
- package/lib/utils/traversalCache.js.map +0 -1
- package/lib/utils/unwrapExpression.js +0 -25
- package/lib/utils/unwrapExpression.js.map +0 -1
- package/lib/utils/unwrapSequence.js +0 -20
- package/lib/utils/unwrapSequence.js.map +0 -1
- package/lib/utils/valueToLiteral.js +0 -65
- package/lib/utils/valueToLiteral.js.map +0 -1
- package/lib/utils/visitors/JSXElementsRemover.js +0 -57
- package/lib/utils/visitors/JSXElementsRemover.js.map +0 -1
- package/lib/vm/createVmContext.js +0 -166
- package/lib/vm/createVmContext.js.map +0 -1
- package/lib/vm/process.js +0 -38
- package/lib/vm/process.js.map +0 -1
- package/types/babel.d.ts +0 -2
- package/types/babel.js +0 -2
- package/types/options/buildOptions.d.ts +0 -6
- package/types/options/buildOptions.js +0 -178
- package/types/options/loadBabelOptions.d.ts +0 -3
- package/types/options/loadBabelOptions.js +0 -26
- package/types/plugins/babel-transform.d.ts +0 -4
- package/types/plugins/babel-transform.js +0 -49
- package/types/plugins/collector.d.ts +0 -23
- package/types/plugins/collector.js +0 -62
- package/types/plugins/dynamic-import.d.ts +0 -6
- package/types/plugins/dynamic-import.js +0 -60
- package/types/plugins/preeval.d.ts +0 -16
- package/types/plugins/preeval.js +0 -69
- package/types/plugins/shaker.d.ts +0 -14
- package/types/plugins/shaker.js +0 -724
- package/types/transform/generators/explodeReexports.d.ts +0 -7
- package/types/transform/generators/explodeReexports.js +0 -65
- package/types/utils/addIdentifierToWywPreval.d.ts +0 -4
- package/types/utils/addIdentifierToWywPreval.js +0 -74
- package/types/utils/collectExportsAndImports.d.ts +0 -31
- package/types/utils/collectExportsAndImports.js +0 -1147
- package/types/utils/collectTemplateDependencies.d.ts +0 -17
- package/types/utils/collectTemplateDependencies.js +0 -220
- package/types/utils/createId.d.ts +0 -2
- package/types/utils/createId.js +0 -9
- package/types/utils/findIdentifiers.d.ts +0 -6
- package/types/utils/findIdentifiers.js +0 -67
- package/types/utils/getConstantStringValue.d.ts +0 -2
- package/types/utils/getConstantStringValue.js +0 -94
- package/types/utils/getMemberExpressionPropertyName.d.ts +0 -2
- package/types/utils/getMemberExpressionPropertyName.js +0 -46
- package/types/utils/getScope.d.ts +0 -2
- package/types/utils/getScope.js +0 -10
- package/types/utils/getSource.d.ts +0 -2
- package/types/utils/getSource.js +0 -22
- package/types/utils/getTagProcessor.d.ts +0 -13
- package/types/utils/getTagProcessor.js +0 -411
- package/types/utils/isExports.d.ts +0 -6
- package/types/utils/isExports.js +0 -19
- package/types/utils/isGlobal.d.ts +0 -2
- package/types/utils/isGlobal.js +0 -9
- package/types/utils/isNodePath.d.ts +0 -3
- package/types/utils/isNodePath.js +0 -6
- package/types/utils/isRemoved.d.ts +0 -5
- package/types/utils/isRemoved.js +0 -41
- package/types/utils/isRequire.d.ts +0 -6
- package/types/utils/isRequire.js +0 -14
- package/types/utils/isTypedNode.d.ts +0 -5
- package/types/utils/isTypedNode.js +0 -9
- package/types/utils/isUnnecessaryReactCall.d.ts +0 -3
- package/types/utils/isUnnecessaryReactCall.js +0 -75
- package/types/utils/removeDangerousCode.d.ts +0 -4
- package/types/utils/removeDangerousCode.js +0 -326
- package/types/utils/replaceImportMetaEnv.d.ts +0 -3
- package/types/utils/replaceImportMetaEnv.js +0 -39
- package/types/utils/scopeHelpers.d.ts +0 -12
- package/types/utils/scopeHelpers.js +0 -580
- package/types/utils/traversalCache.d.ts +0 -4
- package/types/utils/traversalCache.js +0 -27
- package/types/utils/unwrapExpression.d.ts +0 -2
- package/types/utils/unwrapExpression.js +0 -57
- package/types/utils/unwrapSequence.d.ts +0 -8
- package/types/utils/unwrapSequence.js +0 -16
- package/types/utils/valueToLiteral.d.ts +0 -3
- package/types/utils/valueToLiteral.js +0 -63
- package/types/utils/visitors/JSXElementsRemover.d.ts +0 -3
- package/types/utils/visitors/JSXElementsRemover.js +0 -51
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { getOxcNodeChildren, isOxcNode } from "../oxc/ast.js";
|
|
2
|
+
import { applyOxcReplacements } from "../oxc/replacements.js";
|
|
3
|
+
import { collectDeclaredNames, collectImportLocalNames, collectReferencedNames, collectRemovableNamesFromStatements, collectTopLevelBindings, collectTopLevelBindingsFromStatements, collectTopLevelStatementInfos, getImportSpecifierLocalName, isNodeReference } from "./cleanupBindings.js";
|
|
4
|
+
import { GENERATED_HELPER_NAME_RE, parseOxc } from "./shared.js";
|
|
5
|
+
export const createScopedCleanupScope = (parent) => ({
|
|
6
|
+
bindings: new Map(),
|
|
7
|
+
parent
|
|
8
|
+
});
|
|
9
|
+
export const resolveScopedBinding = (scope, name) => {
|
|
10
|
+
let current = scope;
|
|
11
|
+
while (current) {
|
|
12
|
+
const bindingId = current.bindings.get(name);
|
|
13
|
+
if (bindingId) {
|
|
14
|
+
return bindingId;
|
|
15
|
+
}
|
|
16
|
+
current = current.parent;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
export const collectScopedBindingInfos = (program) => {
|
|
21
|
+
const bindings = new Map();
|
|
22
|
+
let sequence = 0;
|
|
23
|
+
const addBinding = (scope, name, kind, declaration) => {
|
|
24
|
+
const id = `${kind}:${name}:${declaration.start}:${sequence}`;
|
|
25
|
+
sequence += 1;
|
|
26
|
+
bindings.set(id, {
|
|
27
|
+
declaration,
|
|
28
|
+
dependencies: new Set(),
|
|
29
|
+
externalReferences: 0,
|
|
30
|
+
id,
|
|
31
|
+
incomingFromBindings: new Set(),
|
|
32
|
+
kind,
|
|
33
|
+
name
|
|
34
|
+
});
|
|
35
|
+
scope.bindings.set(name, id);
|
|
36
|
+
return id;
|
|
37
|
+
};
|
|
38
|
+
const addPatternBindings = (scope, pattern, kind, declaration) => {
|
|
39
|
+
collectDeclaredNames(pattern).forEach((name) => {
|
|
40
|
+
addBinding(scope, name, kind, declaration);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const recordReference = (scope, name, ownerBindingId) => {
|
|
44
|
+
const targetId = resolveScopedBinding(scope, name);
|
|
45
|
+
if (!targetId) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const target = bindings.get(targetId);
|
|
49
|
+
if (!target) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (ownerBindingId && ownerBindingId !== targetId) {
|
|
53
|
+
target.incomingFromBindings.add(ownerBindingId);
|
|
54
|
+
bindings.get(ownerBindingId)?.dependencies.add(targetId);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
target.externalReferences += 1;
|
|
58
|
+
};
|
|
59
|
+
let walk;
|
|
60
|
+
function walkPatternReferenceSubexpressions(node, scope, ownerBindingId) {
|
|
61
|
+
if (node.type === "Identifier") {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (node.type === "TSParameterProperty") {
|
|
65
|
+
walkPatternReferenceSubexpressions(node.parameter, scope, ownerBindingId);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (node.type === "RestElement") {
|
|
69
|
+
walkPatternReferenceSubexpressions(node.argument, scope, ownerBindingId);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (node.type === "AssignmentPattern") {
|
|
73
|
+
walkPatternReferenceSubexpressions(node.left, scope, ownerBindingId);
|
|
74
|
+
walk(node.right, scope, node, ownerBindingId);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (node.type === "ObjectPattern") {
|
|
78
|
+
node.properties.forEach((property) => {
|
|
79
|
+
if (property.type === "RestElement") {
|
|
80
|
+
walkPatternReferenceSubexpressions(property.argument, scope, ownerBindingId);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (property.computed && isOxcNode(property.key)) {
|
|
84
|
+
walk(property.key, scope, property, ownerBindingId);
|
|
85
|
+
}
|
|
86
|
+
walkPatternReferenceSubexpressions(property.value, scope, ownerBindingId);
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (node.type === "ArrayPattern") {
|
|
91
|
+
node.elements.forEach((element) => {
|
|
92
|
+
if (element && isOxcNode(element)) {
|
|
93
|
+
walkPatternReferenceSubexpressions(element, scope, ownerBindingId);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
walk = (node, scope, parent = null, ownerBindingId = null) => {
|
|
99
|
+
if (node.type === "ImportDeclaration") {
|
|
100
|
+
const { specifiers } = node;
|
|
101
|
+
if (Array.isArray(specifiers)) {
|
|
102
|
+
specifiers.forEach((specifier) => {
|
|
103
|
+
const { local } = specifier;
|
|
104
|
+
if (isOxcNode(local) && local.type === "Identifier" && typeof local.name === "string") {
|
|
105
|
+
addBinding(scope, local.name, "import", node);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (node.type === "ExportNamedDeclaration" && node.declaration) {
|
|
112
|
+
walk(node.declaration, scope, node, ownerBindingId);
|
|
113
|
+
collectTopLevelBindings(node).forEach((name) => {
|
|
114
|
+
recordReference(scope, name, ownerBindingId);
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (node.type === "ExportDefaultDeclaration") {
|
|
119
|
+
const { declaration } = node;
|
|
120
|
+
if (isOxcNode(declaration)) {
|
|
121
|
+
walk(declaration, scope, node, ownerBindingId);
|
|
122
|
+
if ((declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") && declaration.id) {
|
|
123
|
+
recordReference(scope, declaration.id.name, ownerBindingId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (node.type === "VariableDeclaration") {
|
|
129
|
+
const { declarations } = node;
|
|
130
|
+
if (!Array.isArray(declarations)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
declarations.forEach((declarator) => {
|
|
134
|
+
const { id } = declarator;
|
|
135
|
+
if (isOxcNode(id)) {
|
|
136
|
+
addPatternBindings(scope, id, "variable", node);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
declarations.forEach((declarator) => {
|
|
140
|
+
const { id } = declarator;
|
|
141
|
+
const { init } = declarator;
|
|
142
|
+
if (!isOxcNode(id) || !isOxcNode(init)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const ownerName = collectDeclaredNames(id)[0] ?? null;
|
|
146
|
+
const nextOwner = ownerName !== null ? resolveScopedBinding(scope, ownerName) : null;
|
|
147
|
+
walk(init, scope, declarator, nextOwner);
|
|
148
|
+
});
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (node.type === "FunctionDeclaration" && node.id) {
|
|
152
|
+
const functionBindingId = addBinding(scope, node.id.name, "function", node);
|
|
153
|
+
const fnScope = createScopedCleanupScope(scope);
|
|
154
|
+
node.params.forEach((param) => {
|
|
155
|
+
addPatternBindings(fnScope, param, "param", param);
|
|
156
|
+
walkPatternReferenceSubexpressions(param, fnScope, functionBindingId);
|
|
157
|
+
});
|
|
158
|
+
if (node.body) {
|
|
159
|
+
walk(node.body, fnScope, node, functionBindingId);
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
164
|
+
const fnScope = createScopedCleanupScope(scope);
|
|
165
|
+
if (node.type === "FunctionExpression" && node.id) {
|
|
166
|
+
addBinding(fnScope, node.id.name, "function", node);
|
|
167
|
+
}
|
|
168
|
+
node.params.forEach((param) => {
|
|
169
|
+
addPatternBindings(fnScope, param, "param", param);
|
|
170
|
+
walkPatternReferenceSubexpressions(param, fnScope, ownerBindingId);
|
|
171
|
+
});
|
|
172
|
+
if (node.body) {
|
|
173
|
+
walk(node.body, fnScope, node, ownerBindingId);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (node.type === "BlockStatement") {
|
|
178
|
+
const blockScope = createScopedCleanupScope(scope);
|
|
179
|
+
getOxcNodeChildren(node).forEach((child) => walk(child, blockScope, node, ownerBindingId));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (isNodeReference(node, parent) && "name" in node && typeof node.name === "string") {
|
|
183
|
+
recordReference(scope, node.name, ownerBindingId);
|
|
184
|
+
}
|
|
185
|
+
getOxcNodeChildren(node).forEach((child) => walk(child, scope, node, ownerBindingId));
|
|
186
|
+
};
|
|
187
|
+
walk(program, createScopedCleanupScope(null));
|
|
188
|
+
return bindings;
|
|
189
|
+
};
|
|
190
|
+
export const collectScopedRemovableBindingIds = (bindings, initialNames) => {
|
|
191
|
+
const removable = new Set();
|
|
192
|
+
let changed = true;
|
|
193
|
+
while (changed) {
|
|
194
|
+
changed = false;
|
|
195
|
+
for (const binding of bindings.values()) {
|
|
196
|
+
if (!removable.has(binding.id) && binding.kind !== "import" && binding.kind !== "param" && binding.externalReferences === 0) {
|
|
197
|
+
const seededByName = initialNames.has(binding.name) || GENERATED_HELPER_NAME_RE.test(binding.name) && binding.incomingFromBindings.size === 0;
|
|
198
|
+
const allIncomingRemovable = binding.incomingFromBindings.size > 0 && [...binding.incomingFromBindings].every((sourceId) => removable.has(sourceId));
|
|
199
|
+
if (seededByName && binding.incomingFromBindings.size === 0 || allIncomingRemovable) {
|
|
200
|
+
removable.add(binding.id);
|
|
201
|
+
changed = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return removable;
|
|
207
|
+
};
|
|
208
|
+
export function expandImportRemovalRange(code, start, end) {
|
|
209
|
+
let removalStart = start;
|
|
210
|
+
while (removalStart > 0 && (code[removalStart - 1] === " " || code[removalStart - 1] === " ")) {
|
|
211
|
+
removalStart -= 1;
|
|
212
|
+
}
|
|
213
|
+
let removalEnd = end;
|
|
214
|
+
if (code[removalEnd] === ";") {
|
|
215
|
+
removalEnd += 1;
|
|
216
|
+
}
|
|
217
|
+
while (removalEnd < code.length && (code[removalEnd] === " " || code[removalEnd] === " ")) {
|
|
218
|
+
removalEnd += 1;
|
|
219
|
+
}
|
|
220
|
+
if (code[removalEnd] === "\r" && code[removalEnd + 1] === "\n") {
|
|
221
|
+
removalEnd += 2;
|
|
222
|
+
} else if (code[removalEnd] === "\n") {
|
|
223
|
+
removalEnd += 1;
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
end: removalEnd,
|
|
227
|
+
start: removalStart,
|
|
228
|
+
value: ""
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
export const collectUnusedScopedDeclarationRemovals = (code, bindings, initialRemovableNames) => {
|
|
232
|
+
const removableBindingIds = collectScopedRemovableBindingIds(bindings, initialRemovableNames);
|
|
233
|
+
const removals = new Map();
|
|
234
|
+
bindings.forEach((binding) => {
|
|
235
|
+
if (!removableBindingIds.has(binding.id) || binding.kind === "import" || binding.kind === "param" || binding.externalReferences > 0 || [...binding.incomingFromBindings].some((sourceId) => !removableBindingIds.has(sourceId))) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (binding.kind === "function" && binding.declaration.type === "FunctionDeclaration") {
|
|
239
|
+
const range = expandImportRemovalRange(code, binding.declaration.start, binding.declaration.end);
|
|
240
|
+
removals.set(`${range.start}:${range.end}`, range);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (binding.declaration.type !== "VariableDeclaration") {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const { declarations } = binding.declaration;
|
|
247
|
+
if (!Array.isArray(declarations) || declarations.length !== 1) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const range = expandImportRemovalRange(code, binding.declaration.start, binding.declaration.end);
|
|
251
|
+
removals.set(`${range.start}:${range.end}`, range);
|
|
252
|
+
});
|
|
253
|
+
return [...removals.values()];
|
|
254
|
+
};
|
|
255
|
+
export const expandImportSpecifierRemovalRange = (code, start, end) => {
|
|
256
|
+
let removalStart = start;
|
|
257
|
+
let removalEnd = end;
|
|
258
|
+
let whitespaceStart = removalStart;
|
|
259
|
+
while (whitespaceStart > 0 && (code[whitespaceStart - 1] === " " || code[whitespaceStart - 1] === " ")) {
|
|
260
|
+
whitespaceStart -= 1;
|
|
261
|
+
}
|
|
262
|
+
if (code[whitespaceStart - 1] !== "{") {
|
|
263
|
+
removalStart = whitespaceStart;
|
|
264
|
+
}
|
|
265
|
+
while (removalEnd < code.length && (code[removalEnd] === " " || code[removalEnd] === " ")) {
|
|
266
|
+
removalEnd += 1;
|
|
267
|
+
}
|
|
268
|
+
if (code[removalEnd] === ",") {
|
|
269
|
+
removalEnd += 1;
|
|
270
|
+
while (removalEnd < code.length && (code[removalEnd] === " " || code[removalEnd] === " ")) {
|
|
271
|
+
removalEnd += 1;
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
while (removalStart > 0 && (code[removalStart - 1] === " " || code[removalStart - 1] === " ")) {
|
|
275
|
+
removalStart -= 1;
|
|
276
|
+
}
|
|
277
|
+
if (code[removalStart - 1] === ",") {
|
|
278
|
+
removalStart -= 1;
|
|
279
|
+
while (removalStart > 0 && (code[removalStart - 1] === " " || code[removalStart - 1] === " ")) {
|
|
280
|
+
removalStart -= 1;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
end: removalEnd,
|
|
286
|
+
start: removalStart,
|
|
287
|
+
value: ""
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
export const mergeEmptyRemovalRanges = (removals) => {
|
|
291
|
+
if (removals.length <= 1) {
|
|
292
|
+
return removals;
|
|
293
|
+
}
|
|
294
|
+
const sorted = [...removals].sort((a, b) => a.start - b.start);
|
|
295
|
+
const merged = [];
|
|
296
|
+
sorted.forEach((removal) => {
|
|
297
|
+
const previous = merged[merged.length - 1];
|
|
298
|
+
if (previous && previous.value === "" && removal.value === "" && removal.start <= previous.end) {
|
|
299
|
+
previous.end = Math.max(previous.end, removal.end);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
merged.push({ ...removal });
|
|
303
|
+
});
|
|
304
|
+
return merged;
|
|
305
|
+
};
|
|
306
|
+
export const collectUnusedImportRemovals = (code, program, referencedNames, removableNames, preserveSideEffectImportLocals) => {
|
|
307
|
+
const removals = [];
|
|
308
|
+
program.body.forEach((statement) => {
|
|
309
|
+
if (statement.type !== "ImportDeclaration") {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const localNames = collectImportLocalNames(statement);
|
|
313
|
+
const removableLocalNames = localNames.filter((localName) => removableNames.has(localName));
|
|
314
|
+
if (removableLocalNames.length > 0 && removableLocalNames.length === localNames.length && removableLocalNames.every((localName) => !referencedNames.has(localName))) {
|
|
315
|
+
if (removableLocalNames.some((localName) => preserveSideEffectImportLocals.has(localName))) {
|
|
316
|
+
removals.push({
|
|
317
|
+
end: statement.end,
|
|
318
|
+
start: statement.start,
|
|
319
|
+
value: `import ${code.slice(statement.source.start, statement.source.end)};`
|
|
320
|
+
});
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
removals.push(expandImportRemovalRange(code, statement.start, statement.end));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const { specifiers } = statement;
|
|
327
|
+
if (!Array.isArray(specifiers) || specifiers.length <= 1) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
specifiers.forEach((specifier) => {
|
|
331
|
+
if (!isOxcNode(specifier)) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const localName = getImportSpecifierLocalName(specifier);
|
|
335
|
+
if (localName && removableNames.has(localName) && !referencedNames.has(localName)) {
|
|
336
|
+
removals.push(expandImportSpecifierRemovalRange(code, specifier.start, specifier.end));
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
return removals;
|
|
341
|
+
};
|
|
342
|
+
export const collectUnusedTopLevelDeclarationRemovals = (code, program, referencedNames, removableNames) => {
|
|
343
|
+
const removals = [];
|
|
344
|
+
program.body.forEach((statement) => {
|
|
345
|
+
if (statement.type !== "VariableDeclaration") {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const localNames = [...collectTopLevelBindings(statement)];
|
|
349
|
+
if (localNames.length > 0 && localNames.every((localName) => removableNames.has(localName)) && localNames.every((localName) => !referencedNames.has(localName))) {
|
|
350
|
+
removals.push(expandImportRemovalRange(code, statement.start, statement.end));
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
return removals;
|
|
354
|
+
};
|
|
355
|
+
export const collectUnusedGeneratedHelperDeclarationRemovals = (code, program, referencedNames) => {
|
|
356
|
+
const removals = [];
|
|
357
|
+
program.body.forEach((statement) => {
|
|
358
|
+
if (statement.type !== "VariableDeclaration") {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const localNames = [...collectTopLevelBindings(statement)];
|
|
362
|
+
if (localNames.length > 0 && localNames.every((localName) => GENERATED_HELPER_NAME_RE.test(localName)) && localNames.every((localName) => !referencedNames.has(localName))) {
|
|
363
|
+
removals.push(expandImportRemovalRange(code, statement.start, statement.end));
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
return removals;
|
|
367
|
+
};
|
|
368
|
+
export const collectTopLevelExpressionStatementRemovals = (code, statements, topLevelBindings, removableExpressionRefs) => {
|
|
369
|
+
const removals = [];
|
|
370
|
+
statements.forEach((statement) => {
|
|
371
|
+
if (statement.node.type !== "ExpressionStatement") {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const { expression } = statement.node;
|
|
375
|
+
const isPureExpression = expression.type === "Identifier" || expression.type === "Literal" || expression.type === "ObjectExpression" || expression.type === "ArrayExpression" || expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression" || expression.type === "TemplateLiteral" && expression.expressions.length === 0;
|
|
376
|
+
if (!isPureExpression) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const localReferences = [...statement.references].filter((name) => topLevelBindings.has(name));
|
|
380
|
+
if (localReferences.length > 0 && localReferences.every((name) => removableExpressionRefs.has(name))) {
|
|
381
|
+
removals.push(expandImportRemovalRange(code, statement.node.start, statement.node.end));
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
return removals;
|
|
385
|
+
};
|
|
386
|
+
export const collectEmptyTopLevelBlockRemovals = (code, program) => {
|
|
387
|
+
const removals = [];
|
|
388
|
+
program.body.forEach((statement) => {
|
|
389
|
+
if (statement.type !== "BlockStatement" || statement.body.length > 0) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
removals.push(expandImportRemovalRange(code, statement.start, statement.end));
|
|
393
|
+
});
|
|
394
|
+
return removals;
|
|
395
|
+
};
|
|
396
|
+
export const removeUnusedAfterReplacement = (code, filename, initialRemovableNames, removableExpressionRefs, preserveSideEffectImportLocals) => {
|
|
397
|
+
let current = code;
|
|
398
|
+
const cumulativeRemovableNames = new Set(initialRemovableNames);
|
|
399
|
+
const applyIfParsable = (next) => {
|
|
400
|
+
try {
|
|
401
|
+
parseOxc(next, filename);
|
|
402
|
+
return next;
|
|
403
|
+
} catch {
|
|
404
|
+
return current;
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
for (let idx = 0; idx < 5; idx += 1) {
|
|
408
|
+
const previous = current;
|
|
409
|
+
const program = parseOxc(current, filename);
|
|
410
|
+
const statements = collectTopLevelStatementInfos(program);
|
|
411
|
+
const removableNames = collectRemovableNamesFromStatements(statements, cumulativeRemovableNames);
|
|
412
|
+
removableNames.forEach((name) => cumulativeRemovableNames.add(name));
|
|
413
|
+
const referencedNames = collectReferencedNames(program);
|
|
414
|
+
const topLevelBindings = collectTopLevelBindingsFromStatements(statements);
|
|
415
|
+
const scopedBindings = collectScopedBindingInfos(program);
|
|
416
|
+
const removals = mergeEmptyRemovalRanges([
|
|
417
|
+
...collectUnusedScopedDeclarationRemovals(current, scopedBindings, cumulativeRemovableNames),
|
|
418
|
+
...collectUnusedTopLevelDeclarationRemovals(current, program, referencedNames, cumulativeRemovableNames),
|
|
419
|
+
...collectUnusedGeneratedHelperDeclarationRemovals(current, program, referencedNames),
|
|
420
|
+
...collectUnusedImportRemovals(current, program, referencedNames, cumulativeRemovableNames, preserveSideEffectImportLocals),
|
|
421
|
+
...collectTopLevelExpressionStatementRemovals(current, statements, topLevelBindings, removableExpressionRefs),
|
|
422
|
+
...collectEmptyTopLevelBlockRemovals(current, program)
|
|
423
|
+
]);
|
|
424
|
+
current = removals.length > 0 ? applyIfParsable(applyOxcReplacements(current, removals)) : current;
|
|
425
|
+
if (current === previous) {
|
|
426
|
+
return current;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return current;
|
|
430
|
+
};
|
|
431
|
+
//# sourceMappingURL=cleanupRemovals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAIA,SAAS,oBAAoB,iBAAiB;AAC9C,SAAS,4BAA4B;AACrC,SACE,sBACA,yBACA,wBACA,qCACA,yBACA,uCACA,+BACA,6BACA,uBACK;AACP,SAAS,0BAA0B,gBAAgB;AAUnD,OAAO,MAAM,4BACX,YACwB;CACxB,UAAU,IAAI,KAAK;CACnB;CACD;AAED,OAAO,MAAM,wBACX,OACA,SACkB;CAClB,IAAI,UAAqC;AACzC,QAAO,SAAS;EACd,MAAM,YAAY,QAAQ,SAAS,IAAI,KAAK;AAC5C,MAAI,WAAW;AACb,UAAO;;AAGT,YAAU,QAAQ;;AAGpB,QAAO;;AAGT,OAAO,MAAM,6BACX,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AACxB,UAAO;UACD;AACN,UAAO;;;AAIX,MAAK,IAAI,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG;EACnC,MAAM,WAAW;EACjB,MAAM,UAAU,SAAS,SAAS,SAAS;EAC3C,MAAM,aAAa,8BAA8B,QAAQ;EACzD,MAAM,iBAAiB,oCACrB,YACA,yBACD;AACD,iBAAe,SAAS,SAAS,yBAAyB,IAAI,KAAK,CAAC;EACpE,MAAM,kBAAkB,uBAAuB,QAAQ;EACvD,MAAM,mBAAmB,sCAAsC,WAAW;EAC1E,MAAM,iBAAiB,0BAA0B,QAAQ;EACzD,MAAM,WAAW,wBAAwB;GACvC,GAAG,uCACD,SACA,gBACA,yBACD;GACD,GAAG,yCACD,SACA,SACA,iBACA,yBACD;GACD,GAAG,gDACD,SACA,SACA,gBACD;GACD,GAAG,4BACD,SACA,SACA,iBACA,0BACA,+BACD;GACD,GAAG,2CACD,SACA,YACA,kBACA,wBACD;GACD,GAAG,kCAAkC,SAAS,QAAQ;GACvD,CAAC;AACF,YACE,SAAS,SAAS,IACd,gBAAgB,qBAAqB,SAAS,SAAS,CAAC,GACxD;AAEN,MAAI,YAAY,UAAU;AACxB,UAAO;;;AAIX,QAAO","names":[],"sources":["../../../src/utils/applyOxcProcessors/cleanupRemovals.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type { Node, Program } from 'oxc-parser';\n\nimport { getOxcNodeChildren, isOxcNode } from '../oxc/ast';\nimport { applyOxcReplacements } from '../oxc/replacements';\nimport {\n collectDeclaredNames,\n collectImportLocalNames,\n collectReferencedNames,\n collectRemovableNamesFromStatements,\n collectTopLevelBindings,\n collectTopLevelBindingsFromStatements,\n collectTopLevelStatementInfos,\n getImportSpecifierLocalName,\n isNodeReference,\n} from './cleanupBindings';\nimport { GENERATED_HELPER_NAME_RE, parseOxc } from './shared';\nimport type {\n AnyNode,\n Replacement,\n ScopedBindingInfo,\n ScopedBindingKind,\n ScopedCleanupScope,\n TopLevelStatementInfo,\n} from './types';\n\nexport const createScopedCleanupScope = (\n parent: ScopedCleanupScope | null\n): ScopedCleanupScope => ({\n bindings: new Map(),\n parent,\n});\n\nexport const resolveScopedBinding = (\n scope: ScopedCleanupScope,\n name: string\n): string | null => {\n let current: ScopedCleanupScope | null = scope;\n while (current) {\n const bindingId = current.bindings.get(name);\n if (bindingId) {\n return bindingId;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nexport const collectScopedBindingInfos = (\n program: Program\n): Map<string, ScopedBindingInfo> => {\n const bindings = new Map<string, ScopedBindingInfo>();\n let sequence = 0;\n\n const addBinding = (\n scope: ScopedCleanupScope,\n name: string,\n kind: ScopedBindingKind,\n declaration: Node\n ): string => {\n const id = `${kind}:${name}:${declaration.start}:${sequence}`;\n sequence += 1;\n\n bindings.set(id, {\n declaration,\n dependencies: new Set(),\n externalReferences: 0,\n id,\n incomingFromBindings: new Set(),\n kind,\n name,\n });\n scope.bindings.set(name, id);\n return id;\n };\n\n const addPatternBindings = (\n scope: ScopedCleanupScope,\n pattern: Node,\n kind: ScopedBindingKind,\n declaration: Node\n ): void => {\n collectDeclaredNames(pattern).forEach((name) => {\n addBinding(scope, name, kind, declaration);\n });\n };\n\n const recordReference = (\n scope: ScopedCleanupScope,\n name: string,\n ownerBindingId: string | null\n ): void => {\n const targetId = resolveScopedBinding(scope, name);\n if (!targetId) {\n return;\n }\n\n const target = bindings.get(targetId);\n if (!target) {\n return;\n }\n\n if (ownerBindingId && ownerBindingId !== targetId) {\n target.incomingFromBindings.add(ownerBindingId);\n bindings.get(ownerBindingId)?.dependencies.add(targetId);\n return;\n }\n\n target.externalReferences += 1;\n };\n\n type ScopedWalk = (\n node: Node,\n scope: ScopedCleanupScope,\n parent?: Node | null,\n ownerBindingId?: string | null\n ) => void;\n\n let walk: ScopedWalk;\n\n function walkPatternReferenceSubexpressions(\n node: Node,\n scope: ScopedCleanupScope,\n ownerBindingId: string | null\n ): void {\n if (node.type === 'Identifier') {\n return;\n }\n\n if (node.type === 'TSParameterProperty') {\n walkPatternReferenceSubexpressions(node.parameter, scope, ownerBindingId);\n return;\n }\n\n if (node.type === 'RestElement') {\n walkPatternReferenceSubexpressions(node.argument, scope, ownerBindingId);\n return;\n }\n\n if (node.type === 'AssignmentPattern') {\n walkPatternReferenceSubexpressions(node.left, scope, ownerBindingId);\n walk(node.right, scope, node, ownerBindingId);\n return;\n }\n\n if (node.type === 'ObjectPattern') {\n node.properties.forEach((property) => {\n if (property.type === 'RestElement') {\n walkPatternReferenceSubexpressions(\n property.argument,\n scope,\n ownerBindingId\n );\n return;\n }\n\n if (property.computed && isOxcNode(property.key)) {\n walk(property.key, scope, property, ownerBindingId);\n }\n\n walkPatternReferenceSubexpressions(\n property.value,\n scope,\n ownerBindingId\n );\n });\n return;\n }\n\n if (node.type === 'ArrayPattern') {\n node.elements.forEach((element) => {\n if (element && isOxcNode(element)) {\n walkPatternReferenceSubexpressions(element, scope, ownerBindingId);\n }\n });\n }\n }\n\n walk = (\n node: Node,\n scope: ScopedCleanupScope,\n parent: Node | null = null,\n ownerBindingId: string | null = null\n ): void => {\n if (node.type === 'ImportDeclaration') {\n const { specifiers } = node as AnyNode;\n if (Array.isArray(specifiers)) {\n specifiers.forEach((specifier) => {\n const { local } = specifier as AnyNode;\n if (\n isOxcNode(local) &&\n local.type === 'Identifier' &&\n typeof local.name === 'string'\n ) {\n addBinding(scope, local.name, 'import', node);\n }\n });\n }\n return;\n }\n\n if (node.type === 'ExportNamedDeclaration' && node.declaration) {\n walk(node.declaration, scope, node, ownerBindingId);\n collectTopLevelBindings(node).forEach((name) => {\n recordReference(scope, name, ownerBindingId);\n });\n return;\n }\n\n if (node.type === 'ExportDefaultDeclaration') {\n const { declaration } = node as AnyNode;\n if (isOxcNode(declaration)) {\n walk(declaration, scope, node, ownerBindingId);\n if (\n (declaration.type === 'FunctionDeclaration' ||\n declaration.type === 'ClassDeclaration') &&\n declaration.id\n ) {\n recordReference(scope, declaration.id.name, ownerBindingId);\n }\n }\n return;\n }\n\n if (node.type === 'VariableDeclaration') {\n const { declarations } = node as AnyNode;\n if (!Array.isArray(declarations)) {\n return;\n }\n\n declarations.forEach((declarator) => {\n const { id } = declarator as AnyNode;\n if (isOxcNode(id)) {\n addPatternBindings(scope, id, 'variable', node);\n }\n });\n\n declarations.forEach((declarator) => {\n const { id } = declarator as AnyNode;\n const { init } = declarator as AnyNode;\n if (!isOxcNode(id) || !isOxcNode(init)) {\n return;\n }\n\n const ownerName = collectDeclaredNames(id)[0] ?? null;\n const nextOwner =\n ownerName !== null ? resolveScopedBinding(scope, ownerName) : null;\n walk(init, scope, declarator as Node, nextOwner);\n });\n return;\n }\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n const functionBindingId = addBinding(\n scope,\n node.id.name,\n 'function',\n node\n );\n const fnScope = createScopedCleanupScope(scope);\n\n node.params.forEach((param) => {\n addPatternBindings(fnScope, param, 'param', param);\n walkPatternReferenceSubexpressions(param, fnScope, functionBindingId);\n });\n\n if (node.body) {\n walk(node.body, fnScope, node, functionBindingId);\n }\n return;\n }\n\n if (\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n const fnScope = createScopedCleanupScope(scope);\n if (node.type === 'FunctionExpression' && node.id) {\n addBinding(fnScope, node.id.name, 'function', node);\n }\n\n node.params.forEach((param) => {\n addPatternBindings(fnScope, param, 'param', param);\n walkPatternReferenceSubexpressions(param, fnScope, ownerBindingId);\n });\n\n if (node.body) {\n walk(node.body, fnScope, node, ownerBindingId);\n }\n return;\n }\n\n if (node.type === 'BlockStatement') {\n const blockScope = createScopedCleanupScope(scope);\n getOxcNodeChildren(node).forEach((child) =>\n walk(child, blockScope, node, ownerBindingId)\n );\n return;\n }\n\n if (\n isNodeReference(node, parent) &&\n 'name' in node &&\n typeof node.name === 'string'\n ) {\n recordReference(scope, node.name, ownerBindingId);\n }\n\n getOxcNodeChildren(node).forEach((child) =>\n walk(child, scope, node, ownerBindingId)\n );\n };\n\n walk(program, createScopedCleanupScope(null));\n return bindings;\n};\n\nexport const collectScopedRemovableBindingIds = (\n bindings: Map<string, ScopedBindingInfo>,\n initialNames: Set<string>\n): Set<string> => {\n const removable = new Set<string>();\n let changed = true;\n\n while (changed) {\n changed = false;\n\n for (const binding of bindings.values()) {\n if (\n !removable.has(binding.id) &&\n binding.kind !== 'import' &&\n binding.kind !== 'param' &&\n binding.externalReferences === 0\n ) {\n const seededByName =\n initialNames.has(binding.name) ||\n (GENERATED_HELPER_NAME_RE.test(binding.name) &&\n binding.incomingFromBindings.size === 0);\n const allIncomingRemovable =\n binding.incomingFromBindings.size > 0 &&\n [...binding.incomingFromBindings].every((sourceId) =>\n removable.has(sourceId)\n );\n\n if (\n (seededByName && binding.incomingFromBindings.size === 0) ||\n allIncomingRemovable\n ) {\n removable.add(binding.id);\n changed = true;\n }\n }\n }\n }\n\n return removable;\n};\n\nexport function expandImportRemovalRange(\n code: string,\n start: number,\n end: number\n): Replacement {\n let removalStart = start;\n while (\n removalStart > 0 &&\n (code[removalStart - 1] === ' ' || code[removalStart - 1] === '\\t')\n ) {\n removalStart -= 1;\n }\n\n let removalEnd = end;\n if (code[removalEnd] === ';') {\n removalEnd += 1;\n }\n\n while (\n removalEnd < code.length &&\n (code[removalEnd] === ' ' || code[removalEnd] === '\\t')\n ) {\n removalEnd += 1;\n }\n\n if (code[removalEnd] === '\\r' && code[removalEnd + 1] === '\\n') {\n removalEnd += 2;\n } else if (code[removalEnd] === '\\n') {\n removalEnd += 1;\n }\n\n return {\n end: removalEnd,\n start: removalStart,\n value: '',\n };\n}\n\nexport const collectUnusedScopedDeclarationRemovals = (\n code: string,\n bindings: Map<string, ScopedBindingInfo>,\n initialRemovableNames: Set<string>\n): Replacement[] => {\n const removableBindingIds = collectScopedRemovableBindingIds(\n bindings,\n initialRemovableNames\n );\n const removals = new Map<string, Replacement>();\n\n bindings.forEach((binding) => {\n if (\n !removableBindingIds.has(binding.id) ||\n binding.kind === 'import' ||\n binding.kind === 'param' ||\n binding.externalReferences > 0 ||\n [...binding.incomingFromBindings].some(\n (sourceId) => !removableBindingIds.has(sourceId)\n )\n ) {\n return;\n }\n\n if (\n binding.kind === 'function' &&\n binding.declaration.type === 'FunctionDeclaration'\n ) {\n const range = expandImportRemovalRange(\n code,\n binding.declaration.start,\n binding.declaration.end\n );\n removals.set(`${range.start}:${range.end}`, range);\n return;\n }\n\n if (binding.declaration.type !== 'VariableDeclaration') {\n return;\n }\n\n const { declarations } = binding.declaration as AnyNode;\n if (!Array.isArray(declarations) || declarations.length !== 1) {\n return;\n }\n\n const range = expandImportRemovalRange(\n code,\n binding.declaration.start,\n binding.declaration.end\n );\n removals.set(`${range.start}:${range.end}`, range);\n });\n\n return [...removals.values()];\n};\n\nexport const expandImportSpecifierRemovalRange = (\n code: string,\n start: number,\n end: number\n): Replacement => {\n let removalStart = start;\n let removalEnd = end;\n\n let whitespaceStart = removalStart;\n while (\n whitespaceStart > 0 &&\n (code[whitespaceStart - 1] === ' ' || code[whitespaceStart - 1] === '\\t')\n ) {\n whitespaceStart -= 1;\n }\n if (code[whitespaceStart - 1] !== '{') {\n removalStart = whitespaceStart;\n }\n\n while (\n removalEnd < code.length &&\n (code[removalEnd] === ' ' || code[removalEnd] === '\\t')\n ) {\n removalEnd += 1;\n }\n\n if (code[removalEnd] === ',') {\n removalEnd += 1;\n while (\n removalEnd < code.length &&\n (code[removalEnd] === ' ' || code[removalEnd] === '\\t')\n ) {\n removalEnd += 1;\n }\n } else {\n while (\n removalStart > 0 &&\n (code[removalStart - 1] === ' ' || code[removalStart - 1] === '\\t')\n ) {\n removalStart -= 1;\n }\n\n if (code[removalStart - 1] === ',') {\n removalStart -= 1;\n while (\n removalStart > 0 &&\n (code[removalStart - 1] === ' ' || code[removalStart - 1] === '\\t')\n ) {\n removalStart -= 1;\n }\n }\n }\n\n return {\n end: removalEnd,\n start: removalStart,\n value: '',\n };\n};\n\nexport const mergeEmptyRemovalRanges = (\n removals: Replacement[]\n): Replacement[] => {\n if (removals.length <= 1) {\n return removals;\n }\n\n const sorted = [...removals].sort((a, b) => a.start - b.start);\n const merged: Replacement[] = [];\n\n sorted.forEach((removal) => {\n const previous = merged[merged.length - 1];\n if (\n previous &&\n previous.value === '' &&\n removal.value === '' &&\n removal.start <= previous.end\n ) {\n previous.end = Math.max(previous.end, removal.end);\n return;\n }\n\n merged.push({ ...removal });\n });\n\n return merged;\n};\n\nexport const collectUnusedImportRemovals = (\n code: string,\n program: Program,\n referencedNames: Set<string>,\n removableNames: Set<string>,\n preserveSideEffectImportLocals: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n const localNames = collectImportLocalNames(statement);\n const removableLocalNames = localNames.filter((localName) =>\n removableNames.has(localName)\n );\n if (\n removableLocalNames.length > 0 &&\n removableLocalNames.length === localNames.length &&\n removableLocalNames.every((localName) => !referencedNames.has(localName))\n ) {\n if (\n removableLocalNames.some((localName) =>\n preserveSideEffectImportLocals.has(localName)\n )\n ) {\n removals.push({\n end: statement.end,\n start: statement.start,\n value: `import ${code.slice(\n statement.source.start,\n statement.source.end\n )};`,\n });\n return;\n }\n\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n return;\n }\n\n const { specifiers } = statement as AnyNode;\n if (!Array.isArray(specifiers) || specifiers.length <= 1) {\n return;\n }\n\n specifiers.forEach((specifier) => {\n if (!isOxcNode(specifier)) {\n return;\n }\n\n const localName = getImportSpecifierLocalName(specifier);\n if (\n localName &&\n removableNames.has(localName) &&\n !referencedNames.has(localName)\n ) {\n removals.push(\n expandImportSpecifierRemovalRange(\n code,\n specifier.start,\n specifier.end\n )\n );\n }\n });\n });\n\n return removals;\n};\n\nexport const collectUnusedTopLevelDeclarationRemovals = (\n code: string,\n program: Program,\n referencedNames: Set<string>,\n removableNames: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'VariableDeclaration') {\n return;\n }\n\n const localNames = [...collectTopLevelBindings(statement)];\n\n if (\n localNames.length > 0 &&\n localNames.every((localName) => removableNames.has(localName)) &&\n localNames.every((localName) => !referencedNames.has(localName))\n ) {\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n }\n });\n\n return removals;\n};\n\nexport const collectUnusedGeneratedHelperDeclarationRemovals = (\n code: string,\n program: Program,\n referencedNames: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'VariableDeclaration') {\n return;\n }\n\n const localNames = [...collectTopLevelBindings(statement)];\n if (\n localNames.length > 0 &&\n localNames.every((localName) =>\n GENERATED_HELPER_NAME_RE.test(localName)\n ) &&\n localNames.every((localName) => !referencedNames.has(localName))\n ) {\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n }\n });\n\n return removals;\n};\n\nexport const collectTopLevelExpressionStatementRemovals = (\n code: string,\n statements: TopLevelStatementInfo[],\n topLevelBindings: Set<string>,\n removableExpressionRefs: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n statements.forEach((statement) => {\n if (statement.node.type !== 'ExpressionStatement') {\n return;\n }\n\n const { expression } = statement.node;\n const isPureExpression =\n expression.type === 'Identifier' ||\n expression.type === 'Literal' ||\n expression.type === 'ObjectExpression' ||\n expression.type === 'ArrayExpression' ||\n expression.type === 'ArrowFunctionExpression' ||\n expression.type === 'FunctionExpression' ||\n (expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0);\n if (!isPureExpression) {\n return;\n }\n\n const localReferences = [...statement.references].filter((name) =>\n topLevelBindings.has(name)\n );\n\n if (\n localReferences.length > 0 &&\n localReferences.every((name) => removableExpressionRefs.has(name))\n ) {\n removals.push(\n expandImportRemovalRange(code, statement.node.start, statement.node.end)\n );\n }\n });\n\n return removals;\n};\n\nexport const collectEmptyTopLevelBlockRemovals = (\n code: string,\n program: Program\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'BlockStatement' || statement.body.length > 0) {\n return;\n }\n\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n });\n\n return removals;\n};\n\nexport const removeUnusedAfterReplacement = (\n code: string,\n filename: string,\n initialRemovableNames: Set<string>,\n removableExpressionRefs: Set<string>,\n preserveSideEffectImportLocals: Set<string>\n): string => {\n let current = code;\n const cumulativeRemovableNames = new Set(initialRemovableNames);\n const applyIfParsable = (next: string): string => {\n try {\n parseOxc(next, filename);\n return next;\n } catch {\n return current;\n }\n };\n\n for (let idx = 0; idx < 5; idx += 1) {\n const previous = current;\n const program = parseOxc(current, filename);\n const statements = collectTopLevelStatementInfos(program);\n const removableNames = collectRemovableNamesFromStatements(\n statements,\n cumulativeRemovableNames\n );\n removableNames.forEach((name) => cumulativeRemovableNames.add(name));\n const referencedNames = collectReferencedNames(program);\n const topLevelBindings = collectTopLevelBindingsFromStatements(statements);\n const scopedBindings = collectScopedBindingInfos(program);\n const removals = mergeEmptyRemovalRanges([\n ...collectUnusedScopedDeclarationRemovals(\n current,\n scopedBindings,\n cumulativeRemovableNames\n ),\n ...collectUnusedTopLevelDeclarationRemovals(\n current,\n program,\n referencedNames,\n cumulativeRemovableNames\n ),\n ...collectUnusedGeneratedHelperDeclarationRemovals(\n current,\n program,\n referencedNames\n ),\n ...collectUnusedImportRemovals(\n current,\n program,\n referencedNames,\n cumulativeRemovableNames,\n preserveSideEffectImportLocals\n ),\n ...collectTopLevelExpressionStatementRemovals(\n current,\n statements,\n topLevelBindings,\n removableExpressionRefs\n ),\n ...collectEmptyTopLevelBlockRemovals(current, program),\n ]);\n current =\n removals.length > 0\n ? applyIfParsable(applyOxcReplacements(current, removals))\n : current;\n\n if (current === previous) {\n return current;\n }\n }\n\n return current;\n};\n"],"file":"cleanupRemovals.js"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
import { basename, dirname } from "path";
|
|
3
|
+
import { ValueType } from "@wyw-in-js/shared";
|
|
4
|
+
import { isOxcNode, walkOxc } from "../oxc/ast.js";
|
|
5
|
+
import { isNodeReference } from "./cleanupBindings.js";
|
|
6
|
+
export const getPropertyKeyName = (property, code) => {
|
|
7
|
+
const { key } = property;
|
|
8
|
+
if (!isOxcNode(key)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
if (key.type === "Identifier") {
|
|
12
|
+
return key.name;
|
|
13
|
+
}
|
|
14
|
+
if (key.type === "Literal") {
|
|
15
|
+
return String(key.value);
|
|
16
|
+
}
|
|
17
|
+
return typeof key.start === "number" && typeof key.end === "number" ? code.slice(key.start, key.end) : null;
|
|
18
|
+
};
|
|
19
|
+
export const getDisplayName = (ancestors, idx, code, filename) => {
|
|
20
|
+
const owner = [...ancestors].reverse().find((node) => {
|
|
21
|
+
return node.type === "Property" || node.type === "JSXOpeningElement" || node.type === "VariableDeclarator";
|
|
22
|
+
});
|
|
23
|
+
if (owner?.type === "Property") {
|
|
24
|
+
const keyName = getPropertyKeyName(owner, code);
|
|
25
|
+
if (keyName) {
|
|
26
|
+
return keyName;
|
|
27
|
+
}
|
|
28
|
+
} else if (owner?.type === "JSXOpeningElement") {
|
|
29
|
+
const { name } = owner;
|
|
30
|
+
if (isOxcNode(name) && name.type === "JSXIdentifier") {
|
|
31
|
+
return name.name;
|
|
32
|
+
}
|
|
33
|
+
} else if (owner?.type === "VariableDeclarator") {
|
|
34
|
+
const { id } = owner;
|
|
35
|
+
if (isOxcNode(id) && id.type === "Identifier") {
|
|
36
|
+
return id.name;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let displayName = basename(filename ?? "unknown").replace(/\.[a-z\d]+$/, "");
|
|
40
|
+
if (filename && /^index\.[a-z\d]+$/.test(basename(filename))) {
|
|
41
|
+
displayName = basename(dirname(filename));
|
|
42
|
+
}
|
|
43
|
+
if (!displayName) {
|
|
44
|
+
throw new Error("Couldn't determine a name for the component. Ensure that it's either:\n" + "- Assigned to a variable\n" + "- Is an object property\n" + "- Is a prop in a JSX element\n");
|
|
45
|
+
}
|
|
46
|
+
return `${displayName}${idx}`;
|
|
47
|
+
};
|
|
48
|
+
export const getTagOwner = (ancestors) => {
|
|
49
|
+
const owner = [...ancestors].reverse().find((node) => node.type === "Property" || node.type === "JSXOpeningElement" || node.type === "VariableDeclarator");
|
|
50
|
+
return owner ?? null;
|
|
51
|
+
};
|
|
52
|
+
export const isTagReferenced = (program, ancestors) => {
|
|
53
|
+
const owner = getTagOwner(ancestors);
|
|
54
|
+
if (owner?.type !== "VariableDeclarator") {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const { id } = owner;
|
|
58
|
+
if (!isOxcNode(id) || id.type !== "Identifier") {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (ancestors.some((node) => node.type === "ExportNamedDeclaration")) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
let referenced = false;
|
|
65
|
+
walkOxc(program, (node, parent) => {
|
|
66
|
+
const referenceName = node.type === "Identifier" || node.type === "JSXIdentifier" ? node.name : null;
|
|
67
|
+
if (referenced || referenceName !== id.name || node.type === "Identifier" && node.start === id.start && node.end === id.end) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
referenced = isNodeReference(node, parent);
|
|
71
|
+
});
|
|
72
|
+
return referenced;
|
|
73
|
+
};
|
|
74
|
+
export const collectSameFileProcessorStaticValues = (expressionValues, processorStaticValuesByLocal) => {
|
|
75
|
+
const staticValues = [];
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
expressionValues.forEach((value) => {
|
|
78
|
+
if (value.kind !== ValueType.LAZY) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const staticValue = processorStaticValuesByLocal.get(value.source);
|
|
82
|
+
if (staticValue === undefined || value.ex.type !== "Identifier" || seen.has(value.ex.name)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
seen.add(value.ex.name);
|
|
86
|
+
staticValues.push({
|
|
87
|
+
name: value.ex.name,
|
|
88
|
+
value: staticValue
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return staticValues;
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=displayName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAEA,SAAS,UAAU,eAAe;AAGlC,SAAS,iBAAiB;AAI1B,SAAS,WAAW,eAAe;AACnC,SAAS,uBAAuB;AAGhC,OAAO,MAAM,sBACX,UACA,SACkB;CAClB,MAAM,EAAE,QAAQ;AAChB,KAAI,CAAC,UAAU,IAAI,EAAE;AACnB,SAAO;;AAGT,KAAI,IAAI,SAAS,cAAc;AAC7B,SAAO,IAAI;;AAGb,KAAI,IAAI,SAAS,WAAW;AAC1B,SAAO,OAAO,IAAI,MAAM;;AAG1B,QAAO,OAAO,IAAI,UAAU,YAAY,OAAO,IAAI,QAAQ,WACvD,KAAK,MAAM,IAAI,OAAO,IAAI,IAAI,GAC9B;;AAGN,OAAO,MAAM,kBACX,WACA,KACA,MACA,aACW;CACX,MAAM,QAAQ,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,MAAM,SAAS;AACpD,SACE,KAAK,SAAS,cACd,KAAK,SAAS,uBACd,KAAK,SAAS;GAEhB;AAEF,KAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,UAAU,mBAAmB,OAAO,KAAK;AAC/C,MAAI,SAAS;AACX,UAAO;;YAEA,OAAO,SAAS,qBAAqB;EAC9C,MAAM,EAAE,SAAS;AACjB,MAAI,UAAU,KAAK,IAAI,KAAK,SAAS,iBAAiB;AACpD,UAAO,KAAK;;YAEL,OAAO,SAAS,sBAAsB;EAC/C,MAAM,EAAE,OAAO;AACf,MAAI,UAAU,GAAG,IAAI,GAAG,SAAS,cAAc;AAC7C,UAAO,GAAG;;;CAId,IAAI,cAAc,SAAS,YAAY,UAAU,CAAC,QAAQ,eAAe,GAAG;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K,IAAI,MAAM,GAAG,KAAK;AACvB,eAAa,KAAK;GAChB,MAAM,MAAM,GAAG;GACf,OAAO;GACR,CAAC;GACF;AAEF,QAAO","names":[],"sources":["../../../src/utils/applyOxcProcessors/displayName.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport { basename, dirname } from 'path';\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\nimport type { Node, Program } from 'oxc-parser';\n\nimport type { OxcStaticValue } from '../collectOxcTemplateDependencies';\nimport { isOxcNode, walkOxc } from '../oxc/ast';\nimport { isNodeReference } from './cleanupBindings';\nimport type { AnyNode } from './types';\n\nexport const getPropertyKeyName = (\n property: AnyNode,\n code: string\n): string | null => {\n const { key } = property;\n if (!isOxcNode(key)) {\n return null;\n }\n\n if (key.type === 'Identifier') {\n return key.name;\n }\n\n if (key.type === 'Literal') {\n return String(key.value);\n }\n\n return typeof key.start === 'number' && typeof key.end === 'number'\n ? code.slice(key.start, key.end)\n : null;\n};\n\nexport const getDisplayName = (\n ancestors: Node[],\n idx: number,\n code: string,\n filename?: string | null\n): string => {\n const owner = [...ancestors].reverse().find((node) => {\n return (\n node.type === 'Property' ||\n node.type === 'JSXOpeningElement' ||\n node.type === 'VariableDeclarator'\n );\n }) as AnyNode | undefined;\n\n if (owner?.type === 'Property') {\n const keyName = getPropertyKeyName(owner, code);\n if (keyName) {\n return keyName;\n }\n } else if (owner?.type === 'JSXOpeningElement') {\n const { name } = owner;\n if (isOxcNode(name) && name.type === 'JSXIdentifier') {\n return name.name;\n }\n } else if (owner?.type === 'VariableDeclarator') {\n const { id } = owner;\n if (isOxcNode(id) && id.type === 'Identifier') {\n return id.name;\n }\n }\n\n let displayName = basename(filename ?? 'unknown').replace(/\\.[a-z\\d]+$/, '');\n if (filename && /^index\\.[a-z\\d]+$/.test(basename(filename))) {\n displayName = basename(dirname(filename));\n }\n\n if (!displayName) {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n\n return `${displayName}${idx}`;\n};\n\nexport const getTagOwner = (ancestors: Node[]): AnyNode | null => {\n const owner = [...ancestors]\n .reverse()\n .find(\n (node) =>\n node.type === 'Property' ||\n node.type === 'JSXOpeningElement' ||\n node.type === 'VariableDeclarator'\n ) as AnyNode | undefined;\n\n return owner ?? null;\n};\n\nexport const isTagReferenced = (\n program: Program,\n ancestors: Node[]\n): boolean => {\n const owner = getTagOwner(ancestors);\n if (owner?.type !== 'VariableDeclarator') {\n return true;\n }\n\n const { id } = owner;\n if (!isOxcNode(id) || id.type !== 'Identifier') {\n return true;\n }\n\n if (ancestors.some((node) => node.type === 'ExportNamedDeclaration')) {\n return true;\n }\n\n let referenced = false;\n walkOxc(program, (node, parent) => {\n const referenceName =\n node.type === 'Identifier' || node.type === 'JSXIdentifier'\n ? node.name\n : null;\n\n if (\n referenced ||\n referenceName !== id.name ||\n (node.type === 'Identifier' &&\n node.start === id.start &&\n node.end === id.end)\n ) {\n return;\n }\n\n referenced = isNodeReference(node, parent);\n });\n\n return referenced;\n};\n\nexport const collectSameFileProcessorStaticValues = (\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[],\n processorStaticValuesByLocal: Map<string, unknown>\n): OxcStaticValue[] => {\n const staticValues: OxcStaticValue[] = [];\n const seen = new Set<string>();\n\n expressionValues.forEach((value) => {\n if (value.kind !== ValueType.LAZY) {\n return;\n }\n\n const staticValue = processorStaticValuesByLocal.get(value.source);\n if (\n staticValue === undefined ||\n value.ex.type !== 'Identifier' ||\n seen.has(value.ex.name)\n ) {\n return;\n }\n\n seen.add(value.ex.name);\n staticValues.push({\n name: value.ex.name,\n value: staticValue,\n });\n });\n\n return staticValues;\n};\n"],"file":"displayName.js"}
|