@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,182 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { createHash } from "crypto";
|
|
3
|
+
import { readFileSync, statSync } from "fs";
|
|
4
|
+
import { isAbsolute } from "path";
|
|
5
|
+
import { oxcShaker } from "../../../shaker.js";
|
|
6
|
+
import { runOxcPreevalStage } from "../../../utils/oxcPreevalStage.js";
|
|
7
|
+
import { stripQueryAndHash } from "../../../utils/parseRequest.js";
|
|
8
|
+
import { isEnvDisabled, parseProgram } from "./environment.js";
|
|
9
|
+
import { STATIC_EXPORT_MAX_NULL_ATTEMPTS } from "./types.js";
|
|
10
|
+
export const staticFileAnalysisCaches = new WeakMap();
|
|
11
|
+
export const staticFileHashCaches = new WeakMap();
|
|
12
|
+
export const staticExportResultCaches = new WeakMap();
|
|
13
|
+
export const staticMetadataPreevalCaches = new WeakMap();
|
|
14
|
+
export const hashStaticContent = (content) => createHash("sha256").update(content).digest("hex");
|
|
15
|
+
export const getWeakCacheMap = (caches, key) => {
|
|
16
|
+
let cache = caches.get(key);
|
|
17
|
+
if (!cache) {
|
|
18
|
+
cache = new Map();
|
|
19
|
+
caches.set(key, cache);
|
|
20
|
+
}
|
|
21
|
+
return cache;
|
|
22
|
+
};
|
|
23
|
+
export const isStaticResolveCacheEnabled = () => {
|
|
24
|
+
const envValue = process.env.WYW_STATIC_RESOLVE_CACHE?.trim().toLowerCase();
|
|
25
|
+
if (envValue) {
|
|
26
|
+
return !isEnvDisabled(envValue);
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
export const staticCachePrefix = (action) => `${action.services.cache.getKeySalt() ?? ""}\0${action.services.options.root ?? ""}`;
|
|
31
|
+
export const staticFileAnalysisCache = (action) => getWeakCacheMap(staticFileAnalysisCaches, action.services.cache);
|
|
32
|
+
export const staticFileHashCache = (action) => getWeakCacheMap(staticFileHashCaches, action.services.cache);
|
|
33
|
+
export const staticExportResultCache = (action) => getWeakCacheMap(staticExportResultCaches, action.services.cache);
|
|
34
|
+
export const staticMetadataPreevalCache = (action) => getWeakCacheMap(staticMetadataPreevalCaches, action.services.cache);
|
|
35
|
+
export const staticFileAnalysisCacheKey = (action, filename, codeHash) => `${staticCachePrefix(action)}\0${filename}\0${codeHash}`;
|
|
36
|
+
export const staticExportCacheKey = (action, filename, exportedName, codeHash) => `${staticCachePrefix(action)}\0${filename}\0${exportedName}\0${codeHash}`;
|
|
37
|
+
export const staticMetadataPreevalCacheKey = (action, filename, codeHash) => `${staticCachePrefix(action)}\0${filename}\0${codeHash}`;
|
|
38
|
+
export const getStaticFileContentHash = (action, dependency) => {
|
|
39
|
+
const filename = stripQueryAndHash(dependency);
|
|
40
|
+
if (!isAbsolute(filename)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
let stat;
|
|
44
|
+
try {
|
|
45
|
+
stat = statSync(filename);
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (!stat.isFile()) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const cache = staticFileHashCache(action);
|
|
53
|
+
const cached = cache.get(filename);
|
|
54
|
+
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
55
|
+
return cached.hash;
|
|
56
|
+
}
|
|
57
|
+
let hash;
|
|
58
|
+
try {
|
|
59
|
+
hash = hashStaticContent(readFileSync(filename));
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
cache.set(filename, {
|
|
64
|
+
hash,
|
|
65
|
+
mtimeMs: stat.mtimeMs,
|
|
66
|
+
size: stat.size
|
|
67
|
+
});
|
|
68
|
+
return hash;
|
|
69
|
+
};
|
|
70
|
+
export const collectStaticDependencyHashes = (action, dependencies) => {
|
|
71
|
+
const hashes = new Map();
|
|
72
|
+
for (const dependency of dependencies) {
|
|
73
|
+
const hash = getStaticFileContentHash(action, dependency);
|
|
74
|
+
if (!hash) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
hashes.set(stripQueryAndHash(dependency), hash);
|
|
78
|
+
}
|
|
79
|
+
return hashes;
|
|
80
|
+
};
|
|
81
|
+
export const areStaticDependencyHashesCurrent = (action, dependencyHashes) => {
|
|
82
|
+
for (const [dependency, expectedHash] of dependencyHashes) {
|
|
83
|
+
if (getStaticFileContentHash(action, dependency) !== expectedHash) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
};
|
|
89
|
+
export const getStaticExportCachedResult = (action, filename, exportedName, codeHash) => {
|
|
90
|
+
if (!isStaticResolveCacheEnabled()) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const cache = staticExportResultCache(action);
|
|
94
|
+
const cacheKey = staticExportCacheKey(action, filename, exportedName, codeHash);
|
|
95
|
+
const cached = cache.get(cacheKey);
|
|
96
|
+
if (!cached) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
if (cached.result === null) {
|
|
100
|
+
// Bounded retry: until the attempt counter has been bumped enough times
|
|
101
|
+
// that we accept the null as stable, treat it as a cache miss so the
|
|
102
|
+
// caller re-walks. The counter is updated in setStaticExportCachedResult.
|
|
103
|
+
if (cached.attempts < STATIC_EXPORT_MAX_NULL_ATTEMPTS) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (areStaticDependencyHashesCurrent(action, cached.dependencyHashes)) {
|
|
109
|
+
return cached.result;
|
|
110
|
+
}
|
|
111
|
+
cache.delete(cacheKey);
|
|
112
|
+
return undefined;
|
|
113
|
+
};
|
|
114
|
+
export const setStaticExportCachedResult = (action, filename, exportedName, codeHash, result) => {
|
|
115
|
+
if (!isStaticResolveCacheEnabled()) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const cache = staticExportResultCache(action);
|
|
119
|
+
const cacheKey = staticExportCacheKey(action, filename, exportedName, codeHash);
|
|
120
|
+
if (!result) {
|
|
121
|
+
const existing = cache.get(cacheKey);
|
|
122
|
+
const attempts = existing && existing.result === null ? existing.attempts + 1 : 1;
|
|
123
|
+
cache.set(cacheKey, {
|
|
124
|
+
attempts,
|
|
125
|
+
result: null
|
|
126
|
+
});
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const dependencyHashes = collectStaticDependencyHashes(action, result.dependencies);
|
|
130
|
+
if (!dependencyHashes) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
cache.set(cacheKey, {
|
|
134
|
+
dependencyHashes,
|
|
135
|
+
result
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
export const getStaticFileAnalysis = (action, filename) => {
|
|
139
|
+
const loadedAndParsed = action.services.loadAndParseFn(action.services, filename, undefined, action.services.log);
|
|
140
|
+
if (loadedAndParsed.evaluator === "ignored" || loadedAndParsed.evaluator !== oxcShaker) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const { code } = loadedAndParsed;
|
|
144
|
+
const codeHash = hashStaticContent(code);
|
|
145
|
+
const cache = staticFileAnalysisCache(action);
|
|
146
|
+
const cacheKey = staticFileAnalysisCacheKey(action, filename, codeHash);
|
|
147
|
+
const cached = cache.get(cacheKey);
|
|
148
|
+
if (cached) {
|
|
149
|
+
return cached;
|
|
150
|
+
}
|
|
151
|
+
const analysis = {
|
|
152
|
+
code,
|
|
153
|
+
codeHash,
|
|
154
|
+
program: parseProgram(code, filename)
|
|
155
|
+
};
|
|
156
|
+
cache.set(cacheKey, analysis);
|
|
157
|
+
return analysis;
|
|
158
|
+
};
|
|
159
|
+
export const getStaticMetadataPreevalResult = (action, filename, code, codeHash) => {
|
|
160
|
+
const cache = staticMetadataPreevalCache(action);
|
|
161
|
+
const cacheKey = staticMetadataPreevalCacheKey(action, filename, codeHash);
|
|
162
|
+
const cached = cache.get(cacheKey);
|
|
163
|
+
if (cached) {
|
|
164
|
+
return cached.result;
|
|
165
|
+
}
|
|
166
|
+
const root = action.services.options.root ?? process.cwd();
|
|
167
|
+
try {
|
|
168
|
+
const result = action.services.eventEmitter.perf("transform:preeval:staticMetadata", () => runOxcPreevalStage(code, {
|
|
169
|
+
filename,
|
|
170
|
+
root
|
|
171
|
+
}, {
|
|
172
|
+
...action.services.options.pluginOptions,
|
|
173
|
+
eventEmitter: action.services.eventEmitter
|
|
174
|
+
}));
|
|
175
|
+
cache.set(cacheKey, { result });
|
|
176
|
+
return result;
|
|
177
|
+
} catch {
|
|
178
|
+
cache.set(cacheKey, { result: null });
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/cache.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport { createHash } from 'crypto';\nimport { readFileSync, statSync } from 'fs';\nimport { isAbsolute } from 'path';\n\nimport { oxcShaker } from '../../../shaker';\nimport { runOxcPreevalStage } from '../../../utils/oxcPreevalStage';\nimport { stripQueryAndHash } from '../../../utils/parseRequest';\nimport type { ITransformAction } from '../../types';\nimport { isEnvDisabled, parseProgram } from './environment';\nimport type {\n StaticExportCacheEntry,\n StaticExportResult,\n StaticFileAnalysis,\n StaticFileHashCacheEntry,\n StaticMetadataPreevalCacheEntry,\n} from './types';\nimport { STATIC_EXPORT_MAX_NULL_ATTEMPTS } from './types';\n\nexport const staticFileAnalysisCaches = new WeakMap<\n object,\n Map<string, StaticFileAnalysis>\n>();\n\nexport const staticFileHashCaches = new WeakMap<\n object,\n Map<string, StaticFileHashCacheEntry>\n>();\n\nexport const staticExportResultCaches = new WeakMap<\n object,\n Map<string, StaticExportCacheEntry>\n>();\n\nexport const staticMetadataPreevalCaches = new WeakMap<\n object,\n Map<string, StaticMetadataPreevalCacheEntry>\n>();\n\nexport const hashStaticContent = (content: string | Buffer): string =>\n createHash('sha256').update(content).digest('hex');\n\nexport const getWeakCacheMap = <TValue>(\n caches: WeakMap<object, Map<string, TValue>>,\n key: object\n): Map<string, TValue> => {\n let cache = caches.get(key);\n if (!cache) {\n cache = new Map();\n caches.set(key, cache);\n }\n\n return cache;\n};\n\nexport const isStaticResolveCacheEnabled = (): boolean => {\n const envValue = process.env.WYW_STATIC_RESOLVE_CACHE?.trim().toLowerCase();\n if (envValue) {\n return !isEnvDisabled(envValue);\n }\n\n return true;\n};\n\nexport const staticCachePrefix = (action: ITransformAction): string =>\n `${action.services.cache.getKeySalt() ?? ''}\\0${\n action.services.options.root ?? ''\n }`;\n\nexport const staticFileAnalysisCache = (\n action: ITransformAction\n): Map<string, StaticFileAnalysis> =>\n getWeakCacheMap(staticFileAnalysisCaches, action.services.cache);\n\nexport const staticFileHashCache = (\n action: ITransformAction\n): Map<string, StaticFileHashCacheEntry> =>\n getWeakCacheMap(staticFileHashCaches, action.services.cache);\n\nexport const staticExportResultCache = (\n action: ITransformAction\n): Map<string, StaticExportCacheEntry> =>\n getWeakCacheMap(staticExportResultCaches, action.services.cache);\n\nexport const staticMetadataPreevalCache = (\n action: ITransformAction\n): Map<string, StaticMetadataPreevalCacheEntry> =>\n getWeakCacheMap(staticMetadataPreevalCaches, action.services.cache);\n\nexport const staticFileAnalysisCacheKey = (\n action: ITransformAction,\n filename: string,\n codeHash: string\n): string => `${staticCachePrefix(action)}\\0${filename}\\0${codeHash}`;\n\nexport const staticExportCacheKey = (\n action: ITransformAction,\n filename: string,\n exportedName: string,\n codeHash: string\n): string =>\n `${staticCachePrefix(action)}\\0${filename}\\0${exportedName}\\0${codeHash}`;\n\nexport const staticMetadataPreevalCacheKey = (\n action: ITransformAction,\n filename: string,\n codeHash: string\n): string => `${staticCachePrefix(action)}\\0${filename}\\0${codeHash}`;\n\nexport const getStaticFileContentHash = (\n action: ITransformAction,\n dependency: string\n): string | null => {\n const filename = stripQueryAndHash(dependency);\n if (!isAbsolute(filename)) {\n return null;\n }\n\n let stat;\n try {\n stat = statSync(filename);\n } catch {\n return null;\n }\n\n if (!stat.isFile()) {\n return null;\n }\n\n const cache = staticFileHashCache(action);\n const cached = cache.get(filename);\n if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {\n return cached.hash;\n }\n\n let hash: string;\n try {\n hash = hashStaticContent(readFileSync(filename));\n } catch {\n return null;\n }\n\n cache.set(filename, {\n hash,\n mtimeMs: stat.mtimeMs,\n size: stat.size,\n });\n return hash;\n};\n\nexport const collectStaticDependencyHashes = (\n action: ITransformAction,\n dependencies: string[]\n): Map<string, string> | null => {\n const hashes = new Map<string, string>();\n for (const dependency of dependencies) {\n const hash = getStaticFileContentHash(action, dependency);\n if (!hash) {\n return null;\n }\n\n hashes.set(stripQueryAndHash(dependency), hash);\n }\n\n return hashes;\n};\n\nexport const areStaticDependencyHashesCurrent = (\n action: ITransformAction,\n dependencyHashes: Map<string, string>\n): boolean => {\n for (const [dependency, expectedHash] of dependencyHashes) {\n if (getStaticFileContentHash(action, dependency) !== expectedHash) {\n return false;\n }\n }\n\n return true;\n};\n\nexport const getStaticExportCachedResult = (\n action: ITransformAction,\n filename: string,\n exportedName: string,\n codeHash: string\n): StaticExportResult | null | undefined => {\n if (!isStaticResolveCacheEnabled()) {\n return undefined;\n }\n\n const cache = staticExportResultCache(action);\n const cacheKey = staticExportCacheKey(\n action,\n filename,\n exportedName,\n codeHash\n );\n const cached = cache.get(cacheKey);\n if (!cached) {\n return undefined;\n }\n\n if (cached.result === null) {\n // Bounded retry: until the attempt counter has been bumped enough times\n // that we accept the null as stable, treat it as a cache miss so the\n // caller re-walks. The counter is updated in setStaticExportCachedResult.\n if (cached.attempts < STATIC_EXPORT_MAX_NULL_ATTEMPTS) {\n return undefined;\n }\n return null;\n }\n\n if (areStaticDependencyHashesCurrent(action, cached.dependencyHashes)) {\n return cached.result;\n }\n\n cache.delete(cacheKey);\n return undefined;\n};\n\nexport const setStaticExportCachedResult = (\n action: ITransformAction,\n filename: string,\n exportedName: string,\n codeHash: string,\n result: StaticExportResult | null\n): void => {\n if (!isStaticResolveCacheEnabled()) {\n return;\n }\n\n const cache = staticExportResultCache(action);\n const cacheKey = staticExportCacheKey(\n action,\n filename,\n exportedName,\n codeHash\n );\n if (!result) {\n const existing = cache.get(cacheKey);\n const attempts =\n existing && existing.result === null ? existing.attempts + 1 : 1;\n cache.set(cacheKey, { attempts, result: null });\n return;\n }\n\n const dependencyHashes = collectStaticDependencyHashes(\n action,\n result.dependencies\n );\n if (!dependencyHashes) {\n return;\n }\n\n cache.set(cacheKey, {\n dependencyHashes,\n result,\n });\n};\n\nexport const getStaticFileAnalysis = (\n action: ITransformAction,\n filename: string\n): StaticFileAnalysis | null => {\n const loadedAndParsed = action.services.loadAndParseFn(\n action.services,\n filename,\n undefined,\n action.services.log\n );\n if (\n loadedAndParsed.evaluator === 'ignored' ||\n loadedAndParsed.evaluator !== oxcShaker\n ) {\n return null;\n }\n\n const { code } = loadedAndParsed;\n const codeHash = hashStaticContent(code);\n const cache = staticFileAnalysisCache(action);\n const cacheKey = staticFileAnalysisCacheKey(action, filename, codeHash);\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const analysis = {\n code,\n codeHash,\n program: parseProgram(code, filename),\n };\n cache.set(cacheKey, analysis);\n return analysis;\n};\n\nexport const getStaticMetadataPreevalResult = (\n action: ITransformAction,\n filename: string,\n code: string,\n codeHash: string\n): ReturnType<typeof runOxcPreevalStage> | null => {\n const cache = staticMetadataPreevalCache(action);\n const cacheKey = staticMetadataPreevalCacheKey(action, filename, codeHash);\n const cached = cache.get(cacheKey);\n if (cached) {\n return cached.result;\n }\n\n const root = action.services.options.root ?? process.cwd();\n try {\n const result = action.services.eventEmitter.perf(\n 'transform:preeval:staticMetadata',\n () =>\n runOxcPreevalStage(\n code,\n {\n filename,\n root,\n },\n {\n ...action.services.options.pluginOptions,\n eventEmitter: action.services.eventEmitter,\n }\n )\n );\n cache.set(cacheKey, { result });\n return result;\n } catch {\n cache.set(cacheKey, { result: null });\n return null;\n }\n};\n"],"file":"cache.js"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { evaluateOxcStaticExpression, isOxcStaticSerializableValue, lookupStaticBinding } from "../../../utils/collectOxcTemplateDependencies.js";
|
|
2
|
+
import { resolveDependency } from "./dependencies.js";
|
|
3
|
+
import { debugStaticResolve, getStaticBindings } from "./environment.js";
|
|
4
|
+
import { resolveImportValue } from "./exportResolver.js";
|
|
5
|
+
import { resolveImportAsOpaqueRuntime } from "./opaqueRuntime.js";
|
|
6
|
+
import { bindStaticResolvedValue, isRuntimeCallbackExpression, parseStaticExpressionSource } from "./staticExpression.js";
|
|
7
|
+
export function* resolveCandidateValue(action, candidate, filename, memo) {
|
|
8
|
+
const env = new Map();
|
|
9
|
+
const dependencies = new Set();
|
|
10
|
+
const sideEffectDependencies = new Set();
|
|
11
|
+
const sideEffectImportLocals = new Set();
|
|
12
|
+
let candidateExpression;
|
|
13
|
+
if (candidate.inlineConstants) {
|
|
14
|
+
for (const [name, value] of Object.entries(candidate.inlineConstants)) {
|
|
15
|
+
env.set(name, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const staticBindingsForCandidate = getStaticBindings(action);
|
|
19
|
+
for (const item of candidate.imports) {
|
|
20
|
+
// staticBindings overrides take precedence over actual import
|
|
21
|
+
// resolution: a registered value (or function) replaces whatever
|
|
22
|
+
// the source module would otherwise provide. Useful for prototyping
|
|
23
|
+
// / SSR theming and for opaque utilities like `cx`.
|
|
24
|
+
//
|
|
25
|
+
// Match the override map first by the raw specifier as written
|
|
26
|
+
// (`@linaria/core`, `./flags`, …). If that misses, resolve to an
|
|
27
|
+
// absolute path and try again — this lets the host key by
|
|
28
|
+
// absolute file path so a single entry covers every relative
|
|
29
|
+
// variant of the same module.
|
|
30
|
+
let override = lookupStaticBinding(staticBindingsForCandidate, item.source, item.imported);
|
|
31
|
+
if (!override.found && staticBindingsForCandidate) {
|
|
32
|
+
const dep = yield* resolveDependency(action, filename, item.source, item.imported);
|
|
33
|
+
if (dep?.resolved) {
|
|
34
|
+
override = lookupStaticBinding(staticBindingsForCandidate, dep.resolved, item.imported);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (override.found) {
|
|
38
|
+
env.set(item.local, override.value);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const resolved = yield* resolveImportValue(action, filename, item, new Set(), memo);
|
|
42
|
+
if (!resolved) {
|
|
43
|
+
debugStaticResolve(action, {
|
|
44
|
+
candidate: candidate.name,
|
|
45
|
+
filename,
|
|
46
|
+
imported: item.imported,
|
|
47
|
+
phase: "candidate",
|
|
48
|
+
reason: "candidate-import-unresolved",
|
|
49
|
+
source: item.source,
|
|
50
|
+
status: "rejected"
|
|
51
|
+
});
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (resolved.callable === "zero-arg" && candidateExpression === undefined) {
|
|
55
|
+
candidateExpression = parseStaticExpressionSource(candidate.source, filename);
|
|
56
|
+
}
|
|
57
|
+
const expressionForBinding = resolved.callable === "zero-arg" ? candidateExpression : null;
|
|
58
|
+
if (resolved.callable === "zero-arg" && !expressionForBinding || expressionForBinding && !bindStaticResolvedValue(env, expressionForBinding, item.local, resolved)) {
|
|
59
|
+
debugStaticResolve(action, {
|
|
60
|
+
candidate: candidate.name,
|
|
61
|
+
filename,
|
|
62
|
+
imported: item.imported,
|
|
63
|
+
phase: "candidate",
|
|
64
|
+
reason: "candidate-callable-usage-unsupported",
|
|
65
|
+
source: item.source,
|
|
66
|
+
status: "rejected"
|
|
67
|
+
});
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (!expressionForBinding) {
|
|
71
|
+
env.set(item.local, resolved.value);
|
|
72
|
+
}
|
|
73
|
+
resolved.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
74
|
+
resolved.sideEffectDependencies?.forEach((dependency) => {
|
|
75
|
+
sideEffectDependencies.add(dependency);
|
|
76
|
+
sideEffectImportLocals.add(item.importLocal ?? item.local);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (candidateExpression === undefined) {
|
|
80
|
+
candidateExpression = parseStaticExpressionSource(candidate.source, filename);
|
|
81
|
+
}
|
|
82
|
+
const value = evaluateOxcStaticExpression(candidate.source, filename, env, getStaticBindings(action));
|
|
83
|
+
// Function-valued candidates are runtime callbacks (e.g. styled-
|
|
84
|
+
// component dynamic prop interpolations like `${props => ...}`). The
|
|
85
|
+
// value isn't serializable, but the candidate IS resolved — the
|
|
86
|
+
// local `_exp = () => target` arrow already lives in the bundle, so
|
|
87
|
+
// the file does not need evalFile to compute it. Mark the result as
|
|
88
|
+
// runtimeOnly so the helper declaration survives pruning.
|
|
89
|
+
if (typeof value === "function" || value === undefined && isRuntimeCallbackExpression(candidateExpression)) {
|
|
90
|
+
debugStaticResolve(action, {
|
|
91
|
+
candidate: candidate.name,
|
|
92
|
+
filename,
|
|
93
|
+
phase: "candidate",
|
|
94
|
+
reason: "runtime-callback",
|
|
95
|
+
status: "resolved"
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
dependencies: [...dependencies],
|
|
99
|
+
runtimeOnly: true,
|
|
100
|
+
sideEffectDependencies: [...sideEffectDependencies],
|
|
101
|
+
sideEffectImportLocals: [...sideEffectImportLocals],
|
|
102
|
+
value
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!isOxcStaticSerializableValue(value)) {
|
|
106
|
+
debugStaticResolve(action, {
|
|
107
|
+
candidate: candidate.name,
|
|
108
|
+
filename,
|
|
109
|
+
phase: "candidate",
|
|
110
|
+
reason: "candidate-expression-non-serializable",
|
|
111
|
+
status: "rejected"
|
|
112
|
+
});
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
debugStaticResolve(action, {
|
|
116
|
+
candidate: candidate.name,
|
|
117
|
+
filename,
|
|
118
|
+
phase: "candidate",
|
|
119
|
+
status: "resolved"
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
dependencies: [...dependencies],
|
|
123
|
+
sideEffectDependencies: [...sideEffectDependencies],
|
|
124
|
+
sideEffectImportLocals: [...sideEffectImportLocals],
|
|
125
|
+
value
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export function* resolveOpaqueRuntimeCandidateValue(action, candidate, filename) {
|
|
129
|
+
if (candidate.imports.length === 0) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const dependencies = new Set();
|
|
133
|
+
const memo = new Map();
|
|
134
|
+
for (const item of candidate.imports) {
|
|
135
|
+
const proof = yield* resolveImportAsOpaqueRuntime(action, filename, item, new Set(), memo);
|
|
136
|
+
if (!proof) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
proof.dependencies.forEach((dependency) => dependencies.add(dependency));
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
dependencies: [...dependencies],
|
|
143
|
+
value: null
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=candidateResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/candidateResolver.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type { Expression } from 'oxc-parser';\n\nimport {\n evaluateOxcStaticExpression,\n isOxcStaticSerializableValue,\n lookupStaticBinding,\n type OxcStaticValueCandidate,\n} from '../../../utils/collectOxcTemplateDependencies';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport { resolveDependency } from './dependencies';\nimport { debugStaticResolve, getStaticBindings } from './environment';\nimport { resolveImportValue } from './exportResolver';\nimport { resolveImportAsOpaqueRuntime } from './opaqueRuntime';\nimport {\n bindStaticResolvedValue,\n isRuntimeCallbackExpression,\n parseStaticExpressionSource,\n} from './staticExpression';\nimport type { OpaqueRuntimeImportProof, StaticExportResult } from './types';\n\nexport function* resolveCandidateValue(\n action: ITransformAction,\n candidate: OxcStaticValueCandidate,\n filename: string,\n memo: Map<string, StaticExportResult | null>\n): SyncScenarioFor<StaticExportResult | null> {\n const env = new Map<string, unknown>();\n const dependencies = new Set<string>();\n const sideEffectDependencies = new Set<string>();\n const sideEffectImportLocals = new Set<string>();\n let candidateExpression: Expression | null | undefined;\n\n if (candidate.inlineConstants) {\n for (const [name, value] of Object.entries(candidate.inlineConstants)) {\n env.set(name, value);\n }\n }\n\n const staticBindingsForCandidate = getStaticBindings(action);\n\n for (const item of candidate.imports) {\n // staticBindings overrides take precedence over actual import\n // resolution: a registered value (or function) replaces whatever\n // the source module would otherwise provide. Useful for prototyping\n // / SSR theming and for opaque utilities like `cx`.\n //\n // Match the override map first by the raw specifier as written\n // (`@linaria/core`, `./flags`, …). If that misses, resolve to an\n // absolute path and try again — this lets the host key by\n // absolute file path so a single entry covers every relative\n // variant of the same module.\n let override = lookupStaticBinding(\n staticBindingsForCandidate,\n item.source,\n item.imported\n );\n if (!override.found && staticBindingsForCandidate) {\n const dep = yield* resolveDependency(\n action,\n filename,\n item.source,\n item.imported\n );\n if (dep?.resolved) {\n override = lookupStaticBinding(\n staticBindingsForCandidate,\n dep.resolved,\n item.imported\n );\n }\n }\n if (override.found) {\n env.set(item.local, override.value);\n continue;\n }\n\n const resolved = yield* resolveImportValue(\n action,\n filename,\n item,\n new Set(),\n memo\n );\n if (!resolved) {\n debugStaticResolve(action, {\n candidate: candidate.name,\n filename,\n imported: item.imported,\n phase: 'candidate',\n reason: 'candidate-import-unresolved',\n source: item.source,\n status: 'rejected',\n });\n return null;\n }\n\n if (resolved.callable === 'zero-arg' && candidateExpression === undefined) {\n candidateExpression = parseStaticExpressionSource(\n candidate.source,\n filename\n );\n }\n\n const expressionForBinding =\n resolved.callable === 'zero-arg' ? candidateExpression : null;\n if (\n (resolved.callable === 'zero-arg' && !expressionForBinding) ||\n (expressionForBinding &&\n !bindStaticResolvedValue(\n env,\n expressionForBinding,\n item.local,\n resolved\n ))\n ) {\n debugStaticResolve(action, {\n candidate: candidate.name,\n filename,\n imported: item.imported,\n phase: 'candidate',\n reason: 'candidate-callable-usage-unsupported',\n source: item.source,\n status: 'rejected',\n });\n return null;\n }\n\n if (!expressionForBinding) {\n env.set(item.local, resolved.value);\n }\n\n resolved.dependencies.forEach((dependency) => dependencies.add(dependency));\n resolved.sideEffectDependencies?.forEach((dependency) => {\n sideEffectDependencies.add(dependency);\n sideEffectImportLocals.add(item.importLocal ?? item.local);\n });\n }\n\n if (candidateExpression === undefined) {\n candidateExpression = parseStaticExpressionSource(\n candidate.source,\n filename\n );\n }\n\n const value = evaluateOxcStaticExpression(\n candidate.source,\n filename,\n env,\n getStaticBindings(action)\n );\n // Function-valued candidates are runtime callbacks (e.g. styled-\n // component dynamic prop interpolations like `${props => ...}`). The\n // value isn't serializable, but the candidate IS resolved — the\n // local `_exp = () => target` arrow already lives in the bundle, so\n // the file does not need evalFile to compute it. Mark the result as\n // runtimeOnly so the helper declaration survives pruning.\n if (\n typeof value === 'function' ||\n (value === undefined && isRuntimeCallbackExpression(candidateExpression))\n ) {\n debugStaticResolve(action, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'runtime-callback',\n status: 'resolved',\n });\n return {\n dependencies: [...dependencies],\n runtimeOnly: true,\n sideEffectDependencies: [...sideEffectDependencies],\n sideEffectImportLocals: [...sideEffectImportLocals],\n value,\n };\n }\n\n if (!isOxcStaticSerializableValue(value)) {\n debugStaticResolve(action, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'candidate-expression-non-serializable',\n status: 'rejected',\n });\n return null;\n }\n\n debugStaticResolve(action, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n status: 'resolved',\n });\n\n return {\n dependencies: [...dependencies],\n sideEffectDependencies: [...sideEffectDependencies],\n sideEffectImportLocals: [...sideEffectImportLocals],\n value,\n };\n}\n\nexport function* resolveOpaqueRuntimeCandidateValue(\n action: ITransformAction,\n candidate: OxcStaticValueCandidate,\n filename: string\n): SyncScenarioFor<StaticExportResult | null> {\n if (candidate.imports.length === 0) {\n return null;\n }\n\n const dependencies = new Set<string>();\n const memo = new Map<string, OpaqueRuntimeImportProof | null>();\n\n for (const item of candidate.imports) {\n const proof = yield* resolveImportAsOpaqueRuntime(\n action,\n filename,\n item,\n new Set(),\n memo\n );\n if (!proof) {\n return null;\n }\n\n proof.dependencies.forEach((dependency) => dependencies.add(dependency));\n }\n\n return {\n dependencies: [...dependencies],\n value: null,\n };\n}\n"],"file":"candidateResolver.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { Entrypoint } from "../../Entrypoint.js";
|
|
3
|
+
import { getWeakCacheMap } from "./cache.js";
|
|
4
|
+
export const isRelativeSource = (source) => source.startsWith("./") || source.startsWith("../") || source === "." || source === "..";
|
|
5
|
+
export const dependencyResolutionCaches = new WeakMap();
|
|
6
|
+
// Bare package and alias resolution can depend on the importer through nested
|
|
7
|
+
// packages, package boundaries, tsconfig paths, or bundler aliases.
|
|
8
|
+
export const dependencyResolutionCacheKey = (importer, source, imported) => `${importer}\0${source}\0${imported}`;
|
|
9
|
+
export function* resolveDependency(action, importer, source, imported) {
|
|
10
|
+
const entrypoint = importer === action.entrypoint.name ? action.entrypoint : Entrypoint.createRoot(action.services, importer, [imported], undefined);
|
|
11
|
+
const imports = new Map([[source, [imported]]]);
|
|
12
|
+
const [resolved] = yield* action.getNext("resolveImports", entrypoint, {
|
|
13
|
+
imports,
|
|
14
|
+
phase: "initial"
|
|
15
|
+
});
|
|
16
|
+
// Non-relative sources (package names, aliases) can still be importer-
|
|
17
|
+
// dependent because of nested packages, tsconfig boundaries, and bundler
|
|
18
|
+
// aliases. Cache only within the same importer context.
|
|
19
|
+
if (!isRelativeSource(source)) {
|
|
20
|
+
const cache = getWeakCacheMap(dependencyResolutionCaches, action.services.cache);
|
|
21
|
+
const cacheKey = dependencyResolutionCacheKey(importer, source, imported);
|
|
22
|
+
if (resolved?.resolved) {
|
|
23
|
+
cache.set(cacheKey, resolved);
|
|
24
|
+
return resolved;
|
|
25
|
+
}
|
|
26
|
+
const cached = cache.get(cacheKey);
|
|
27
|
+
if (cached?.resolved) {
|
|
28
|
+
return cached;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return resolved ?? null;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAEA,SAAS,kBAAkB;AAG3B,SAAS,uBAAuB;AAEhC,OAAO,MAAM,oBAAoB,WAC/B,OAAO,WAAW,KAAK,IACvB,OAAO,WAAW,MAAM,IACxB,WAAW,OACX,WAAW;AAEb,OAAO,MAAM,6BAA6B,IAAI,SAG3C;;;AAIH,OAAO,MAAM,gCACX,UACA,QACA,aACW,GAAG,SAAS,IAAI,OAAO,IAAI;AAExC,OAAO,UAAU,kBACf,QACA,UACA,QACA,UAC+C;CAC/C,MAAM,aACJ,aAAa,OAAO,WAAW,OAC3B,OAAO,aACP,WAAW,WAAW,OAAO,UAAU,UAAU,CAAC,SAAS,EAAE,UAAU;CAC7E,MAAM,UAAU,IAAI,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;CAC/C,MAAM,CAAC,YAAY,OAAO,OAAO,QAAQ,kBAAkB,YAAY;EACrE;EACA,OAAO;EACR,CAAC;;;;AAKF,KAAI,CAAC,iBAAiB,OAAO,EAAE;EAC7B,MAAM,QAAQ,gBACZ,4BACA,OAAO,SAAS,MACjB;EACD,MAAM,WAAW,6BAA6B,UAAU,QAAQ,SAAS;AACzE,MAAI,UAAU,UAAU;AACtB,SAAM,IAAI,UAAU,SAAS;AAC7B,UAAO;;EAGT,MAAM,SAAS,MAAM,IAAI,SAAS;AAClC,MAAI,QAAQ,UAAU;AACpB,UAAO;;;AAIX,QAAO,YAAY","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/dependencies.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport { Entrypoint } from '../../Entrypoint';\nimport type { IEntrypointDependency } from '../../Entrypoint.types';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport { getWeakCacheMap } from './cache';\n\nexport const isRelativeSource = (source: string): boolean =>\n source.startsWith('./') ||\n source.startsWith('../') ||\n source === '.' ||\n source === '..';\n\nexport const dependencyResolutionCaches = new WeakMap<\n object,\n Map<string, IEntrypointDependency>\n>();\n\n// Bare package and alias resolution can depend on the importer through nested\n// packages, package boundaries, tsconfig paths, or bundler aliases.\nexport const dependencyResolutionCacheKey = (\n importer: string,\n source: string,\n imported: string\n): string => `${importer}\\0${source}\\0${imported}`;\n\nexport function* resolveDependency(\n action: ITransformAction,\n importer: string,\n source: string,\n imported: string\n): SyncScenarioFor<IEntrypointDependency | null> {\n const entrypoint =\n importer === action.entrypoint.name\n ? action.entrypoint\n : Entrypoint.createRoot(action.services, importer, [imported], undefined);\n const imports = new Map([[source, [imported]]]);\n const [resolved] = yield* action.getNext('resolveImports', entrypoint, {\n imports,\n phase: 'initial',\n });\n\n // Non-relative sources (package names, aliases) can still be importer-\n // dependent because of nested packages, tsconfig boundaries, and bundler\n // aliases. Cache only within the same importer context.\n if (!isRelativeSource(source)) {\n const cache = getWeakCacheMap(\n dependencyResolutionCaches,\n action.services.cache\n );\n const cacheKey = dependencyResolutionCacheKey(importer, source, imported);\n if (resolved?.resolved) {\n cache.set(cacheKey, resolved);\n return resolved;\n }\n\n const cached = cache.get(cacheKey);\n if (cached?.resolved) {\n return cached;\n }\n }\n\n return resolved ?? null;\n}\n"],"file":"dependencies.js"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
|
|
2
|
+
import { isAbsolute, relative } from "path";
|
|
3
|
+
import { parseOxcProgram } from "../../../utils/oxc/parse.js";
|
|
4
|
+
import { stripQueryAndHash } from "../../../utils/parseRequest.js";
|
|
5
|
+
export const isInsideRoot = (filename, root) => {
|
|
6
|
+
const relativePath = relative(root, filename);
|
|
7
|
+
return relativePath === "" || !!relativePath && !relativePath.startsWith("..") && !isAbsolute(relativePath);
|
|
8
|
+
};
|
|
9
|
+
export const nodeModulesPattern = /[\\/]node_modules[\\/]/;
|
|
10
|
+
export const isLocalStaticMetadataFile = (filename, root) => {
|
|
11
|
+
const strippedFilename = stripQueryAndHash(filename);
|
|
12
|
+
if (isInsideRoot(strippedFilename, root)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return isAbsolute(strippedFilename) && !nodeModulesPattern.test(strippedFilename);
|
|
16
|
+
};
|
|
17
|
+
export const isEnvDisabled = (value) => value === "0" || value === "false" || value === "no" || value === "off";
|
|
18
|
+
export const getEvalStrategy = (action) => action.services.options.pluginOptions.eval?.strategy ?? "execute";
|
|
19
|
+
export const getStaticStrategyFailure = (filename, dependencyNames) => new Error(`[wyw-in-js] eval.strategy: "static" cannot fall back to the build-time evaluator for ${filename}. ` + `Unresolved values: ${[...dependencyNames].join(", ")}.`);
|
|
20
|
+
export const debugStaticResolve = (action, event) => {
|
|
21
|
+
const labels = Object.fromEntries(Object.entries({
|
|
22
|
+
...event,
|
|
23
|
+
type: "staticResolve"
|
|
24
|
+
}).filter(([, value]) => value !== undefined));
|
|
25
|
+
action.services.eventEmitter.single(labels);
|
|
26
|
+
};
|
|
27
|
+
export const parseProgram = (code, filename) => parseOxcProgram(code, filename, "unambiguous");
|
|
28
|
+
export const getStaticBindings = (action) => action.services.options.pluginOptions?.staticBindings;
|
|
29
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAEA,SAAS,YAAY,gBAAgB;AAIrC,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAIlC,OAAO,MAAM,gBAAgB,UAAkB,SAA0B;CACvE,MAAM,eAAe,SAAS,MAAM,SAAS;AAC7C,QACE,iBAAiB,MAChB,CAAC,CAAC,gBACD,CAAC,aAAa,WAAW,KAAK,IAC9B,CAAC,WAAW,aAAa;;AAI/B,OAAO,MAAM,qBAAqB;AAElC,OAAO,MAAM,6BACX,UACA,SACY;CACZ,MAAM,mBAAmB,kBAAkB,SAAS;AACpD,KAAI,aAAa,kBAAkB,KAAK,EAAE;AACxC,SAAO;;AAGT,QACE,WAAW,iBAAiB,IAAI,CAAC,mBAAmB,KAAK,iBAAiB;;AAI9E,OAAO,MAAM,iBAAiB,UAC5B,UAAU,OAAO,UAAU,WAAW,UAAU,QAAQ,UAAU;AAEpE,OAAO,MAAM,mBAAmB,WAC9B,OAAO,SAAS,QAAQ,cAAc,MAAM,YAAY;AAE1D,OAAO,MAAM,4BACX,UACA,oBAEA,IAAI,MACF,wFAAwF,SAAS,MAC/F,sBAAsB,CAAC,GAAG,gBAAgB,CAAC,KAAK,KAAK,CAAC,GACzD;AAEH,OAAO,MAAM,sBACX,QACA,UACS;CACT,MAAM,SAAS,OAAO,YACpB,OAAO,QAAQ;EACb,GAAG;EACH,MAAM;EACP,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,UAAU,CAC9C;AAED,QAAO,SAAS,aAAa,OAAO,OAAO;;AAG7C,OAAO,MAAM,gBAAgB,MAAc,aACzC,gBAAgB,MAAM,UAAU,cAAc;AAEhD,OAAO,MAAM,qBACX,WAEA,OAAO,SAAS,QAAQ,eAAe","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/environment.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport { isAbsolute, relative } from 'path';\n\nimport type { Program } from 'oxc-parser';\n\nimport { parseOxcProgram } from '../../../utils/oxc/parse';\nimport { stripQueryAndHash } from '../../../utils/parseRequest';\nimport type { ITransformAction } from '../../types';\nimport type { StaticResolveDebugEvent } from './types';\n\nexport const isInsideRoot = (filename: string, root: string): boolean => {\n const relativePath = relative(root, filename);\n return (\n relativePath === '' ||\n (!!relativePath &&\n !relativePath.startsWith('..') &&\n !isAbsolute(relativePath))\n );\n};\n\nexport const nodeModulesPattern = /[\\\\/]node_modules[\\\\/]/;\n\nexport const isLocalStaticMetadataFile = (\n filename: string,\n root: string\n): boolean => {\n const strippedFilename = stripQueryAndHash(filename);\n if (isInsideRoot(strippedFilename, root)) {\n return true;\n }\n\n return (\n isAbsolute(strippedFilename) && !nodeModulesPattern.test(strippedFilename)\n );\n};\n\nexport const isEnvDisabled = (value: string): boolean =>\n value === '0' || value === 'false' || value === 'no' || value === 'off';\n\nexport const getEvalStrategy = (action: ITransformAction) =>\n action.services.options.pluginOptions.eval?.strategy ?? 'execute';\n\nexport const getStaticStrategyFailure = (\n filename: string,\n dependencyNames: Iterable<string>\n): Error =>\n new Error(\n `[wyw-in-js] eval.strategy: \"static\" cannot fall back to the build-time evaluator for ${filename}. ` +\n `Unresolved values: ${[...dependencyNames].join(', ')}.`\n );\n\nexport const debugStaticResolve = (\n action: ITransformAction,\n event: StaticResolveDebugEvent\n): void => {\n const labels = Object.fromEntries(\n Object.entries({\n ...event,\n type: 'staticResolve',\n }).filter(([, value]) => value !== undefined)\n );\n\n action.services.eventEmitter.single(labels);\n};\n\nexport const parseProgram = (code: string, filename: string): Program =>\n parseOxcProgram(code, filename, 'unambiguous');\n\nexport const getStaticBindings = (\n action: ITransformAction\n): Record<string, Record<string, unknown>> | undefined =>\n action.services.options.pluginOptions?.staticBindings;\n"],"file":"environment.js"}
|