@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,113 @@
|
|
|
1
|
+
import { getOxcNodeChildren } from "../oxc/ast.js";
|
|
2
|
+
import { isBindingPosition, isInTypeContext, isObjectPropertyKey, isPropertyOnlyIdentifier, resolveBindingAt } from "./scopeAnalysis.js";
|
|
3
|
+
import { evaluateStatic, literalCode } from "./staticEvaluator.js";
|
|
4
|
+
export const getConstantReplacement = (binding, ctx) => {
|
|
5
|
+
const init = binding?.declarator?.init;
|
|
6
|
+
if (!init) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (init.type === "Literal") {
|
|
10
|
+
return literalCode(init.value);
|
|
11
|
+
}
|
|
12
|
+
if (init.type === "ObjectExpression" && binding?.isRoot && binding.declarator?.id.type === "Identifier") {
|
|
13
|
+
const evaluated = evaluateStatic(binding.declarator.id, ctx);
|
|
14
|
+
return literalCode(evaluated);
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
18
|
+
export const collectIdentifierReferenceReplacements = (expression, replacements) => {
|
|
19
|
+
const localReplacements = [];
|
|
20
|
+
const ancestors = [];
|
|
21
|
+
const walk = (current, parent) => {
|
|
22
|
+
if (current.type === "Identifier" && replacements.has(current.name) && !isInTypeContext(ancestors) && !isBindingPosition(current, parent) && !isPropertyOnlyIdentifier(current, parent) && !isObjectPropertyKey(current, parent)) {
|
|
23
|
+
const replacement = replacements.get(current.name);
|
|
24
|
+
// Shorthand property `{ width }` → `{ width: 500 }` when the
|
|
25
|
+
// identifier is the value side of a shorthand ObjectProperty.
|
|
26
|
+
const isShorthandValue = !!parent && parent.type === "Property" && parent.shorthand && parent.value === current;
|
|
27
|
+
localReplacements.push({
|
|
28
|
+
start: isShorthandValue ? parent.start : current.start,
|
|
29
|
+
end: current.end,
|
|
30
|
+
value: isShorthandValue ? `${current.name}: ${replacement}` : replacement
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
ancestors.push(current);
|
|
34
|
+
getOxcNodeChildren(current).forEach((child) => walk(child, current));
|
|
35
|
+
ancestors.pop();
|
|
36
|
+
};
|
|
37
|
+
walk(expression, null);
|
|
38
|
+
return localReplacements;
|
|
39
|
+
};
|
|
40
|
+
export const applyExpressionReplacements = (expression, replacements, code) => {
|
|
41
|
+
let result = code.slice(expression.start, expression.end);
|
|
42
|
+
replacements.sort((a, b) => b.start - a.start).forEach((replacement) => {
|
|
43
|
+
const start = replacement.start - expression.start;
|
|
44
|
+
const end = replacement.end - expression.start;
|
|
45
|
+
result = result.slice(0, start) + replacement.value + result.slice(end);
|
|
46
|
+
});
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
export const replaceIdentifierReferences = (expression, replacements, code) => {
|
|
50
|
+
return applyExpressionReplacements(expression, collectIdentifierReferenceReplacements(expression, replacements), code);
|
|
51
|
+
};
|
|
52
|
+
const staticImportAliasPart = (value) => value.replace(/[^A-Za-z0-9_$]/g, "_") || "value";
|
|
53
|
+
const allocateStaticImportAlias = (binding, imported, ctx) => {
|
|
54
|
+
const key = `${binding.importedFrom ?? ""}\0${binding.name}\0${imported}`;
|
|
55
|
+
const existing = ctx.staticImportAliases.get(key);
|
|
56
|
+
if (existing) {
|
|
57
|
+
return existing;
|
|
58
|
+
}
|
|
59
|
+
const namespacePart = staticImportAliasPart(binding.name);
|
|
60
|
+
const importedPart = staticImportAliasPart(imported);
|
|
61
|
+
let alias = `_wyw_static_${namespacePart}_${importedPart}`;
|
|
62
|
+
let idx = 1;
|
|
63
|
+
while (ctx.usedNames.has(alias)) {
|
|
64
|
+
idx += 1;
|
|
65
|
+
alias = `_wyw_static_${namespacePart}_${importedPart}_${idx}`;
|
|
66
|
+
}
|
|
67
|
+
ctx.usedNames.add(alias);
|
|
68
|
+
ctx.staticImportAliases.set(key, alias);
|
|
69
|
+
return alias;
|
|
70
|
+
};
|
|
71
|
+
const staticMemberPropertyName = (expression) => {
|
|
72
|
+
if (!expression.computed && expression.property.type === "Identifier") {
|
|
73
|
+
return expression.property.name;
|
|
74
|
+
}
|
|
75
|
+
if (expression.computed && expression.property.type === "Literal" && typeof expression.property.value === "string") {
|
|
76
|
+
return expression.property.value;
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
};
|
|
80
|
+
export const collectStaticNamespaceMemberReferences = (expression, ctx) => {
|
|
81
|
+
const coveredReferenceStarts = new Set();
|
|
82
|
+
const imports = new Map();
|
|
83
|
+
const replacements = [];
|
|
84
|
+
const walk = (node) => {
|
|
85
|
+
if (node.type === "MemberExpression" && node.object.type === "Identifier") {
|
|
86
|
+
const binding = resolveBindingAt(ctx, node.object.name, node.object.start);
|
|
87
|
+
const imported = staticMemberPropertyName(node);
|
|
88
|
+
if (binding?.importedFrom && binding.imported === "*" && imported !== null) {
|
|
89
|
+
const alias = allocateStaticImportAlias(binding, imported, ctx);
|
|
90
|
+
imports.set(`${binding.importedFrom}\0${imported}\0${alias}`, {
|
|
91
|
+
imported,
|
|
92
|
+
importLocal: binding.name,
|
|
93
|
+
local: alias,
|
|
94
|
+
source: binding.importedFrom
|
|
95
|
+
});
|
|
96
|
+
replacements.push({
|
|
97
|
+
end: node.end,
|
|
98
|
+
start: node.start,
|
|
99
|
+
value: alias
|
|
100
|
+
});
|
|
101
|
+
coveredReferenceStarts.add(node.object.start);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getOxcNodeChildren(node).forEach(walk);
|
|
105
|
+
};
|
|
106
|
+
walk(expression);
|
|
107
|
+
return {
|
|
108
|
+
coveredReferenceStarts,
|
|
109
|
+
imports: [...imports.values()],
|
|
110
|
+
replacements
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
//# s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BAAyB,IAAI,KAAa;CAChD,MAAM,UAAU,IAAI,KAAuC;CAC3D,MAAM,eAA8B,EAAE;CAEtC,MAAM,QAAQ,SAAqB;AACjC,MAAI,KAAK,SAAS,sBAAsB,KAAK,OAAO,SAAS,cAAc;GACzE,MAAM,UAAU,iBACd,KACA,KAAK,OAAO,MACZ,KAAK,OAAO,MACb;GACD,MAAM,WAAW,yBAAyB,KAAK;AAC/C,OACE,SAAS,gBACT,QAAQ,aAAa,OACrB,aAAa,MACb;IACA,MAAM,QAAQ,0BAA0B,SAAS,UAAU,IAAI;AAC/D,YAAQ,IAAI,GAAG,QAAQ,aAAa,IAAI,SAAS,IAAI,SAAS;KAC5D;KACA,aAAa,QAAQ;KACrB,OAAO;KACP,QAAQ,QAAQ;KACjB,CAAC;AACF,iBAAa,KAAK;KAChB,KAAK,KAAK;KACV,OAAO,KAAK;KACZ,OAAO;KACR,CAAC;AACF,2BAAuB,IAAI,KAAK,OAAO,MAAM;;;AAIjD,qBAAmB,KAAK,CAAC,QAAQ,KAAK;;AAGxC,MAAK,WAAW;AAEhB,QAAO;EACL;EACA,SAAS,CAAC,GAAG,QAAQ,QAAQ,CAAC;EAC9B;EACD","names":[],"sources":["../../../src/utils/collectOxcTemplateDependencies/expressionReplacements.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport type { Expression, MemberExpression, Node } from 'oxc-parser';\n\nimport { getOxcNodeChildren } from '../oxc/ast';\nimport {\n isBindingPosition,\n isInTypeContext,\n isObjectPropertyKey,\n isPropertyOnlyIdentifier,\n resolveBindingAt,\n} from './scopeAnalysis';\nimport { evaluateStatic, literalCode } from './staticEvaluator';\nimport type {\n Binding,\n ExtractionContext,\n OxcStaticImportReference,\n Replacement,\n} from './types';\n\nexport const getConstantReplacement = (\n binding: Binding | undefined,\n ctx: ExtractionContext\n): string | null => {\n const init = binding?.declarator?.init;\n if (!init) {\n return null;\n }\n\n if (init.type === 'Literal') {\n return literalCode(init.value);\n }\n\n if (\n init.type === 'ObjectExpression' &&\n binding?.isRoot &&\n binding.declarator?.id.type === 'Identifier'\n ) {\n const evaluated = evaluateStatic(binding.declarator.id, ctx);\n return literalCode(evaluated);\n }\n\n return null;\n};\n\nexport const collectIdentifierReferenceReplacements = (\n expression: Expression,\n replacements: Map<string, string>\n): Replacement[] => {\n const localReplacements: Replacement[] = [];\n const ancestors: Node[] = [];\n\n const walk = (current: Node, parent: Node | null) => {\n if (\n current.type === 'Identifier' &&\n replacements.has(current.name) &&\n !isInTypeContext(ancestors) &&\n !isBindingPosition(current, parent) &&\n !isPropertyOnlyIdentifier(current, parent) &&\n !isObjectPropertyKey(current, parent)\n ) {\n const replacement = replacements.get(current.name)!;\n // Shorthand property `{ width }` → `{ width: 500 }` when the\n // identifier is the value side of a shorthand ObjectProperty.\n const isShorthandValue =\n !!parent &&\n parent.type === 'Property' &&\n (parent as unknown as { shorthand?: boolean }).shorthand &&\n parent.value === current;\n localReplacements.push({\n start: isShorthandValue ? parent.start : current.start,\n end: current.end,\n value: isShorthandValue\n ? `${current.name}: ${replacement}`\n : replacement,\n });\n }\n\n ancestors.push(current);\n getOxcNodeChildren(current).forEach((child) => walk(child, current));\n ancestors.pop();\n };\n\n walk(expression, null);\n return localReplacements;\n};\n\nexport const applyExpressionReplacements = (\n expression: Expression,\n replacements: Replacement[],\n code: string\n): string => {\n let result = code.slice(expression.start, expression.end);\n replacements\n .sort((a, b) => b.start - a.start)\n .forEach((replacement) => {\n const start = replacement.start - expression.start;\n const end = replacement.end - expression.start;\n result = result.slice(0, start) + replacement.value + result.slice(end);\n });\n return result;\n};\n\nexport const replaceIdentifierReferences = (\n expression: Expression,\n replacements: Map<string, string>,\n code: string\n): string => {\n return applyExpressionReplacements(\n expression,\n collectIdentifierReferenceReplacements(expression, replacements),\n code\n );\n};\n\nconst staticImportAliasPart = (value: string): string =>\n value.replace(/[^A-Za-z0-9_$]/g, '_') || 'value';\n\nconst allocateStaticImportAlias = (\n binding: Binding,\n imported: string,\n ctx: ExtractionContext\n): string => {\n const key = `${binding.importedFrom ?? ''}\\0${binding.name}\\0${imported}`;\n const existing = ctx.staticImportAliases.get(key);\n if (existing) {\n return existing;\n }\n\n const namespacePart = staticImportAliasPart(binding.name);\n const importedPart = staticImportAliasPart(imported);\n let alias = `_wyw_static_${namespacePart}_${importedPart}`;\n let idx = 1;\n while (ctx.usedNames.has(alias)) {\n idx += 1;\n alias = `_wyw_static_${namespacePart}_${importedPart}_${idx}`;\n }\n\n ctx.usedNames.add(alias);\n ctx.staticImportAliases.set(key, alias);\n return alias;\n};\n\nconst staticMemberPropertyName = (\n expression: MemberExpression\n): string | null => {\n if (!expression.computed && expression.property.type === 'Identifier') {\n return expression.property.name;\n }\n\n if (\n expression.computed &&\n expression.property.type === 'Literal' &&\n typeof expression.property.value === 'string'\n ) {\n return expression.property.value;\n }\n\n return null;\n};\n\nexport const collectStaticNamespaceMemberReferences = (\n expression: Expression,\n ctx: ExtractionContext\n): {\n coveredReferenceStarts: Set<number>;\n imports: OxcStaticImportReference[];\n replacements: Replacement[];\n} => {\n const coveredReferenceStarts = new Set<number>();\n const imports = new Map<string, OxcStaticImportReference>();\n const replacements: Replacement[] = [];\n\n const walk = (node: Node): void => {\n if (node.type === 'MemberExpression' && node.object.type === 'Identifier') {\n const binding = resolveBindingAt(\n ctx,\n node.object.name,\n node.object.start\n );\n const imported = staticMemberPropertyName(node);\n if (\n binding?.importedFrom &&\n binding.imported === '*' &&\n imported !== null\n ) {\n const alias = allocateStaticImportAlias(binding, imported, ctx);\n imports.set(`${binding.importedFrom}\\0${imported}\\0${alias}`, {\n imported,\n importLocal: binding.name,\n local: alias,\n source: binding.importedFrom,\n });\n replacements.push({\n end: node.end,\n start: node.start,\n value: alias,\n });\n coveredReferenceStarts.add(node.object.start);\n }\n }\n\n getOxcNodeChildren(node).forEach(walk);\n };\n\n walk(expression);\n\n return {\n coveredReferenceStarts,\n imports: [...imports.values()],\n replacements,\n };\n};\n"],"file":"expressionReplacements.js"}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { getOxcNodeChildren } from "../oxc/ast.js";
|
|
2
|
+
import { parseOxcProgram } from "../oxc/parse.js";
|
|
3
|
+
import { createOxcSourceLocation } from "../oxc/sourceLocations.js";
|
|
4
|
+
export const containsTaggedTemplateExpression = (node) => {
|
|
5
|
+
if (node.type === "TaggedTemplateExpression") {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return getOxcNodeChildren(node).some(containsTaggedTemplateExpression);
|
|
9
|
+
};
|
|
10
|
+
export const parseOxc = (code, filename) => {
|
|
11
|
+
return parseOxcProgram(code, filename, "unambiguous");
|
|
12
|
+
};
|
|
13
|
+
const toSpanKey = (start, end) => `${start}:${end}`;
|
|
14
|
+
export const createSpanLookup = (spans) => {
|
|
15
|
+
if (!spans || spans.length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return new Set(spans.map((span) => toSpanKey(span.start, span.end)));
|
|
19
|
+
};
|
|
20
|
+
const matchesSpanLookup = (node, spanLookup) => !spanLookup || spanLookup.has(toSpanKey(node.start, node.end));
|
|
21
|
+
export const getSourceLocation = (start, end, ctx) => createOxcSourceLocation(start, end, ctx.loc, ctx.filename);
|
|
22
|
+
const createScope = (parent, node, root = false, functionBoundary = false) => ({
|
|
23
|
+
bindings: new Map(),
|
|
24
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
25
|
+
end: node.end,
|
|
26
|
+
functionBoundary,
|
|
27
|
+
params: new Set(),
|
|
28
|
+
parent,
|
|
29
|
+
root,
|
|
30
|
+
start: node.start
|
|
31
|
+
});
|
|
32
|
+
const normalizeDeclarationKind = (declarationKind) => {
|
|
33
|
+
if (declarationKind === "var") {
|
|
34
|
+
return "var";
|
|
35
|
+
}
|
|
36
|
+
if (declarationKind === "let") {
|
|
37
|
+
return "let";
|
|
38
|
+
}
|
|
39
|
+
return "const";
|
|
40
|
+
};
|
|
41
|
+
const moduleExportName = (node) => node.type === "Literal" ? String(node.value) : node.name;
|
|
42
|
+
const getImportSpecifierInfo = (statement, specifier) => {
|
|
43
|
+
const local = specifier.local?.name;
|
|
44
|
+
if (!local) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (specifier.type === "ImportDefaultSpecifier") {
|
|
48
|
+
return {
|
|
49
|
+
imported: "default",
|
|
50
|
+
local
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
54
|
+
return {
|
|
55
|
+
imported: "*",
|
|
56
|
+
local
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (statement.importKind === "type" || specifier.importKind === "type") {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
imported: moduleExportName(specifier.imported),
|
|
64
|
+
local
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const getDeclarationScope = (scope, declarationKind) => {
|
|
68
|
+
if (declarationKind !== "var") {
|
|
69
|
+
return scope;
|
|
70
|
+
}
|
|
71
|
+
let current = scope;
|
|
72
|
+
while (current && !current.functionBoundary) {
|
|
73
|
+
current = current.parent;
|
|
74
|
+
}
|
|
75
|
+
return current ?? scope;
|
|
76
|
+
};
|
|
77
|
+
const collectBindingNames = (node) => {
|
|
78
|
+
if (node.type === "Identifier") {
|
|
79
|
+
return [node.name];
|
|
80
|
+
}
|
|
81
|
+
if (node.type === "RestElement") {
|
|
82
|
+
return collectBindingNames(node.argument);
|
|
83
|
+
}
|
|
84
|
+
if (node.type === "AssignmentPattern") {
|
|
85
|
+
return collectBindingNames(node.left);
|
|
86
|
+
}
|
|
87
|
+
if (node.type === "ObjectPattern") {
|
|
88
|
+
return node.properties.flatMap((property) => property.type === "RestElement" ? collectBindingNames(property.argument) : collectBindingNames(property.value));
|
|
89
|
+
}
|
|
90
|
+
if (node.type === "ArrayPattern") {
|
|
91
|
+
return node.elements.flatMap((element) => element ? collectBindingNames(element) : []);
|
|
92
|
+
}
|
|
93
|
+
if (node.type === "TSParameterProperty") {
|
|
94
|
+
return collectBindingNames(node.parameter);
|
|
95
|
+
}
|
|
96
|
+
return [];
|
|
97
|
+
};
|
|
98
|
+
export const isInTypeContext = (ancestors) => ancestors.some((ancestor) => ancestor.type.startsWith("TS") || ancestor.type.startsWith("JSDoc"));
|
|
99
|
+
export const isPropertyOnlyIdentifier = (node, parent) => !!parent && parent.type === "MemberExpression" && parent.property === node && !parent.computed;
|
|
100
|
+
export const isObjectPropertyKey = (node, parent) => !!parent && parent.type === "Property" && parent.key === node && !parent.computed && parent.value !== node;
|
|
101
|
+
export const isBindingPosition = (node, parent) => {
|
|
102
|
+
if (!parent) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (parent.type === "VariableDeclarator" && parent.id === node) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if ((parent.type === "FunctionDeclaration" || parent.type === "FunctionExpression" || parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.id === node) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if ((parent.type === "ImportSpecifier" || parent.type === "ImportDefaultSpecifier" || parent.type === "ImportNamespaceSpecifier") && "local" in parent && parent.local === node) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
const visit = (node, scope, enter, parent = null, ancestors = []) => {
|
|
117
|
+
const visitNode = (currentNode, currentScope, currentParent) => {
|
|
118
|
+
let nextScope;
|
|
119
|
+
if (currentNode.type === "Program") {
|
|
120
|
+
nextScope = createScope(null, currentNode, true, true);
|
|
121
|
+
} else if (currentNode.type === "BlockStatement" || currentNode.type === "FunctionDeclaration" || currentNode.type === "FunctionExpression" || currentNode.type === "ArrowFunctionExpression") {
|
|
122
|
+
nextScope = createScope(currentScope, currentNode, false, currentNode.type !== "BlockStatement");
|
|
123
|
+
} else if (currentScope) {
|
|
124
|
+
nextScope = currentScope;
|
|
125
|
+
} else {
|
|
126
|
+
nextScope = createScope(null, currentNode, false, true);
|
|
127
|
+
}
|
|
128
|
+
if (currentNode.type === "FunctionDeclaration" || currentNode.type === "FunctionExpression" || currentNode.type === "ArrowFunctionExpression") {
|
|
129
|
+
currentNode.params.forEach((param) => {
|
|
130
|
+
collectBindingNames(param).forEach((name) => {
|
|
131
|
+
nextScope.params.add(name);
|
|
132
|
+
nextScope.bindings.set(name, {
|
|
133
|
+
declaredAt: param.start,
|
|
134
|
+
declaration: null,
|
|
135
|
+
declarator: null,
|
|
136
|
+
functionNode: null,
|
|
137
|
+
isRoot: false,
|
|
138
|
+
kind: "param",
|
|
139
|
+
name,
|
|
140
|
+
scope: nextScope
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
enter(currentNode, nextScope, currentParent, ancestors);
|
|
146
|
+
ancestors.push(currentNode);
|
|
147
|
+
getOxcNodeChildren(currentNode).forEach((child) => visitNode(child, nextScope, currentNode));
|
|
148
|
+
ancestors.pop();
|
|
149
|
+
};
|
|
150
|
+
visitNode(node, scope, parent);
|
|
151
|
+
};
|
|
152
|
+
export const analyzeProgram = (program, { collectTargetExpressions = false, collectTemplateLiterals = false, expressionSpanLookup = null, templateSpanLookup = null } = {}) => {
|
|
153
|
+
const bindings = new Map();
|
|
154
|
+
const usedNames = new Set();
|
|
155
|
+
const templateLiterals = [];
|
|
156
|
+
const targetExpressions = [];
|
|
157
|
+
const addBinding = (scope, binding) => {
|
|
158
|
+
scope.bindings.set(binding.name, binding);
|
|
159
|
+
const existing = bindings.get(binding.name) ?? [];
|
|
160
|
+
existing.push(binding);
|
|
161
|
+
bindings.set(binding.name, existing);
|
|
162
|
+
};
|
|
163
|
+
const collectTargets = (node, ancestors) => {
|
|
164
|
+
if (collectTemplateLiterals && node.type === "TemplateLiteral" && node.expressions.length > 0 && !ancestors.some((ancestor) => ancestor.type === "TemplateLiteral") && matchesSpanLookup(node, templateSpanLookup)) {
|
|
165
|
+
templateLiterals.push(node);
|
|
166
|
+
}
|
|
167
|
+
if (collectTargetExpressions && expressionSpanLookup && matchesSpanLookup(node, expressionSpanLookup)) {
|
|
168
|
+
targetExpressions.push(node);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
visit(program, null, (node, scope, _parent, ancestors) => {
|
|
172
|
+
collectTargets(node, ancestors);
|
|
173
|
+
if (node.type === "Identifier") {
|
|
174
|
+
usedNames.add(node.name);
|
|
175
|
+
}
|
|
176
|
+
if (isInTypeContext(ancestors)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
180
|
+
node.params.forEach((param) => {
|
|
181
|
+
collectBindingNames(param).forEach((name) => {
|
|
182
|
+
const binding = scope.bindings.get(name);
|
|
183
|
+
if (binding) {
|
|
184
|
+
addBinding(scope, binding);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
if (node.type !== "FunctionDeclaration") {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (node.type === "ImportDeclaration") {
|
|
193
|
+
const source = node.source.value;
|
|
194
|
+
node.specifiers.forEach((specifier) => {
|
|
195
|
+
const importInfo = getImportSpecifierInfo(node, specifier);
|
|
196
|
+
if (!importInfo) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
addBinding(scope, {
|
|
200
|
+
declaredAt: specifier.start,
|
|
201
|
+
declaration: null,
|
|
202
|
+
declarator: null,
|
|
203
|
+
functionNode: null,
|
|
204
|
+
imported: importInfo.imported,
|
|
205
|
+
importedFrom: source,
|
|
206
|
+
isRoot: scope.root,
|
|
207
|
+
kind: "import",
|
|
208
|
+
name: importInfo.local,
|
|
209
|
+
scope
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (node.type !== "VariableDeclaration") {
|
|
215
|
+
if (node.type === "FunctionDeclaration" && node.id) {
|
|
216
|
+
const declarationScope = scope.parent ?? scope;
|
|
217
|
+
const binding = {
|
|
218
|
+
declaredAt: node.start,
|
|
219
|
+
declaration: null,
|
|
220
|
+
declarator: null,
|
|
221
|
+
functionNode: node,
|
|
222
|
+
isRoot: declarationScope.root,
|
|
223
|
+
kind: "function",
|
|
224
|
+
name: node.id.name,
|
|
225
|
+
scope: declarationScope
|
|
226
|
+
};
|
|
227
|
+
addBinding(declarationScope, binding);
|
|
228
|
+
}
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
node.declarations.forEach((declarator) => {
|
|
232
|
+
collectBindingNames(declarator.id).forEach((name) => {
|
|
233
|
+
const declarationKind = normalizeDeclarationKind(node.kind);
|
|
234
|
+
const declarationScope = getDeclarationScope(scope, declarationKind);
|
|
235
|
+
const binding = {
|
|
236
|
+
declarationKind,
|
|
237
|
+
declaredAt: declarator.start,
|
|
238
|
+
declaration: node,
|
|
239
|
+
declarator,
|
|
240
|
+
functionNode: null,
|
|
241
|
+
isRoot: declarationScope.root,
|
|
242
|
+
kind: "variable",
|
|
243
|
+
name,
|
|
244
|
+
scope: declarationScope
|
|
245
|
+
};
|
|
246
|
+
addBinding(declarationScope, binding);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
bindingsByName: bindings,
|
|
252
|
+
rootMutationsByBinding: collectRootMutations(program),
|
|
253
|
+
targetExpressions: targetExpressions.sort((a, b) => a.start - b.start),
|
|
254
|
+
templateLiterals,
|
|
255
|
+
usedNames
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
export const resolveBindingAt = (ctx, name, referenceStart) => {
|
|
259
|
+
const cachedBindings = ctx.bindingResolutionCache.get(name);
|
|
260
|
+
if (cachedBindings?.has(referenceStart)) {
|
|
261
|
+
return cachedBindings.get(referenceStart) ?? undefined;
|
|
262
|
+
}
|
|
263
|
+
const bindings = ctx.bindingsByName.get(name);
|
|
264
|
+
const bindingCache = cachedBindings ?? new Map();
|
|
265
|
+
if (!cachedBindings) {
|
|
266
|
+
ctx.bindingResolutionCache.set(name, bindingCache);
|
|
267
|
+
}
|
|
268
|
+
if (!bindings || bindings.length === 0) {
|
|
269
|
+
bindingCache.set(referenceStart, null);
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
let binding;
|
|
273
|
+
bindings.forEach((candidate) => {
|
|
274
|
+
if (candidate.scope.start > referenceStart || referenceStart >= candidate.scope.end) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (!binding || candidate.scope.depth > binding.scope.depth || candidate.scope.depth === binding.scope.depth && candidate.declaredAt > binding.declaredAt) {
|
|
278
|
+
binding = candidate;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
bindingCache.set(referenceStart, binding ?? null);
|
|
282
|
+
return binding;
|
|
283
|
+
};
|
|
284
|
+
const collectRootMutations = (program) => {
|
|
285
|
+
const mutations = new Map();
|
|
286
|
+
const getRootMutationTarget = (node) => {
|
|
287
|
+
if (node.type === "Identifier") {
|
|
288
|
+
return {
|
|
289
|
+
binding: node.name,
|
|
290
|
+
path: []
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
if (node.type !== "MemberExpression") {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
const parent = getRootMutationTarget(node.object);
|
|
297
|
+
if (!parent) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
let key = null;
|
|
301
|
+
if (node.computed && node.property.type === "Literal" && (typeof node.property.value === "string" || typeof node.property.value === "number")) {
|
|
302
|
+
key = node.property.value;
|
|
303
|
+
} else if (!node.computed && node.property.type === "Identifier") {
|
|
304
|
+
key = node.property.name;
|
|
305
|
+
}
|
|
306
|
+
if (key === null) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
binding: parent.binding,
|
|
311
|
+
path: [...parent.path, key]
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
program.body.forEach((statement) => {
|
|
315
|
+
if (statement.type !== "ExpressionStatement") {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const { expression } = statement;
|
|
319
|
+
if (expression.type === "AssignmentExpression") {
|
|
320
|
+
const target = getRootMutationTarget(expression.left);
|
|
321
|
+
if (!target || target.path.length === 0) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const bucket = mutations.get(target.binding) ?? [];
|
|
325
|
+
bucket.push(expression);
|
|
326
|
+
mutations.set(target.binding, bucket);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (expression.type === "UpdateExpression") {
|
|
330
|
+
const target = getRootMutationTarget(expression.argument);
|
|
331
|
+
if (!target || target.path.length === 0) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const bucket = mutations.get(target.binding) ?? [];
|
|
335
|
+
bucket.push(expression);
|
|
336
|
+
mutations.set(target.binding, bucket);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
return mutations;
|
|
340
|
+
};
|
|
341
|
+
const hasLocalBinding = (scope, name) => {
|
|
342
|
+
let current = scope;
|
|
343
|
+
while (current) {
|
|
344
|
+
if (current.bindings.has(name)) {
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
current = current.parent;
|
|
348
|
+
}
|
|
349
|
+
return false;
|
|
350
|
+
};
|
|
351
|
+
const hasLocalBindingCached = (scope, name, cache) => {
|
|
352
|
+
const scopeCache = cache.get(scope);
|
|
353
|
+
if (scopeCache?.has(name)) {
|
|
354
|
+
return scopeCache.get(name);
|
|
355
|
+
}
|
|
356
|
+
const result = hasLocalBinding(scope, name);
|
|
357
|
+
const nextScopeCache = scopeCache ?? new Map();
|
|
358
|
+
nextScopeCache.set(name, result);
|
|
359
|
+
if (!scopeCache) {
|
|
360
|
+
cache.set(scope, nextScopeCache);
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
};
|
|
364
|
+
export const findReferences = (node, referenceCache) => {
|
|
365
|
+
const cachedReferences = referenceCache?.get(node);
|
|
366
|
+
if (cachedReferences) {
|
|
367
|
+
return cachedReferences;
|
|
368
|
+
}
|
|
369
|
+
const refs = new Map();
|
|
370
|
+
const localBindingCache = new WeakMap();
|
|
371
|
+
visit(node, null, (current, scope, parent, ancestors) => {
|
|
372
|
+
if (current.type !== "Identifier" || isInTypeContext(ancestors) || isBindingPosition(current, parent) || isPropertyOnlyIdentifier(current, parent) || isObjectPropertyKey(current, parent) || hasLocalBindingCached(scope, current.name, localBindingCache)) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const key = `${current.start}:${current.end}:${current.name}`;
|
|
376
|
+
refs.set(key, {
|
|
377
|
+
end: current.end,
|
|
378
|
+
name: current.name,
|
|
379
|
+
start: current.start
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
const resolvedReferences = [...refs.values()];
|
|
383
|
+
referenceCache?.set(node, resolvedReferences);
|
|
384
|
+
return resolvedReferences;
|
|
385
|
+
};
|
|
386
|
+
export const isBindingDeclaredWithin = (binding, container) => container.start <= binding.declaredAt && binding.declaredAt < container.end;
|
|
387
|
+
//# sourceMappingURL=scopeAnalysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAgBA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AAYxC,OAAO,MAAM,oCAAoC,SAAwB;AACvE,KAAI,KAAK,SAAS,4BAA4B;AAC5C,SAAO;;AAGT,QAAO,mBAAmB,KAAK,CAAC,KAAK,iCAAiC;;AAGxE,OAAO,MAAM,YAAY,MAAc,aAA8B;AACnE,QAAO,gBAAgB,MAAM,UAAU,cAAc;;AAGvD,MAAM,aAAa,OAAe,QAAwB,GAAG,MAAM,GAAG;AAEtE,OAAO,MAAM,oBAAoB,UAAyC;AACxE,KAAI,CAAC,SAAS,MAAM,WAAW,G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,qBAAqB,CAAC,GAAG,KAAK,QAAQ,CAAC;AAC7C,iBAAgB,IAAI,MAAM,mBAAmB;AAC7C,QAAO;;AAGT,OAAO,MAAM,2BACX,SACA,cAEA,UAAU,SAAS,QAAQ,cAAc,QAAQ,aAAa,UAAU","names":[],"sources":["../../../src/utils/collectOxcTemplateDependencies/scopeAnalysis.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type { SourceLocation } from '@wyw-in-js/shared';\nimport type {\n AssignmentExpression,\n Expression,\n ImportDeclaration,\n ImportSpecifier,\n ModuleExportName,\n Node,\n Program,\n TemplateLiteral,\n UpdateExpression,\n VariableDeclaration,\n} from 'oxc-parser';\n\nimport { getOxcNodeChildren } from '../oxc/ast';\nimport { parseOxcProgram } from '../oxc/parse';\nimport { createOxcSourceLocation } from '../oxc/sourceLocations';\nimport type {\n Binding,\n ExpressionSpan,\n ExtractionContext,\n ProgramAnalysis,\n ReferenceIdentifier,\n Scope,\n ScopedDeclarationKind,\n SpanLookup,\n} from './types';\n\nexport const containsTaggedTemplateExpression = (node: Node): boolean => {\n if (node.type === 'TaggedTemplateExpression') {\n return true;\n }\n\n return getOxcNodeChildren(node).some(containsTaggedTemplateExpression);\n};\n\nexport const parseOxc = (code: string, filename: string): Program => {\n return parseOxcProgram(code, filename, 'unambiguous');\n};\n\nconst toSpanKey = (start: number, end: number): string => `${start}:${end}`;\n\nexport const createSpanLookup = (spans?: ExpressionSpan[]): SpanLookup => {\n if (!spans || spans.length === 0) {\n return null;\n }\n\n return new Set(spans.map((span) => toSpanKey(span.start, span.end)));\n};\n\nconst matchesSpanLookup = (\n node: Pick<Node, 'start' | 'end'>,\n spanLookup: SpanLookup\n): boolean => !spanLookup || spanLookup.has(toSpanKey(node.start, node.end));\n\nexport const getSourceLocation = (\n start: number,\n end: number,\n ctx: Pick<ExtractionContext, 'filename' | 'loc'>\n): SourceLocation => createOxcSourceLocation(start, end, ctx.loc, ctx.filename);\n\nconst createScope = (\n parent: Scope | null,\n node: Pick<Node, 'start' | 'end'>,\n root = false,\n functionBoundary = false\n): Scope => ({\n bindings: new Map(),\n depth: parent ? parent.depth + 1 : 0,\n end: node.end,\n functionBoundary,\n params: new Set(),\n parent,\n root,\n start: node.start,\n});\n\nconst normalizeDeclarationKind = (\n declarationKind: VariableDeclaration['kind']\n): ScopedDeclarationKind => {\n if (declarationKind === 'var') {\n return 'var';\n }\n\n if (declarationKind === 'let') {\n return 'let';\n }\n\n return 'const';\n};\n\nconst moduleExportName = (node: ModuleExportName): string =>\n node.type === 'Literal' ? String(node.value) : node.name;\n\nconst getImportSpecifierInfo = (\n statement: ImportDeclaration,\n specifier: ImportDeclaration['specifiers'][number]\n): { imported: 'default' | '*' | string; local: string } | null => {\n const local = specifier.local?.name;\n if (!local) {\n return null;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n return {\n imported: 'default',\n local,\n };\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n return {\n imported: '*',\n local,\n };\n }\n\n if (\n statement.importKind === 'type' ||\n (specifier as ImportSpecifier).importKind === 'type'\n ) {\n return null;\n }\n\n return {\n imported: moduleExportName((specifier as ImportSpecifier).imported),\n local,\n };\n};\n\nconst getDeclarationScope = (\n scope: Scope,\n declarationKind: ScopedDeclarationKind\n): Scope => {\n if (declarationKind !== 'var') {\n return scope;\n }\n\n let current: Scope | null = scope;\n while (current && !current.functionBoundary) {\n current = current.parent;\n }\n\n return current ?? scope;\n};\n\nconst collectBindingNames = (node: Node): string[] => {\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectBindingNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectBindingNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) =>\n element ? collectBindingNames(element) : []\n );\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingNames(node.parameter);\n }\n\n return [];\n};\n\nexport const isInTypeContext = (ancestors: Node[]): boolean =>\n ancestors.some(\n (ancestor) =>\n ancestor.type.startsWith('TS') || ancestor.type.startsWith('JSDoc')\n );\n\nexport const isPropertyOnlyIdentifier = (\n node: Node,\n parent: Node | null\n): boolean =>\n !!parent &&\n parent.type === 'MemberExpression' &&\n parent.property === node &&\n !parent.computed;\n\nexport const isObjectPropertyKey = (node: Node, parent: Node | null): boolean =>\n !!parent &&\n parent.type === 'Property' &&\n parent.key === node &&\n !parent.computed &&\n parent.value !== node;\n\nexport const isBindingPosition = (node: Node, parent: Node | null): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'VariableDeclarator' && parent.id === node) {\n return true;\n }\n\n if (\n (parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression' ||\n parent.type === 'ClassDeclaration' ||\n parent.type === 'ClassExpression') &&\n parent.id === node\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ImportSpecifier' ||\n parent.type === 'ImportDefaultSpecifier' ||\n parent.type === 'ImportNamespaceSpecifier') &&\n 'local' in parent &&\n parent.local === node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst visit = (\n node: Node,\n scope: Scope | null,\n enter: (\n node: Node,\n scope: Scope,\n parent: Node | null,\n ancestors: Node[]\n ) => void,\n parent: Node | null = null,\n ancestors: Node[] = []\n): void => {\n const visitNode = (\n currentNode: Node,\n currentScope: Scope | null,\n currentParent: Node | null\n ): void => {\n let nextScope: Scope;\n if (currentNode.type === 'Program') {\n nextScope = createScope(null, currentNode, true, true);\n } else if (\n currentNode.type === 'BlockStatement' ||\n currentNode.type === 'FunctionDeclaration' ||\n currentNode.type === 'FunctionExpression' ||\n currentNode.type === 'ArrowFunctionExpression'\n ) {\n nextScope = createScope(\n currentScope,\n currentNode,\n false,\n currentNode.type !== 'BlockStatement'\n );\n } else if (currentScope) {\n nextScope = currentScope;\n } else {\n nextScope = createScope(null, currentNode, false, true);\n }\n\n if (\n currentNode.type === 'FunctionDeclaration' ||\n currentNode.type === 'FunctionExpression' ||\n currentNode.type === 'ArrowFunctionExpression'\n ) {\n currentNode.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n nextScope.params.add(name);\n nextScope.bindings.set(name, {\n declaredAt: param.start,\n declaration: null,\n declarator: null,\n functionNode: null,\n isRoot: false,\n kind: 'param',\n name,\n scope: nextScope,\n });\n });\n });\n }\n\n enter(currentNode, nextScope, currentParent, ancestors);\n\n ancestors.push(currentNode);\n getOxcNodeChildren(currentNode).forEach((child) =>\n visitNode(child, nextScope, currentNode)\n );\n ancestors.pop();\n };\n\n visitNode(node, scope, parent);\n};\n\nexport const analyzeProgram = (\n program: Program,\n {\n collectTargetExpressions = false,\n collectTemplateLiterals = false,\n expressionSpanLookup = null,\n templateSpanLookup = null,\n }: {\n collectTargetExpressions?: boolean;\n collectTemplateLiterals?: boolean;\n expressionSpanLookup?: SpanLookup;\n templateSpanLookup?: SpanLookup;\n } = {}\n): ProgramAnalysis => {\n const bindings = new Map<string, Binding[]>();\n const usedNames = new Set<string>();\n const templateLiterals: TemplateLiteral[] = [];\n const targetExpressions: Expression[] = [];\n\n const addBinding = (scope: Scope, binding: Binding): void => {\n scope.bindings.set(binding.name, binding);\n const existing = bindings.get(binding.name) ?? [];\n existing.push(binding);\n bindings.set(binding.name, existing);\n };\n\n const collectTargets = (node: Node, ancestors: Node[]): void => {\n if (\n collectTemplateLiterals &&\n node.type === 'TemplateLiteral' &&\n node.expressions.length > 0 &&\n !ancestors.some((ancestor) => ancestor.type === 'TemplateLiteral') &&\n matchesSpanLookup(node, templateSpanLookup)\n ) {\n templateLiterals.push(node);\n }\n\n if (\n collectTargetExpressions &&\n expressionSpanLookup &&\n matchesSpanLookup(node, expressionSpanLookup)\n ) {\n targetExpressions.push(node as Expression);\n }\n };\n\n visit(program, null, (node, scope, _parent, ancestors) => {\n collectTargets(node, ancestors);\n\n if (node.type === 'Identifier') {\n usedNames.add(node.name);\n }\n\n if (isInTypeContext(ancestors)) {\n return;\n }\n\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n node.params.forEach((param) => {\n collectBindingNames(param).forEach((name) => {\n const binding = scope.bindings.get(name);\n if (binding) {\n addBinding(scope, binding);\n }\n });\n });\n\n if (node.type !== 'FunctionDeclaration') {\n return;\n }\n }\n\n if (node.type === 'ImportDeclaration') {\n const source = node.source.value;\n node.specifiers.forEach((specifier) => {\n const importInfo = getImportSpecifierInfo(node, specifier);\n if (!importInfo) {\n return;\n }\n\n addBinding(scope, {\n declaredAt: specifier.start,\n declaration: null,\n declarator: null,\n functionNode: null,\n imported: importInfo.imported,\n importedFrom: source,\n isRoot: scope.root,\n kind: 'import',\n name: importInfo.local,\n scope,\n });\n });\n return;\n }\n\n if (node.type !== 'VariableDeclaration') {\n if (node.type === 'FunctionDeclaration' && node.id) {\n const declarationScope = scope.parent ?? scope;\n const binding: Binding = {\n declaredAt: node.start,\n declaration: null,\n declarator: null,\n functionNode: node,\n isRoot: declarationScope.root,\n kind: 'function',\n name: node.id.name,\n scope: declarationScope,\n };\n addBinding(declarationScope, binding);\n }\n\n return;\n }\n\n node.declarations.forEach((declarator) => {\n collectBindingNames(declarator.id).forEach((name) => {\n const declarationKind = normalizeDeclarationKind(node.kind);\n const declarationScope = getDeclarationScope(scope, declarationKind);\n const binding: Binding = {\n declarationKind,\n declaredAt: declarator.start,\n declaration: node,\n declarator,\n functionNode: null,\n isRoot: declarationScope.root,\n kind: 'variable',\n name,\n scope: declarationScope,\n };\n addBinding(declarationScope, binding);\n });\n });\n });\n\n return {\n bindingsByName: bindings,\n rootMutationsByBinding: collectRootMutations(program),\n targetExpressions: targetExpressions.sort((a, b) => a.start - b.start),\n templateLiterals,\n usedNames,\n };\n};\n\nexport const resolveBindingAt = (\n ctx: Pick<ExtractionContext, 'bindingResolutionCache' | 'bindingsByName'>,\n name: string,\n referenceStart: number\n): Binding | undefined => {\n const cachedBindings = ctx.bindingResolutionCache.get(name);\n if (cachedBindings?.has(referenceStart)) {\n return cachedBindings.get(referenceStart) ?? undefined;\n }\n\n const bindings = ctx.bindingsByName.get(name);\n const bindingCache = cachedBindings ?? new Map<number, Binding | null>();\n if (!cachedBindings) {\n ctx.bindingResolutionCache.set(name, bindingCache);\n }\n\n if (!bindings || bindings.length === 0) {\n bindingCache.set(referenceStart, null);\n return undefined;\n }\n\n let binding: Binding | undefined;\n bindings.forEach((candidate) => {\n if (\n candidate.scope.start > referenceStart ||\n referenceStart >= candidate.scope.end\n ) {\n return;\n }\n\n if (\n !binding ||\n candidate.scope.depth > binding.scope.depth ||\n (candidate.scope.depth === binding.scope.depth &&\n candidate.declaredAt > binding.declaredAt)\n ) {\n binding = candidate;\n }\n });\n\n bindingCache.set(referenceStart, binding ?? null);\n return binding;\n};\n\nconst collectRootMutations = (\n program: Program\n): Map<string, Array<AssignmentExpression | UpdateExpression>> => {\n const mutations = new Map<\n string,\n Array<AssignmentExpression | UpdateExpression>\n >();\n\n const getRootMutationTarget = (\n node: Node\n ): { binding: string; path: Array<string | number> } | null => {\n if (node.type === 'Identifier') {\n return {\n binding: node.name,\n path: [],\n };\n }\n\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n const parent = getRootMutationTarget(node.object);\n if (!parent) {\n return null;\n }\n\n let key: string | number | null = null;\n if (\n node.computed &&\n node.property.type === 'Literal' &&\n (typeof node.property.value === 'string' ||\n typeof node.property.value === 'number')\n ) {\n key = node.property.value;\n } else if (!node.computed && node.property.type === 'Identifier') {\n key = node.property.name;\n }\n if (key === null) {\n return null;\n }\n\n return {\n binding: parent.binding,\n path: [...parent.path, key],\n };\n };\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ExpressionStatement') {\n return;\n }\n\n const { expression } = statement;\n if (expression.type === 'AssignmentExpression') {\n const target = getRootMutationTarget(expression.left);\n if (!target || target.path.length === 0) {\n return;\n }\n\n const bucket = mutations.get(target.binding) ?? [];\n bucket.push(expression);\n mutations.set(target.binding, bucket);\n return;\n }\n\n if (expression.type === 'UpdateExpression') {\n const target = getRootMutationTarget(expression.argument);\n if (!target || target.path.length === 0) {\n return;\n }\n\n const bucket = mutations.get(target.binding) ?? [];\n bucket.push(expression);\n mutations.set(target.binding, bucket);\n }\n });\n\n return mutations;\n};\n\nconst hasLocalBinding = (scope: Scope, name: string): boolean => {\n let current: Scope | null = scope;\n\n while (current) {\n if (current.bindings.has(name)) {\n return true;\n }\n\n current = current.parent;\n }\n\n return false;\n};\n\nconst hasLocalBindingCached = (\n scope: Scope,\n name: string,\n cache: WeakMap<Scope, Map<string, boolean>>\n): boolean => {\n const scopeCache = cache.get(scope);\n if (scopeCache?.has(name)) {\n return scopeCache.get(name)!;\n }\n\n const result = hasLocalBinding(scope, name);\n const nextScopeCache = scopeCache ?? new Map<string, boolean>();\n nextScopeCache.set(name, result);\n if (!scopeCache) {\n cache.set(scope, nextScopeCache);\n }\n\n return result;\n};\n\nexport const findReferences = (\n node: Node,\n referenceCache?: WeakMap<Node, ReferenceIdentifier[]>\n): ReferenceIdentifier[] => {\n const cachedReferences = referenceCache?.get(node);\n if (cachedReferences) {\n return cachedReferences;\n }\n\n const refs = new Map<string, ReferenceIdentifier>();\n const localBindingCache = new WeakMap<Scope, Map<string, boolean>>();\n\n visit(node, null, (current, scope, parent, ancestors) => {\n if (\n current.type !== 'Identifier' ||\n isInTypeContext(ancestors) ||\n isBindingPosition(current, parent) ||\n isPropertyOnlyIdentifier(current, parent) ||\n isObjectPropertyKey(current, parent) ||\n hasLocalBindingCached(scope, current.name, localBindingCache)\n ) {\n return;\n }\n\n const key = `${current.start}:${current.end}:${current.name}`;\n refs.set(key, {\n end: current.end,\n name: current.name,\n start: current.start,\n });\n });\n\n const resolvedReferences = [...refs.values()];\n referenceCache?.set(node, resolvedReferences);\n return resolvedReferences;\n};\n\nexport const isBindingDeclaredWithin = (\n binding: Binding,\n container: Node\n): boolean =>\n container.start <= binding.declaredAt && binding.declaredAt < container.end;\n"],"file":"scopeAnalysis.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const lookupStaticBinding = (staticBindings, source, imported) => {
|
|
2
|
+
if (!staticBindings || !source || !imported) {
|
|
3
|
+
return { found: false };
|
|
4
|
+
}
|
|
5
|
+
const sourceMap = staticBindings[source];
|
|
6
|
+
if (!sourceMap) {
|
|
7
|
+
return { found: false };
|
|
8
|
+
}
|
|
9
|
+
if (!Object.prototype.hasOwnProperty.call(sourceMap, imported)) {
|
|
10
|
+
return { found: false };
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
found: true,
|
|
14
|
+
value: sourceMap[imported]
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=staticBindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAEA,OAAO,MAAM,uBACX,gBACA,QACA,aACuD;AACvD,KAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,UAAU;AAC3C,SAAO,EAAE,OAAO,OAAO;;CAEzB,MAAM,YAAY,eAAe;AACjC,KAAI,CAAC,WAAW;AACd,SAAO,EAAE,OAAO,OAAO;;AAEzB,KAAI,CAAC,OAAO,UAAU,eAAe,KAAK,WAAW,SAAS,EAAE;AAC9D,SAAO,EAAE,OAAO,OAAO;;AAEzB,QAAO;EAAE,OAAO;EAAM,OAAO,UAAU;EAAW","names":[],"sources":["../../../src/utils/collectOxcTemplateDependencies/staticBindings.ts"],"version":3,"sourcesContent":["import type { StaticBindings } from './types';\n\nexport const lookupStaticBinding = (\n staticBindings: StaticBindings | undefined,\n source: string | undefined,\n imported: string | undefined\n): { found: true; value: unknown } | { found: false } => {\n if (!staticBindings || !source || !imported) {\n return { found: false };\n }\n const sourceMap = staticBindings[source];\n if (!sourceMap) {\n return { found: false };\n }\n if (!Object.prototype.hasOwnProperty.call(sourceMap, imported)) {\n return { found: false };\n }\n return { found: true, value: sourceMap[imported] };\n};\n"],"file":"staticBindings.js"}
|