@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 @@
|
|
|
1
|
+
{"mappings":";AAEA,OAAO,QAAQ;AACf,OAAO,UAAU;AAIjB,SAAS,mBAAyC;AAElD,SAAS,8CAA8C;AAKvD,SAAS,mBAAmB,mBAAmB;AAC/C,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAqClC,MAAM,2BAA2B,IAAI,KAAa;AAElD,MAAM,UAAU,UACd,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,UAAU,SACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,eAAe,SAAuB;CAC1C,MAAM,SAAiB,EAAE;CACzB,MAAM,SAAS;AAEf,QAAO,KAAK,OAAO,CAAC,SAAS,QAAQ;AACnC,MAAI,QAAQ,UAAU,QAAQ,WAAW,QAAQ,SAAS,QAAQ,SAAS;AACzE;;EAGF,MAAM,QAAQ,OAAO;AACrB,MAAI,OAAO,MAAM,EAAE;AACjB,UAAO,KAAK,MAAM;AAClB;;AAGF,MAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,SAAM,SAAS,SAAS;AACtB,QAAI,OAAO,KAAK,EAAE;AAChB,YAAO,KAAK,KAAK;;KAEnB;;GAEJ;AAEF,QAAO;;AAGT,MAAM,YACJ,MACA,aAC8C;AAC9C,KAAI;EACF,MAAM,SAAS,eAAe,UAAU,MAAM,cAAc;AAC5D,SAAO;GACL,YAAY,OAAO,OAAO;GAC1B,SAAS,OAAO;GACjB;UACM,OAAO;AACd,MAAI,QAAQ,IAAI,uBAAuB;GACrC,MAAM,WAAW,KAAK,KACpB,QACA,kBAAkB,KACf,SAAS,SAAS,CAClB,QAAQ,kBAAk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AS,UAAU,IAAI,KAAK,CAAC,GAChE;AACA,QAAK,WAAW,KAAK;;AAGvB,MACE,UAAU,qBACT,UAAU,IAAI,cAAc,IAC3B,QAAQ,mBACR,UAAU,QAAQ,MAAM,SACtB,kBAAkB,KAAK,QAAQ,QAAQ,CACxC,GACH;AACA,QAAK,UAAU;;GAEjB;AAEF,QAAO,MAAM,SAAS,GAAG;EACvB,MAAM,UAAU,MAAM,OAAO;AAC7B,UAAQ,WAAW,SAAS,SAAS;GACnC,MAAM,QAAQ,cAAc,IAAI,KAAK;AACrC,OAAI,OAAO;AACT,SAAK,MAAM;;IAEb;AACF,UAAQ,SAAS,SAAS,YAAY;AACpC,sBAAmB,IAAI,QAAQ,EAAE,SAAS,aAAa;AACrD,SAAK,SAAS;KACd;IACF;;CAGJ,MAAM,eAA8B,EAAE;AACtC,YAAW,SAAS,cAAc;AAChC,MAAI,CAAC,eAAe,IAAI,UAAU,EAAE;AAClC,gBAAa,KAAK;IAChB,KAAK,UAAU,KAAK;IACpB,OAAO,UAAU,KAAK;IACtB,OAAO;IACR,CAAC;AACF;;AAGF,MAAI,CAAC,qBAAqB,IAAI,UAAU,EAAE;GACxC,MAAM,cAAc,oBAAoB,MAAM,UAAU,KAAK;AAC7D,OAAI,aAAa;AACf,iBAAa,KAAK,YAAY;;AAEhC;;EAGF,MAAM,mBAAmB,iCACvB,MACA,UAAU,MACV,UACD;AACD,MAAI,kBAAkB;AACpB,gBAAa,KAAK,iBAAiB;;GAErC;CAEF,MAAM,UAAU,6BACd,kBAAkB,MAAM,aAAa,EACrC,SACD;CACD,MAAM,WAAW,QAAQ;CACzB,MAAM,gBAAgB,uCACpB,QAAQ,OAAO,SACf,UACA,QAAQ,OAAO,WAChB;AACD,oBAAmB,cAAc,SAAS,UAAU,QAAQ;AAE5D,QAAO;EACL,MAAM;EACN,SAAS,aAAa,cAAc;EACrC","names":[],"sources":["../../src/utils/oxcShaker.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport fs from 'fs';\nimport path from 'path';\n\nimport type { Node, Program } from 'oxc-parser';\n\nimport { syncResolve, type ImportOverrides } from '@wyw-in-js/shared';\n\nimport { collectOxcExportsAndImportsFromProgram } from './collectOxcExportsAndImports';\nimport type {\n collectOxcExportsAndImports,\n OxcCollectedImport,\n} from './collectOxcExportsAndImports';\nimport { getImportOverride, toImportKey } from './importOverrides';\nimport { parseOxcCached } from './parseOxc';\nimport { stripQueryAndHash } from './parseRequest';\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype Replacement = {\n end: number;\n start: number;\n value: string;\n};\n\ntype OxcShakerOptions = {\n importOverrides?: ImportOverrides;\n keepSideEffects?: boolean;\n onlyExports: string[];\n root?: string;\n};\n\ntype StatementInfo = {\n bindings: Set<string>;\n exportNames: Set<string>;\n imports: OxcCollectedImport[];\n mutations: Set<string>;\n node: Node;\n references: Set<string>;\n sideEffectImport: boolean;\n};\n\nexport type OxcShakerResult = {\n code: string;\n imports: Map<string, string[]>;\n};\ntype ParsedOxcProgram = ReturnType<typeof parseOxc>;\ntype RemoveUnusedImportSpecifiersResult = {\n code: string;\n parsed: ParsedOxcProgram;\n};\n\nconst warnedDynamicImportFiles = new Set<string>();\n\nconst isNode = (value: unknown): value is Node =>\n !!value &&\n typeof value === 'object' &&\n 'type' in value &&\n typeof (value as { type?: unknown }).type === 'string';\n\nconst getChildren = (node: Node): Node[] => {\n const result: Node[] = [];\n const record = node as AnyNode;\n\n Object.keys(record).forEach((key) => {\n if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {\n return;\n }\n\n const value = record[key];\n if (isNode(value)) {\n result.push(value);\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (isNode(item)) {\n result.push(item);\n }\n });\n }\n });\n\n return result;\n};\n\nconst parseOxc = (\n code: string,\n filename: string\n): { isEsModule: boolean; program: Program } => {\n try {\n const parsed = parseOxcCached(filename, code, 'unambiguous');\n return {\n isEsModule: parsed.module.hasModuleSyntax,\n program: parsed.program,\n };\n } catch (error) {\n if (process.env.WYW_DEBUG_SHAKER_DUMP) {\n const dumpFile = path.join(\n '/tmp',\n `wyw-oxc-shaker-${path\n .basename(filename)\n .replace(/[^a-z0-9_.-]/gi, '_')}-${Date.now()}.js`\n );\n fs.writeFileSync(dumpFile, code);\n const message =\n error instanceof Error\n ? error.message\n : 'Unknown Oxc shaker parse error';\n throw new Error(`${message} [${filename}] [dump: ${dumpFile}]`);\n }\n\n throw error;\n }\n};\n\nconst applyReplacements = (\n code: string,\n replacements: Replacement[]\n): string => {\n let result = code;\n replacements\n .sort((a, b) => b.start - a.start)\n .forEach((replacement) => {\n result =\n result.slice(0, replacement.start) +\n replacement.value +\n result.slice(replacement.end);\n });\n\n return result;\n};\n\nconst collectBindingNames = (node: Node | null | undefined): string[] => {\n if (!node) {\n return [];\n }\n\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectBindingNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectBindingNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) => collectBindingNames(element));\n }\n\n return [];\n};\n\nconst declarationBindings = (\n declaration: Node | null | undefined\n): string[] => {\n if (!declaration) {\n return [];\n }\n\n if (declaration.type === 'VariableDeclaration') {\n return declaration.declarations.flatMap((item) =>\n collectBindingNames(item.id)\n );\n }\n\n if (\n (declaration.type === 'FunctionDeclaration' ||\n declaration.type === 'ClassDeclaration' ||\n declaration.type === 'TSEnumDeclaration') &&\n declaration.id\n ) {\n return [declaration.id.name];\n }\n\n return [];\n};\n\nconst moduleExportName = (node: Node): string | null => {\n if (node.type === 'Identifier' || node.type === 'Literal') {\n return String((node as AnyNode).name ?? (node as AnyNode).value);\n }\n\n return null;\n};\n\nconst isBindingIdentifier = (node: Node, parent: Node | null): boolean => {\n if (node.type !== 'Identifier' || !parent) {\n return false;\n }\n\n const parentNode = parent as AnyNode;\n if (parent.type === 'VariableDeclarator' && parentNode.id === node) {\n return true;\n }\n\n if (\n (parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression' ||\n parent.type === 'ClassDeclaration' ||\n parent.type === 'ClassExpression' ||\n parent.type === 'TSEnumDeclaration') &&\n parentNode.id === node\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ImportSpecifier' ||\n parent.type === 'ImportDefaultSpecifier' ||\n parent.type === 'ImportNamespaceSpecifier') &&\n parentNode.local === node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isIdentifierReference = (\n node: Node,\n parent: Node | null,\n grandparent: Node | null\n): boolean => {\n if (node.type !== 'Identifier') {\n return false;\n }\n\n if (isBindingIdentifier(node, parent)) {\n return false;\n }\n\n if (!parent) {\n return true;\n }\n\n const parentNode = parent as AnyNode;\n if (\n parent.type === 'Property' &&\n parentNode.key === node &&\n !parentNode.computed\n ) {\n return false;\n }\n\n if (\n parent.type === 'MemberExpression' &&\n parentNode.property === node &&\n !parentNode.computed\n ) {\n return false;\n }\n\n if (parent.type === 'ExportSpecifier' && parentNode.exported === node) {\n return false;\n }\n\n if (parent.type === 'ExportSpecifier' && parentNode.local === node) {\n return grandparent?.type === 'ExportNamedDeclaration'\n ? !grandparent.source\n : true;\n }\n\n // The `imported` name of `import { X as Y }` is what to take from the source\n // module — it does not reference a local binding `X` in the current module.\n if (parent.type === 'ImportSpecifier' && parentNode.imported === node) {\n return false;\n }\n\n return true;\n};\n\nconst TS_EXPRESSION_WRAPPER_TYPES = new Set([\n 'TSAsExpression',\n 'TSSatisfiesExpression',\n 'TSTypeAssertion',\n 'TSNonNullExpression',\n 'TSInstantiationExpression',\n]);\n\nconst collectReferences = (node: Node): Set<string> => {\n const references = new Set<string>();\n\n const visit = (\n current: Node,\n parent: Node | null = null,\n grandparent: Node | null = null\n ): void => {\n if (TS_EXPRESSION_WRAPPER_TYPES.has(current.type)) {\n const expression = (current as AnyNode).expression as Node | undefined;\n if (expression) {\n visit(expression, current, parent);\n }\n return;\n }\n\n if (current.type.startsWith('TS') && current.type !== 'TSEnumDeclaration') {\n return;\n }\n\n if (isIdentifierReference(current, parent, grandparent)) {\n references.add((current as AnyNode).name as string);\n }\n\n getChildren(current).forEach((child) => visit(child, current, parent));\n };\n\n visit(node);\n\n return references;\n};\n\nconst getMutatedBinding = (node: Node): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'MemberExpression' && node.object.type === 'Identifier') {\n return node.object.name;\n }\n\n return null;\n};\n\nconst getMutationCallTarget = (node: Node): string | null => {\n if (node.type !== 'CallExpression') {\n return null;\n }\n\n const { callee } = node;\n if (\n callee.type !== 'MemberExpression' ||\n callee.object.type !== 'Identifier' ||\n callee.object.name !== 'Object' ||\n callee.computed ||\n callee.property.type !== 'Identifier'\n ) {\n return null;\n }\n\n if (\n callee.property.name !== 'assign' &&\n callee.property.name !== 'defineProperty' &&\n callee.property.name !== 'defineProperties'\n ) {\n return null;\n }\n\n const [target] = node.arguments;\n if (!target || target.type === 'SpreadElement') {\n return null;\n }\n\n return getMutatedBinding(target);\n};\n\nconst collectMutations = (node: Node): Set<string> => {\n const mutations = new Set<string>();\n\n const visit = (current: Node): void => {\n if (current.type === 'AssignmentExpression') {\n const mutated = getMutatedBinding(current.left);\n if (mutated) {\n mutations.add(mutated);\n }\n } else if (current.type === 'UpdateExpression') {\n const mutated = getMutatedBinding(current.argument);\n if (mutated) {\n mutations.add(mutated);\n }\n } else {\n const mutated = getMutationCallTarget(current);\n if (mutated) {\n mutations.add(mutated);\n }\n }\n\n getChildren(current).forEach(visit);\n };\n\n visit(node);\n return mutations;\n};\n\nconst buildStatementInfo = (\n program: Program,\n collected: ReturnType<typeof collectOxcExportsAndImports>\n): StatementInfo[] => {\n const { exports: collectedExports, imports: collectedImports } = collected;\n const importsByStart = new Map<number, OxcCollectedImport[]>();\n collectedImports.forEach((item) => {\n const bucket = importsByStart.get(item.local.start) ?? [];\n bucket.push(item);\n importsByStart.set(item.local.start, bucket);\n });\n\n return program.body.map((statement) => {\n const node = statement as Node;\n const exportNames = new Set<string>();\n const bindings = new Set<string>();\n const imports: OxcCollectedImport[] = [];\n const references = collectReferences(node);\n let sideEffectImport = false;\n\n if (node.type === 'ImportDeclaration') {\n sideEffectImport = node.specifiers.length === 0;\n node.specifiers.forEach((specifier) => {\n bindings.add(specifier.local.name);\n const matched = importsByStart.get(specifier.local.start) ?? [];\n imports.push(...matched);\n });\n\n if (sideEffectImport) {\n const matched = collectedImports.filter(\n (item) =>\n item.imported === 'side-effect' &&\n item.local.start === node.start &&\n item.local.end === node.end\n );\n imports.push(...matched);\n }\n } else if (node.type === 'ExportNamedDeclaration') {\n declarationBindings(node.declaration).forEach((name) =>\n bindings.add(name)\n );\n if (node.declaration) {\n declarationBindings(node.declaration).forEach((name) =>\n exportNames.add(name)\n );\n }\n\n node.specifiers.forEach((specifier) => {\n const local = moduleExportName(specifier.local);\n const exported = moduleExportName(specifier.exported);\n if (local && !node.source) references.add(local);\n if (exported) exportNames.add(exported);\n });\n } else if (node.type === 'ExportDefaultDeclaration') {\n exportNames.add('default');\n declarationBindings(node.declaration).forEach((name) =>\n bindings.add(name)\n );\n } else if (node.type === 'ExportAllDeclaration') {\n if (node.exported) {\n const exported = moduleExportName(node.exported);\n if (exported) {\n exportNames.add(exported);\n }\n } else {\n exportNames.add('*');\n }\n } else {\n Object.entries(collectedExports).forEach(([exported, local]) => {\n if (local.start >= node.start && local.end <= node.end) {\n exportNames.add(exported);\n }\n });\n declarationBindings(node).forEach((name) => bindings.add(name));\n }\n\n return {\n bindings,\n exportNames,\n imports,\n mutations: collectMutations(node),\n node,\n references,\n sideEffectImport,\n };\n });\n};\n\nconst collectImportLocalNames = (node: Node): string[] => {\n if (node.type !== 'ImportDeclaration') {\n return [];\n }\n\n return node.specifiers.map((specifier) => specifier.local.name);\n};\n\nconst getImportSpecifierLocalName = (node: Node): string | null => {\n const { local } = node as AnyNode;\n return isNode(local) && 'name' in local && typeof local.name === 'string'\n ? local.name\n : null;\n};\n\nconst expandImportRemovalRange = (\n code: string,\n start: number,\n end: number\n): Replacement => {\n let removalStart = start;\n while (\n removalStart > 0 &&\n (code[removalStart - 1] === ' ' || code[removalStart - 1] === '\\t')\n ) {\n removalStart -= 1;\n }\n\n let removalEnd = end;\n if (code[removalEnd] === ';') {\n removalEnd += 1;\n }\n\n while (\n removalEnd < code.length &&\n (code[removalEnd] === ' ' || code[removalEnd] === '\\t')\n ) {\n removalEnd += 1;\n }\n\n if (code[removalEnd] === '\\r' && code[removalEnd + 1] === '\\n') {\n removalEnd += 2;\n } else if (code[removalEnd] === '\\n') {\n removalEnd += 1;\n }\n\n return {\n end: removalEnd,\n start: removalStart,\n value: '',\n };\n};\n\nconst expandImportSpecifierRemovalRange = (\n code: string,\n start: number,\n end: number\n): Replacement => {\n let removalStart = start;\n let removalEnd = end;\n\n let whitespaceStart = removalStart;\n while (\n whitespaceStart > 0 &&\n (code[whitespaceStart - 1] === ' ' || code[whitespaceStart - 1] === '\\t')\n ) {\n whitespaceStart -= 1;\n }\n if (code[whitespaceStart - 1] !== '{') {\n removalStart = whitespaceStart;\n }\n\n while (\n removalEnd < code.length &&\n (code[removalEnd] === ' ' || code[removalEnd] === '\\t')\n ) {\n removalEnd += 1;\n }\n\n if (code[removalEnd] === ',') {\n removalEnd += 1;\n while (\n removalEnd < code.length &&\n (code[removalEnd] === ' ' || code[removalEnd] === '\\t')\n ) {\n removalEnd += 1;\n }\n } else {\n while (\n removalStart > 0 &&\n (code[removalStart - 1] === ' ' || code[removalStart - 1] === '\\t')\n ) {\n removalStart -= 1;\n }\n\n if (code[removalStart - 1] === ',') {\n removalStart -= 1;\n while (\n removalStart > 0 &&\n (code[removalStart - 1] === ' ' || code[removalStart - 1] === '\\t')\n ) {\n removalStart -= 1;\n }\n }\n }\n\n return {\n end: removalEnd,\n start: removalStart,\n value: '',\n };\n};\n\nconst mergeEmptyRemovalRanges = (removals: Replacement[]): Replacement[] => {\n if (removals.length <= 1) {\n return removals;\n }\n\n const sorted = [...removals].sort((a, b) => a.start - b.start);\n const merged: Replacement[] = [];\n\n sorted.forEach((removal) => {\n const previous = merged[merged.length - 1];\n if (\n previous &&\n previous.value === '' &&\n removal.value === '' &&\n removal.start <= previous.end\n ) {\n previous.end = Math.max(previous.end, removal.end);\n return;\n }\n\n merged.push({ ...removal });\n });\n\n return merged;\n};\n\nconst removeUnusedImportSpecifiers = (\n code: string,\n filename: string\n): RemoveUnusedImportSpecifiersResult => {\n const parsed = parseOxc(code, filename);\n const { program } = parsed;\n const referencedNames = new Set<string>();\n\n program.body.forEach((statement) => {\n if (statement.type === 'ImportDeclaration') {\n return;\n }\n\n collectReferences(statement as Node).forEach((name) =>\n referencedNames.add(name)\n );\n });\n\n const removals: Replacement[] = [];\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n if (statement.specifiers.length === 0) {\n return;\n }\n\n const localNames = collectImportLocalNames(statement);\n if (localNames.every((localName) => !referencedNames.has(localName))) {\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n return;\n }\n\n if (statement.specifiers.length <= 1) {\n return;\n }\n\n statement.specifiers.forEach((specifier) => {\n const localName = getImportSpecifierLocalName(specifier);\n if (localName && !referencedNames.has(localName)) {\n removals.push(\n expandImportSpecifierRemovalRange(\n code,\n specifier.start,\n specifier.end\n )\n );\n }\n });\n });\n\n if (removals.length === 0) {\n return {\n code,\n parsed,\n };\n }\n\n const mergedRemovals = mergeEmptyRemovalRanges(removals);\n const nextCode = applyReplacements(code, mergedRemovals);\n\n try {\n return {\n code: nextCode,\n parsed: parseOxc(nextCode, filename),\n };\n } catch {\n return {\n code,\n parsed,\n };\n }\n};\n\nconst hasImportOverride = (\n source: string,\n options: Pick<OxcShakerOptions, 'importOverrides' | 'root'>\n): boolean => {\n const { importOverrides } = options;\n if (!importOverrides || Object.keys(importOverrides).length === 0) {\n return false;\n }\n\n const stripped = stripQueryAndHash(source);\n const direct =\n getImportOverride(importOverrides, source) ??\n (stripped !== source ? getImportOverride(importOverrides, stripped) : null);\n\n if (direct && ('mock' in direct || 'noShake' in direct)) {\n return true;\n }\n\n if (!stripped.startsWith('.') && !path.isAbsolute(stripped)) {\n return false;\n }\n\n return false;\n};\n\nconst importsToMap = (\n collected: ReturnType<typeof collectOxcExportsAndImports>\n): Map<string, string[]> => {\n const result = new Map<string, string[]>();\n\n const add = (source: string, imported: string): void => {\n const bucket = result.get(source) ?? [];\n if (!bucket.includes(imported)) {\n bucket.push(imported);\n }\n\n result.set(source, bucket);\n };\n\n collected.imports.forEach((item) => {\n const imported = item.imported || 'side-effect';\n add(item.source, imported);\n });\n\n collected.reexports.forEach((item) => {\n add(item.source, item.imported || 'side-effect');\n });\n\n return result;\n};\n\nconst dynamicImportWarningsEnabled = (): boolean =>\n Boolean(process.env.WYW_WARN_DYNAMIC_IMPORTS) &&\n process.env.WYW_WARN_DYNAMIC_IMPORTS !== '0' &&\n process.env.WYW_WARN_DYNAMIC_IMPORTS !== 'false';\n\nconst filterDynamicImportsForWarning = (\n imports: OxcCollectedImport[],\n filename: string,\n options: OxcShakerOptions\n): string[] => {\n const sources = Array.from(\n new Set(\n imports\n .filter((item) => item.type === 'dynamic')\n .map((item) => item.source)\n )\n ).sort();\n\n if (\n !options.importOverrides ||\n Object.keys(options.importOverrides).length === 0\n ) {\n return sources;\n }\n\n const shouldWarn = (source: string): boolean => {\n const strippedSource = stripQueryAndHash(source);\n const direct =\n getImportOverride(options.importOverrides, source) ??\n (strippedSource !== source\n ? getImportOverride(options.importOverrides, strippedSource)\n : undefined);\n\n if (direct !== undefined) {\n return false;\n }\n\n const isFileImport =\n strippedSource.startsWith('.') || path.isAbsolute(strippedSource);\n if (!isFileImport) {\n return true;\n }\n\n try {\n const resolved = syncResolve(strippedSource, filename, []);\n const importKey = toImportKey({\n resolved,\n root: options.root,\n source: strippedSource,\n }).key;\n\n return (\n getImportOverride(options.importOverrides, importKey) === undefined\n );\n } catch {\n return true;\n }\n };\n\n return sources.filter(shouldWarn);\n};\n\nconst warnDynamicImports = (\n imports: OxcCollectedImport[],\n filename: string,\n options: OxcShakerOptions\n): void => {\n if (\n !dynamicImportWarningsEnabled() ||\n warnedDynamicImportFiles.has(filename)\n ) {\n return;\n }\n\n const sourcesToWarn = filterDynamicImportsForWarning(\n imports,\n filename,\n options\n );\n if (sourcesToWarn.length === 0) {\n return;\n }\n\n warnedDynamicImportFiles.add(filename);\n\n const overrideKeys = sourcesToWarn\n .map((source) => {\n const strippedSource = stripQueryAndHash(source);\n const isFileImport =\n strippedSource.startsWith('.') || path.isAbsolute(strippedSource);\n\n if (!isFileImport) {\n return { key: source, source };\n }\n\n try {\n const resolved = syncResolve(strippedSource, filename, []);\n return {\n key: toImportKey({\n resolved,\n root: options.root,\n source: strippedSource,\n }).key,\n source,\n };\n } catch {\n return { key: strippedSource, source };\n }\n })\n .filter((item, index, array) => {\n const firstIndexForKey = array.findIndex((i) => i.key === item.key);\n return firstIndexForKey === index;\n });\n\n const warning = [\n `[wyw-in-js] Dynamic imports reached prepare stage`,\n ``,\n `file: ${filename}`,\n `count: ${sourcesToWarn.length}`,\n `sources:`,\n ...sourcesToWarn.map((source) => ` - ${source}`),\n ``,\n `note: these imports will be resolved/processed even if they are lazy (e.g. React.lazy(() => import(...)))`,\n ``,\n `tip: if the imported module is runtime-only or heavy, mock it during evaluation via importOverrides:`,\n ` importOverrides: {`,\n ...overrideKeys.map(\n ({ key, source }) =>\n ` '${key}': { mock: './path/to/mock' }, // from ${source}`\n ),\n ` }`,\n ``,\n `note: importOverrides affects only build-time evaluation (it does not change your bundler runtime behavior)`,\n ].join('\\n');\n\n // eslint-disable-next-line no-console\n console.warn(warning);\n};\n\nconst removeExportKeyword = (code: string, node: Node): Replacement | null => {\n if (\n node.type !== 'ExportNamedDeclaration' ||\n !node.declaration ||\n node.start === node.declaration.start\n ) {\n return null;\n }\n\n return {\n end: node.declaration.start,\n start: node.start,\n value: '',\n };\n};\n\nconst splitExportedVariableDeclaration = (\n code: string,\n node: Node,\n requested: Set<string>\n): Replacement | null => {\n if (\n node.type !== 'ExportNamedDeclaration' ||\n !node.declaration ||\n node.declaration.type !== 'VariableDeclaration' ||\n node.declaration.declarations.length <= 1\n ) {\n return null;\n }\n\n const declarators = node.declaration.declarations;\n const declaratorNames = declarators.map((declarator) =>\n collectBindingNames(declarator.id)\n );\n const requestedNames = declaratorNames\n .flat()\n .filter((name) => requested.has(name));\n\n if (\n requestedNames.length === 0 ||\n requestedNames.length === declaratorNames.flat().length\n ) {\n return null;\n }\n\n const declarationCode = `${node.declaration.kind} ${declarators\n .map((declarator) => code.slice(declarator.start, declarator.end))\n .join(', ')};`;\n\n return {\n end: node.end,\n start: node.start,\n value: `${declarationCode}\\nexport { ${requestedNames.join(', ')} };`,\n };\n};\n\nexport const shakeOxcToESM = (\n code: string,\n filename: string,\n options: OxcShakerOptions\n): OxcShakerResult => {\n const parsed = parseOxc(code, filename);\n const { program } = parsed;\n const collected = collectOxcExportsAndImportsFromProgram(\n program,\n code,\n parsed.isEsModule\n );\n const statements = buildStatementInfo(program, collected);\n const bindingOwners = new Map<string, StatementInfo>();\n statements.forEach((statement) => {\n statement.bindings.forEach((binding) => {\n if (!bindingOwners.has(binding)) {\n bindingOwners.set(binding, statement);\n }\n });\n });\n\n const requested = new Set(options.onlyExports);\n const keepAllExports = requested.has('*');\n const liveStatements = new Set<StatementInfo>();\n const liveExportStatements = new Set<StatementInfo>();\n const queue: StatementInfo[] = [];\n const mutationsByBinding = new Map<string, StatementInfo[]>();\n\n statements.forEach((statement) => {\n statement.mutations.forEach((binding) => {\n const bucket = mutationsByBinding.get(binding) ?? [];\n bucket.push(statement);\n mutationsByBinding.set(binding, bucket);\n });\n });\n\n const mark = (statement: StatementInfo, exported = false): void => {\n if (!liveStatements.has(statement)) {\n liveStatements.add(statement);\n queue.push(statement);\n }\n\n if (exported) {\n liveExportStatements.add(statement);\n }\n };\n\n statements.forEach((statement) => {\n const hasWildcardReexport = statement.exportNames.has('*');\n if (\n statement.exportNames.size > 0 &&\n (keepAllExports ||\n (hasWildcardReexport &&\n requested.size > 0 &&\n !requested.has('side-effect')) ||\n [...statement.exportNames].some((name) => requested.has(name)))\n ) {\n mark(statement, true);\n }\n\n if (\n statement.sideEffectImport &&\n (requested.has('side-effect') ||\n options.keepSideEffects ||\n statement.imports.some((item) =>\n hasImportOverride(item.source, options)\n ))\n ) {\n mark(statement);\n }\n });\n\n while (queue.length > 0) {\n const current = queue.shift()!;\n current.references.forEach((name) => {\n const owner = bindingOwners.get(name);\n if (owner) {\n mark(owner);\n }\n });\n current.bindings.forEach((binding) => {\n mutationsByBinding.get(binding)?.forEach((mutation) => {\n mark(mutation);\n });\n });\n }\n\n const replacements: Replacement[] = [];\n statements.forEach((statement) => {\n if (!liveStatements.has(statement)) {\n replacements.push({\n end: statement.node.end,\n start: statement.node.start,\n value: '',\n });\n return;\n }\n\n if (!liveExportStatements.has(statement)) {\n const replacement = removeExportKeyword(code, statement.node);\n if (replacement) {\n replacements.push(replacement);\n }\n return;\n }\n\n const splitReplacement = splitExportedVariableDeclaration(\n code,\n statement.node,\n requested\n );\n if (splitReplacement) {\n replacements.push(splitReplacement);\n }\n });\n\n const cleaned = removeUnusedImportSpecifiers(\n applyReplacements(code, replacements),\n filename\n );\n const nextCode = cleaned.code;\n const nextCollected = collectOxcExportsAndImportsFromProgram(\n cleaned.parsed.program,\n nextCode,\n cleaned.parsed.isEsModule\n );\n warnDynamicImports(nextCollected.imports, filename, options);\n\n return {\n code: nextCode,\n imports: importsToMap(nextCollected),\n };\n};\n"],"file":"oxcShaker.js"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
const MAX_PARSE_CACHE_ENTRIES = 200;
|
|
3
|
+
const parseCache = new Map();
|
|
4
|
+
const getAstType = (filename) => filename.endsWith(".ts") || filename.endsWith(".tsx") ? "ts" : "js";
|
|
5
|
+
const makeCacheKey = (filename, code, sourceType) => `${sourceType}\0${filename}\0${code}`;
|
|
6
|
+
const setCachedParse = (key, value) => {
|
|
7
|
+
parseCache.set(key, value);
|
|
8
|
+
if (parseCache.size > MAX_PARSE_CACHE_ENTRIES) {
|
|
9
|
+
const oldestKey = parseCache.keys().next().value;
|
|
10
|
+
if (oldestKey) {
|
|
11
|
+
parseCache.delete(oldestKey);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
};
|
|
16
|
+
export const parseOxcCached = (filename, code, sourceType) => {
|
|
17
|
+
const cacheKey = makeCacheKey(filename, code, sourceType);
|
|
18
|
+
const cached = parseCache.get(cacheKey);
|
|
19
|
+
if (cached) {
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
const parsed = parseSync(filename, code, {
|
|
23
|
+
astType: getAstType(filename),
|
|
24
|
+
range: true,
|
|
25
|
+
sourceType
|
|
26
|
+
});
|
|
27
|
+
const fatalError = parsed.errors.find((error) => error.severity === "Error");
|
|
28
|
+
if (fatalError) {
|
|
29
|
+
throw new Error(fatalError.message);
|
|
30
|
+
}
|
|
31
|
+
return setCachedParse(cacheKey, {
|
|
32
|
+
module: { hasModuleSyntax: parsed.module.hasModuleSyntax },
|
|
33
|
+
program: parsed.program
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const parseOxcProgramCached = (filename, code, sourceType) => parseOxcCached(filename, code, sourceType).program;
|
|
37
|
+
//# sourceMappingURL=parseOxc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,SAAS,iBAAiB;AAY1B,MAAM,0BAA0B;AAChC,MAAM,aAAa,IAAI,KAAwB;AAE/C,MAAM,cAAc,aAClB,SAAS,SAAS,MAAM,IAAI,SAAS,SAAS,OAAO,GAAG,OAAO;AAEjE,MAAM,gBACJ,UACA,MACA,eACW,GAAG,WAAW,IAAI,SAAS,IAAI;AAE5C,MAAM,kBAAkB,KAAa,UAAgC;AACnE,YAAW,IAAI,KAAK,MAAM;AAC1B,KAAI,WAAW,OAAO,yBAAyB;EAC7C,MAAM,YAAY,WAAW,MAAM,CAAC,MAAM,CAAC;AAC3C,MAAI,WAAW;AACb,cAAW,OAAO,UAAU;;;AAIhC,QAAO;;AAGT,OAAO,MAAM,kBACX,UACA,MACA,eACc;CACd,MAAM,WAAW,aAAa,UAAU,MAAM,WAAW;CACzD,MAAM,SAAS,WAAW,IAAI,SAAS;AACvC,KAAI,QAAQ;AACV,SAAO;;CAGT,MAAM,SAAS,UAAU,UAAU,MAAM;EACvC,SAAS,WAAW,SAAS;EAC7B,OAAO;EACP;EACD,CAAC;CACF,MAAM,aAAa,OAAO,OAAO,MAAM,UAAU,MAAM,aAAa,QAAQ;AAC5E,KAAI,YAAY;AACd,QAAM,IAAI,MAAM,WAAW,QAAQ;;AAGrC,QAAO,eAAe,UAAU;EAC9B,QAAQ,EACN,iBAAiB,OAAO,OAAO,iBAChC;EACD,SAAS,OAAO;EACjB,CAAC;;AAGJ,OAAO,MAAM,yBACX,UACA,MACA,eACY,eAAe,UAAU,MAAM,WAAW,CAAC","names":[],"sources":["../../src/utils/parseOxc.ts"],"version":3,"sourcesContent":["import { parseSync } from 'oxc-parser';\nimport type { Program } from 'oxc-parser';\n\ntype OxcSourceType = 'module' | 'unambiguous';\n\ntype ParsedOxc = {\n module: {\n hasModuleSyntax: boolean;\n };\n program: Program;\n};\n\nconst MAX_PARSE_CACHE_ENTRIES = 200;\nconst parseCache = new Map<string, ParsedOxc>();\n\nconst getAstType = (filename: string): 'js' | 'ts' =>\n filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js';\n\nconst makeCacheKey = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): string => `${sourceType}\\0${filename}\\0${code}`;\n\nconst setCachedParse = (key: string, value: ParsedOxc): ParsedOxc => {\n parseCache.set(key, value);\n if (parseCache.size > MAX_PARSE_CACHE_ENTRIES) {\n const oldestKey = parseCache.keys().next().value;\n if (oldestKey) {\n parseCache.delete(oldestKey);\n }\n }\n\n return value;\n};\n\nexport const parseOxcCached = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): ParsedOxc => {\n const cacheKey = makeCacheKey(filename, code, sourceType);\n const cached = parseCache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const parsed = parseSync(filename, code, {\n astType: getAstType(filename),\n range: true,\n sourceType,\n });\n const fatalError = parsed.errors.find((error) => error.severity === 'Error');\n if (fatalError) {\n throw new Error(fatalError.message);\n }\n\n return setCachedParse(cacheKey, {\n module: {\n hasModuleSyntax: parsed.module.hasModuleSyntax,\n },\n program: parsed.program as Program,\n });\n};\n\nexport const parseOxcProgramCached = (\n filename: string,\n code: string,\n sourceType: OxcSourceType\n): Program => parseOxcCached(filename, code, sourceType).program;\n"],"file":"parseOxc.js"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
const getFirstSuffixIndex = request => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const getFirstSuffixIndex = (request) => {
|
|
2
|
+
const queryIdx = request.indexOf("?");
|
|
3
|
+
const hashIdx = request.indexOf("#");
|
|
4
|
+
if (queryIdx === -1) return hashIdx;
|
|
5
|
+
if (hashIdx === -1) return queryIdx;
|
|
6
|
+
return Math.min(queryIdx, hashIdx);
|
|
7
7
|
};
|
|
8
|
-
export const parseRequest = request => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
export const parseRequest = (request) => {
|
|
9
|
+
const firstSuffixIndex = getFirstSuffixIndex(request);
|
|
10
|
+
if (firstSuffixIndex === -1) {
|
|
11
|
+
return {
|
|
12
|
+
filename: request,
|
|
13
|
+
hash: "",
|
|
14
|
+
query: ""
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const filename = request.slice(0, firstSuffixIndex);
|
|
18
|
+
const queryIdx = request.indexOf("?");
|
|
19
|
+
const hashIdx = request.indexOf("#");
|
|
20
|
+
const query = queryIdx === -1 ? "" : request.slice(queryIdx + 1, hashIdx !== -1 ? hashIdx : undefined);
|
|
21
|
+
const hash = hashIdx === -1 ? "" : request.slice(hashIdx + 1);
|
|
22
|
+
return {
|
|
23
|
+
filename,
|
|
24
|
+
hash,
|
|
25
|
+
query
|
|
26
|
+
};
|
|
27
27
|
};
|
|
28
|
-
export const stripQueryAndHash = request => parseRequest(request).filename;
|
|
29
|
-
//# sourceMappingURL=parseRequest.js.map
|
|
28
|
+
export const stripQueryAndHash = (request) => parseRequest(request).filename;
|
|
29
|
+
//# sourceMappingURL=parseRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAMA,MAAM,uBAAuB,YAAoB;CAC/C,MAAM,WAAW,QAAQ,QAAQ,IAAI;CACrC,MAAM,UAAU,QAAQ,QAAQ,IAAI;AAEpC,KAAI,aAAa,CAAC,EAAG,QAAO;AAC5B,KAAI,YAAY,CAAC,EAAG,QAAO;AAE3B,QAAO,KAAK,IAAI,UAAU,QAAQ;;AAGpC,OAAO,MAAM,gBAAgB,YAAmC;CAC9D,MAAM,mBAAmB,oBAAoB,QAAQ;AACrD,KAAI,qBAAqB,CAAC,GAAG;AAC3B,SAAO;GAAE,UAAU;GAAS,MAAM;GAAI,OAAO;GAAI;;CAGnD,MAAM,WAAW,QAAQ,MAAM,GAAG,iBAAiB;CAEnD,MAAM,WAAW,QAAQ,QAAQ,IAAI;CACrC,MAAM,UAAU,QAAQ,QAAQ,IAAI;CAEpC,MAAM,QACJ,aAAa,CAAC,IACV,KACA,QAAQ,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,UAAU,UAAU;CACvE,MAAM,OAAO,YAAY,CAAC,IAAI,KAAK,QAAQ,MAAM,UAAU,EAAE;AAE7D,QAAO;EAAE;EAAU;EAAM;EAAO;;AAGlC,OAAO,MAAM,qBAAqB,YAChC,aAAa,QAAQ,CAAC","names":[],"sources":["../../src/utils/parseRequest.ts"],"version":3,"sourcesContent":["export type ParsedRequest = {\n filename: string;\n hash: string;\n query: string;\n};\n\nconst getFirstSuffixIndex = (request: string) => {\n const queryIdx = request.indexOf('?');\n const hashIdx = request.indexOf('#');\n\n if (queryIdx === -1) return hashIdx;\n if (hashIdx === -1) return queryIdx;\n\n return Math.min(queryIdx, hashIdx);\n};\n\nexport const parseRequest = (request: string): ParsedRequest => {\n const firstSuffixIndex = getFirstSuffixIndex(request);\n if (firstSuffixIndex === -1) {\n return { filename: request, hash: '', query: '' };\n }\n\n const filename = request.slice(0, firstSuffixIndex);\n\n const queryIdx = request.indexOf('?');\n const hashIdx = request.indexOf('#');\n\n const query =\n queryIdx === -1\n ? ''\n : request.slice(queryIdx + 1, hashIdx !== -1 ? hashIdx : undefined);\n const hash = hashIdx === -1 ? '' : request.slice(hashIdx + 1);\n\n return { filename, hash, query };\n};\n\nexport const stripQueryAndHash = (request: string) =>\n parseRequest(request).filename;\n"],"file":"parseRequest.js"}
|
package/esm/utils/peek.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const peek = (stack, offset = 1) => stack[stack.length - offset];
|
|
2
|
-
//# sourceMappingURL=peek.js.map
|
|
2
|
+
//# sourceMappingURL=peek.js.map
|
package/esm/utils/peek.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"
|
|
1
|
+
{"mappings":"AAAA,OAAO,MAAM,QAAW,OAAY,SAAS,MAC3C,MAAM,MAAM,SAAS","names":[],"sources":["../../src/utils/peek.ts"],"version":3,"sourcesContent":["export const peek = <T>(stack: T[], offset = 1): T =>\n stack[stack.length - offset];\n"],"file":"peek.js"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import { dirname, join } from "path";
|
|
4
|
+
import { BaseProcessor } from "@wyw-in-js/processor-utils";
|
|
5
|
+
import { findPackageJSON, syncResolve } from "@wyw-in-js/shared";
|
|
6
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
7
|
+
const definedTagsCache = new Map();
|
|
8
|
+
const resolvedTagResolverSourceCache = new Map();
|
|
9
|
+
const packageProcessorLookupCache = new Map();
|
|
10
|
+
const tagResolverProcessorLookupCache = new WeakMap();
|
|
11
|
+
const createTagResolverLookupCacheKey = (source, imported, filename) => `${filename ?? ""}\0${source}\0${imported}`;
|
|
12
|
+
const createPackageLookupCacheKey = (source, imported) => `${source}\0${imported}`;
|
|
13
|
+
const URL_SCHEME_RE = /^[A-Za-z][A-Za-z\d+.-]*:/;
|
|
14
|
+
const isPackageLookupCandidate = (source) => {
|
|
15
|
+
if (!source || source.startsWith(".") || source.startsWith("/") || source.startsWith("\\") || source.startsWith("\0") || source.startsWith("@/") || source.startsWith("~/") || source.startsWith("#") || source.includes("?") || source.includes("#") || URL_SCHEME_RE.test(source)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (source.startsWith("@")) {
|
|
19
|
+
const [scope, pkg] = source.split("/", 2);
|
|
20
|
+
return scope.length > 1 && !!pkg;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
const getTagResolverLookupCache = (tagResolver) => {
|
|
25
|
+
const existing = tagResolverProcessorLookupCache.get(tagResolver);
|
|
26
|
+
if (existing) {
|
|
27
|
+
return existing;
|
|
28
|
+
}
|
|
29
|
+
const created = new Map();
|
|
30
|
+
tagResolverProcessorLookupCache.set(tagResolver, created);
|
|
31
|
+
return created;
|
|
32
|
+
};
|
|
33
|
+
const getResolvedTagResolverSource = (source, sourceFile) => {
|
|
34
|
+
if (!sourceFile) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const key = `${sourceFile}\0${source}`;
|
|
38
|
+
if (resolvedTagResolverSourceCache.has(key)) {
|
|
39
|
+
return resolvedTagResolverSourceCache.get(key);
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const resolved = syncResolve(source, sourceFile, []);
|
|
43
|
+
resolvedTagResolverSourceCache.set(key, resolved);
|
|
44
|
+
return resolved;
|
|
45
|
+
} catch {
|
|
46
|
+
resolvedTagResolverSourceCache.set(key, undefined);
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const getDefinedTagsFromPackage = (pkgName, filename) => {
|
|
51
|
+
if (definedTagsCache.has(pkgName)) {
|
|
52
|
+
return definedTagsCache.get(pkgName);
|
|
53
|
+
}
|
|
54
|
+
const packageJSONPath = findPackageJSON(pkgName, filename);
|
|
55
|
+
if (!packageJSONPath) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const packageDir = dirname(packageJSONPath);
|
|
59
|
+
const packageJSON = JSON.parse(readFileSync(packageJSONPath, "utf8"));
|
|
60
|
+
const definedTags = packageJSON["wyw-in-js"]?.tags;
|
|
61
|
+
const normalizedTags = definedTags ? Object.entries(definedTags).reduce((acc, [key, value]) => ({
|
|
62
|
+
...acc,
|
|
63
|
+
[key]: value.startsWith(".") ? join(packageDir, value) : nodeRequire.resolve(value, { paths: [packageDir] })
|
|
64
|
+
}), {}) : undefined;
|
|
65
|
+
definedTagsCache.set(pkgName, normalizedTags);
|
|
66
|
+
return normalizedTags;
|
|
67
|
+
};
|
|
68
|
+
const isValidProcessorClass = (module) => module instanceof BaseProcessor.constructor;
|
|
69
|
+
const getProcessorFromPackage = (packageName, tagName, filename) => {
|
|
70
|
+
const definedTags = getDefinedTagsFromPackage(packageName, filename);
|
|
71
|
+
const processorPath = definedTags?.[tagName];
|
|
72
|
+
if (!processorPath) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const Processor = nodeRequire(processorPath).default;
|
|
76
|
+
if (!isValidProcessorClass(Processor)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return Processor;
|
|
80
|
+
};
|
|
81
|
+
const getProcessorFromFile = (processorPath) => {
|
|
82
|
+
const Processor = nodeRequire(processorPath).default;
|
|
83
|
+
if (!isValidProcessorClass(Processor)) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return Processor;
|
|
87
|
+
};
|
|
88
|
+
export const getProcessorForImport = ({ imported, source }, filename, options) => {
|
|
89
|
+
const { tagResolver } = options;
|
|
90
|
+
const packageLookupCandidate = isPackageLookupCandidate(source);
|
|
91
|
+
if (!tagResolver && !packageLookupCandidate) {
|
|
92
|
+
return [null, {
|
|
93
|
+
imported,
|
|
94
|
+
source
|
|
95
|
+
}];
|
|
96
|
+
}
|
|
97
|
+
const cacheKey = tagResolver ? createTagResolverLookupCacheKey(source, imported, filename) : createPackageLookupCacheKey(source, imported);
|
|
98
|
+
const lookupCache = tagResolver ? getTagResolverLookupCache(tagResolver) : packageProcessorLookupCache;
|
|
99
|
+
if (lookupCache.has(cacheKey)) {
|
|
100
|
+
return [lookupCache.get(cacheKey) ?? null, {
|
|
101
|
+
imported,
|
|
102
|
+
source
|
|
103
|
+
}];
|
|
104
|
+
}
|
|
105
|
+
let customFile = null;
|
|
106
|
+
if (tagResolver) {
|
|
107
|
+
const tagResolverMeta = {
|
|
108
|
+
sourceFile: filename,
|
|
109
|
+
resolvedSource: getResolvedTagResolverSource(source, filename)
|
|
110
|
+
};
|
|
111
|
+
customFile = tagResolver(source, imported, tagResolverMeta);
|
|
112
|
+
}
|
|
113
|
+
let processor = null;
|
|
114
|
+
if (customFile) {
|
|
115
|
+
processor = getProcessorFromFile(customFile);
|
|
116
|
+
} else if (packageLookupCandidate) {
|
|
117
|
+
processor = getProcessorFromPackage(source, imported, filename);
|
|
118
|
+
}
|
|
119
|
+
lookupCache.set(cacheKey, processor);
|
|
120
|
+
return [processor, {
|
|
121
|
+
imported,
|
|
122
|
+
source
|
|
123
|
+
}];
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=processorLookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAE9B,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB,mBAAmB;AAG7C,MAAM,cAAc,cAAc,OAAO,KAAK,IAAI;AAMlD,MAAM,mBAAmB,IAAI,KAAiD;AAC9E,MAAM,iCAAiC,IAAI,KAAiC;AAC5E,MAAM,8BAA8B,IAAI,KAAoC;AAC5E,MAAM,kCAAkC,IAAI,SAGzC;AAEH,MAAM,mCACJ,QACA,UACA,aACW,GAAG,YAAY,GAAG,IAAI,OAAO,IAAI;AAE9C,MAAM,+BACJ,QACA,aACW,GAAG,OAAO,IAAI;AAE3B,MAAM,gBAAgB;AAEtB,MAAM,4BAA4B,WAA4B;AAC5D,KACE,CAAC,UACD,OAAO,WAAW,IAAI,IACtB,OAAO,WAAW,IAAI,IACtB,OAAO,WAAW,KAAK,IACvB,OAAO,WAAW,KAAK,IACvB,OAAO,WAAW,KAAK,IACvB,OAAO,WAAW,KAAK,IACvB,OAAO,WAAW,IAAI,IACtB,OAAO,SAAS,IAAI,IACpB,OAAO,SAAS,IAAI,IACpB,cAAc,KAAK,OAAO,EAC1B;AACA,SAAO;;AAGT,KAAI,OAAO,WAAW,IAAI,EAAE;EAC1B,MAAM,CAAC,OAAO,OAAO,OAAO,MAAM,KAAK,EAAE;AACzC,SAAO,MAAM,SAAS,KAAK,CAAC,CAAC;;AAG/B,QAAO;;AAGT,MAAM,6BACJ,gBACuC;CACvC,MAAM,WAAW,gCAAgC,IAAI,YAAY;AACjE,KAAI,UAAU;AACZ,SAAO;;CAGT,MAAM,UAAU,IAAI,KAAoC;AACxD,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AAO;;AAGT,QAAO;;AAGT,MAAM,wBAAwB,kBAAiD;CAC7E,MAAM,YAAY,YAAY,cAAc,CAAC;AAC7C,KAAI,CAAC,sBAAsB,UAAU,EAAE;AACrC,SAAO;;AAGT,QAAO;;AAGT,OAAO,MAAM,yBACX,EAAE,UAAU,UACZ,UACA,YACuC;CACvC,MAAM,EAAE,gBAAgB;CACxB,MAAM,yBAAyB,yBAAyB,OAAO;AAE/D,KAAI,CAAC,eAAe,CAAC,wBAAwB;AAC3C,SAAO,CAAC,MAAM;GAAE;GAAU;GAAQ,CAAC;;CAGrC,MAAM,WAAW,cACb,gCAAgC,QAAQ,UAAU,SAAS,GAC3D,4BAA4B,QAAQ,SAAS;CACjD,MAAM,cAAc,cAChB,0BAA0B,YAAY,GACtC;AAEJ,KAAI,YAAY,IAAI,SAAS,EAAE;AAC7B,SAAO,CAAC,YAAY,IAAI,SAAS,IAAI,MAAM;GAAE;GAAU;GAAQ,CAAC;;CAGlE,IAAI,aAA4B;AAChC,KAAI,aAAa;EACf,MAAM,kBAAmC;GACvC,YAAY;GACZ,gBAAgB,6BAA6B,QAAQ,SAAS;GAC/D;AAED,eAAa,YAAY,QAAQ,UAAU,gBAAgB;;CAE7D,IAAI,YAAmC;AACvC,KAAI,YAAY;AACd,cAAY,qBAAqB,WAAW;YACnC,wBAAwB;AACjC,cAAY,wBAAwB,QAAQ,UAAU,SAAS;;AAGjE,aAAY,IAAI,UAAU,UAAU;AACpC,QAAO,CAAC,WAAW;EAAE;EAAU;EAAQ,CAAC","names":[],"sources":["../../src/utils/processorLookup.ts"],"version":3,"sourcesContent":["import { readFileSync } from 'fs';\nimport { createRequire } from 'module';\nimport { dirname, join } from 'path';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type { TagSource } from '@wyw-in-js/processor-utils';\nimport { findPackageJSON, syncResolve } from '@wyw-in-js/shared';\nimport type { StrictOptions, TagResolverMeta } from '@wyw-in-js/shared';\n\nconst nodeRequire = createRequire(import.meta.url);\n\nexport type ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst resolvedTagResolverSourceCache = new Map<string, string | undefined>();\nconst packageProcessorLookupCache = new Map<string, ProcessorClass | null>();\nconst tagResolverProcessorLookupCache = new WeakMap<\n NonNullable<StrictOptions['tagResolver']>,\n Map<string, ProcessorClass | null>\n>();\n\nconst createTagResolverLookupCacheKey = (\n source: string,\n imported: string,\n filename: string | null | undefined\n): string => `${filename ?? ''}\\0${source}\\0${imported}`;\n\nconst createPackageLookupCacheKey = (\n source: string,\n imported: string\n): string => `${source}\\0${imported}`;\n\nconst URL_SCHEME_RE = /^[A-Za-z][A-Za-z\\d+.-]*:/;\n\nconst isPackageLookupCandidate = (source: string): boolean => {\n if (\n !source ||\n source.startsWith('.') ||\n source.startsWith('/') ||\n source.startsWith('\\\\') ||\n source.startsWith('\\0') ||\n source.startsWith('@/') ||\n source.startsWith('~/') ||\n source.startsWith('#') ||\n source.includes('?') ||\n source.includes('#') ||\n URL_SCHEME_RE.test(source)\n ) {\n return false;\n }\n\n if (source.startsWith('@')) {\n const [scope, pkg] = source.split('/', 2);\n return scope.length > 1 && !!pkg;\n }\n\n return true;\n};\n\nconst getTagResolverLookupCache = (\n tagResolver: NonNullable<StrictOptions['tagResolver']>\n): Map<string, ProcessorClass | null> => {\n const existing = tagResolverProcessorLookupCache.get(tagResolver);\n if (existing) {\n return existing;\n }\n\n const created = new Map<string, ProcessorClass | null>();\n tagResolverProcessorLookupCache.set(tagResolver, created);\n return created;\n};\n\nconst getResolvedTagResolverSource = (\n source: string,\n sourceFile: string | null | undefined\n): string | undefined => {\n if (!sourceFile) {\n return undefined;\n }\n\n const key = `${sourceFile}\\0${source}`;\n if (resolvedTagResolverSourceCache.has(key)) {\n return resolvedTagResolverSourceCache.get(key);\n }\n\n try {\n const resolved = syncResolve(source, sourceFile, []);\n resolvedTagResolverSourceCache.set(key, resolved);\n return resolved;\n } catch {\n resolvedTagResolverSourceCache.set(key, undefined);\n return undefined;\n }\n};\n\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : nodeRequire.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nconst isValidProcessorClass = (module: unknown): module is ProcessorClass =>\n module instanceof BaseProcessor.constructor;\n\nconst getProcessorFromPackage = (\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null => {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = nodeRequire(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n};\n\nconst getProcessorFromFile = (processorPath: string): ProcessorClass | null => {\n const Processor = nodeRequire(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n};\n\nexport const getProcessorForImport = (\n { imported, source }: { imported: string; source: string },\n filename: string | null | undefined,\n options: Pick<StrictOptions, 'tagResolver'>\n): [ProcessorClass | null, TagSource] => {\n const { tagResolver } = options;\n const packageLookupCandidate = isPackageLookupCandidate(source);\n\n if (!tagResolver && !packageLookupCandidate) {\n return [null, { imported, source }];\n }\n\n const cacheKey = tagResolver\n ? createTagResolverLookupCacheKey(source, imported, filename)\n : createPackageLookupCacheKey(source, imported);\n const lookupCache = tagResolver\n ? getTagResolverLookupCache(tagResolver)\n : packageProcessorLookupCache;\n\n if (lookupCache.has(cacheKey)) {\n return [lookupCache.get(cacheKey) ?? null, { imported, source }];\n }\n\n let customFile: string | null = null;\n if (tagResolver) {\n const tagResolverMeta: TagResolverMeta = {\n sourceFile: filename,\n resolvedSource: getResolvedTagResolverSource(source, filename),\n };\n\n customFile = tagResolver(source, imported, tagResolverMeta);\n }\n let processor: ProcessorClass | null = null;\n if (customFile) {\n processor = getProcessorFromFile(customFile);\n } else if (packageLookupCandidate) {\n processor = getProcessorFromPackage(source, imported, filename);\n }\n\n lookupCache.set(cacheKey, processor);\n return [processor, { imported, source }];\n};\n"],"file":"processorLookup.js"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export const unknownProcessorStaticValue = Symbol("unknownProcessorStaticValue");
|
|
2
|
+
export const createProcessorStaticContext = (processor) => {
|
|
3
|
+
const processorWithInternals = processor;
|
|
4
|
+
return {
|
|
5
|
+
addDependency: () => {},
|
|
6
|
+
debug: () => {},
|
|
7
|
+
fileContext: processorWithInternals.context ?? {},
|
|
8
|
+
metadata: {
|
|
9
|
+
className: processor.className,
|
|
10
|
+
displayName: processor.displayName,
|
|
11
|
+
isReferenced: processor.isReferenced,
|
|
12
|
+
location: processor.location,
|
|
13
|
+
slug: processor.slug,
|
|
14
|
+
tagSource: processor.tagSource
|
|
15
|
+
},
|
|
16
|
+
options: processorWithInternals.options ?? {},
|
|
17
|
+
unresolved: (reason, details) => ({
|
|
18
|
+
...details ? { details } : {},
|
|
19
|
+
kind: "unresolved",
|
|
20
|
+
reason
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const isProcessorStaticValue = (value) => {
|
|
25
|
+
if (typeof value !== "object" || value === null || !("kind" in value)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const candidate = value;
|
|
29
|
+
switch (candidate.kind) {
|
|
30
|
+
case "class-name": return typeof candidate.className === "string";
|
|
31
|
+
case "opaque-component": return candidate.className === undefined || typeof candidate.className === "string";
|
|
32
|
+
case "runtime-callback":
|
|
33
|
+
case "serializable": return true;
|
|
34
|
+
case "selector-chain": return typeof candidate.className === "string" && Array.isArray(candidate.selectors) && candidate.selectors.every((selector) => typeof selector === "string");
|
|
35
|
+
case "unresolved": return typeof candidate.reason === "string";
|
|
36
|
+
default: return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const getProcessorStaticValue = (processor) => {
|
|
40
|
+
if (!processor.getStaticValue) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const value = processor.getStaticValue(createProcessorStaticContext(processor));
|
|
45
|
+
return isProcessorStaticValue(value) ? value : null;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
export const processorStaticValueToRuntimeValue = (value) => {
|
|
51
|
+
switch (value.kind) {
|
|
52
|
+
case "class-name": return value.value === undefined ? value.className : value.value;
|
|
53
|
+
case "opaque-component":
|
|
54
|
+
case "runtime-callback": return value.value === undefined ? unknownProcessorStaticValue : value.value;
|
|
55
|
+
case "selector-chain":
|
|
56
|
+
case "serializable": return value.value;
|
|
57
|
+
case "unresolved": return unknownProcessorStaticValue;
|
|
58
|
+
default: return unknownProcessorStaticValue;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const resolveProcessorStaticRuntimeValue = (processor) => {
|
|
62
|
+
const staticValue = getProcessorStaticValue(processor);
|
|
63
|
+
return staticValue ? processorStaticValueToRuntimeValue(staticValue) : unknownProcessorStaticValue;
|
|
64
|
+
};
|
|
65
|
+
export const resolveProcessorStaticClassName = (processor) => {
|
|
66
|
+
const staticValue = getProcessorStaticValue(processor);
|
|
67
|
+
if (staticValue?.kind !== "class-name") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const runtimeValue = processorStaticValueToRuntimeValue(staticValue);
|
|
71
|
+
return typeof runtimeValue === "string" ? runtimeValue : staticValue.className;
|
|
72
|
+
};
|
|
73
|
+
export const processorLiteralValue = (expression) => {
|
|
74
|
+
const expressionWithValue = expression;
|
|
75
|
+
if (expression.type === "StringLiteral" || expression.type === "NumericLiteral" || expression.type === "BooleanLiteral" || expression.type === "Literal") {
|
|
76
|
+
return expressionWithValue.value;
|
|
77
|
+
}
|
|
78
|
+
if (expression.type === "NullLiteral") {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return unknownProcessorStaticValue;
|
|
82
|
+
};
|
|
83
|
+
export const processorPropertyKeyName = (key) => {
|
|
84
|
+
if (key.type === "Identifier") {
|
|
85
|
+
return key.name;
|
|
86
|
+
}
|
|
87
|
+
const value = processorLiteralValue(key);
|
|
88
|
+
return typeof value === "string" ? value : null;
|
|
89
|
+
};
|
|
90
|
+
export const processorObjectPropertyValue = (expression, name) => {
|
|
91
|
+
if (expression.type !== "ObjectExpression") {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const { properties } = expression;
|
|
95
|
+
if (!properties) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
for (const property of properties) {
|
|
99
|
+
if ((property.type === "ObjectProperty" || property.type === "Property") && property.key && processorPropertyKeyName(property.key) === name) {
|
|
100
|
+
return property.value ?? null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
export const processorExpressionToStaticValue = (expression, resolveHelperCall) => {
|
|
106
|
+
const literal = processorLiteralValue(expression);
|
|
107
|
+
if (literal !== unknownProcessorStaticValue) {
|
|
108
|
+
return literal;
|
|
109
|
+
}
|
|
110
|
+
if (expression.type === "ArrayExpression") {
|
|
111
|
+
const { elements } = expression;
|
|
112
|
+
if (!elements) {
|
|
113
|
+
return unknownProcessorStaticValue;
|
|
114
|
+
}
|
|
115
|
+
const result = [];
|
|
116
|
+
for (const element of elements) {
|
|
117
|
+
if (element === null) {
|
|
118
|
+
result.push(null);
|
|
119
|
+
} else {
|
|
120
|
+
const value = processorExpressionToStaticValue(element, resolveHelperCall);
|
|
121
|
+
if (value === unknownProcessorStaticValue) {
|
|
122
|
+
return unknownProcessorStaticValue;
|
|
123
|
+
}
|
|
124
|
+
result.push(value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
if (expression.type === "ObjectExpression") {
|
|
130
|
+
const metaExpression = processorObjectPropertyValue(expression, "__wyw_meta");
|
|
131
|
+
if (!metaExpression || metaExpression.type !== "ObjectExpression") {
|
|
132
|
+
return unknownProcessorStaticValue;
|
|
133
|
+
}
|
|
134
|
+
const classNameExpression = processorObjectPropertyValue(metaExpression, "className");
|
|
135
|
+
const className = classNameExpression ? processorLiteralValue(classNameExpression) : unknownProcessorStaticValue;
|
|
136
|
+
if (typeof className !== "string") {
|
|
137
|
+
return unknownProcessorStaticValue;
|
|
138
|
+
}
|
|
139
|
+
const extendsExpression = processorObjectPropertyValue(metaExpression, "extends");
|
|
140
|
+
const extended = extendsExpression ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall) : null;
|
|
141
|
+
if (extended === unknownProcessorStaticValue) {
|
|
142
|
+
return unknownProcessorStaticValue;
|
|
143
|
+
}
|
|
144
|
+
return { __wyw_meta: {
|
|
145
|
+
className,
|
|
146
|
+
extends: extended
|
|
147
|
+
} };
|
|
148
|
+
}
|
|
149
|
+
if (expression.type === "CallExpression") {
|
|
150
|
+
const call = expression;
|
|
151
|
+
if (call.arguments?.length === 0 && call.callee?.type === "Identifier") {
|
|
152
|
+
return resolveHelperCall(call.callee.name);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return unknownProcessorStaticValue;
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=processorStaticSemantics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings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,EAAE,aAAa;AAGrB,MAAI,CAAC,UAAU;AACb,UAAO;;EAGT,MAAM,SAAoB,EAAE;AAC5B,OAAK,MAAM,WAAW,UAAU;AAC9B,OAAI,YAAY,MAAM;AACpB,WAAO,KAAK,KAAK;UACZ;IACL,MAAM,QAAQ,iCACZ,SACA,kBACD;AACD,QAAI,UAAU,6BAA6B;AACzC,YAAO;;AAGT,WAAO,KAAK,MAAM;;;AAItB,SAAO;;AAGT,KAAI,WAAW,SAAS,oBAAoB;EAC1C,MAAM,iBAAiB,6BACrB,YACA,aACD;AACD,MAAI,CAAC,kBAAkB,eAAe,SAAS,oBAAoB;AACjE,UAAO;;EAGT,MAAM,sBAAsB,6BAC1B,gBACA,YACD;EACD,MAAM,YAAY,sBACd,sBAAsB,oBAAoB,GAC1C;AACJ,MAAI,OAAO,cAAc,UAAU;AACjC,UAAO;;EAGT,MAAM,oBAAoB,6BACxB,gBACA,UACD;EACD,MAAM,WAAW,oBACb,iCAAiC,mBAAmB,kBAAkB,GACtE;AACJ,MAAI,aAAa,6BAA6B;AAC5C,UAAO;;AAGT,SAAO,EACL,YAAY;GACV;GACA,SAAS;GACV,EACF;;AAGH,KAAI,WAAW,SAAS,kBAAkB;EACxC,MAAM,OAAO;AAIb,MAAI,KAAK,WAAW,WAAW,KAAK,KAAK,QAAQ,SAAS,cAAc;AACtE,UAAO,kBACJ,KAAK,OAAkD,KACzD;;;AAIL,QAAO","names":[],"sources":["../../src/utils/processorStaticSemantics.ts"],"version":3,"sourcesContent":["import type {\n BaseProcessor,\n Expression as ProcessorExpression,\n ProcessorStaticContext,\n ProcessorStaticValue,\n} from '@wyw-in-js/processor-utils';\n\nexport const unknownProcessorStaticValue = Symbol(\n 'unknownProcessorStaticValue'\n);\n\nexport type UnknownProcessorStaticValue = typeof unknownProcessorStaticValue;\n\ntype ProcessorWithStaticInternals = BaseProcessor & {\n context?: ProcessorStaticContext['fileContext'];\n options?: ProcessorStaticContext['options'];\n};\n\nexport const createProcessorStaticContext = (\n processor: BaseProcessor\n): ProcessorStaticContext => {\n const processorWithInternals = processor as ProcessorWithStaticInternals;\n\n return {\n addDependency: () => {},\n debug: () => {},\n fileContext:\n processorWithInternals.context ??\n ({} as ProcessorStaticContext['fileContext']),\n metadata: {\n className: processor.className,\n displayName: processor.displayName,\n isReferenced: processor.isReferenced,\n location: processor.location,\n slug: processor.slug,\n tagSource: processor.tagSource,\n },\n options:\n processorWithInternals.options ??\n ({} as ProcessorStaticContext['options']),\n unresolved: (reason, details) => ({\n ...(details ? { details } : {}),\n kind: 'unresolved',\n reason,\n }),\n };\n};\n\nexport const isProcessorStaticValue = (\n value: unknown\n): value is ProcessorStaticValue => {\n if (typeof value !== 'object' || value === null || !('kind' in value)) {\n return false;\n }\n\n const candidate = value as ProcessorStaticValue;\n switch (candidate.kind) {\n case 'class-name':\n return typeof candidate.className === 'string';\n case 'opaque-component':\n return (\n candidate.className === undefined ||\n typeof candidate.className === 'string'\n );\n case 'runtime-callback':\n case 'serializable':\n return true;\n case 'selector-chain':\n return (\n typeof candidate.className === 'string' &&\n Array.isArray(candidate.selectors) &&\n candidate.selectors.every((selector) => typeof selector === 'string')\n );\n case 'unresolved':\n return typeof candidate.reason === 'string';\n default:\n return false;\n }\n};\n\nexport const getProcessorStaticValue = (\n processor: BaseProcessor\n): ProcessorStaticValue | null => {\n if (!processor.getStaticValue) {\n return null;\n }\n\n try {\n const value = processor.getStaticValue(\n createProcessorStaticContext(processor)\n );\n return isProcessorStaticValue(value) ? value : null;\n } catch {\n return null;\n }\n};\n\nexport const processorStaticValueToRuntimeValue = (\n value: ProcessorStaticValue\n): unknown | UnknownProcessorStaticValue => {\n switch (value.kind) {\n case 'class-name':\n return value.value === undefined ? value.className : value.value;\n case 'opaque-component':\n case 'runtime-callback':\n return value.value === undefined\n ? unknownProcessorStaticValue\n : value.value;\n case 'selector-chain':\n case 'serializable':\n return value.value;\n case 'unresolved':\n return unknownProcessorStaticValue;\n default:\n return unknownProcessorStaticValue;\n }\n};\n\nexport const resolveProcessorStaticRuntimeValue = (\n processor: BaseProcessor\n): unknown | UnknownProcessorStaticValue => {\n const staticValue = getProcessorStaticValue(processor);\n return staticValue\n ? processorStaticValueToRuntimeValue(staticValue)\n : unknownProcessorStaticValue;\n};\n\nexport const resolveProcessorStaticClassName = (\n processor: BaseProcessor\n): string | null => {\n const staticValue = getProcessorStaticValue(processor);\n if (staticValue?.kind !== 'class-name') {\n return null;\n }\n\n const runtimeValue = processorStaticValueToRuntimeValue(staticValue);\n return typeof runtimeValue === 'string'\n ? runtimeValue\n : staticValue.className;\n};\n\nexport const processorLiteralValue = (\n expression: ProcessorExpression\n): unknown | UnknownProcessorStaticValue => {\n const expressionWithValue = expression as ProcessorExpression & {\n value?: unknown;\n };\n\n if (\n expression.type === 'StringLiteral' ||\n expression.type === 'NumericLiteral' ||\n expression.type === 'BooleanLiteral' ||\n expression.type === 'Literal'\n ) {\n return expressionWithValue.value;\n }\n\n if (expression.type === 'NullLiteral') {\n return null;\n }\n\n return unknownProcessorStaticValue;\n};\n\nexport const processorPropertyKeyName = (\n key: ProcessorExpression\n): string | null => {\n if (key.type === 'Identifier') {\n return (key as ProcessorExpression & { name: string }).name;\n }\n\n const value = processorLiteralValue(key);\n return typeof value === 'string' ? value : null;\n};\n\nexport const processorObjectPropertyValue = (\n expression: ProcessorExpression,\n name: string\n): ProcessorExpression | null => {\n if (expression.type !== 'ObjectExpression') {\n return null;\n }\n\n const { properties } = expression as ProcessorExpression & {\n properties?: Array<\n ProcessorExpression & {\n key?: ProcessorExpression;\n type: string;\n value?: ProcessorExpression;\n }\n >;\n };\n if (!properties) {\n return null;\n }\n\n for (const property of properties) {\n if (\n (property.type === 'ObjectProperty' || property.type === 'Property') &&\n property.key &&\n processorPropertyKeyName(property.key) === name\n ) {\n return property.value ?? null;\n }\n }\n\n return null;\n};\n\nexport const processorExpressionToStaticValue = (\n expression: ProcessorExpression,\n resolveHelperCall: (name: string) => unknown | UnknownProcessorStaticValue\n): unknown | UnknownProcessorStaticValue => {\n const literal = processorLiteralValue(expression);\n if (literal !== unknownProcessorStaticValue) {\n return literal;\n }\n\n if (expression.type === 'ArrayExpression') {\n const { elements } = expression as ProcessorExpression & {\n elements?: Array<ProcessorExpression | null>;\n };\n if (!elements) {\n return unknownProcessorStaticValue;\n }\n\n const result: unknown[] = [];\n for (const element of elements) {\n if (element === null) {\n result.push(null);\n } else {\n const value = processorExpressionToStaticValue(\n element,\n resolveHelperCall\n );\n if (value === unknownProcessorStaticValue) {\n return unknownProcessorStaticValue;\n }\n\n result.push(value);\n }\n }\n\n return result;\n }\n\n if (expression.type === 'ObjectExpression') {\n const metaExpression = processorObjectPropertyValue(\n expression,\n '__wyw_meta'\n );\n if (!metaExpression || metaExpression.type !== 'ObjectExpression') {\n return unknownProcessorStaticValue;\n }\n\n const classNameExpression = processorObjectPropertyValue(\n metaExpression,\n 'className'\n );\n const className = classNameExpression\n ? processorLiteralValue(classNameExpression)\n : unknownProcessorStaticValue;\n if (typeof className !== 'string') {\n return unknownProcessorStaticValue;\n }\n\n const extendsExpression = processorObjectPropertyValue(\n metaExpression,\n 'extends'\n );\n const extended = extendsExpression\n ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall)\n : null;\n if (extended === unknownProcessorStaticValue) {\n return unknownProcessorStaticValue;\n }\n\n return {\n __wyw_meta: {\n className,\n extends: extended,\n },\n };\n }\n\n if (expression.type === 'CallExpression') {\n const call = expression as ProcessorExpression & {\n arguments?: ProcessorExpression[];\n callee?: ProcessorExpression;\n };\n if (call.arguments?.length === 0 && call.callee?.type === 'Identifier') {\n return resolveHelperCall(\n (call.callee as ProcessorExpression & { name: string }).name\n );\n }\n }\n\n return unknownProcessorStaticValue;\n};\n"],"file":"processorStaticSemantics.js"}
|