@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,152 @@
|
|
|
1
|
+
import { ValueType } from "@wyw-in-js/shared";
|
|
2
|
+
import { isNotNull } from "../isNotNull.js";
|
|
3
|
+
import { buildOxcCodeFrameError } from "../oxc/sourceLocations.js";
|
|
4
|
+
import { getMemberName, unwrapQualifiedExpression } from "./processorUsages.js";
|
|
5
|
+
import { GENERATED_HELPER_NAME_RE, getSourceLocation } from "./shared.js";
|
|
6
|
+
export const literalExpressionValue = (expression, code, source, location) => {
|
|
7
|
+
if (expression.type !== "Literal") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (expression.value === null || typeof expression.value === "string" || typeof expression.value === "number" || typeof expression.value === "boolean") {
|
|
11
|
+
let type;
|
|
12
|
+
if (expression.value === null) {
|
|
13
|
+
type = "NullLiteral";
|
|
14
|
+
} else if (typeof expression.value === "string") {
|
|
15
|
+
type = "StringLiteral";
|
|
16
|
+
} else if (typeof expression.value === "number") {
|
|
17
|
+
type = "NumericLiteral";
|
|
18
|
+
} else {
|
|
19
|
+
type = "BooleanLiteral";
|
|
20
|
+
}
|
|
21
|
+
const ex = expression.value === null ? {
|
|
22
|
+
loc: location,
|
|
23
|
+
type
|
|
24
|
+
} : {
|
|
25
|
+
loc: location,
|
|
26
|
+
type,
|
|
27
|
+
value: expression.value
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
buildCodeFrameError: (message) => buildOxcCodeFrameError(code, location, message),
|
|
31
|
+
ex,
|
|
32
|
+
kind: ValueType.CONST,
|
|
33
|
+
source,
|
|
34
|
+
value: expression.value
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
export const expressionValue = (expression, code, loc, filename) => {
|
|
40
|
+
const source = code.slice(expression.start, expression.end);
|
|
41
|
+
const location = getSourceLocation(expression.start, expression.end, loc, filename);
|
|
42
|
+
const literal = literalExpressionValue(expression, code, source, location);
|
|
43
|
+
if (literal) {
|
|
44
|
+
return literal;
|
|
45
|
+
}
|
|
46
|
+
const helperCallName = expression.type === "CallExpression" && expression.arguments.length === 0 && expression.callee.type === "Identifier" && GENERATED_HELPER_NAME_RE.test(expression.callee.name) ? expression.callee.name : null;
|
|
47
|
+
let ex;
|
|
48
|
+
if (expression.type === "Identifier") {
|
|
49
|
+
ex = {
|
|
50
|
+
loc: location,
|
|
51
|
+
name: expression.name,
|
|
52
|
+
type: "Identifier"
|
|
53
|
+
};
|
|
54
|
+
} else if (helperCallName) {
|
|
55
|
+
ex = {
|
|
56
|
+
loc: location,
|
|
57
|
+
name: helperCallName,
|
|
58
|
+
type: "Identifier"
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
ex = {
|
|
62
|
+
loc: location,
|
|
63
|
+
name: code.slice(expression.start, expression.end),
|
|
64
|
+
type: "Identifier"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
buildCodeFrameError: (message) => buildOxcCodeFrameError(code, location, message),
|
|
69
|
+
ex,
|
|
70
|
+
kind: expression.type === "ArrowFunctionExpression" || expression.type === "FunctionExpression" ? ValueType.FUNCTION : ValueType.LAZY,
|
|
71
|
+
source
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export const withCurrentExpressionLocation = (value, expression, loc, filename) => {
|
|
75
|
+
const location = getSourceLocation(expression.start, expression.end, loc, filename);
|
|
76
|
+
if (value.kind === ValueType.CONST) {
|
|
77
|
+
return {
|
|
78
|
+
...value,
|
|
79
|
+
ex: {
|
|
80
|
+
...value.ex,
|
|
81
|
+
loc: location
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (value.kind === ValueType.FUNCTION) {
|
|
86
|
+
return {
|
|
87
|
+
...value,
|
|
88
|
+
ex: {
|
|
89
|
+
...value.ex,
|
|
90
|
+
loc: location
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
...value,
|
|
96
|
+
ex: {
|
|
97
|
+
...value.ex,
|
|
98
|
+
loc: location
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export const shiftExpressionValue = (expressionValues, expression, code, loc, filename) => expressionValues.length > 0 ? withCurrentExpressionLocation(expressionValues.shift(), expression, loc, filename) : expressionValue(expression, code, loc, filename);
|
|
103
|
+
export const zipTemplate = (template, code, loc, filename, expressionValues) => {
|
|
104
|
+
const parts = template.quasi.quasis.flatMap((quasi, idx) => {
|
|
105
|
+
const expression = template.quasi.expressions[idx];
|
|
106
|
+
const templateElement = {
|
|
107
|
+
...quasi,
|
|
108
|
+
loc: getSourceLocation(quasi.start, quasi.end, loc, filename)
|
|
109
|
+
};
|
|
110
|
+
return [templateElement, expression ? shiftExpressionValue(expressionValues, expression, code, loc, filename) : null].filter(isNotNull);
|
|
111
|
+
});
|
|
112
|
+
return ["template", parts];
|
|
113
|
+
};
|
|
114
|
+
export const buildCalleeParams = (node, code, loc, filename, expressionValues, collapseQualifiedCallee = false) => {
|
|
115
|
+
const expression = unwrapQualifiedExpression(node);
|
|
116
|
+
if (collapseQualifiedCallee && (expression.type === "Identifier" || expression.type === "MemberExpression")) {
|
|
117
|
+
return [["callee", expression]];
|
|
118
|
+
}
|
|
119
|
+
if (expression.type === "Identifier") {
|
|
120
|
+
return [["callee", {
|
|
121
|
+
name: expression.name,
|
|
122
|
+
type: "Identifier"
|
|
123
|
+
}]];
|
|
124
|
+
}
|
|
125
|
+
if (expression.type === "MemberExpression") {
|
|
126
|
+
const params = buildCalleeParams(expression.object, code, loc, filename, expressionValues, collapseQualifiedCallee);
|
|
127
|
+
const member = getMemberName(expression);
|
|
128
|
+
return params && member ? [...params, ["member", member]] : null;
|
|
129
|
+
}
|
|
130
|
+
if (expression.type === "CallExpression") {
|
|
131
|
+
const call = expression;
|
|
132
|
+
const params = buildCalleeParams(call.callee, code, loc, filename, expressionValues, collapseQualifiedCallee);
|
|
133
|
+
if (!params) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const callValues = call.arguments.filter((arg) => arg.type !== "SpreadElement").map((arg) => shiftExpressionValue(expressionValues, arg, code, loc, filename));
|
|
137
|
+
return [...params, ["call", ...callValues]];
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
};
|
|
141
|
+
export const buildParams = (usage, code, loc, filename, expressionValues, collapseQualifiedCallee) => {
|
|
142
|
+
const params = buildCalleeParams(usage.callee, code, loc, filename, expressionValues, collapseQualifiedCallee);
|
|
143
|
+
if (!params) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
if (usage.kind === "template") {
|
|
147
|
+
return [...params, zipTemplate(usage.target, code, loc, filename, expressionValues)];
|
|
148
|
+
}
|
|
149
|
+
const callValues = usage.target.arguments.filter((arg) => arg.type !== "SpreadElement").map((arg) => shiftExpressionValue(expressionValues, arg, code, loc, filename));
|
|
150
|
+
return [...params, ["call", ...callValues]];
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=expressionValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAEA,SAAS,iBAAiB;AAG1B,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AACvC,SAAS,eAAe,iCAAiC;AACzD,SAAS,0BAA0B,yBAAyB;AAO5D,OAAO,MAAM,0BACX,YACA,MACA,QACA,aAC2B;AAC3B,KAAI,WAAW,SAAS,WAAW;AACjC,SAAO;;AAGT,KACE,WAAW,UAAU,QACrB,OAAO,WAAW,UAAU,YAC5B,OAAO,WAAW,UAAU,YAC5B,OAAO,WAAW,UAAU,WAC5B;EACA,IAAI;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;EACD,MAAM,SAAS,cAAc,WAAW;AACxC,SAAO,UAAU,SAAS,CAAC,GAAG,QAAQ,CAAC,UAAU,OAAO,CAAC,GAAG;;AAG9D,KAAI,WAAW,SAAS,kBAAkB;EACxC,MAAM,OAAO;EACb,MAAM,SAAS,kBACb,KAAK,QACL,MACA,KACA,UACA,kBACA,wBACD;AACD,MAAI,CAAC,QAAQ;AACX,UAAO;;EAGT,MAAM,aAAa,KAAK,UACrB,QAAQ,QAAQ,IAAI,SAAS,gBAAgB,CAC7C,KAAK,QACJ,qBACE,kBACA,KACA,MACA,KACA,SACD,CACF;AAEH,SAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,GAAG,WAAW,CAAC;;AAG7C,QAAO;;AAGT,OAAO,MAAM,eACX,OACA,MACA,KACA,UACA,kBACA,4BACkB;CAClB,MAAM,SAAS,kBACb,MAAM,QACN,MACA,KACA,UACA,kBACA,wBACD;AACD,KAAI,CAAC,QAAQ;AACX,SAAO;;AAGT,KAAI,MAAM,SAAS,YAAY;AAC7B,SAAO,CACL,GAAG,QACH,YAAY,MAAM,QAAQ,MAAM,KAAK,UAAU,iBAAiB,CACjE;;CAGH,MAAM,aAAa,MAAM,OAAO,UAC7B,QAAQ,QAAQ,IAAI,SAAS,gBAAgB,CAC7C,KAAK,QACJ,qBACE,kBACA,KACA,MACA,KACA,SACD,CACF;AAEH,QAAO,CAAC,GAAG,QAAQ,CAAC,QAAQ,GAAG,WAAW,CAAC","names":[],"sources":["../../../src/utils/applyOxcProcessors/expressionValues.ts"],"version":3,"sourcesContent":["import type { Param, Params, SourceLocation } from '@wyw-in-js/processor-utils';\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\nimport type { Expression, TaggedTemplateExpression } from 'oxc-parser';\n\nimport { isNotNull } from '../isNotNull';\nimport { buildOxcCodeFrameError } from '../oxc/sourceLocations';\nimport { getMemberName, unwrapQualifiedExpression } from './processorUsages';\nimport { GENERATED_HELPER_NAME_RE, getSourceLocation } from './shared';\nimport type {\n CallExpressionLike,\n LocationLookup,\n ProcessorUsage,\n} from './types';\n\nexport const literalExpressionValue = (\n expression: Expression,\n code: string,\n source: string,\n location: SourceLocation\n): ExpressionValue | null => {\n if (expression.type !== 'Literal') {\n return null;\n }\n\n if (\n expression.value === null ||\n typeof expression.value === 'string' ||\n typeof expression.value === 'number' ||\n typeof expression.value === 'boolean'\n ) {\n let type:\n | 'BooleanLiteral'\n | 'NullLiteral'\n | 'NumericLiteral'\n | 'StringLiteral';\n if (expression.value === null) {\n type = 'NullLiteral';\n } else if (typeof expression.value === 'string') {\n type = 'StringLiteral';\n } else if (typeof expression.value === 'number') {\n type = 'NumericLiteral';\n } else {\n type = 'BooleanLiteral';\n }\n\n const ex =\n expression.value === null\n ? { loc: location, type }\n : {\n loc: location,\n type,\n value: expression.value,\n };\n\n return {\n buildCodeFrameError: (message: string) =>\n buildOxcCodeFrameError(code, location, message),\n ex,\n kind: ValueType.CONST,\n source,\n value: expression.value,\n } as ExpressionValue;\n }\n\n return null;\n};\n\nexport const expressionValue = (\n expression: Expression,\n code: string,\n loc: LocationLookup,\n filename?: string | null\n): ExpressionValue => {\n const source = code.slice(expression.start, expression.end);\n const location = getSourceLocation(\n expression.start,\n expression.end,\n loc,\n filename\n );\n const literal = literalExpressionValue(expression, code, source, location);\n if (literal) {\n return literal;\n }\n\n const helperCallName =\n expression.type === 'CallExpression' &&\n expression.arguments.length === 0 &&\n expression.callee.type === 'Identifier' &&\n GENERATED_HELPER_NAME_RE.test(expression.callee.name)\n ? expression.callee.name\n : null;\n\n let ex: ExpressionValue['ex'];\n if (expression.type === 'Identifier') {\n ex = { loc: location, name: expression.name, type: 'Identifier' };\n } else if (helperCallName) {\n ex = { loc: location, name: helperCallName, type: 'Identifier' };\n } else {\n ex = {\n loc: location,\n name: code.slice(expression.start, expression.end),\n type: 'Identifier',\n };\n }\n\n return {\n buildCodeFrameError: (message: string) =>\n buildOxcCodeFrameError(code, location, message),\n ex,\n kind:\n expression.type === 'ArrowFunctionExpression' ||\n expression.type === 'FunctionExpression'\n ? ValueType.FUNCTION\n : ValueType.LAZY,\n source,\n } as ExpressionValue;\n};\n\nexport const withCurrentExpressionLocation = (\n value: ExpressionValue,\n expression: Expression,\n loc: LocationLookup,\n filename?: string | null\n): ExpressionValue => {\n const location = getSourceLocation(\n expression.start,\n expression.end,\n loc,\n filename\n );\n\n if (value.kind === ValueType.CONST) {\n return {\n ...value,\n ex: {\n ...value.ex,\n loc: location,\n },\n };\n }\n\n if (value.kind === ValueType.FUNCTION) {\n return {\n ...value,\n ex: {\n ...value.ex,\n loc: location,\n },\n };\n }\n\n return {\n ...value,\n ex: {\n ...value.ex,\n loc: location,\n },\n };\n};\n\nexport const shiftExpressionValue = (\n expressionValues: ExpressionValue[],\n expression: Expression,\n code: string,\n loc: LocationLookup,\n filename?: string | null\n): ExpressionValue =>\n expressionValues.length > 0\n ? withCurrentExpressionLocation(\n expressionValues.shift()!,\n expression,\n loc,\n filename\n )\n : expressionValue(expression, code, loc, filename);\n\nexport const zipTemplate = (\n template: TaggedTemplateExpression,\n code: string,\n loc: LocationLookup,\n filename: string | null | undefined,\n expressionValues: ExpressionValue[]\n): Param => {\n const parts = template.quasi.quasis.flatMap((quasi, idx) => {\n const expression = template.quasi.expressions[idx];\n const templateElement = {\n ...quasi,\n loc: getSourceLocation(quasi.start, quasi.end, loc, filename),\n };\n\n return [\n templateElement,\n expression\n ? shiftExpressionValue(\n expressionValues,\n expression as Expression,\n code,\n loc,\n filename\n )\n : null,\n ].filter(isNotNull);\n });\n\n return ['template', parts] as Param;\n};\n\nexport const buildCalleeParams = (\n node: Expression,\n code: string,\n loc: LocationLookup,\n filename: string | null | undefined,\n expressionValues: ExpressionValue[],\n collapseQualifiedCallee = false\n): Params | null => {\n const expression = unwrapQualifiedExpression(node);\n\n if (\n collapseQualifiedCallee &&\n (expression.type === 'Identifier' || expression.type === 'MemberExpression')\n ) {\n return [['callee', expression] as Param];\n }\n\n if (expression.type === 'Identifier') {\n return [['callee', { name: expression.name, type: 'Identifier' }]];\n }\n\n if (expression.type === 'MemberExpression') {\n const params = buildCalleeParams(\n expression.object,\n code,\n loc,\n filename,\n expressionValues,\n collapseQualifiedCallee\n );\n const member = getMemberName(expression);\n return params && member ? [...params, ['member', member]] : null;\n }\n\n if (expression.type === 'CallExpression') {\n const call = expression as CallExpressionLike;\n const params = buildCalleeParams(\n call.callee,\n code,\n loc,\n filename,\n expressionValues,\n collapseQualifiedCallee\n );\n if (!params) {\n return null;\n }\n\n const callValues = call.arguments\n .filter((arg) => arg.type !== 'SpreadElement')\n .map((arg) =>\n shiftExpressionValue(\n expressionValues,\n arg as Expression,\n code,\n loc,\n filename\n )\n );\n\n return [...params, ['call', ...callValues]];\n }\n\n return null;\n};\n\nexport const buildParams = (\n usage: ProcessorUsage,\n code: string,\n loc: LocationLookup,\n filename: string | null | undefined,\n expressionValues: ExpressionValue[],\n collapseQualifiedCallee: boolean\n): Params | null => {\n const params = buildCalleeParams(\n usage.callee,\n code,\n loc,\n filename,\n expressionValues,\n collapseQualifiedCallee\n );\n if (!params) {\n return null;\n }\n\n if (usage.kind === 'template') {\n return [\n ...params,\n zipTemplate(usage.target, code, loc, filename, expressionValues),\n ];\n }\n\n const callValues = usage.target.arguments\n .filter((arg) => arg.type !== 'SpreadElement')\n .map((arg) =>\n shiftExpressionValue(\n expressionValues,\n arg as Expression,\n code,\n loc,\n filename\n )\n );\n\n return [...params, ['call', ...callValues]];\n};\n"],"file":"expressionValues.js"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { BaseProcessor, expressionToCode } from "@wyw-in-js/processor-utils";
|
|
2
|
+
import { createOxcAstService } from "../oxcAstService.js";
|
|
3
|
+
import { buildOxcCodeFrameError } from "../oxc/sourceLocations.js";
|
|
4
|
+
import { getDisplayName } from "./displayName.js";
|
|
5
|
+
import { getRootIdentifier } from "./processorUsages.js";
|
|
6
|
+
import { getSourceLocation } from "./shared.js";
|
|
7
|
+
let didWarnSkipSymbolMismatch = false;
|
|
8
|
+
export const isReplacementPure = (replacement) => replacement.type === "CallExpression";
|
|
9
|
+
export const shouldCollectStaticExpressionValues = (options) => (options.eval?.strategy ?? "hybrid") !== "execute";
|
|
10
|
+
export const createProcessor = (definedProcessor, params, target, replacementTarget, ancestors, fileContext, options, code, loc, idx, isReferenced, usedNames, replacements) => {
|
|
11
|
+
const [Processor, tagSource] = definedProcessor;
|
|
12
|
+
const astService = createOxcAstService(usedNames);
|
|
13
|
+
const replacer = (replacement, isPure) => {
|
|
14
|
+
const next = typeof replacement === "function" ? replacement(target) : replacement;
|
|
15
|
+
const replacementCode = expressionToCode(next);
|
|
16
|
+
replacements.push({
|
|
17
|
+
start: replacementTarget.start,
|
|
18
|
+
end: replacementTarget.end,
|
|
19
|
+
value: isPure && isReplacementPure(next) ? `/*#__PURE__*/${replacementCode}` : replacementCode
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
try {
|
|
23
|
+
let displayName;
|
|
24
|
+
try {
|
|
25
|
+
displayName = getDisplayName(ancestors, idx, code, fileContext.filename);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && error.message.startsWith("Couldn't determine a name for the component")) {
|
|
28
|
+
let displayNameNode = target;
|
|
29
|
+
if (target.type === "TaggedTemplateExpression") {
|
|
30
|
+
displayNameNode = target.tag;
|
|
31
|
+
} else if (target.type === "CallExpression") {
|
|
32
|
+
displayNameNode = target.callee;
|
|
33
|
+
}
|
|
34
|
+
const pointerNode = displayNameNode.type === "MemberExpression" ? getRootIdentifier(displayNameNode) ?? displayNameNode : displayNameNode;
|
|
35
|
+
throw buildOxcCodeFrameError(code, getSourceLocation(pointerNode.start, pointerNode.end, loc, fileContext.filename), error.message);
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
astService,
|
|
41
|
+
processor: new Processor(params, tagSource, astService, getSourceLocation(target.start, target.end, loc, fileContext.filename), replacer, displayName, isReferenced, idx, options, fileContext)
|
|
42
|
+
};
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (e === BaseProcessor.SKIP) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (typeof e === "symbol" && e.description === BaseProcessor.SKIP.description) {
|
|
48
|
+
if (!didWarnSkipSymbolMismatch) {
|
|
49
|
+
didWarnSkipSymbolMismatch = true;
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.warn([
|
|
52
|
+
"[wyw-in-js] Processor threw Symbol('skip') that does not match BaseProcessor.SKIP identity.",
|
|
53
|
+
"This usually means duplicate copies of @wyw-in-js/processor-utils (or the processor) are bundled/installed.",
|
|
54
|
+
"Consider deduping dependencies to avoid subtle issues (instanceof checks, sentinels, etc)."
|
|
55
|
+
].join("\n"));
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=processorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,SAAS,eAAe,wBAAwB;AAShD,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAQlC,IAAI,4BAA4B;AAChC,OAAO,MAAM,qBAAqB,gBAChC,YAAY,SAAS;AAEvB,OAAO,MAAM,uCACX,aACa,QAAQ,MAAM,YAAY,cAAc;AAEvD,OAAO,MAAM,mBACX,kBACA,QACA,QACA,mBACA,WACA,aACA,SAIA,MACA,KACA,KACA,cACA,WACA,iBAC4B;CAC5B,MAAM,CAAC,WAAW,aAAa;CAC/B,MAAM,aAAa,oBAAoB,UAAU;CAEjD,MAAM,YACJ,aAGA,WACG;EACH,MAAM,OACJ,OAAO,gBAAgB,aAAa,YAAY,OAAO,GAAG;EAC5D,MAAM,kBAAkB,iBAAiB,KAAK;AAC9C,eAAa,KAAK;GAChB,OAAO,kBAAkB;GACzB,KAAK,kBAAkB;GACvB,OACE,UAAU,kBAAkB,KAAK,GAC7B,gBAAgB,oBAChB;GACP,CAAC;;AAGJ,KAAI;EACF,IAAI;AACJ,MAAI;AACF,iBAAc,eAAe,WAAW,KAAK,MAAM,YAAY,SAAS;WACjE,OAAO;AACd,OACE,iBAAiB,SACjB,MAAM,QAAQ,WAAW,8CAA8C,EACvE;IACA,IAAI,kBAAwB;AAC5B,QAAI,OAAO,SAAS,4BAA4B;AAC9C,uBAAkB,OAAO;eAChB,OAAO,SAAS,kBAAkB;AAC3C,uBAAkB,OAAO;;IAE3B,MAAM,cACJ,gBAAgB,SAAS,qBACrB,kBAAkB,gBAAgB,IAAI,kBACtC;AACN,UAAM,uBACJ,MACA,kBACE,YAAY,OACZ,YAAY,KACZ,KACA,YAAY,SACb,EACD,MAAM,QACP;;AAEH,SAAM;;AAGR,SAAO;GACL;GACA,WAAW,IAAI,UACb,QACA,WACA,YACA,kBAAkB,OAAO,OAAO,OAAO,KAAK,KAAK,YAAY,SAAS,EACtE,UACA,aACA,cACA,KACA,SACA,YACD;GACF;UACM,GAAG;AACV,MAAI,MAAM,cAAc,MAAM;AAC5B,UAAO;;AAGT,MACE,OAAO,MAAM,YACb,EAAE,gBAAgB,cAAc,KAAK,aACrC;AACA,OAAI,CAAC,2BAA2B;AAC9B,gCAA4B;;AAE5B,YAAQ,KACN;KACE;KACA;KACA;KACD,CAAC,KAAK,KAAK,CACb;;AAGH,UAAO;;AAGT,QAAM","names":[],"sources":["../../../src/utils/applyOxcProcessors/processorFactory.ts"],"version":3,"sourcesContent":["import { BaseProcessor, expressionToCode } from '@wyw-in-js/processor-utils';\nimport type {\n Expression as ProcessorExpression,\n IFileContext,\n Params,\n} from '@wyw-in-js/processor-utils';\nimport type { StrictOptions } from '@wyw-in-js/shared';\nimport type { Expression, Node } from 'oxc-parser';\n\nimport { createOxcAstService } from '../oxcAstService';\nimport { buildOxcCodeFrameError } from '../oxc/sourceLocations';\nimport { getDisplayName } from './displayName';\nimport { getRootIdentifier } from './processorUsages';\nimport { getSourceLocation } from './shared';\nimport type {\n CreatedProcessor,\n DefinedProcessor,\n LocationLookup,\n Replacement,\n} from './types';\n\nlet didWarnSkipSymbolMismatch = false;\nexport const isReplacementPure = (replacement: ProcessorExpression): boolean =>\n replacement.type === 'CallExpression';\n\nexport const shouldCollectStaticExpressionValues = (\n options: Pick<StrictOptions, 'eval'>\n): boolean => (options.eval?.strategy ?? 'hybrid') !== 'execute';\n\nexport const createProcessor = (\n definedProcessor: DefinedProcessor,\n params: Params,\n target: Expression,\n replacementTarget: Expression,\n ancestors: Node[],\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'extensions' | 'tagResolver'\n >,\n code: string,\n loc: LocationLookup,\n idx: number,\n isReferenced: boolean,\n usedNames: Set<string>,\n replacements: Replacement[]\n): CreatedProcessor | null => {\n const [Processor, tagSource] = definedProcessor;\n const astService = createOxcAstService(usedNames);\n\n const replacer = (\n replacement:\n | ProcessorExpression\n | ((tagPath: unknown) => ProcessorExpression),\n isPure: boolean\n ) => {\n const next =\n typeof replacement === 'function' ? replacement(target) : replacement;\n const replacementCode = expressionToCode(next);\n replacements.push({\n start: replacementTarget.start,\n end: replacementTarget.end,\n value:\n isPure && isReplacementPure(next)\n ? `/*#__PURE__*/${replacementCode}`\n : replacementCode,\n });\n };\n\n try {\n let displayName: string;\n try {\n displayName = getDisplayName(ancestors, idx, code, fileContext.filename);\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.startsWith(\"Couldn't determine a name for the component\")\n ) {\n let displayNameNode: Node = target;\n if (target.type === 'TaggedTemplateExpression') {\n displayNameNode = target.tag;\n } else if (target.type === 'CallExpression') {\n displayNameNode = target.callee;\n }\n const pointerNode =\n displayNameNode.type === 'MemberExpression'\n ? getRootIdentifier(displayNameNode) ?? displayNameNode\n : displayNameNode;\n throw buildOxcCodeFrameError(\n code,\n getSourceLocation(\n pointerNode.start,\n pointerNode.end,\n loc,\n fileContext.filename\n ),\n error.message\n );\n }\n throw error;\n }\n\n return {\n astService,\n processor: new Processor(\n params,\n tagSource,\n astService,\n getSourceLocation(target.start, target.end, loc, fileContext.filename),\n replacer,\n displayName,\n isReferenced,\n idx,\n options,\n fileContext\n ),\n };\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n return null;\n }\n\n if (\n typeof e === 'symbol' &&\n e.description === BaseProcessor.SKIP.description\n ) {\n if (!didWarnSkipSymbolMismatch) {\n didWarnSkipSymbolMismatch = true;\n // eslint-disable-next-line no-console\n console.warn(\n [\n \"[wyw-in-js] Processor threw Symbol('skip') that does not match BaseProcessor.SKIP identity.\",\n 'This usually means duplicate copies of @wyw-in-js/processor-utils (or the processor) are bundled/installed.',\n 'Consider deduping dependencies to avoid subtle issues (instanceof checks, sentinels, etc).',\n ].join('\\n')\n );\n }\n\n return null;\n }\n\n throw e;\n }\n};\n"],"file":"processorFactory.js"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { getOxcNodeChildren } from "../oxc/ast.js";
|
|
2
|
+
export const getMemberName = (node) => {
|
|
3
|
+
if (node.computed) {
|
|
4
|
+
return node.property.type === "Literal" && typeof node.property.value === "string" ? node.property.value : null;
|
|
5
|
+
}
|
|
6
|
+
return node.property.type === "Identifier" ? node.property.name : null;
|
|
7
|
+
};
|
|
8
|
+
export const unwrapQualifiedExpression = (node) => {
|
|
9
|
+
if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion" || node.type === "ParenthesizedExpression") {
|
|
10
|
+
return unwrapQualifiedExpression(node.expression);
|
|
11
|
+
}
|
|
12
|
+
if (node.type === "SequenceExpression") {
|
|
13
|
+
const sequence = node;
|
|
14
|
+
return unwrapQualifiedExpression(sequence.expressions[sequence.expressions.length - 1] ?? node);
|
|
15
|
+
}
|
|
16
|
+
return node;
|
|
17
|
+
};
|
|
18
|
+
export const getRootIdentifier = (node) => {
|
|
19
|
+
const expression = unwrapQualifiedExpression(node);
|
|
20
|
+
if (expression.type === "Identifier") {
|
|
21
|
+
return expression;
|
|
22
|
+
}
|
|
23
|
+
if (expression.type === "MemberExpression") {
|
|
24
|
+
return getRootIdentifier(expression.object);
|
|
25
|
+
}
|
|
26
|
+
if (expression.type === "CallExpression") {
|
|
27
|
+
return getRootIdentifier(expression.callee);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
export const getQualifiedName = (node) => {
|
|
32
|
+
const expression = unwrapQualifiedExpression(node);
|
|
33
|
+
if (expression.type === "Identifier") {
|
|
34
|
+
return expression.name;
|
|
35
|
+
}
|
|
36
|
+
if (expression.type === "MemberExpression") {
|
|
37
|
+
const object = getQualifiedName(expression.object);
|
|
38
|
+
const member = getMemberName(expression);
|
|
39
|
+
return object && member ? `${object}.${member}` : null;
|
|
40
|
+
}
|
|
41
|
+
if (expression.type === "CallExpression") {
|
|
42
|
+
return getQualifiedName(expression.callee);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
export const resolveDefinedProcessor = (callee, definedProcessors) => {
|
|
47
|
+
const qualified = getQualifiedName(callee);
|
|
48
|
+
if (qualified) {
|
|
49
|
+
const definedProcessor = definedProcessors.get(qualified);
|
|
50
|
+
if (definedProcessor) {
|
|
51
|
+
return {
|
|
52
|
+
collapseQualifiedCallee: qualified.includes("."),
|
|
53
|
+
definedProcessor
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const root = getRootIdentifier(callee);
|
|
58
|
+
if (!root) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const definedProcessor = definedProcessors.get(root.name);
|
|
62
|
+
return definedProcessor ? {
|
|
63
|
+
collapseQualifiedCallee: false,
|
|
64
|
+
definedProcessor
|
|
65
|
+
} : null;
|
|
66
|
+
};
|
|
67
|
+
export const isCallTagOfTaggedTemplate = (node, parent) => parent?.type === "TaggedTemplateExpression" && parent.tag === node;
|
|
68
|
+
export const expandReplacementTarget = (target, ancestors) => {
|
|
69
|
+
let current = target;
|
|
70
|
+
for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
|
|
71
|
+
const ancestor = ancestors[idx];
|
|
72
|
+
if (ancestor.type === "SequenceExpression" && ancestor.expressions[ancestor.expressions.length - 1] === current) {
|
|
73
|
+
current = ancestor;
|
|
74
|
+
} else if (ancestor.type === "ParenthesizedExpression" && ancestor.expression === current) {
|
|
75
|
+
current = ancestor;
|
|
76
|
+
} else {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return current;
|
|
81
|
+
};
|
|
82
|
+
export const collectProcessorUsages = (program, definedProcessors) => {
|
|
83
|
+
const usages = [];
|
|
84
|
+
const walk = (node, ancestors, parent = null) => {
|
|
85
|
+
if (node.type === "TaggedTemplateExpression") {
|
|
86
|
+
const callee = node.tag;
|
|
87
|
+
const resolvedProcessor = resolveDefinedProcessor(callee, definedProcessors);
|
|
88
|
+
if (resolvedProcessor) {
|
|
89
|
+
usages.push({
|
|
90
|
+
ancestors,
|
|
91
|
+
callee,
|
|
92
|
+
collapseQualifiedCallee: resolvedProcessor.collapseQualifiedCallee,
|
|
93
|
+
definedProcessor: resolvedProcessor.definedProcessor,
|
|
94
|
+
kind: "template",
|
|
95
|
+
replacementTarget: expandReplacementTarget(node, ancestors),
|
|
96
|
+
target: node
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
} else if (node.type === "CallExpression" && !isCallTagOfTaggedTemplate(node, parent)) {
|
|
100
|
+
const { callee } = node;
|
|
101
|
+
const resolvedProcessor = resolveDefinedProcessor(callee, definedProcessors);
|
|
102
|
+
if (resolvedProcessor) {
|
|
103
|
+
usages.push({
|
|
104
|
+
ancestors,
|
|
105
|
+
callee,
|
|
106
|
+
collapseQualifiedCallee: resolvedProcessor.collapseQualifiedCallee,
|
|
107
|
+
definedProcessor: resolvedProcessor.definedProcessor,
|
|
108
|
+
kind: "call",
|
|
109
|
+
replacementTarget: expandReplacementTarget(node, ancestors),
|
|
110
|
+
target: node
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
getOxcNodeChildren(node).forEach((child) => walk(child, [...ancestors, node], node));
|
|
115
|
+
};
|
|
116
|
+
walk(program, []);
|
|
117
|
+
return usages.sort((a, b) => a.target.start - b.target.start);
|
|
118
|
+
};
|
|
119
|
+
export const expressionSpan = (expression) => ({
|
|
120
|
+
end: expression.end,
|
|
121
|
+
start: expression.start
|
|
122
|
+
});
|
|
123
|
+
export const collectCallArgumentSpans = (node) => {
|
|
124
|
+
const expression = unwrapQualifiedExpression(node);
|
|
125
|
+
if (expression.type === "CallExpression") {
|
|
126
|
+
const call = expression;
|
|
127
|
+
const calleeSpans = collectCallArgumentSpans(call.callee);
|
|
128
|
+
const argumentSpans = call.arguments.flatMap((arg) => arg.type === "SpreadElement" ? [] : [expressionSpan(arg)]);
|
|
129
|
+
return [...calleeSpans, ...argumentSpans];
|
|
130
|
+
}
|
|
131
|
+
if (expression.type === "MemberExpression") {
|
|
132
|
+
return collectCallArgumentSpans(expression.object);
|
|
133
|
+
}
|
|
134
|
+
return [];
|
|
135
|
+
};
|
|
136
|
+
export const collectUsageExpressionSpans = (usage) => {
|
|
137
|
+
const calleeSpans = collectCallArgumentSpans(usage.callee);
|
|
138
|
+
if (usage.kind === "template") {
|
|
139
|
+
return [...calleeSpans, ...usage.target.quasi.expressions.map((expression) => expressionSpan(expression))];
|
|
140
|
+
}
|
|
141
|
+
return [...calleeSpans, ...usage.target.arguments.flatMap((arg) => arg.type === "SpreadElement" ? [] : [expressionSpan(arg)])];
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=processorUsages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAQA,SAAS,0BAA0B;AAWnC,OAAO,MAAM,iBAAiB,SAA0C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AAIN,qBAAmB,KAAK,CAAC,SAAS,UAChC,KAAK,OAAO,CAAC,GAAG,WAAW,KAAK,EAAE,KAAK,CACxC;;AAGH,MAAK,SAAS,EAAE,CAAC;AAEjB,QAAO,OAAO,MAAM,GAAG,MAAM,EAAE,OAAO,QAAQ,EAAE,OAAO,MAAM;;AAG/D,OAAO,MAAM,kBAAkB,gBAA4C;CACzE,KAAK,WAAW;CAChB,OAAO,WAAW;CACnB;AAED,OAAO,MAAM,4BACX,SACqB;CACrB,MAAM,aAAa,0BAA0B,KAAK;AAElD,KAAI,WAAW,SAAS,kBAAkB;EACxC,MAAM,OAAO;EACb,MAAM,cAAc,yBAAyB,KAAK,OAAO;EACzD,MAAM,gBAAgB,KAAK,UAAU,SAAS,QAC5C,IAAI,SAAS,kBAAkB,EAAE,GAAG,CAAC,eAAe,IAAkB,CAAC,CACxE;AACD,SAAO,CAAC,GAAG,aAAa,GAAG,cAAc;;AAG3C,KAAI,WAAW,SAAS,oBAAoB;AAC1C,SAAO,yBAAyB,WAAW,OAAO;;AAGpD,QAAO,EAAE;;AAGX,OAAO,MAAM,+BACX,UACqB;CACrB,MAAM,cAAc,yBAAyB,MAAM,OAAO;AAC1D,KAAI,MAAM,SAAS,YAAY;AAC7B,SAAO,CACL,GAAG,aACH,GAAG,MAAM,OAAO,MAAM,YAAY,KAAK,eACrC,eAAe,WAAyB,CACzC,CACF;;AAGH,QAAO,CACL,GAAG,aACH,GAAG,MAAM,OAAO,UAAU,SAAS,QACjC,IAAI,SAAS,kBAAkB,EAAE,GAAG,CAAC,eAAe,IAAkB,CAAC,CACxE,CACF","names":[],"sources":["../../../src/utils/applyOxcProcessors/processorUsages.ts"],"version":3,"sourcesContent":["import type {\n CallExpression,\n Expression,\n MemberExpression,\n Node,\n Program,\n} from 'oxc-parser';\n\nimport { getOxcNodeChildren } from '../oxc/ast';\nimport type {\n CallExpressionLike,\n DefinedProcessor,\n ExpressionSpan,\n OxcIdentifier,\n ProcessorUsage,\n QualifiedExpression,\n SequenceExpressionLike,\n} from './types';\n\nexport const getMemberName = (node: MemberExpression): string | null => {\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nexport const unwrapQualifiedExpression = (node: Expression): Expression => {\n if (\n node.type === 'TSAsExpression' ||\n node.type === 'TSSatisfiesExpression' ||\n node.type === 'TSNonNullExpression' ||\n node.type === 'TSTypeAssertion' ||\n node.type === 'ParenthesizedExpression'\n ) {\n return unwrapQualifiedExpression(\n (node as QualifiedExpression & { expression: Expression }).expression\n );\n }\n\n if (node.type === 'SequenceExpression') {\n const sequence = node as SequenceExpressionLike;\n return unwrapQualifiedExpression(\n sequence.expressions[sequence.expressions.length - 1] ?? node\n );\n }\n\n return node;\n};\n\nexport const getRootIdentifier = (node: Expression): OxcIdentifier | null => {\n const expression = unwrapQualifiedExpression(node);\n\n if (expression.type === 'Identifier') {\n return expression;\n }\n\n if (expression.type === 'MemberExpression') {\n return getRootIdentifier(expression.object);\n }\n\n if (expression.type === 'CallExpression') {\n return getRootIdentifier((expression as CallExpressionLike).callee);\n }\n\n return null;\n};\n\nexport const getQualifiedName = (node: Expression): string | null => {\n const expression = unwrapQualifiedExpression(node);\n\n if (expression.type === 'Identifier') {\n return expression.name;\n }\n\n if (expression.type === 'MemberExpression') {\n const object = getQualifiedName(expression.object);\n const member = getMemberName(expression);\n return object && member ? `${object}.${member}` : null;\n }\n\n if (expression.type === 'CallExpression') {\n return getQualifiedName((expression as CallExpressionLike).callee);\n }\n\n return null;\n};\n\nexport const resolveDefinedProcessor = (\n callee: Expression,\n definedProcessors: Map<string, DefinedProcessor>\n): {\n collapseQualifiedCallee: boolean;\n definedProcessor: DefinedProcessor;\n} | null => {\n const qualified = getQualifiedName(callee);\n if (qualified) {\n const definedProcessor = definedProcessors.get(qualified);\n if (definedProcessor) {\n return {\n collapseQualifiedCallee: qualified.includes('.'),\n definedProcessor,\n };\n }\n }\n\n const root = getRootIdentifier(callee);\n if (!root) {\n return null;\n }\n\n const definedProcessor = definedProcessors.get(root.name);\n return definedProcessor\n ? {\n collapseQualifiedCallee: false,\n definedProcessor,\n }\n : null;\n};\n\nexport const isCallTagOfTaggedTemplate = (\n node: Node,\n parent: Node | null\n): boolean =>\n parent?.type === 'TaggedTemplateExpression' && parent.tag === node;\n\nexport const expandReplacementTarget = (\n target: Expression,\n ancestors: Node[]\n): Expression => {\n let current: Expression = target;\n\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'SequenceExpression' &&\n ancestor.expressions[ancestor.expressions.length - 1] === current\n ) {\n current = ancestor as Expression;\n } else if (\n ancestor.type === 'ParenthesizedExpression' &&\n ancestor.expression === current\n ) {\n current = ancestor as Expression;\n } else {\n break;\n }\n }\n\n return current;\n};\n\nexport const collectProcessorUsages = (\n program: Program,\n definedProcessors: Map<string, DefinedProcessor>\n): ProcessorUsage[] => {\n const usages: ProcessorUsage[] = [];\n\n const walk = (\n node: Node,\n ancestors: Node[],\n parent: Node | null = null\n ): void => {\n if (node.type === 'TaggedTemplateExpression') {\n const callee = node.tag as Expression;\n const resolvedProcessor = resolveDefinedProcessor(\n callee,\n definedProcessors\n );\n if (resolvedProcessor) {\n usages.push({\n ancestors,\n callee,\n collapseQualifiedCallee: resolvedProcessor.collapseQualifiedCallee,\n definedProcessor: resolvedProcessor.definedProcessor,\n kind: 'template',\n replacementTarget: expandReplacementTarget(node, ancestors),\n target: node,\n });\n }\n } else if (\n node.type === 'CallExpression' &&\n !isCallTagOfTaggedTemplate(node, parent)\n ) {\n const { callee } = node as CallExpressionLike;\n const resolvedProcessor = resolveDefinedProcessor(\n callee,\n definedProcessors\n );\n if (resolvedProcessor) {\n usages.push({\n ancestors,\n callee,\n collapseQualifiedCallee: resolvedProcessor.collapseQualifiedCallee,\n definedProcessor: resolvedProcessor.definedProcessor,\n kind: 'call',\n replacementTarget: expandReplacementTarget(\n node as CallExpression,\n ancestors\n ),\n target: node as CallExpression,\n });\n }\n }\n\n getOxcNodeChildren(node).forEach((child) =>\n walk(child, [...ancestors, node], node)\n );\n };\n\n walk(program, []);\n\n return usages.sort((a, b) => a.target.start - b.target.start);\n};\n\nexport const expressionSpan = (expression: Expression): ExpressionSpan => ({\n end: expression.end,\n start: expression.start,\n});\n\nexport const collectCallArgumentSpans = (\n node: Expression\n): ExpressionSpan[] => {\n const expression = unwrapQualifiedExpression(node);\n\n if (expression.type === 'CallExpression') {\n const call = expression as CallExpressionLike;\n const calleeSpans = collectCallArgumentSpans(call.callee);\n const argumentSpans = call.arguments.flatMap((arg) =>\n arg.type === 'SpreadElement' ? [] : [expressionSpan(arg as Expression)]\n );\n return [...calleeSpans, ...argumentSpans];\n }\n\n if (expression.type === 'MemberExpression') {\n return collectCallArgumentSpans(expression.object);\n }\n\n return [];\n};\n\nexport const collectUsageExpressionSpans = (\n usage: ProcessorUsage\n): ExpressionSpan[] => {\n const calleeSpans = collectCallArgumentSpans(usage.callee);\n if (usage.kind === 'template') {\n return [\n ...calleeSpans,\n ...usage.target.quasi.expressions.map((expression) =>\n expressionSpan(expression as Expression)\n ),\n ];\n }\n\n return [\n ...calleeSpans,\n ...usage.target.arguments.flatMap((arg) =>\n arg.type === 'SpreadElement' ? [] : [expressionSpan(arg as Expression)]\n ),\n ];\n};\n"],"file":"processorUsages.js"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { isOxcNode } from "../oxc/ast.js";
|
|
2
|
+
import { processorExpressionToStaticValue, resolveProcessorStaticRuntimeValue, unknownProcessorStaticValue } from "../processorStaticSemantics.js";
|
|
3
|
+
import { GENERATED_HELPER_NAME_RE, JS_IDENTIFIER_RE, WYW_META_EXTENDS_HELPER_RE } from "./shared.js";
|
|
4
|
+
export const oxcLiteralValue = (expression) => {
|
|
5
|
+
const expressionWithValue = expression;
|
|
6
|
+
const expressionType = expression.type;
|
|
7
|
+
if (expressionType === "StringLiteral" || expressionType === "NumericLiteral" || expressionType === "BooleanLiteral" || expressionType === "Literal") {
|
|
8
|
+
return expressionWithValue.value;
|
|
9
|
+
}
|
|
10
|
+
if (expressionType === "NullLiteral") {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return unknownProcessorStaticValue;
|
|
14
|
+
};
|
|
15
|
+
export const oxcPropertyKeyName = (key) => {
|
|
16
|
+
if (key.type === "Identifier") {
|
|
17
|
+
return key.name;
|
|
18
|
+
}
|
|
19
|
+
const value = oxcLiteralValue(key);
|
|
20
|
+
return typeof value === "string" ? value : null;
|
|
21
|
+
};
|
|
22
|
+
export const collectStaticObjectPropertyNames = (objectExpression) => {
|
|
23
|
+
if (objectExpression.type !== "ObjectExpression") {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const { properties } = objectExpression;
|
|
27
|
+
if (!properties) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const names = new Set();
|
|
31
|
+
for (const property of properties) {
|
|
32
|
+
const propertyType = property.type;
|
|
33
|
+
if (propertyType !== "ObjectProperty" && propertyType !== "Property") {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
if (!property.key || !property.value) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const name = oxcPropertyKeyName(property.key);
|
|
40
|
+
if (!name || names.has(name)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
names.add(name);
|
|
44
|
+
}
|
|
45
|
+
return names;
|
|
46
|
+
};
|
|
47
|
+
export const getSameFileProcessorObjectProperty = (ancestors) => {
|
|
48
|
+
let propertyIndex = -1;
|
|
49
|
+
for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
|
|
50
|
+
if (ancestors[idx].type === "Property") {
|
|
51
|
+
propertyIndex = idx;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (propertyIndex <= 0) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const property = ancestors[propertyIndex];
|
|
59
|
+
const objectExpression = ancestors[propertyIndex - 1];
|
|
60
|
+
if (!property.key || objectExpression.type !== "ObjectExpression") {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const propertyName = oxcPropertyKeyName(property.key);
|
|
64
|
+
const propertyNames = collectStaticObjectPropertyNames(objectExpression);
|
|
65
|
+
if (!propertyName || !propertyNames) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
for (let idx = propertyIndex - 2; idx >= 0; idx -= 1) {
|
|
69
|
+
const ancestor = ancestors[idx];
|
|
70
|
+
if (ancestor.type === "VariableDeclarator") {
|
|
71
|
+
const { id, init } = ancestor;
|
|
72
|
+
if (isOxcNode(id) && id.type === "Identifier" && init === objectExpression) {
|
|
73
|
+
return {
|
|
74
|
+
localName: id.name,
|
|
75
|
+
propertyName,
|
|
76
|
+
propertyNames
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
export const createSameFileProcessorStaticValueResolver = (processorsByLocal, expressionValues) => {
|
|
84
|
+
const expressionSourceByName = new Map();
|
|
85
|
+
expressionValues.forEach((value) => {
|
|
86
|
+
if (value.ex.type === "Identifier") {
|
|
87
|
+
expressionSourceByName.set(value.ex.name, value.source);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const memo = new Map();
|
|
91
|
+
const resolving = new Set();
|
|
92
|
+
function resolveLocal(local) {
|
|
93
|
+
if (memo.has(local)) {
|
|
94
|
+
return memo.get(local);
|
|
95
|
+
}
|
|
96
|
+
const processor = processorsByLocal.get(local);
|
|
97
|
+
if (!processor || resolving.has(local)) {
|
|
98
|
+
return unknownProcessorStaticValue;
|
|
99
|
+
}
|
|
100
|
+
resolving.add(local);
|
|
101
|
+
const contractValue = resolveProcessorStaticRuntimeValue(processor);
|
|
102
|
+
const value = contractValue !== unknownProcessorStaticValue ? contractValue : processorExpressionToStaticValue(processor.value, (helperName) => {
|
|
103
|
+
const source = expressionSourceByName.get(helperName);
|
|
104
|
+
return source ? resolveLocal(source) : unknownProcessorStaticValue;
|
|
105
|
+
});
|
|
106
|
+
resolving.delete(local);
|
|
107
|
+
memo.set(local, value);
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
function resolveProcessor(processor) {
|
|
111
|
+
const contractValue = resolveProcessorStaticRuntimeValue(processor);
|
|
112
|
+
if (contractValue !== unknownProcessorStaticValue) {
|
|
113
|
+
return contractValue;
|
|
114
|
+
}
|
|
115
|
+
return processorExpressionToStaticValue(processor.value, (helperName) => {
|
|
116
|
+
const source = expressionSourceByName.get(helperName);
|
|
117
|
+
return source ? resolveLocal(source) : unknownProcessorStaticValue;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
resolveLocal,
|
|
122
|
+
resolveProcessor
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export const collectSameFileProcessorStaticValuesByLocal = (processorsByLocal, expressionValues) => {
|
|
126
|
+
const { resolveLocal } = createSameFileProcessorStaticValueResolver(processorsByLocal, expressionValues);
|
|
127
|
+
const result = new Map();
|
|
128
|
+
processorsByLocal.forEach((_processor, local) => {
|
|
129
|
+
const value = resolveLocal(local);
|
|
130
|
+
if (value !== unknownProcessorStaticValue) {
|
|
131
|
+
result.set(local, value);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return result;
|
|
135
|
+
};
|
|
136
|
+
export const collectSameFileProcessorObjectStaticValuesByLocal = (processorObjectsByLocal, processorsByLocal, expressionValues) => {
|
|
137
|
+
const { resolveProcessor } = createSameFileProcessorStaticValueResolver(processorsByLocal, expressionValues);
|
|
138
|
+
const result = new Map();
|
|
139
|
+
for (const [local, object] of processorObjectsByLocal) {
|
|
140
|
+
if (object.properties.size === object.propertyNames.size) {
|
|
141
|
+
const value = {};
|
|
142
|
+
let complete = true;
|
|
143
|
+
for (const propertyName of object.propertyNames) {
|
|
144
|
+
const processor = object.properties.get(propertyName);
|
|
145
|
+
if (!processor) {
|
|
146
|
+
complete = false;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
const propertyValue = resolveProcessor(processor);
|
|
150
|
+
if (propertyValue === unknownProcessorStaticValue) {
|
|
151
|
+
complete = false;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
value[propertyName] = propertyValue;
|
|
155
|
+
}
|
|
156
|
+
if (complete) {
|
|
157
|
+
result.set(local, value);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
};
|
|
163
|
+
export const collectWYWMetaExtendsHelperNames = (code) => {
|
|
164
|
+
const names = new Set();
|
|
165
|
+
let match = WYW_META_EXTENDS_HELPER_RE.exec(code);
|
|
166
|
+
while (match) {
|
|
167
|
+
const name = match[1];
|
|
168
|
+
if (name && GENERATED_HELPER_NAME_RE.test(name)) {
|
|
169
|
+
names.add(name);
|
|
170
|
+
}
|
|
171
|
+
match = WYW_META_EXTENDS_HELPER_RE.exec(code);
|
|
172
|
+
}
|
|
173
|
+
return names;
|
|
174
|
+
};
|
|
175
|
+
export const collectCandidateInlineConstants = (candidate, processorStaticValuesByLocal) => {
|
|
176
|
+
const inlineConstants = {};
|
|
177
|
+
let hasInlineConstant = false;
|
|
178
|
+
let match = JS_IDENTIFIER_RE.exec(candidate.source);
|
|
179
|
+
while (match) {
|
|
180
|
+
const name = match[0];
|
|
181
|
+
if (processorStaticValuesByLocal.has(name)) {
|
|
182
|
+
inlineConstants[name] = processorStaticValuesByLocal.get(name);
|
|
183
|
+
hasInlineConstant = true;
|
|
184
|
+
}
|
|
185
|
+
match = JS_IDENTIFIER_RE.exec(candidate.source);
|
|
186
|
+
}
|
|
187
|
+
return hasInlineConstant ? inlineConstants : null;
|
|
188
|
+
};
|
|
189
|
+
export const addCandidateInlineConstants = (candidates, processorStaticValuesByLocal) => {
|
|
190
|
+
if (processorStaticValuesByLocal.size === 0) {
|
|
191
|
+
return candidates;
|
|
192
|
+
}
|
|
193
|
+
return candidates.map((candidate) => {
|
|
194
|
+
const inlineConstants = collectCandidateInlineConstants(candidate, processorStaticValuesByLocal);
|
|
195
|
+
if (!inlineConstants) {
|
|
196
|
+
return candidate;
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
...candidate,
|
|
200
|
+
inlineConstants: {
|
|
201
|
+
...candidate.inlineConstants,
|
|
202
|
+
...inlineConstants
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=sameFileStaticValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAOA,SAAS,iBAAiB;AAC1B,SACE,kCACA,oCAEA,mCACK;AACP,SACE,0BACA,kBACA,kCACK;AAGP,OAAO,MAAM,mBACX,eAC0C;CAC1C,MAAM,sBAAsB;CAG5B,MAAM,iBAAiB,WAAW;AAElC,KACE,mBAAmB,mBACnB,mBAAmB,oBACnB,mBAAmB,oBACnB,mBAAmB,WACnB;AACA,SAAO,oBAAoB;;AAG7B,KAAI,mBAAmB,eAAe;AACpC,SAAO;;AAGT,QAAO;;AAGT,OAAO,MAAM,sBAAsB,QAA6B;AAC9D,KAAI,IAAI,SAAS,cAAc;AAC7B,SAAQ,IAAgC;;CAG1C,MAAM,QAAQ,gBAAgB,IAAI;AAClC,QAAO,OAAO,UAAU,WAAW,QAAQ;;AAG7C,OAAO,MAAM,oCACX,qBACuB;AACvB,KAAI,iBAAiB,SAAS,oBAAoB;AAChD,SAAO;;CAGT,MAAM,EAAE,eAAe;AAUvB,KAAI,CAAC,YAAY;AACf,SAAO;;CAGT,MAAM,QAAQ,IAAI,KAAa;AAC/B,MAAK,MAAM,YAAY,YAAY;EACjC,MAAM,eAAe,SAAS;AAC9B,MAAI,iBAAiB,oBAAoB,iBAAiB,YAAY;AACpE,UAAO;;AAGT,M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ricted-syntax */\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport type { Node } from 'oxc-parser';\n\nimport type { OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';\nimport { isOxcNode } from '../oxc/ast';\nimport {\n processorExpressionToStaticValue,\n resolveProcessorStaticRuntimeValue,\n type UnknownProcessorStaticValue,\n unknownProcessorStaticValue,\n} from '../processorStaticSemantics';\nimport {\n GENERATED_HELPER_NAME_RE,\n JS_IDENTIFIER_RE,\n WYW_META_EXTENDS_HELPER_RE,\n} from './shared';\nimport type { AnyNode, SameFileProcessorObject } from './types';\n\nexport const oxcLiteralValue = (\n expression: Node\n): unknown | UnknownProcessorStaticValue => {\n const expressionWithValue = expression as Node & {\n value?: unknown;\n };\n const expressionType = expression.type as string;\n\n if (\n expressionType === 'StringLiteral' ||\n expressionType === 'NumericLiteral' ||\n expressionType === 'BooleanLiteral' ||\n expressionType === 'Literal'\n ) {\n return expressionWithValue.value;\n }\n\n if (expressionType === 'NullLiteral') {\n return null;\n }\n\n return unknownProcessorStaticValue;\n};\n\nexport const oxcPropertyKeyName = (key: Node): string | null => {\n if (key.type === 'Identifier') {\n return (key as Node & { name: string }).name;\n }\n\n const value = oxcLiteralValue(key);\n return typeof value === 'string' ? value : null;\n};\n\nexport const collectStaticObjectPropertyNames = (\n objectExpression: Node\n): Set<string> | null => {\n if (objectExpression.type !== 'ObjectExpression') {\n return null;\n }\n\n const { properties } = objectExpression as Node & {\n properties?: Array<\n Node & {\n computed?: boolean;\n key?: Node;\n type: string;\n value?: Node;\n }\n >;\n };\n if (!properties) {\n return null;\n }\n\n const names = new Set<string>();\n for (const property of properties) {\n const propertyType = property.type as string;\n if (propertyType !== 'ObjectProperty' && propertyType !== 'Property') {\n return null;\n }\n\n if (!property.key || !property.value) {\n return null;\n }\n\n const name = oxcPropertyKeyName(property.key);\n if (!name || names.has(name)) {\n return null;\n }\n\n names.add(name);\n }\n\n return names;\n};\n\nexport const getSameFileProcessorObjectProperty = (\n ancestors: Node[]\n): {\n localName: string;\n propertyName: string;\n propertyNames: Set<string>;\n} | null => {\n let propertyIndex = -1;\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n if (ancestors[idx].type === 'Property') {\n propertyIndex = idx;\n break;\n }\n }\n\n if (propertyIndex <= 0) {\n return null;\n }\n\n const property = ancestors[propertyIndex] as Node & {\n key?: Node;\n };\n const objectExpression = ancestors[propertyIndex - 1];\n if (!property.key || objectExpression.type !== 'ObjectExpression') {\n return null;\n }\n\n const propertyName = oxcPropertyKeyName(property.key);\n const propertyNames = collectStaticObjectPropertyNames(objectExpression);\n if (!propertyName || !propertyNames) {\n return null;\n }\n\n for (let idx = propertyIndex - 2; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx] as AnyNode;\n if (ancestor.type === 'VariableDeclarator') {\n const { id, init } = ancestor;\n if (\n isOxcNode(id) &&\n id.type === 'Identifier' &&\n init === objectExpression\n ) {\n return {\n localName: id.name,\n propertyName,\n propertyNames,\n };\n }\n }\n }\n\n return null;\n};\n\nexport const createSameFileProcessorStaticValueResolver = (\n processorsByLocal: Map<string, BaseProcessor>,\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[]\n): {\n resolveLocal: (local: string) => unknown | UnknownProcessorStaticValue;\n resolveProcessor: (\n processor: BaseProcessor\n ) => unknown | UnknownProcessorStaticValue;\n} => {\n const expressionSourceByName = new Map<string, string>();\n expressionValues.forEach((value) => {\n if (value.ex.type === 'Identifier') {\n expressionSourceByName.set(value.ex.name, value.source);\n }\n });\n\n const memo = new Map<string, unknown | UnknownProcessorStaticValue>();\n const resolving = new Set<string>();\n\n function resolveLocal(local: string): unknown | UnknownProcessorStaticValue {\n if (memo.has(local)) {\n return memo.get(local)!;\n }\n\n const processor = processorsByLocal.get(local);\n if (!processor || resolving.has(local)) {\n return unknownProcessorStaticValue;\n }\n\n resolving.add(local);\n const contractValue = resolveProcessorStaticRuntimeValue(processor);\n const value =\n contractValue !== unknownProcessorStaticValue\n ? contractValue\n : processorExpressionToStaticValue(processor.value, (helperName) => {\n const source = expressionSourceByName.get(helperName);\n return source ? resolveLocal(source) : unknownProcessorStaticValue;\n });\n resolving.delete(local);\n memo.set(local, value);\n return value;\n }\n\n function resolveProcessor(\n processor: BaseProcessor\n ): unknown | UnknownProcessorStaticValue {\n const contractValue = resolveProcessorStaticRuntimeValue(processor);\n if (contractValue !== unknownProcessorStaticValue) {\n return contractValue;\n }\n\n return processorExpressionToStaticValue(processor.value, (helperName) => {\n const source = expressionSourceByName.get(helperName);\n return source ? resolveLocal(source) : unknownProcessorStaticValue;\n });\n }\n\n return { resolveLocal, resolveProcessor };\n};\n\nexport const collectSameFileProcessorStaticValuesByLocal = (\n processorsByLocal: Map<string, BaseProcessor>,\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[]\n): Map<string, unknown> => {\n const { resolveLocal } = createSameFileProcessorStaticValueResolver(\n processorsByLocal,\n expressionValues\n );\n\n const result = new Map<string, unknown>();\n processorsByLocal.forEach((_processor, local) => {\n const value = resolveLocal(local);\n if (value !== unknownProcessorStaticValue) {\n result.set(local, value);\n }\n });\n\n return result;\n};\n\nexport const collectSameFileProcessorObjectStaticValuesByLocal = (\n processorObjectsByLocal: Map<string, SameFileProcessorObject>,\n processorsByLocal: Map<string, BaseProcessor>,\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[]\n): Map<string, unknown> => {\n const { resolveProcessor } = createSameFileProcessorStaticValueResolver(\n processorsByLocal,\n expressionValues\n );\n\n const result = new Map<string, unknown>();\n for (const [local, object] of processorObjectsByLocal) {\n if (object.properties.size === object.propertyNames.size) {\n const value: Record<string, unknown> = {};\n let complete = true;\n for (const propertyName of object.propertyNames) {\n const processor = object.properties.get(propertyName);\n if (!processor) {\n complete = false;\n break;\n }\n\n const propertyValue = resolveProcessor(processor);\n if (propertyValue === unknownProcessorStaticValue) {\n complete = false;\n break;\n }\n\n value[propertyName] = propertyValue;\n }\n\n if (complete) {\n result.set(local, value);\n }\n }\n }\n\n return result;\n};\n\nexport const collectWYWMetaExtendsHelperNames = (code: string): Set<string> => {\n const names = new Set<string>();\n\n let match = WYW_META_EXTENDS_HELPER_RE.exec(code);\n while (match) {\n const name = match[1];\n if (name && GENERATED_HELPER_NAME_RE.test(name)) {\n names.add(name);\n }\n match = WYW_META_EXTENDS_HELPER_RE.exec(code);\n }\n return names;\n};\n\nexport const collectCandidateInlineConstants = (\n candidate: OxcStaticValueCandidate,\n processorStaticValuesByLocal: Map<string, unknown>\n): Record<string, unknown> | null => {\n const inlineConstants: Record<string, unknown> = {};\n let hasInlineConstant = false;\n\n let match = JS_IDENTIFIER_RE.exec(candidate.source);\n while (match) {\n const name = match[0];\n if (processorStaticValuesByLocal.has(name)) {\n inlineConstants[name] = processorStaticValuesByLocal.get(name);\n hasInlineConstant = true;\n }\n match = JS_IDENTIFIER_RE.exec(candidate.source);\n }\n\n return hasInlineConstant ? inlineConstants : null;\n};\n\nexport const addCandidateInlineConstants = (\n candidates: OxcStaticValueCandidate[],\n processorStaticValuesByLocal: Map<string, unknown>\n): OxcStaticValueCandidate[] => {\n if (processorStaticValuesByLocal.size === 0) {\n return candidates;\n }\n\n return candidates.map((candidate) => {\n const inlineConstants = collectCandidateInlineConstants(\n candidate,\n processorStaticValuesByLocal\n );\n\n if (!inlineConstants) {\n return candidate;\n }\n\n return {\n ...candidate,\n inlineConstants: {\n ...candidate.inlineConstants,\n ...inlineConstants,\n },\n };\n });\n};\n"],"file":"sameFileStaticValues.js"}
|