@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0
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 +7 -0
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +35 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +230 -89
- package/esm/eval/broker.js.map +1 -1
- package/esm/eval/protocol.js.map +1 -1
- package/esm/eval/runner.js +143 -24
- package/esm/eval/runner.js.map +1 -1
- package/esm/module.js +70 -43
- package/esm/module.js.map +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/generators/collect.js +1 -0
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +35 -20
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +48 -2
- 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 +272 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +184 -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 +1 -2910
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
- package/esm/transform/generators/transform.js +58 -45
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +33 -4
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform.js +3 -1
- package/esm/transform.js.map +1 -1
- package/esm/utils/EventEmitter.js +55 -9
- package/esm/utils/EventEmitter.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 +517 -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 +1 -1216
- package/esm/utils/applyOxcProcessors.js.map +1 -1
- package/esm/utils/collectOxcExportsAndImports.js +8 -0
- package/esm/utils/collectOxcExportsAndImports.js.map +1 -1
- 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 +5 -193
- package/esm/utils/collectOxcRuntime.js.map +1 -1
- 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 +3 -1397
- package/esm/utils/collectOxcTemplateDependencies.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 +58 -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/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 +17 -73
- package/esm/utils/oxcPreevalStage.js.map +1 -1
- package/esm/utils/oxcPreevalTransforms.js +106 -66
- package/esm/utils/oxcPreevalTransforms.js.map +1 -1
- package/esm/utils/parseOxc.js +6 -1
- package/esm/utils/parseOxc.js.map +1 -1
- package/esm/utils/processorStaticSemantics.js +157 -0
- package/esm/utils/processorStaticSemantics.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +3 -3
- package/esm/utils/resolveWithConditions.js.map +1 -1
- package/package.json +6 -5
- package/types/cache.js +8 -0
- package/types/debug/fileReporter.js +46 -1
- package/types/eval/broker.d.ts +6 -2
- package/types/eval/broker.js +244 -95
- package/types/eval/protocol.d.ts +15 -1
- package/types/module.d.ts +4 -1
- package/types/module.js +97 -48
- package/types/transform/Entrypoint.types.d.ts +4 -0
- package/types/transform/generators/collect.js +1 -0
- package/types/transform/generators/resolveImports.d.ts +3 -1
- package/types/transform/generators/resolveImports.js +49 -2
- 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 +312 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +198 -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 -2
- package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
- package/types/transform/generators/transform.js +64 -49
- package/types/transform/helpers/loadWywOptions.js +23 -3
- package/types/transform.js +3 -1
- package/types/utils/EventEmitter.d.ts +16 -1
- package/types/utils/EventEmitter.js +57 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +9 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +169 -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 +567 -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 -16
- package/types/utils/applyOxcProcessors.js +1 -1391
- package/types/utils/collectOxcExportsAndImports.js +8 -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 +17 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +2 -12
- package/types/utils/collectOxcRuntime.js +5 -224
- 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 -38
- package/types/utils/collectOxcTemplateDependencies.js +3 -1580
- 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 +61 -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/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 +2 -18
- package/types/utils/oxcPreevalStage.js +17 -79
- package/types/utils/oxcPreevalTransforms.js +111 -75
- package/types/utils/parseOxc.js +6 -1
- package/types/utils/processorStaticSemantics.d.ts +13 -0
- package/types/utils/processorStaticSemantics.js +191 -0
- package/types/utils/resolveWithConditions.js +3 -3
- package/esm/eval/resolverStrategy.js +0 -51
- package/esm/eval/resolverStrategy.js.map +0 -1
- package/types/eval/resolverStrategy.d.ts +0 -13
- package/types/eval/resolverStrategy.js +0 -46
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAEA,SAAS,UAAU,eAAe;AAElC,SAAS,eAAe,wBAAwB;AAShD,SAAS,iBAAiB;AAU1B,SAAS,6CAA6C;AACtD,SAAS,oBAAoB;AAC7B,SACE,wCAGK;AACP,SAAS,iBAAiB;AAC1B,SACE,qBACA,gCAGK;AACP,SAAS,6BAA6B;AACtC,SAAS,6BAAkD;AA8F3D,IAAI,4BAA4B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ACA,SACA,aACD;AAED,QAAO;EACL,MAAM,gBACF,aAAa,KAAK,mDAChB,6BACE,sBACA,UACA,uBACA,IAAI,IAAI,CAAC,GAAG,yBAAyB,GAAG,UAAU,gBAAgB,CAAC,EACnE,QAAQ,kCAAkC,IAAI,KAAK,CACpD,CACF,GACD;EACJ;EACA,uBAAuB,UAAU;EACjC,cAAc,UAAU;EACzB","names":[],"sources":["../../src/utils/applyOxcProcessors.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport { basename, dirname } from 'path';\n\nimport { BaseProcessor, expressionToCode } from '@wyw-in-js/processor-utils';\nimport type {\n Expression as ProcessorExpression,\n IFileContext,\n Param,\n Params,\n SourceLocation,\n} from '@wyw-in-js/processor-utils';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\nimport type {\n CallExpression,\n Expression,\n MemberExpression,\n Node,\n Program,\n TaggedTemplateExpression,\n} from 'oxc-parser';\n\nimport { collectOxcProcessorImportsFromProgram } from './collectOxcExportsAndImports';\nimport { EventEmitter } from './EventEmitter';\nimport {\n collectOxcExpressionDependencies,\n type OxcStaticValue,\n type OxcStaticValueCandidate,\n} from './collectOxcTemplateDependencies';\nimport { isNotNull } from './isNotNull';\nimport {\n createOxcAstService,\n printOxcAstServiceImport,\n type AddedImport,\n type OxcAstService,\n} from './oxcAstService';\nimport { parseOxcProgramCached } from './parseOxc';\nimport { getProcessorForImport, type ProcessorClass } from './processorLookup';\n\ntype DefinedProcessor = [ProcessorClass, { imported: string; source: string }];\n\ntype Replacement = {\n end: number;\n start: number;\n value: string;\n};\n\ntype ApplyOxcProcessorsResult = {\n code: string;\n processors: BaseProcessor[];\n staticValueCandidates: OxcStaticValueCandidate[];\n staticValues: OxcStaticValue[];\n};\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype OxcIdentifier = Expression & {\n name: string;\n type: 'Identifier';\n};\n\ntype ProcessorUsage =\n | {\n ancestors: Node[];\n callee: Expression;\n collapseQualifiedCallee: boolean;\n definedProcessor: DefinedProcessor;\n kind: 'call';\n replacementTarget: Expression;\n target: CallExpression;\n }\n | {\n ancestors: Node[];\n callee: Expression;\n collapseQualifiedCallee: boolean;\n definedProcessor: DefinedProcessor;\n kind: 'template';\n replacementTarget: Expression;\n target: TaggedTemplateExpression;\n };\n\ntype ExpressionSpan = {\n end: number;\n start: number;\n};\n\ntype CreatedProcessor = {\n astService: OxcAstService;\n processor: BaseProcessor;\n};\n\ntype QualifiedExpression = Expression & {\n expressions?: Expression[];\n};\n\ntype CallExpressionLike = Expression & {\n arguments: Node[];\n callee: Expression;\n type: 'CallExpression';\n};\n\ntype SequenceExpressionLike = Expression & {\n expressions: Expression[];\n type: 'SequenceExpression';\n};\n\ntype LocationLookup = (offset: number) => SourceLocation['start'];\n\ntype TopLevelStatementInfo = {\n bindings: Set<string>;\n node: Node;\n references: Set<string>;\n};\n\ntype ScopedBindingKind = 'function' | 'import' | 'param' | 'variable';\n\ntype ScopedBindingInfo = {\n declaration: Node;\n dependencies: Set<string>;\n externalReferences: number;\n id: string;\n incomingFromBindings: Set<string>;\n kind: ScopedBindingKind;\n name: string;\n};\n\ntype ScopedCleanupScope = {\n bindings: Map<string, string>;\n parent: ScopedCleanupScope | null;\n};\n\nlet didWarnSkipSymbolMismatch = false;\nconst GENERATED_HELPER_NAME_RE = /^_exp\\d*$/;\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 = (code: string, filename: string): Program => {\n return parseOxcProgramCached(filename, code, 'module');\n};\n\nconst visit = (\n node: Node,\n enter: (node: Node, parent: Node | null) => void,\n parent: Node | null = null\n): void => {\n enter(node, parent);\n getChildren(node).forEach((child) => visit(child, enter, node));\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 insertAddedImports = (\n code: string,\n program: Program,\n addedImports: AddedImport[]\n): string => {\n if (addedImports.length === 0) {\n return code;\n }\n\n const uniqueImports = [\n ...new Map(\n addedImports.map((item) => [\n `${item.source}\\0${item.imported}\\0${item.local}`,\n item,\n ])\n ).values(),\n ];\n const importBlock = uniqueImports.map(printOxcAstServiceImport).join('\\n');\n const lastImport = [...program.body]\n .reverse()\n .find((statement) => statement.type === 'ImportDeclaration');\n const hashbangEnd = code.startsWith('#!')\n ? (() => {\n const newline = code.indexOf('\\n');\n return newline === -1 ? code.length : newline + 1;\n })()\n : 0;\n const insertionPoint = lastImport?.end ?? hashbangEnd;\n const prefix = code.slice(0, insertionPoint);\n const suffix = code.slice(insertionPoint);\n const leadingBreak = prefix.length > 0 && !prefix.endsWith('\\n') ? '\\n' : '';\n const trailingBreak =\n suffix.length > 0 && !suffix.startsWith('\\n') ? '\\n' : '';\n\n return `${prefix}${leadingBreak}${importBlock}${trailingBreak}${suffix}`;\n};\n\nconst createLocationLookup = (code: string): LocationLookup => {\n const lineStarts = [0];\n for (let idx = 0; idx < code.length; idx += 1) {\n if (code[idx] === '\\n') {\n lineStarts.push(idx + 1);\n }\n }\n\n return (offset) => {\n let low = 0;\n let high = lineStarts.length - 1;\n\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n const next = lineStarts[mid + 1] ?? Infinity;\n if (lineStarts[mid] <= offset && offset < next) {\n return {\n column: offset - lineStarts[mid],\n line: mid + 1,\n };\n }\n\n if (offset < lineStarts[mid]) {\n high = mid - 1;\n } else {\n low = mid + 1;\n }\n }\n\n const lastLine = lineStarts.length - 1;\n return {\n column: Math.max(0, offset - lineStarts[lastLine]),\n line: lastLine + 1,\n };\n };\n};\n\nconst getSourceLocation = (\n start: number,\n end: number,\n loc: LocationLookup,\n filename?: string | null\n): SourceLocation => ({\n end: loc(end),\n filename: filename ?? undefined,\n start: loc(start),\n});\n\nconst buildCodeFrameError = (\n code: string,\n location: SourceLocation,\n message: string\n): Error => {\n const lines = code.split('\\n');\n const startLine = location.start.line;\n const endLine = location.end.line;\n const frameStart = Math.max(1, startLine - 2);\n const frameEnd = Math.min(lines.length, endLine + 2);\n const lineNoWidth = String(frameEnd).length;\n const frame: string[] = [];\n\n for (let lineNo = frameStart; lineNo <= frameEnd; lineNo += 1) {\n const marker = lineNo === startLine ? '>' : ' ';\n const line = lines[lineNo - 1] ?? '';\n frame.push(\n line.length > 0\n ? `${marker} ${String(lineNo).padStart(lineNoWidth)} | ${line}`\n : `${marker} ${String(lineNo).padStart(lineNoWidth)} |`\n );\n\n if (lineNo === startLine) {\n const pointerLength =\n startLine === endLine\n ? Math.max(1, location.end.column - location.start.column)\n : 1;\n frame.push(\n ` ${' '.repeat(lineNoWidth)} | ${' '.repeat(\n location.start.column\n )}${'^'.repeat(pointerLength)}`\n );\n }\n }\n\n const prefix = location.filename ? `${location.filename}: ` : '';\n return new Error(`${prefix}${message}\\n${frame.join('\\n')}`);\n};\n\nconst collectUsedNames = (program: Program): Set<string> => {\n const names = new Set<string>();\n visit(program, (node) => {\n if (node.type === 'Identifier') {\n names.add(node.name);\n }\n });\n\n return names;\n};\n\nconst isNodeReference = (node: Node, parent: Node | null): boolean => {\n if (node.type === 'Identifier') {\n const parentRecord = parent as AnyNode | null;\n\n if (!parentRecord) {\n return true;\n }\n\n if (\n parent?.type === 'ImportDeclaration' ||\n parent?.type === 'ImportSpecifier' ||\n parent?.type === 'ImportDefaultSpecifier' ||\n parent?.type === 'ImportNamespaceSpecifier'\n ) {\n return false;\n }\n\n if (\n parent?.type === 'MemberExpression' &&\n parentRecord.property === node &&\n !parentRecord.computed\n ) {\n return false;\n }\n\n if (\n (parent?.type === 'VariableDeclarator' ||\n parent?.type === 'FunctionDeclaration' ||\n parent?.type === 'ClassDeclaration' ||\n parent?.type === 'ClassExpression') &&\n parentRecord.id === node\n ) {\n return false;\n }\n\n if (\n (parent?.type === 'PropertyDefinition' ||\n parent?.type === 'MethodDefinition') &&\n parentRecord.key === node &&\n !parentRecord.computed\n ) {\n return false;\n }\n\n if (\n parent?.type === 'Property' &&\n parentRecord.key === node &&\n parentRecord.value !== node &&\n !parentRecord.computed\n ) {\n return false;\n }\n\n return true;\n }\n\n if (node.type === 'JSXIdentifier') {\n const parentRecord = parent as AnyNode | null;\n if (parent?.type === 'JSXAttribute' && parentRecord?.name === node) {\n return false;\n }\n\n return true;\n }\n\n return false;\n};\n\nconst collectReferencedNames = (root: Node): Set<string> => {\n const names = new Set<string>();\n\n const walk = (node: Node, parent: Node | null = null): void => {\n if (node.type === 'ImportDeclaration') {\n return;\n }\n\n if (\n isNodeReference(node, parent) &&\n 'name' in node &&\n typeof node.name === 'string'\n ) {\n names.add(node.name);\n }\n\n getChildren(node).forEach((child) => walk(child, node));\n };\n\n walk(root);\n return names;\n};\n\nconst collectImportLocalNames = (node: Node): string[] => {\n if (node.type !== 'ImportDeclaration') {\n return [];\n }\n\n const { specifiers } = node as AnyNode;\n if (!Array.isArray(specifiers)) {\n return [];\n }\n\n return specifiers\n .map((specifier) => {\n const { local } = specifier as AnyNode;\n return isNode(local) && 'name' in local && typeof local.name === 'string'\n ? local.name\n : null;\n })\n .filter(isNotNull);\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 collectDeclaredNames = (node: Node): string[] => {\n if (node.type === 'Identifier') {\n return [node.name];\n }\n\n if (node.type === 'RestElement') {\n return collectDeclaredNames(node.argument);\n }\n\n if (node.type === 'AssignmentPattern') {\n return collectDeclaredNames(node.left);\n }\n\n if (node.type === 'ObjectPattern') {\n return node.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectDeclaredNames(property.argument)\n : collectDeclaredNames(property.value)\n );\n }\n\n if (node.type === 'ArrayPattern') {\n return node.elements.flatMap((element) =>\n element ? collectDeclaredNames(element) : []\n );\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectDeclaredNames(node.parameter);\n }\n\n return [];\n};\n\nconst collectTopLevelBindings = (statement: Node): Set<string> => {\n const bindings = new Set<string>();\n\n if (statement.type === 'ImportDeclaration') {\n collectImportLocalNames(statement).forEach((name) => bindings.add(name));\n return bindings;\n }\n\n if (statement.type === 'VariableDeclaration') {\n const { declarations } = statement as AnyNode;\n if (!Array.isArray(declarations)) {\n return bindings;\n }\n\n declarations.forEach((declarator) => {\n const { id } = declarator as AnyNode;\n if (isNode(id)) {\n collectDeclaredNames(id).forEach((name) => bindings.add(name));\n }\n });\n return bindings;\n }\n\n if (\n (statement.type === 'FunctionDeclaration' ||\n statement.type === 'ClassDeclaration' ||\n statement.type === 'TSEnumDeclaration') &&\n 'id' in statement\n ) {\n const { id } = statement as AnyNode;\n if (isNode(id) && id.type === 'Identifier') {\n bindings.add(id.name);\n }\n return bindings;\n }\n\n if (statement.type === 'ExportNamedDeclaration') {\n const { declaration } = statement as AnyNode;\n return isNode(declaration)\n ? collectTopLevelBindings(declaration)\n : bindings;\n }\n\n return bindings;\n};\n\nconst collectTopLevelStatementInfos = (\n program: Program\n): TopLevelStatementInfo[] =>\n program.body.map((statement) => ({\n bindings: collectTopLevelBindings(statement),\n node: statement,\n references: collectReferencedNames(statement),\n }));\n\nconst collectTopLevelBindingsFromStatements = (\n statements: TopLevelStatementInfo[]\n): Set<string> =>\n new Set(statements.flatMap((statement) => [...statement.bindings]));\n\nconst collectRemovableNamesFromStatements = (\n statements: TopLevelStatementInfo[],\n initialNames: Set<string>\n): Set<string> => {\n const removable = new Set(initialNames);\n const bindingToStatement = new Map<string, TopLevelStatementInfo>();\n\n statements.forEach((statement) => {\n statement.bindings.forEach((name) => {\n bindingToStatement.set(name, statement);\n });\n });\n\n const queue = [...removable];\n while (queue.length > 0) {\n const name = queue.shift()!;\n const statement = bindingToStatement.get(name);\n if (statement) {\n statement.references.forEach((reference) => {\n if (bindingToStatement.has(reference) && !removable.has(reference)) {\n removable.add(reference);\n queue.push(reference);\n }\n });\n }\n }\n\n return removable;\n};\n\nconst createScopedCleanupScope = (\n parent: ScopedCleanupScope | null\n): ScopedCleanupScope => ({\n bindings: new Map(),\n parent,\n});\n\nconst resolveScopedBinding = (\n scope: ScopedCleanupScope,\n name: string\n): string | null => {\n let current: ScopedCleanupScope | null = scope;\n while (current) {\n const bindingId = current.bindings.get(name);\n if (bindingId) {\n return bindingId;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst collectScopedBindingInfos = (\n program: Program\n): Map<string, ScopedBindingInfo> => {\n const bindings = new Map<string, ScopedBindingInfo>();\n let sequence = 0;\n\n const addBinding = (\n scope: ScopedCleanupScope,\n name: string,\n kind: ScopedBindingKind,\n declaration: Node\n ): string => {\n const id = `${kind}:${name}:${declaration.start}:${sequence}`;\n sequence += 1;\n\n bindings.set(id, {\n declaration,\n dependencies: new Set(),\n externalReferences: 0,\n id,\n incomingFromBindings: new Set(),\n kind,\n name,\n });\n scope.bindings.set(name, id);\n return id;\n };\n\n const addPatternBindings = (\n scope: ScopedCleanupScope,\n pattern: Node,\n kind: ScopedBindingKind,\n declaration: Node\n ): void => {\n collectDeclaredNames(pattern).forEach((name) => {\n addBinding(scope, name, kind, declaration);\n });\n };\n\n const recordReference = (\n scope: ScopedCleanupScope,\n name: string,\n ownerBindingId: string | null\n ): void => {\n const targetId = resolveScopedBinding(scope, name);\n if (!targetId) {\n return;\n }\n\n const target = bindings.get(targetId);\n if (!target) {\n return;\n }\n\n if (ownerBindingId && ownerBindingId !== targetId) {\n target.incomingFromBindings.add(ownerBindingId);\n bindings.get(ownerBindingId)?.dependencies.add(targetId);\n return;\n }\n\n target.externalReferences += 1;\n };\n\n type ScopedWalk = (\n node: Node,\n scope: ScopedCleanupScope,\n parent?: Node | null,\n ownerBindingId?: string | null\n ) => void;\n\n let walk: ScopedWalk;\n\n function walkPatternReferenceSubexpressions(\n node: Node,\n scope: ScopedCleanupScope,\n ownerBindingId: string | null\n ): void {\n if (node.type === 'Identifier') {\n return;\n }\n\n if (node.type === 'TSParameterProperty') {\n walkPatternReferenceSubexpressions(node.parameter, scope, ownerBindingId);\n return;\n }\n\n if (node.type === 'RestElement') {\n walkPatternReferenceSubexpressions(node.argument, scope, ownerBindingId);\n return;\n }\n\n if (node.type === 'AssignmentPattern') {\n walkPatternReferenceSubexpressions(node.left, scope, ownerBindingId);\n walk(node.right, scope, node, ownerBindingId);\n return;\n }\n\n if (node.type === 'ObjectPattern') {\n node.properties.forEach((property) => {\n if (property.type === 'RestElement') {\n walkPatternReferenceSubexpressions(\n property.argument,\n scope,\n ownerBindingId\n );\n return;\n }\n\n if (property.computed && isNode(property.key)) {\n walk(property.key, scope, property, ownerBindingId);\n }\n\n walkPatternReferenceSubexpressions(\n property.value,\n scope,\n ownerBindingId\n );\n });\n return;\n }\n\n if (node.type === 'ArrayPattern') {\n node.elements.forEach((element) => {\n if (element && isNode(element)) {\n walkPatternReferenceSubexpressions(element, scope, ownerBindingId);\n }\n });\n }\n }\n\n walk = (\n node: Node,\n scope: ScopedCleanupScope,\n parent: Node | null = null,\n ownerBindingId: string | null = null\n ): void => {\n if (node.type === 'ImportDeclaration') {\n const { specifiers } = node as AnyNode;\n if (Array.isArray(specifiers)) {\n specifiers.forEach((specifier) => {\n const { local } = specifier as AnyNode;\n if (\n isNode(local) &&\n local.type === 'Identifier' &&\n typeof local.name === 'string'\n ) {\n addBinding(scope, local.name, 'import', node);\n }\n });\n }\n return;\n }\n\n if (node.type === 'ExportNamedDeclaration' && node.declaration) {\n walk(node.declaration, scope, node, ownerBindingId);\n collectTopLevelBindings(node).forEach((name) => {\n recordReference(scope, name, ownerBindingId);\n });\n return;\n }\n\n if (node.type === 'ExportDefaultDeclaration') {\n const { declaration } = node as AnyNode;\n if (isNode(declaration)) {\n walk(declaration, scope, node, ownerBindingId);\n if (\n (declaration.type === 'FunctionDeclaration' ||\n declaration.type === 'ClassDeclaration') &&\n declaration.id\n ) {\n recordReference(scope, declaration.id.name, ownerBindingId);\n }\n }\n return;\n }\n\n if (node.type === 'VariableDeclaration') {\n const { declarations } = node as AnyNode;\n if (!Array.isArray(declarations)) {\n return;\n }\n\n declarations.forEach((declarator) => {\n const { id } = declarator as AnyNode;\n if (isNode(id)) {\n addPatternBindings(scope, id, 'variable', node);\n }\n });\n\n declarations.forEach((declarator) => {\n const { id } = declarator as AnyNode;\n const { init } = declarator as AnyNode;\n if (!isNode(id) || !isNode(init)) {\n return;\n }\n\n const ownerName = collectDeclaredNames(id)[0] ?? null;\n const nextOwner =\n ownerName !== null ? resolveScopedBinding(scope, ownerName) : null;\n walk(init, scope, declarator as Node, nextOwner);\n });\n return;\n }\n\n if (node.type === 'FunctionDeclaration' && node.id) {\n const functionBindingId = addBinding(\n scope,\n node.id.name,\n 'function',\n node\n );\n const fnScope = createScopedCleanupScope(scope);\n\n node.params.forEach((param) => {\n addPatternBindings(fnScope, param, 'param', param);\n walkPatternReferenceSubexpressions(param, fnScope, functionBindingId);\n });\n\n if (node.body) {\n walk(node.body, fnScope, node, functionBindingId);\n }\n return;\n }\n\n if (\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n const fnScope = createScopedCleanupScope(scope);\n if (node.type === 'FunctionExpression' && node.id) {\n addBinding(fnScope, node.id.name, 'function', node);\n }\n\n node.params.forEach((param) => {\n addPatternBindings(fnScope, param, 'param', param);\n walkPatternReferenceSubexpressions(param, fnScope, ownerBindingId);\n });\n\n if (node.body) {\n walk(node.body, fnScope, node, ownerBindingId);\n }\n return;\n }\n\n if (node.type === 'BlockStatement') {\n const blockScope = createScopedCleanupScope(scope);\n getChildren(node).forEach((child) =>\n walk(child, blockScope, node, ownerBindingId)\n );\n return;\n }\n\n if (\n isNodeReference(node, parent) &&\n 'name' in node &&\n typeof node.name === 'string'\n ) {\n recordReference(scope, node.name, ownerBindingId);\n }\n\n getChildren(node).forEach((child) =>\n walk(child, scope, node, ownerBindingId)\n );\n };\n\n walk(program, createScopedCleanupScope(null));\n return bindings;\n};\n\nconst collectScopedRemovableBindingIds = (\n bindings: Map<string, ScopedBindingInfo>,\n initialNames: Set<string>\n): Set<string> => {\n const removable = new Set<string>();\n let changed = true;\n\n while (changed) {\n changed = false;\n\n for (const binding of bindings.values()) {\n if (\n !removable.has(binding.id) &&\n binding.kind !== 'import' &&\n binding.kind !== 'param' &&\n binding.externalReferences === 0\n ) {\n const seededByName =\n initialNames.has(binding.name) ||\n (GENERATED_HELPER_NAME_RE.test(binding.name) &&\n binding.incomingFromBindings.size === 0);\n const allIncomingRemovable =\n binding.incomingFromBindings.size > 0 &&\n [...binding.incomingFromBindings].every((sourceId) =>\n removable.has(sourceId)\n );\n\n if (\n (seededByName && binding.incomingFromBindings.size === 0) ||\n allIncomingRemovable\n ) {\n removable.add(binding.id);\n changed = true;\n }\n }\n }\n }\n\n return removable;\n};\n\nfunction 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 collectUnusedScopedDeclarationRemovals = (\n code: string,\n bindings: Map<string, ScopedBindingInfo>,\n initialRemovableNames: Set<string>\n): Replacement[] => {\n const removableBindingIds = collectScopedRemovableBindingIds(\n bindings,\n initialRemovableNames\n );\n const removals = new Map<string, Replacement>();\n\n bindings.forEach((binding) => {\n if (\n !removableBindingIds.has(binding.id) ||\n binding.kind === 'import' ||\n binding.kind === 'param' ||\n binding.externalReferences > 0 ||\n [...binding.incomingFromBindings].some(\n (sourceId) => !removableBindingIds.has(sourceId)\n )\n ) {\n return;\n }\n\n if (\n binding.kind === 'function' &&\n binding.declaration.type === 'FunctionDeclaration'\n ) {\n const range = expandImportRemovalRange(\n code,\n binding.declaration.start,\n binding.declaration.end\n );\n removals.set(`${range.start}:${range.end}`, range);\n return;\n }\n\n if (binding.declaration.type !== 'VariableDeclaration') {\n return;\n }\n\n const { declarations } = binding.declaration as AnyNode;\n if (!Array.isArray(declarations) || declarations.length !== 1) {\n return;\n }\n\n const range = expandImportRemovalRange(\n code,\n binding.declaration.start,\n binding.declaration.end\n );\n removals.set(`${range.start}:${range.end}`, range);\n });\n\n return [...removals.values()];\n};\n\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 collectUnusedImportRemovals = (\n code: string,\n program: Program,\n referencedNames: Set<string>,\n removableNames: Set<string>,\n preserveSideEffectImportLocals: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'ImportDeclaration') {\n return;\n }\n\n const localNames = collectImportLocalNames(statement);\n const removableLocalNames = localNames.filter((localName) =>\n removableNames.has(localName)\n );\n if (\n removableLocalNames.length > 0 &&\n removableLocalNames.length === localNames.length &&\n removableLocalNames.every((localName) => !referencedNames.has(localName))\n ) {\n if (\n removableLocalNames.some((localName) =>\n preserveSideEffectImportLocals.has(localName)\n )\n ) {\n removals.push({\n end: statement.end,\n start: statement.start,\n value: `import ${code.slice(\n statement.source.start,\n statement.source.end\n )};`,\n });\n return;\n }\n\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n return;\n }\n\n const { specifiers } = statement as AnyNode;\n if (!Array.isArray(specifiers) || specifiers.length <= 1) {\n return;\n }\n\n specifiers.forEach((specifier) => {\n if (!isNode(specifier)) {\n return;\n }\n\n const localName = getImportSpecifierLocalName(specifier);\n if (\n localName &&\n removableNames.has(localName) &&\n !referencedNames.has(localName)\n ) {\n removals.push(\n expandImportSpecifierRemovalRange(\n code,\n specifier.start,\n specifier.end\n )\n );\n }\n });\n });\n\n return removals;\n};\n\nconst collectUnusedTopLevelDeclarationRemovals = (\n code: string,\n program: Program,\n referencedNames: Set<string>,\n removableNames: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'VariableDeclaration') {\n return;\n }\n\n const localNames = [...collectTopLevelBindings(statement)];\n\n if (\n localNames.length > 0 &&\n localNames.every((localName) => removableNames.has(localName)) &&\n localNames.every((localName) => !referencedNames.has(localName))\n ) {\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n }\n });\n\n return removals;\n};\n\nconst collectUnusedGeneratedHelperDeclarationRemovals = (\n code: string,\n program: Program,\n referencedNames: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'VariableDeclaration') {\n return;\n }\n\n const localNames = [...collectTopLevelBindings(statement)];\n if (\n localNames.length > 0 &&\n localNames.every((localName) =>\n GENERATED_HELPER_NAME_RE.test(localName)\n ) &&\n localNames.every((localName) => !referencedNames.has(localName))\n ) {\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n }\n });\n\n return removals;\n};\n\nconst collectTopLevelExpressionStatementRemovals = (\n code: string,\n statements: TopLevelStatementInfo[],\n topLevelBindings: Set<string>,\n removableExpressionRefs: Set<string>\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n statements.forEach((statement) => {\n if (statement.node.type !== 'ExpressionStatement') {\n return;\n }\n\n const { expression } = statement.node;\n const isPureExpression =\n expression.type === 'Identifier' ||\n expression.type === 'Literal' ||\n expression.type === 'ObjectExpression' ||\n expression.type === 'ArrayExpression' ||\n expression.type === 'ArrowFunctionExpression' ||\n expression.type === 'FunctionExpression' ||\n (expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0);\n if (!isPureExpression) {\n return;\n }\n\n const localReferences = [...statement.references].filter((name) =>\n topLevelBindings.has(name)\n );\n\n if (\n localReferences.length > 0 &&\n localReferences.every((name) => removableExpressionRefs.has(name))\n ) {\n removals.push(\n expandImportRemovalRange(code, statement.node.start, statement.node.end)\n );\n }\n });\n\n return removals;\n};\n\nconst collectEmptyTopLevelBlockRemovals = (\n code: string,\n program: Program\n): Replacement[] => {\n const removals: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (statement.type !== 'BlockStatement' || statement.body.length > 0) {\n return;\n }\n\n removals.push(\n expandImportRemovalRange(code, statement.start, statement.end)\n );\n });\n\n return removals;\n};\n\nconst removeUnusedAfterReplacement = (\n code: string,\n filename: string,\n initialRemovableNames: Set<string>,\n removableExpressionRefs: Set<string>,\n preserveSideEffectImportLocals: Set<string>\n): string => {\n let current = code;\n const cumulativeRemovableNames = new Set(initialRemovableNames);\n const applyIfParsable = (next: string): string => {\n try {\n parseOxc(next, filename);\n return next;\n } catch {\n return current;\n }\n };\n\n for (let idx = 0; idx < 5; idx += 1) {\n const previous = current;\n const program = parseOxc(current, filename);\n const statements = collectTopLevelStatementInfos(program);\n const removableNames = collectRemovableNamesFromStatements(\n statements,\n cumulativeRemovableNames\n );\n removableNames.forEach((name) => cumulativeRemovableNames.add(name));\n const referencedNames = collectReferencedNames(program);\n const topLevelBindings = collectTopLevelBindingsFromStatements(statements);\n const scopedBindings = collectScopedBindingInfos(program);\n const removals = mergeEmptyRemovalRanges([\n ...collectUnusedScopedDeclarationRemovals(\n current,\n scopedBindings,\n cumulativeRemovableNames\n ),\n ...collectUnusedTopLevelDeclarationRemovals(\n current,\n program,\n referencedNames,\n cumulativeRemovableNames\n ),\n ...collectUnusedGeneratedHelperDeclarationRemovals(\n current,\n program,\n referencedNames\n ),\n ...collectUnusedImportRemovals(\n current,\n program,\n referencedNames,\n cumulativeRemovableNames,\n preserveSideEffectImportLocals\n ),\n ...collectTopLevelExpressionStatementRemovals(\n current,\n statements,\n topLevelBindings,\n removableExpressionRefs\n ),\n ...collectEmptyTopLevelBlockRemovals(current, program),\n ]);\n current =\n removals.length > 0\n ? applyIfParsable(applyReplacements(current, removals))\n : current;\n\n if (current === previous) {\n return current;\n }\n }\n\n return current;\n};\n\nconst getMemberName = (node: MemberExpression): string | null => {\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst unwrapQualifiedExpression = (node: Expression): Expression => {\n if (\n node.type === 'TSAsExpression' ||\n node.type === 'TSSatisfiesExpression' ||\n node.type === 'TSNonNullExpression' ||\n node.type === 'TSTypeAssertion' ||\n node.type === 'ParenthesizedExpression'\n ) {\n return unwrapQualifiedExpression(\n (node as QualifiedExpression & { expression: Expression }).expression\n );\n }\n\n if (node.type === 'SequenceExpression') {\n const sequence = node as SequenceExpressionLike;\n return unwrapQualifiedExpression(\n sequence.expressions[sequence.expressions.length - 1] ?? node\n );\n }\n\n return node;\n};\n\nconst getRootIdentifier = (node: Expression): OxcIdentifier | null => {\n const expression = unwrapQualifiedExpression(node);\n\n if (expression.type === 'Identifier') {\n return expression;\n }\n\n if (expression.type === 'MemberExpression') {\n return getRootIdentifier(expression.object);\n }\n\n if (expression.type === 'CallExpression') {\n return getRootIdentifier((expression as CallExpressionLike).callee);\n }\n\n return null;\n};\n\nconst getQualifiedName = (node: Expression): string | null => {\n const expression = unwrapQualifiedExpression(node);\n\n if (expression.type === 'Identifier') {\n return expression.name;\n }\n\n if (expression.type === 'MemberExpression') {\n const object = getQualifiedName(expression.object);\n const member = getMemberName(expression);\n return object && member ? `${object}.${member}` : null;\n }\n\n if (expression.type === 'CallExpression') {\n return getQualifiedName((expression as CallExpressionLike).callee);\n }\n\n return null;\n};\n\nconst resolveDefinedProcessor = (\n callee: Expression,\n definedProcessors: Map<string, DefinedProcessor>\n): {\n collapseQualifiedCallee: boolean;\n definedProcessor: DefinedProcessor;\n} | null => {\n const qualified = getQualifiedName(callee);\n if (qualified) {\n const definedProcessor = definedProcessors.get(qualified);\n if (definedProcessor) {\n return {\n collapseQualifiedCallee: qualified.includes('.'),\n definedProcessor,\n };\n }\n }\n\n const root = getRootIdentifier(callee);\n if (!root) {\n return null;\n }\n\n const definedProcessor = definedProcessors.get(root.name);\n return definedProcessor\n ? {\n collapseQualifiedCallee: false,\n definedProcessor,\n }\n : null;\n};\n\nconst isCallTagOfTaggedTemplate = (node: Node, parent: Node | null): boolean =>\n parent?.type === 'TaggedTemplateExpression' && parent.tag === node;\n\nconst expandReplacementTarget = (\n target: Expression,\n ancestors: Node[]\n): Expression => {\n let current: Expression = target;\n\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx];\n if (\n ancestor.type === 'SequenceExpression' &&\n ancestor.expressions[ancestor.expressions.length - 1] === current\n ) {\n current = ancestor as Expression;\n } else if (\n ancestor.type === 'ParenthesizedExpression' &&\n ancestor.expression === current\n ) {\n current = ancestor as Expression;\n } else {\n break;\n }\n }\n\n return current;\n};\n\nconst collectProcessorUsages = (\n program: Program,\n definedProcessors: Map<string, DefinedProcessor>\n): ProcessorUsage[] => {\n const usages: ProcessorUsage[] = [];\n\n const walk = (\n node: Node,\n ancestors: Node[],\n parent: Node | null = null\n ): void => {\n if (node.type === 'TaggedTemplateExpression') {\n const callee = node.tag as Expression;\n const resolvedProcessor = resolveDefinedProcessor(\n callee,\n definedProcessors\n );\n if (resolvedProcessor) {\n usages.push({\n ancestors,\n callee,\n collapseQualifiedCallee: resolvedProcessor.collapseQualifiedCallee,\n definedProcessor: resolvedProcessor.definedProcessor,\n kind: 'template',\n replacementTarget: expandReplacementTarget(node, ancestors),\n target: node,\n });\n }\n } else if (\n node.type === 'CallExpression' &&\n !isCallTagOfTaggedTemplate(node, parent)\n ) {\n const { callee } = node as CallExpressionLike;\n const resolvedProcessor = resolveDefinedProcessor(\n callee,\n definedProcessors\n );\n if (resolvedProcessor) {\n usages.push({\n ancestors,\n callee,\n collapseQualifiedCallee: resolvedProcessor.collapseQualifiedCallee,\n definedProcessor: resolvedProcessor.definedProcessor,\n kind: 'call',\n replacementTarget: expandReplacementTarget(\n node as CallExpression,\n ancestors\n ),\n target: node as CallExpression,\n });\n }\n }\n\n getChildren(node).forEach((child) =>\n walk(child, [...ancestors, node], node)\n );\n };\n\n walk(program, []);\n\n return usages.sort((a, b) => a.target.start - b.target.start);\n};\n\nconst expressionSpan = (expression: Expression): ExpressionSpan => ({\n end: expression.end,\n start: expression.start,\n});\n\nconst collectCallArgumentSpans = (node: Expression): ExpressionSpan[] => {\n const expression = unwrapQualifiedExpression(node);\n\n if (expression.type === 'CallExpression') {\n const call = expression as CallExpressionLike;\n const calleeSpans = collectCallArgumentSpans(call.callee);\n const argumentSpans = call.arguments.flatMap((arg) =>\n arg.type === 'SpreadElement' ? [] : [expressionSpan(arg as Expression)]\n );\n return [...calleeSpans, ...argumentSpans];\n }\n\n if (expression.type === 'MemberExpression') {\n return collectCallArgumentSpans(expression.object);\n }\n\n return [];\n};\n\nconst collectUsageExpressionSpans = (\n usage: ProcessorUsage\n): ExpressionSpan[] => {\n const calleeSpans = collectCallArgumentSpans(usage.callee);\n if (usage.kind === 'template') {\n return [\n ...calleeSpans,\n ...usage.target.quasi.expressions.map((expression) =>\n expressionSpan(expression as Expression)\n ),\n ];\n }\n\n return [\n ...calleeSpans,\n ...usage.target.arguments.flatMap((arg) =>\n arg.type === 'SpreadElement' ? [] : [expressionSpan(arg as Expression)]\n ),\n ];\n};\n\nconst literalExpressionValue = (\n expression: Expression,\n code: string,\n source: string,\n location: SourceLocation\n): ExpressionValue | null => {\n if (expression.type !== 'Literal') {\n return null;\n }\n\n if (\n expression.value === null ||\n typeof expression.value === 'string' ||\n typeof expression.value === 'number' ||\n typeof expression.value === 'boolean'\n ) {\n let type:\n | 'BooleanLiteral'\n | 'NullLiteral'\n | 'NumericLiteral'\n | 'StringLiteral';\n if (expression.value === null) {\n type = 'NullLiteral';\n } else if (typeof expression.value === 'string') {\n type = 'StringLiteral';\n } else if (typeof expression.value === 'number') {\n type = 'NumericLiteral';\n } else {\n type = 'BooleanLiteral';\n }\n\n const ex =\n expression.value === null\n ? { loc: location, type }\n : {\n loc: location,\n type,\n value: expression.value,\n };\n\n return {\n buildCodeFrameError: (message: string) =>\n buildCodeFrameError(code, location, message),\n ex,\n kind: ValueType.CONST,\n source,\n value: expression.value,\n } as ExpressionValue;\n }\n\n return null;\n};\n\nconst expressionValue = (\n expression: Expression,\n code: string,\n loc: LocationLookup,\n filename?: string | null\n): ExpressionValue => {\n const source = code.slice(expression.start, expression.end);\n const location = getSourceLocation(\n expression.start,\n expression.end,\n loc,\n filename\n );\n const literal = literalExpressionValue(expression, code, source, location);\n if (literal) {\n return literal;\n }\n\n const helperCallName =\n expression.type === 'CallExpression' &&\n expression.arguments.length === 0 &&\n expression.callee.type === 'Identifier' &&\n GENERATED_HELPER_NAME_RE.test(expression.callee.name)\n ? expression.callee.name\n : null;\n\n let ex: ExpressionValue['ex'];\n if (expression.type === 'Identifier') {\n ex = { loc: location, name: expression.name, type: 'Identifier' };\n } else if (helperCallName) {\n ex = { loc: location, name: helperCallName, type: 'Identifier' };\n } else {\n ex = {\n loc: location,\n name: code.slice(expression.start, expression.end),\n type: 'Identifier',\n };\n }\n\n return {\n buildCodeFrameError: (message: string) =>\n buildCodeFrameError(code, location, message),\n ex,\n kind:\n expression.type === 'ArrowFunctionExpression' ||\n expression.type === 'FunctionExpression'\n ? ValueType.FUNCTION\n : ValueType.LAZY,\n source,\n } as ExpressionValue;\n};\n\nconst withCurrentExpressionLocation = (\n value: ExpressionValue,\n expression: Expression,\n loc: LocationLookup,\n filename?: string | null\n): ExpressionValue => {\n const location = getSourceLocation(\n expression.start,\n expression.end,\n loc,\n filename\n );\n\n if (value.kind === ValueType.CONST) {\n return {\n ...value,\n ex: {\n ...value.ex,\n loc: location,\n },\n };\n }\n\n if (value.kind === ValueType.FUNCTION) {\n return {\n ...value,\n ex: {\n ...value.ex,\n loc: location,\n },\n };\n }\n\n return {\n ...value,\n ex: {\n ...value.ex,\n loc: location,\n },\n };\n};\n\nconst shiftExpressionValue = (\n expressionValues: ExpressionValue[],\n expression: Expression,\n code: string,\n loc: LocationLookup,\n filename?: string | null\n): ExpressionValue =>\n expressionValues.length > 0\n ? withCurrentExpressionLocation(\n expressionValues.shift()!,\n expression,\n loc,\n filename\n )\n : expressionValue(expression, code, loc, filename);\n\nconst zipTemplate = (\n template: TaggedTemplateExpression,\n code: string,\n loc: LocationLookup,\n filename: string | null | undefined,\n expressionValues: ExpressionValue[]\n): Param => {\n const parts = template.quasi.quasis.flatMap((quasi, idx) => {\n const expression = template.quasi.expressions[idx];\n const templateElement = {\n ...quasi,\n loc: getSourceLocation(quasi.start, quasi.end, loc, filename),\n };\n\n return [\n templateElement,\n expression\n ? shiftExpressionValue(\n expressionValues,\n expression as Expression,\n code,\n loc,\n filename\n )\n : null,\n ].filter(isNotNull);\n });\n\n return ['template', parts] as Param;\n};\n\nconst buildCalleeParams = (\n node: Expression,\n code: string,\n loc: LocationLookup,\n filename: string | null | undefined,\n expressionValues: ExpressionValue[],\n collapseQualifiedCallee = false\n): Params | null => {\n const expression = unwrapQualifiedExpression(node);\n\n if (\n collapseQualifiedCallee &&\n (expression.type === 'Identifier' || expression.type === 'MemberExpression')\n ) {\n return [['callee', expression] as Param];\n }\n\n if (expression.type === 'Identifier') {\n return [['callee', { name: expression.name, type: 'Identifier' }]];\n }\n\n if (expression.type === 'MemberExpression') {\n const params = buildCalleeParams(\n expression.object,\n code,\n loc,\n filename,\n expressionValues,\n collapseQualifiedCallee\n );\n const member = getMemberName(expression);\n return params && member ? [...params, ['member', member]] : null;\n }\n\n if (expression.type === 'CallExpression') {\n const call = expression as CallExpressionLike;\n const params = buildCalleeParams(\n call.callee,\n code,\n loc,\n filename,\n expressionValues,\n collapseQualifiedCallee\n );\n if (!params) {\n return null;\n }\n\n const callValues = call.arguments\n .filter((arg) => arg.type !== 'SpreadElement')\n .map((arg) =>\n shiftExpressionValue(\n expressionValues,\n arg as Expression,\n code,\n loc,\n filename\n )\n );\n\n return [...params, ['call', ...callValues]];\n }\n\n return null;\n};\n\nconst buildParams = (\n usage: ProcessorUsage,\n code: string,\n loc: LocationLookup,\n filename: string | null | undefined,\n expressionValues: ExpressionValue[],\n collapseQualifiedCallee: boolean\n): Params | null => {\n const params = buildCalleeParams(\n usage.callee,\n code,\n loc,\n filename,\n expressionValues,\n collapseQualifiedCallee\n );\n if (!params) {\n return null;\n }\n\n if (usage.kind === 'template') {\n return [\n ...params,\n zipTemplate(usage.target, code, loc, filename, expressionValues),\n ];\n }\n\n const callValues = usage.target.arguments\n .filter((arg) => arg.type !== 'SpreadElement')\n .map((arg) =>\n shiftExpressionValue(\n expressionValues,\n arg as Expression,\n code,\n loc,\n filename\n )\n );\n\n return [...params, ['call', ...callValues]];\n};\n\nconst getPropertyKeyName = (property: AnyNode, code: string): string | null => {\n const { key } = property;\n if (!isNode(key)) {\n return null;\n }\n\n if (key.type === 'Identifier') {\n return key.name;\n }\n\n if (key.type === 'Literal') {\n return String(key.value);\n }\n\n return typeof key.start === 'number' && typeof key.end === 'number'\n ? code.slice(key.start, key.end)\n : null;\n};\n\nconst getDisplayName = (\n ancestors: Node[],\n idx: number,\n code: string,\n filename?: string | null\n): string => {\n const owner = [...ancestors].reverse().find((node) => {\n return (\n node.type === 'Property' ||\n node.type === 'JSXOpeningElement' ||\n node.type === 'VariableDeclarator'\n );\n }) as AnyNode | undefined;\n\n if (owner?.type === 'Property') {\n const keyName = getPropertyKeyName(owner, code);\n if (keyName) {\n return keyName;\n }\n } else if (owner?.type === 'JSXOpeningElement') {\n const { name } = owner;\n if (isNode(name) && name.type === 'JSXIdentifier') {\n return name.name;\n }\n } else if (owner?.type === 'VariableDeclarator') {\n const { id } = owner;\n if (isNode(id) && id.type === 'Identifier') {\n return id.name;\n }\n }\n\n let displayName = basename(filename ?? 'unknown').replace(/\\.[a-z\\d]+$/, '');\n if (filename && /^index\\.[a-z\\d]+$/.test(basename(filename))) {\n displayName = basename(dirname(filename));\n }\n\n if (!displayName) {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n\n return `${displayName}${idx}`;\n};\n\nconst getTagOwner = (ancestors: Node[]): AnyNode | null => {\n const owner = [...ancestors]\n .reverse()\n .find(\n (node) =>\n node.type === 'Property' ||\n node.type === 'JSXOpeningElement' ||\n node.type === 'VariableDeclarator'\n ) as AnyNode | undefined;\n\n return owner ?? null;\n};\n\nconst isTagReferenced = (program: Program, ancestors: Node[]): boolean => {\n const owner = getTagOwner(ancestors);\n if (owner?.type !== 'VariableDeclarator') {\n return true;\n }\n\n const { id } = owner;\n if (!isNode(id) || id.type !== 'Identifier') {\n return true;\n }\n\n if (ancestors.some((node) => node.type === 'ExportNamedDeclaration')) {\n return true;\n }\n\n let referenced = false;\n visit(program, (node, parent) => {\n const referenceName =\n node.type === 'Identifier' || node.type === 'JSXIdentifier'\n ? node.name\n : null;\n\n if (\n referenced ||\n referenceName !== id.name ||\n (node.type === 'Identifier' &&\n node.start === id.start &&\n node.end === id.end)\n ) {\n return;\n }\n\n referenced = isNodeReference(node, parent);\n });\n\n return referenced;\n};\n\nconst isReplacementPure = (replacement: ProcessorExpression): boolean =>\n replacement.type === 'CallExpression';\n\nconst createProcessor = (\n definedProcessor: DefinedProcessor,\n params: Params,\n target: Expression,\n replacementTarget: Expression,\n ancestors: Node[],\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'extensions' | 'evaluate' | 'tagResolver'\n >,\n code: string,\n loc: LocationLookup,\n idx: number,\n isReferenced: boolean,\n usedNames: Set<string>,\n replacements: Replacement[]\n): CreatedProcessor | null => {\n const [Processor, tagSource] = definedProcessor;\n const astService = createOxcAstService(usedNames);\n\n const replacer = (\n replacement:\n | ProcessorExpression\n | ((tagPath: unknown) => ProcessorExpression),\n isPure: boolean\n ) => {\n const next =\n typeof replacement === 'function' ? replacement(target) : replacement;\n const replacementCode = expressionToCode(next);\n replacements.push({\n start: replacementTarget.start,\n end: replacementTarget.end,\n value:\n isPure && isReplacementPure(next)\n ? `/*#__PURE__*/${replacementCode}`\n : replacementCode,\n });\n };\n\n try {\n let displayName: string;\n try {\n displayName = getDisplayName(ancestors, idx, code, fileContext.filename);\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.startsWith(\"Couldn't determine a name for the component\")\n ) {\n let displayNameNode: Node = target;\n if (target.type === 'TaggedTemplateExpression') {\n displayNameNode = target.tag;\n } else if (target.type === 'CallExpression') {\n displayNameNode = target.callee;\n }\n const pointerNode =\n displayNameNode.type === 'MemberExpression'\n ? getRootIdentifier(displayNameNode) ?? displayNameNode\n : displayNameNode;\n throw buildCodeFrameError(\n code,\n getSourceLocation(\n pointerNode.start,\n pointerNode.end,\n loc,\n fileContext.filename\n ),\n error.message\n );\n }\n throw error;\n }\n\n return {\n astService,\n processor: new Processor(\n params,\n tagSource,\n astService,\n getSourceLocation(target.start, target.end, loc, fileContext.filename),\n replacer,\n displayName,\n isReferenced,\n idx,\n options,\n fileContext\n ),\n };\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n return null;\n }\n\n if (\n typeof e === 'symbol' &&\n e.description === BaseProcessor.SKIP.description\n ) {\n if (!didWarnSkipSymbolMismatch) {\n didWarnSkipSymbolMismatch = true;\n // eslint-disable-next-line no-console\n console.warn(\n [\n \"[wyw-in-js] Processor threw Symbol('skip') that does not match BaseProcessor.SKIP identity.\",\n 'This usually means duplicate copies of @wyw-in-js/processor-utils (or the processor) are bundled/installed.',\n 'Consider deduping dependencies to avoid subtle issues (instanceof checks, sentinels, etc).',\n ].join('\\n')\n );\n }\n\n return null;\n }\n\n throw e;\n }\n};\n\nexport const applyOxcProcessors = (\n code: string,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'extensions' | 'evaluate' | 'tagResolver'\n > & {\n eventEmitter?: EventEmitter;\n preserveSideEffectImportLocals?: Set<string>;\n },\n callback: (processor: BaseProcessor) => void,\n cleanupUnused = false\n): ApplyOxcProcessorsResult => {\n const filename = fileContext.filename ?? 'unknown.js';\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n let workingCode = code;\n let program = parseOxc(workingCode, filename);\n const definedProcessors = new Map<string, DefinedProcessor>();\n const removableImportLocals = new Set<string>();\n const removableExpressionRefs = new Set<string>();\n\n eventEmitter.perf('transform:preeval:processTemplate:imports', () => {\n const imports = eventEmitter.perf(\n 'transform:preeval:processTemplate:imports:analysis',\n () => collectOxcProcessorImportsFromProgram(program, workingCode)\n );\n\n eventEmitter.perf(\n 'transform:preeval:processTemplate:imports:lookup',\n () => {\n imports.forEach((item) => {\n const localName = item.local.name ?? item.local.code;\n if (item.imported === 'side-effect' || !localName) {\n return;\n }\n\n const [processor, tagSource] = getProcessorForImport(\n {\n imported: item.imported,\n source: item.source,\n },\n filename,\n options\n );\n\n if (processor) {\n definedProcessors.set(localName, [processor, tagSource]);\n removableImportLocals.add(localName);\n const rootLocalName = localName.split('.')[0];\n if (rootLocalName) {\n removableImportLocals.add(rootLocalName);\n }\n }\n });\n }\n );\n });\n\n if (definedProcessors.size === 0) {\n return {\n code: workingCode,\n processors: [],\n staticValueCandidates: [],\n staticValues: [],\n };\n }\n\n let processorUsages = eventEmitter.perf(\n 'transform:preeval:processTemplate:usages',\n () => collectProcessorUsages(program, definedProcessors)\n );\n if (processorUsages.length === 0) {\n return {\n code: workingCode,\n processors: [],\n staticValueCandidates: [],\n staticValues: [],\n };\n }\n\n const targetExpressionSpans = processorUsages.flatMap(\n collectUsageExpressionSpans\n );\n\n const extracted =\n targetExpressionSpans.length > 0\n ? eventEmitter.perf('transform:preeval:processTemplate:deps', () =>\n collectOxcExpressionDependencies(\n workingCode,\n filename,\n options.evaluate,\n targetExpressionSpans\n )\n )\n : {\n code: workingCode,\n dependencyNames: [],\n expressionValues: [],\n staticValueCandidates: [],\n staticValues: [],\n };\n\n if (extracted.code !== workingCode) {\n workingCode = extracted.code;\n program = eventEmitter.perf(\n 'transform:preeval:processTemplate:reparse',\n () => parseOxc(workingCode, filename)\n );\n processorUsages = eventEmitter.perf(\n 'transform:preeval:processTemplate:usages',\n () => collectProcessorUsages(program, definedProcessors)\n );\n }\n\n const templateExpressionValues = extracted.expressionValues.map(\n (value) =>\n ({\n ...value,\n buildCodeFrameError: (message: string) =>\n buildCodeFrameError(code, value.ex.loc!, message),\n }) as ExpressionValue\n );\n const loc = createLocationLookup(workingCode);\n const usedNames = eventEmitter.perf(\n 'transform:preeval:processTemplate:usedNames',\n () => collectUsedNames(program)\n );\n const addedImports: AddedImport[] = [];\n const replacements: Replacement[] = [];\n const processors: BaseProcessor[] = [];\n extracted.dependencyNames.forEach((name: string) =>\n removableImportLocals.add(name)\n );\n\n eventEmitter.perf('transform:preeval:processTemplate:processors', () => {\n processorUsages.forEach((usage, idx) => {\n const params = buildParams(\n usage,\n workingCode,\n loc,\n filename,\n templateExpressionValues,\n usage.collapseQualifiedCallee\n );\n if (!params) {\n return;\n }\n\n const created = createProcessor(\n usage.definedProcessor,\n params,\n usage.target,\n usage.replacementTarget,\n usage.ancestors,\n fileContext,\n options,\n workingCode,\n loc,\n idx,\n isTagReferenced(program, usage.ancestors),\n usedNames,\n replacements\n );\n\n if (!created) {\n return;\n }\n\n const { astService, processor } = created;\n\n const owner = getTagOwner(usage.ancestors);\n if (owner?.type === 'VariableDeclarator') {\n const { id } = owner;\n if (isNode(id) && id.type === 'Identifier') {\n removableExpressionRefs.add(id.name);\n }\n }\n\n processors.push(processor);\n callback(processor);\n addedImports.push(...astService.getAddedImports());\n });\n });\n\n const replacedCode = applyReplacements(workingCode, replacements);\n const codeWithAddedImports = insertAddedImports(\n replacedCode,\n program,\n addedImports\n );\n\n return {\n code: cleanupUnused\n ? eventEmitter.perf('transform:preeval:processTemplate:cleanup', () =>\n removeUnusedAfterReplacement(\n codeWithAddedImports,\n filename,\n removableImportLocals,\n new Set([...removableExpressionRefs, ...extracted.dependencyNames]),\n options.preserveSideEffectImportLocals ?? new Set()\n )\n )\n : codeWithAddedImports,\n processors,\n staticValueCandidates: extracted.staticValueCandidates,\n staticValues: extracted.staticValues,\n };\n};\n"],"file":"applyOxcProcessors.js"}
|
|
1
|
+
{"mappings":"AAAA,SAAS,0BAA0B","names":[],"sources":["../../src/utils/applyOxcProcessors.ts"],"version":3,"sourcesContent":["export { applyOxcProcessors } from './applyOxcProcessors/applyOxcProcessors';\n"],"file":"applyOxcProcessors.js"}
|
|
@@ -862,6 +862,14 @@ const getChildren = (node) => {
|
|
|
862
862
|
return result;
|
|
863
863
|
};
|
|
864
864
|
const precollectRequireSources = (node, state) => {
|
|
865
|
+
// Cheap text precheck at the Program entry: if the file body has no
|
|
866
|
+
// 'require(' substring there can be no CommonJS require() init to collect.
|
|
867
|
+
// Skip the full AST walk — meaningful saving on ESM-only modules in large
|
|
868
|
+
// monorepos. Done at Program-level only so nested recursion doesn't pay
|
|
869
|
+
// the indexOf cost per node.
|
|
870
|
+
if (node.type === "Program" && state.code.indexOf("require(") === -1) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
865
873
|
if (node.type === "VariableDeclarator" && node.id.type === "Identifier") {
|
|
866
874
|
const source = node.init ? sourceFromRequireSyntax(node.init) : null;
|
|
867
875
|
if (source) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AA2BA,SAAS,sBAAsB;AAsF/B,MAAM,eAAe,YAAiC;CACpD,UAAU,IAAI,KAAK;CACnB;CACD;AAED,MAAM,UAAU,UACd,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,UAAU,SACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,iBAAiB,MAAY,MAAc,UAA6B;CAC5E,MAAM,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI;CACtC,KAAK,KAAK;CACV,MAAM,SA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;EACd,gBAAgB,IAAI,KAAK;EACzB,QAAQ;GACN,aAAa,EAAE;GACf,SAAS,EAAE;GACX,SAAS,EAAE;GACX;GACA,WAAW,EAAE;GACd;EACF;AAED,0BAAyB,SAAS,MAAM;AACxC,OACE,SACA;EAAE,KAAK;EAAW,QAAQ;EAAM,OAAO;EAAW,EAClD,OACA,MACD;AACD,+BAA8B,MAAM;AAEpC,QAAO,MAAM;;AAGf,OAAO,SAAS,sCACd,SACA,MACsB;CACtB,MAAM,YAAY,YAAY,KAAK;CACnC,MAAM,QAAuB;EAC3B;EACA,YAAY,EAAE;EACd,gBAAgB,IAAI,KAAK;EACzB,QAAQ;GACN,aAAa,EAAE;GACf,SAAS,EAAE;GACX,SAAS,EAAE;GACX,YAAY;GACZ,WAAW,EAAE;GACd;EACF;AAED,0BAAyB,SAAS,MAAM;AACxC,OACE,SACA;EAAE,KAAK;EAAW,QAAQ;EAAM,OAAO;EAAW,EAClD,OACA,cACD;AAED,QAAO,MAAM,OAAO;;AAGtB,OAAO,SAAS,4BACd,MACA,UACmB;CACnB,MAAM,SAAS,eAAe,UAAU,MAAM,cAAc;AAE5D,QAAO,uCACL,OAAO,SACP,MACA,OAAO,OAAO,gBACf","names":[],"sources":["../../src/utils/collectOxcExportsAndImports.ts"],"version":3,"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define,no-restricted-syntax,no-continue */\n\nimport type {\n AssignmentExpression,\n BindingPattern,\n CallExpression,\n Class as OxcClass,\n ExportAllDeclaration,\n ExportDefaultDeclaration,\n ExportNamedDeclaration,\n ExportSpecifier,\n Expression,\n ExpressionStatement,\n Function as OxcFunction,\n ImportDeclaration,\n ImportExpression,\n ImportSpecifier,\n MemberExpression,\n ModuleExportName,\n Node,\n ObjectExpression,\n ObjectPattern,\n Program,\n PropertyKey,\n VariableDeclarator,\n} from 'oxc-parser';\n\nimport { parseOxcCached } from './parseOxc';\n\ntype ImportKind = 'cjs' | 'dynamic' | 'esm';\n\nexport type OxcLocal = {\n code: string;\n end: number;\n name?: string;\n start: number;\n};\n\nexport type OxcCollectedImport = {\n imported: string | 'default' | '*' | 'side-effect';\n local: OxcLocal;\n source: string;\n type: ImportKind;\n};\n\nexport type OxcCollectedExport = {\n exported: string | 'default' | '*';\n local: OxcLocal;\n};\n\nexport type OxcCollectedReexport = {\n exported: string | 'default' | '*';\n imported: string | 'default' | '*';\n local: OxcLocal;\n source: string;\n};\n\nexport type OxcCollectedState = {\n deadExports: string[];\n exports: Record<string | 'default' | '*', OxcLocal>;\n imports: OxcCollectedImport[];\n isEsModule: boolean;\n reexports: OxcCollectedReexport[];\n};\n\ntype VisitMode = 'all' | 'importsOnly';\n\ntype NamespaceBinding = {\n kind: 'namespace';\n local: OxcLocal;\n name: string;\n source: string;\n type: ImportKind;\n used: boolean;\n};\n\ntype LocalBinding = {\n kind: 'local';\n name: string;\n};\n\ntype Binding = LocalBinding | NamespaceBinding;\n\ntype Scope = {\n bindings: Map<string, Binding>;\n parent: Scope | null;\n};\n\ntype ChildContext = {\n key: string;\n parent: Node | null;\n};\n\ntype VisitContext = ChildContext & {\n scope: Scope;\n};\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype OxcIdentifier = Node & { name: string; type: 'Identifier' };\n\ntype Destructed = {\n as: Node;\n what: string | '*';\n};\n\ntype AnalyzerState = {\n code: string;\n namespaces: NamespaceBinding[];\n requireSources: Map<string, string>;\n result: OxcCollectedState;\n};\n\nconst createScope = (parent: Scope | null): Scope => ({\n bindings: new Map(),\n parent,\n});\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 localFromNode = (node: Node, code: string, name?: string): OxcLocal => ({\n code: code.slice(node.start, node.end),\n end: node.end,\n name: name ?? (node.type === 'Identifier' ? node.name : undefined),\n start: node.start,\n});\n\nconst nameFromModuleExport = (node: ModuleExportName): string =>\n node.type === 'Literal' ? node.value : node.name;\n\nconst nameFromPropertyKey = (key: PropertyKey): string | null => {\n if (key.type === 'Identifier') {\n return key.name;\n }\n\n if (key.type === 'Literal' && typeof key.value === 'string') {\n return key.value;\n }\n\n return null;\n};\n\nconst nameFromMemberProperty = (node: MemberExpression): string | null => {\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst defineBinding = (scope: Scope, binding: Binding): void => {\n scope.bindings.set(binding.name, binding);\n};\n\nconst lookupBinding = (scope: Scope, name: string): Binding | null => {\n let current: Scope | null = scope;\n while (current) {\n const binding = current.bindings.get(name);\n if (binding) {\n return binding;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst collectBindingNames = (pattern: BindingPattern): string[] => {\n if (pattern.type === 'Identifier') {\n return [pattern.name];\n }\n\n if (pattern.type === 'AssignmentPattern') {\n return collectBindingNames(pattern.left);\n }\n\n if (pattern.type === 'ObjectPattern') {\n return pattern.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (pattern.type === 'ArrayPattern') {\n return pattern.elements.flatMap((element) =>\n element ? collectBindingLikeNames(element) : []\n );\n }\n\n return [];\n};\n\nconst collectBindingLikeNames = (node: Node): string[] => {\n if (node.type === 'RestElement') {\n return collectBindingLikeNames(node.argument);\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingLikeNames(node.parameter);\n }\n\n return collectBindingNames(node as BindingPattern);\n};\n\nconst declareLocalPattern = (scope: Scope, pattern: BindingPattern): void => {\n collectBindingNames(pattern).forEach((name) =>\n defineBinding(scope, { kind: 'local', name })\n );\n};\n\nconst declareLocalBindingLike = (scope: Scope, node: Node): void => {\n collectBindingLikeNames(node).forEach((name) =>\n defineBinding(scope, { kind: 'local', name })\n );\n};\n\nconst isTypeOnlyImport = (\n declaration: ImportDeclaration,\n specifier?: ImportSpecifier\n): boolean =>\n declaration.importKind === 'type' || specifier?.importKind === 'type';\n\nconst isTypeOnlyExport = (\n declaration:\n | ExportAllDeclaration\n | ExportDefaultDeclaration\n | ExportNamedDeclaration\n | ExportSpecifier\n): boolean => 'exportKind' in declaration && declaration.exportKind === 'type';\n\nconst addImport = (\n state: AnalyzerState,\n item: Omit<OxcCollectedImport, 'local'> & { local: Node; name?: string }\n): void => {\n state.result.imports.push({\n imported: item.imported,\n local: localFromNode(item.local, state.code, item.name),\n source: item.source,\n type: item.type,\n });\n};\n\nconst addExport = (\n state: AnalyzerState,\n exported: string | 'default' | '*',\n local: Node,\n name?: string\n): void => {\n const { result } = state;\n result.exports[exported] = localFromNode(local, state.code, name);\n};\n\nconst addReexport = (\n state: AnalyzerState,\n item: Omit<OxcCollectedReexport, 'local'> & { local: Node }\n): void => {\n state.result.reexports.push({\n exported: item.exported,\n imported: item.imported,\n local: localFromNode(item.local, state.code),\n source: item.source,\n });\n};\n\nconst collectDestructed = (pattern: ObjectPattern): Destructed[] =>\n pattern.properties.flatMap((property) => {\n if (property.type === 'RestElement') {\n return collectBindingNames(property.argument).map(() => ({\n as: property.argument,\n what: '*' as const,\n }));\n }\n\n const firstKey = nameFromPropertyKey(property.key);\n if (!firstKey) {\n return [];\n }\n\n if (property.value.type === 'ObjectPattern') {\n return collectBindingNames(property.value).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n }\n\n if (property.value.type === 'ArrayPattern') {\n return collectBindingNames(property.value).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n }\n\n if (property.value.type === 'AssignmentPattern') {\n return collectBindingNames(property.value.left).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n }\n\n return collectBindingNames(property.value).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n });\n\nconst getStringConstant = (expression: Expression): string | null => {\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return expression.value;\n }\n\n if (\n expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0\n ) {\n return expression.quasis[0]?.value.cooked ?? null;\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n const left = getStringConstant(expression.left);\n const right = getStringConstant(expression.right);\n return left === null || right === null ? null : left + right;\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression' &&\n nameFromMemberProperty(expression.callee) === 'concat'\n ) {\n const base = getStringConstant(expression.callee.object);\n if (base === null) {\n return null;\n }\n\n const parts = expression.arguments.map((arg) =>\n arg.type === 'SpreadElement' ? null : getStringConstant(arg)\n );\n if (parts.some((part) => part === null)) {\n return null;\n }\n\n return [base, ...(parts as string[])].join('');\n }\n\n if (\n expression.type === 'TSAsExpression' ||\n expression.type === 'TSSatisfiesExpression' ||\n expression.type === 'TSNonNullExpression' ||\n expression.type === 'TSTypeAssertion' ||\n expression.type === 'ParenthesizedExpression'\n ) {\n return getStringConstant(expression.expression);\n }\n\n return null;\n};\n\nconst isRequireCall = (node: Node, scope: Scope): boolean =>\n node.type === 'CallExpression' &&\n node.callee.type === 'Identifier' &&\n node.callee.name === 'require' &&\n lookupBinding(scope, 'require') === null;\n\nconst sourceFromRequireLike = (\n node: Node,\n scope: Scope,\n state: AnalyzerState\n): string | null => {\n if (isRequireCall(node, scope)) {\n const call = node as CallExpression;\n const [sourceArg] = call.arguments;\n if (!sourceArg || sourceArg.type === 'SpreadElement') {\n return null;\n }\n\n return getStringConstant(sourceArg);\n }\n\n if (node.type === 'Identifier') {\n return state.requireSources.get(node.name) ?? null;\n }\n\n if (node.type === 'CallExpression') {\n for (const arg of node.arguments) {\n if (arg.type === 'SpreadElement') {\n continue;\n }\n\n const source = sourceFromRequireLike(arg, scope, state);\n if (source) {\n return source;\n }\n }\n }\n\n return null;\n};\n\nconst sourceFromDirectRequireBinding = (\n node: Node,\n scope: Scope,\n state: AnalyzerState\n): string | null => {\n if (isRequireCall(node, scope)) {\n const call = node as CallExpression;\n const [sourceArg] = call.arguments;\n if (!sourceArg || sourceArg.type === 'SpreadElement') {\n return null;\n }\n\n return getStringConstant(sourceArg);\n }\n\n if (node.type === 'Identifier') {\n return state.requireSources.get(node.name) ?? null;\n }\n\n return null;\n};\n\nconst sourceFromRequireSyntax = (node: Node): string | null => {\n if (\n node.type === 'CallExpression' &&\n node.callee.type === 'Identifier' &&\n node.callee.name === 'require'\n ) {\n const [sourceArg] = node.arguments;\n return sourceArg && sourceArg.type !== 'SpreadElement'\n ? getStringConstant(sourceArg)\n : null;\n }\n\n if (node.type === 'CallExpression') {\n for (const arg of node.arguments) {\n if (arg.type === 'SpreadElement') {\n continue;\n }\n\n const source = sourceFromRequireSyntax(arg);\n if (source) {\n return source;\n }\n }\n }\n\n return null;\n};\n\nconst sourceFromImportedMember = (\n node: Node,\n scope: Scope,\n state: AnalyzerState\n): { imported: string | '*' | 'default'; source: string } | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n const source = sourceFromRequireLike(node.object, scope, state);\n const imported = nameFromMemberProperty(node);\n if (!source || !imported) {\n return null;\n }\n\n return { imported, source };\n};\n\nconst isExportsObject = (node: Node): boolean =>\n node.type === 'Identifier' && node.name === 'exports';\n\nconst getExportAssignmentName = (node: Node): string | 'default' | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n if (isExportsObject(node.object)) {\n return nameFromMemberProperty(node);\n }\n\n if (\n node.object.type === 'Identifier' &&\n node.object.name === 'module' &&\n nameFromMemberProperty(node) === 'exports'\n ) {\n return 'default';\n }\n\n return null;\n};\n\nconst getCalleeName = (node: Expression): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'MemberExpression') {\n return nameFromMemberProperty(node);\n }\n\n return null;\n};\n\nconst getObjectProperty = (\n objectExpression: ObjectExpression,\n name: string\n): Node | null => {\n for (const property of objectExpression.properties) {\n if (property.type === 'SpreadElement') {\n continue;\n }\n\n if (nameFromPropertyKey(property.key) === name) {\n return property.value;\n }\n }\n\n return null;\n};\n\nconst getReturnedExpression = (node: Node): Expression | null => {\n if (node.type === 'ArrowFunctionExpression') {\n return node.body.type === 'BlockStatement'\n ? getReturnedExpression(node.body)\n : node.body;\n }\n\n if (\n node.type === 'FunctionExpression' ||\n node.type === 'FunctionDeclaration'\n ) {\n return node.body ? getReturnedExpression(node.body) : null;\n }\n\n if (node.type === 'BlockStatement') {\n const returned = node.body.find(\n (statement) => statement.type === 'ReturnStatement'\n );\n return returned?.type === 'ReturnStatement' ? returned.argument : null;\n }\n\n return null;\n};\n\nconst collectFromImportDeclaration = (\n node: ImportDeclaration,\n scope: Scope,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyImport(node)) {\n return;\n }\n\n const source = node.source.value;\n if (node.specifiers.length === 0) {\n addImport(state, {\n imported: 'side-effect',\n local: node,\n source,\n type: 'esm',\n });\n return;\n }\n\n node.specifiers.forEach((specifier) => {\n if (\n specifier.type === 'ImportSpecifier' &&\n isTypeOnlyImport(node, specifier)\n ) {\n return;\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n const binding: NamespaceBinding = {\n kind: 'namespace',\n local: localFromNode(specifier.local, state.code, specifier.local.name),\n name: specifier.local.name,\n source,\n type: 'esm',\n used: false,\n };\n defineBinding(scope, binding);\n state.namespaces.push(binding);\n return;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n defineBinding(scope, { kind: 'local', name: specifier.local.name });\n addImport(state, {\n imported: 'default',\n local: specifier.local,\n name: specifier.local.name,\n source,\n type: 'esm',\n });\n return;\n }\n\n defineBinding(scope, { kind: 'local', name: specifier.local.name });\n addImport(state, {\n imported: nameFromModuleExport(specifier.imported),\n local: specifier.local,\n name: specifier.local.name,\n source,\n type: 'esm',\n });\n });\n};\n\nconst collectExportedDeclaration = (\n declaration: ExportNamedDeclaration['declaration'],\n state: AnalyzerState\n): void => {\n if (!declaration) {\n return;\n }\n\n if (declaration.type === 'VariableDeclaration') {\n declaration.declarations.forEach((declarator) => {\n exportFromVariableDeclarator(declarator, state);\n });\n return;\n }\n\n if (declaration.type === 'TSEnumDeclaration') {\n addExport(state, declaration.id.name, declaration.id, declaration.id.name);\n return;\n }\n\n if (\n declaration.type === 'FunctionDeclaration' ||\n declaration.type === 'ClassDeclaration'\n ) {\n const { id } = declaration as OxcFunction | OxcClass;\n if (id) {\n addExport(state, id.name, id, id.name);\n }\n }\n};\n\nconst collectFromExportNamedDeclaration = (\n node: ExportNamedDeclaration,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyExport(node)) {\n return;\n }\n\n const source = node.source?.value;\n node.specifiers.forEach((specifier) => {\n if (isTypeOnlyExport(specifier)) {\n return;\n }\n\n const exported = nameFromModuleExport(specifier.exported);\n const imported = nameFromModuleExport(specifier.local);\n\n if (source) {\n addReexport(state, {\n exported,\n imported,\n local: specifier,\n source,\n });\n return;\n }\n\n addExport(state, exported, specifier.local, imported);\n });\n\n collectExportedDeclaration(node.declaration, state);\n};\n\nconst collectFromExportAllDeclaration = (\n node: ExportAllDeclaration,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyExport(node)) {\n return;\n }\n\n addReexport(state, {\n exported: node.exported ? nameFromModuleExport(node.exported) : '*',\n imported: '*',\n local: node,\n source: node.source.value,\n });\n};\n\nconst collectFromExportDefaultDeclaration = (\n node: ExportDefaultDeclaration,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyExport(node)) {\n return;\n }\n\n addExport(state, 'default', node.declaration);\n};\n\nconst exportFromVariableDeclarator = (\n node: VariableDeclarator,\n state: AnalyzerState\n): void => {\n if (node.id.type === 'Identifier') {\n addExport(state, node.id.name, node.init ?? node.id, node.id.name);\n return;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectDestructed(node.id).forEach((destructed) => {\n if (destructed.as.type === 'Identifier') {\n addExport(\n state,\n destructed.as.name,\n node.init ?? destructed.as,\n destructed.as.name\n );\n }\n });\n return;\n }\n\n if (node.id.type === 'ArrayPattern') {\n collectBindingNames(node.id).forEach((name) =>\n addExport(state, name, node.init ?? node.id, name)\n );\n }\n};\n\nconst collectFromImportExpression = (\n node: ImportExpression,\n parent: Node | null,\n state: AnalyzerState\n): void => {\n const source = getStringConstant(node.source);\n if (!source) {\n return;\n }\n\n let container = parent;\n let awaited = false;\n if (container?.type === 'AwaitExpression') {\n awaited = true;\n container = findParentContainer(container);\n }\n\n if (container?.type === 'VariableDeclarator') {\n importFromVariableDeclarator(container, awaited, source, 'dynamic', state);\n }\n};\n\nconst collectFromWywDynamicImport = (\n node: CallExpression,\n parent: Node | null,\n state: AnalyzerState\n): void => {\n if (\n node.callee.type !== 'Identifier' ||\n node.callee.name !== '__wyw_dynamic_import'\n ) {\n return;\n }\n\n const [sourceArg] = node.arguments;\n if (!sourceArg || sourceArg.type === 'SpreadElement') {\n return;\n }\n\n const source = getStringConstant(sourceArg);\n if (!source) {\n return;\n }\n\n let container = parent;\n let awaited = false;\n if (container?.type === 'AwaitExpression') {\n awaited = true;\n container = findParentContainer(container);\n }\n\n if (container?.type === 'VariableDeclarator') {\n importFromVariableDeclarator(container, awaited, source, 'dynamic', state);\n return;\n }\n\n addImport(state, {\n imported: '*',\n local: node,\n source,\n type: 'dynamic',\n });\n};\n\nconst parentContainers = new WeakMap<Node, Node | null>();\n\nconst findParentContainer = (node: Node): Node | null =>\n parentContainers.get(node) ?? null;\n\nconst importFromVariableDeclarator = (\n node: VariableDeclarator,\n isSync: boolean,\n source: string,\n type: ImportKind,\n state: AnalyzerState\n): void => {\n if (node.id.type === 'Identifier') {\n addImport(state, {\n imported: '*',\n local: node.id,\n name: node.id.name,\n source,\n type,\n });\n return;\n }\n\n if (!isSync || node.id.type !== 'ObjectPattern') {\n return;\n }\n\n collectDestructed(node.id).forEach((destructed) => {\n addImport(state, {\n imported: destructed.what,\n local: destructed.as,\n source,\n type,\n });\n });\n};\n\nconst collectFromRequireDeclarator = (\n node: VariableDeclarator,\n scope: Scope,\n state: AnalyzerState\n): boolean => {\n if (!node.init) {\n return false;\n }\n\n const memberImport = sourceFromImportedMember(node.init, scope, state);\n if (memberImport) {\n if (node.id.type === 'Identifier') {\n defineBinding(scope, { kind: 'local', name: node.id.name });\n addImport(state, {\n imported: memberImport.imported,\n local: node.id,\n name: node.id.name,\n source: memberImport.source,\n type: 'cjs',\n });\n }\n return true;\n }\n\n const source = sourceFromRequireLike(node.init, scope, state);\n if (!source) {\n return false;\n }\n\n if (node.id.type === 'Identifier') {\n state.requireSources.set(node.id.name, source);\n const binding: NamespaceBinding = {\n kind: 'namespace',\n local: localFromNode(node.id, state.code, node.id.name),\n name: node.id.name,\n source,\n type: 'cjs',\n used: false,\n };\n defineBinding(scope, binding);\n state.namespaces.push(binding);\n return true;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectDestructed(node.id).forEach((destructed) => {\n addImport(state, {\n imported: destructed.what,\n local: destructed.as,\n source,\n type: 'cjs',\n });\n });\n return true;\n }\n\n return false;\n};\n\nconst collectFromNamespaceReference = (\n node: OxcIdentifier,\n parent: Node | null,\n ctx: VisitContext,\n state: AnalyzerState\n): void => {\n const binding = lookupBinding(ctx.scope, node.name);\n if (!binding || binding.kind !== 'namespace') {\n return;\n }\n\n if (isBindingPosition(node, parent, ctx.key)) {\n return;\n }\n\n if (isTypeNode(parent)) {\n return;\n }\n\n binding.used = true;\n\n if (parent?.type === 'MemberExpression' && parent.object === node) {\n const imported = nameFromMemberProperty(parent);\n addImport(state, {\n imported: imported ?? '*',\n local: imported ? parent : node,\n source: binding.source,\n type: binding.type,\n });\n return;\n }\n\n if (parent?.type === 'VariableDeclarator' && parent.init === node) {\n if (parent.id.type === 'ObjectPattern') {\n collectDestructed(parent.id).forEach((destructed) => {\n addImport(state, {\n imported: destructed.what,\n local: destructed.as,\n source: binding.source,\n type: binding.type,\n });\n });\n return;\n }\n }\n\n addImport(state, {\n imported: '*',\n local: node,\n name: node.name,\n source: binding.source,\n type: binding.type,\n });\n};\n\nconst isBindingPosition = (\n node: Node,\n parent: Node | null,\n key: string\n): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'ImportNamespaceSpecifier' && key === 'local') {\n return true;\n }\n\n if (\n (parent.type === 'ImportSpecifier' ||\n parent.type === 'ImportDefaultSpecifier') &&\n key === 'local'\n ) {\n return true;\n }\n\n if (parent.type === 'VariableDeclarator' && key === 'id') {\n return true;\n }\n\n if (parent.type === 'FunctionDeclaration' && key === 'id') {\n return true;\n }\n\n if (parent.type === 'ClassDeclaration' && key === 'id') {\n return true;\n }\n\n if (\n parent.type === 'Property' &&\n parent.value === node &&\n parent.key !== node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isTypeNode = (node: Node | null): boolean =>\n !!node && (node.type.startsWith('TS') || node.type.startsWith('JSDoc'));\n\nconst collectFromAssignmentExpression = (\n node: AssignmentExpression,\n ctx: VisitContext,\n state: AnalyzerState\n): void => {\n if (node.operator !== '=') {\n return;\n }\n\n const exported = getExportAssignmentName(node.left);\n if (!exported || exported === '__esModule') {\n return;\n }\n\n const imported = sourceFromImportedMember(node.right, ctx.scope, state);\n if (imported) {\n addReexport(state, {\n exported,\n imported: imported.imported,\n local: node,\n source: imported.source,\n });\n return;\n }\n\n const directRequireSource = sourceFromDirectRequireBinding(\n node.right,\n ctx.scope,\n state\n );\n if (directRequireSource) {\n addReexport(state, {\n exported,\n imported: '*',\n local: node,\n source: directRequireSource,\n });\n return;\n }\n\n addExport(state, exported, node.right);\n};\n\nconst collectFromRequireExpressionStatement = (\n node: ExpressionStatement,\n scope: Scope,\n state: AnalyzerState\n): void => {\n const source = sourceFromDirectRequireBinding(node.expression, scope, state);\n if (!source) {\n return;\n }\n\n addImport(state, {\n imported: 'side-effect',\n local: node.expression,\n source,\n type: 'cjs',\n });\n};\n\nconst collectFromDefineProperty = (\n node: CallExpression,\n ctx: VisitContext,\n state: AnalyzerState\n): boolean => {\n if (\n node.callee.type !== 'MemberExpression' ||\n node.callee.object.type !== 'Identifier' ||\n node.callee.object.name !== 'Object' ||\n nameFromMemberProperty(node.callee) !== 'defineProperty'\n ) {\n return false;\n }\n\n const [target, nameArg, descriptor] = node.arguments;\n if (\n !target ||\n !nameArg ||\n !descriptor ||\n target.type === 'SpreadElement' ||\n nameArg.type === 'SpreadElement' ||\n descriptor.type === 'SpreadElement' ||\n !isExportsObject(target)\n ) {\n return false;\n }\n\n const exported = getStringConstant(nameArg);\n if (!exported || exported === '__esModule') {\n return true;\n }\n\n if (descriptor.type === 'ObjectExpression') {\n const getter = getObjectProperty(descriptor, 'get');\n const returned = getter ? getReturnedExpression(getter) : null;\n const imported = returned\n ? sourceFromImportedMember(returned, ctx.scope, state)\n : null;\n\n if (imported) {\n addReexport(state, {\n exported,\n imported: imported.imported,\n local: node,\n source: imported.source,\n });\n return true;\n }\n\n const directRequireSource = returned\n ? sourceFromDirectRequireBinding(returned, ctx.scope, state)\n : null;\n if (directRequireSource) {\n addReexport(state, {\n exported,\n imported: '*',\n local: node,\n source: directRequireSource,\n });\n return true;\n }\n\n if (returned) {\n addExport(state, exported, returned);\n return true;\n }\n }\n\n addExport(state, exported, node);\n return true;\n};\n\nconst collectFromHelperCall = (\n node: CallExpression,\n ctx: VisitContext,\n state: AnalyzerState\n): void => {\n const callee = getCalleeName(node.callee);\n if (!callee) {\n return;\n }\n\n if (collectFromDefineProperty(node, ctx, state)) {\n return;\n }\n\n if (callee === 'forEach' && node.callee.type === 'MemberExpression') {\n const { object } = node.callee;\n if (\n object.type === 'CallExpression' &&\n object.callee.type === 'MemberExpression' &&\n object.callee.object.type === 'Identifier' &&\n object.callee.object.name === 'Object' &&\n nameFromMemberProperty(object.callee) === 'keys'\n ) {\n const [keysArg] = object.arguments;\n if (keysArg && keysArg.type !== 'SpreadElement') {\n const source = sourceFromRequireLike(keysArg, ctx.scope, state);\n if (source) {\n addReexport(state, {\n exported: '*',\n imported: '*',\n local: node,\n source,\n });\n }\n }\n }\n return;\n }\n\n if (\n /(?:^|_)exportStar$/i.test(callee) ||\n callee === '_export_star' ||\n callee === '__reExport'\n ) {\n for (const arg of node.arguments) {\n if (arg.type === 'SpreadElement') {\n continue;\n }\n\n const source = sourceFromRequireLike(arg, ctx.scope, state);\n if (source) {\n addReexport(state, {\n exported: '*',\n imported: '*',\n local: node,\n source,\n });\n return;\n }\n }\n }\n\n if (callee === '__export' || callee === '_export') {\n const [firstArg, secondArg] = node.arguments;\n if (firstArg && firstArg.type !== 'SpreadElement') {\n const source = sourceFromRequireLike(firstArg, ctx.scope, state);\n if (source) {\n addReexport(state, {\n exported: '*',\n imported: '*',\n local: node,\n source,\n });\n return;\n }\n }\n\n if (secondArg?.type === 'ObjectExpression') {\n secondArg.properties.forEach((property) => {\n if (property.type === 'SpreadElement') {\n return;\n }\n\n const exported = nameFromPropertyKey(property.key);\n const returned = getReturnedExpression(property.value);\n if (!exported || !returned) {\n return;\n }\n\n const imported = sourceFromImportedMember(returned, ctx.scope, state);\n if (imported) {\n addReexport(state, {\n exported,\n imported: imported.imported,\n local: property,\n source: imported.source,\n });\n return;\n }\n\n const directRequireSource = sourceFromDirectRequireBinding(\n returned,\n ctx.scope,\n state\n );\n if (directRequireSource) {\n addReexport(state, {\n exported,\n imported: '*',\n local: property,\n source: directRequireSource,\n });\n return;\n }\n\n addExport(state, exported, returned);\n });\n }\n }\n};\n\nconst visit = (\n node: Node,\n ctx: VisitContext,\n state: AnalyzerState,\n mode: VisitMode = 'all'\n): void => {\n if (mode === 'all') {\n parentContainers.set(node, ctx.parent);\n }\n\n let { scope } = ctx;\n if (\n node.type === 'Program' ||\n node.type === 'BlockStatement' ||\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n scope = createScope(ctx.scope);\n }\n\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n node.params.forEach((param) => declareLocalBindingLike(scope, param));\n }\n\n if (node.type === 'ImportDeclaration') {\n collectFromImportDeclaration(node, scope, state);\n } else if (mode === 'all' && node.type === 'ExportNamedDeclaration') {\n collectFromExportNamedDeclaration(node, state);\n } else if (mode === 'all' && node.type === 'ExportAllDeclaration') {\n collectFromExportAllDeclaration(node, state);\n } else if (mode === 'all' && node.type === 'ExportDefaultDeclaration') {\n collectFromExportDefaultDeclaration(node, state);\n } else if (node.type === 'VariableDeclarator') {\n if (!collectFromRequireDeclarator(node, scope, state)) {\n declareLocalPattern(scope, node.id);\n }\n } else if (mode === 'all' && node.type === 'ImportExpression') {\n collectFromImportExpression(node, ctx.parent, state);\n } else if (mode === 'all' && node.type === 'CallExpression') {\n collectFromWywDynamicImport(node, ctx.parent, state);\n collectFromHelperCall(node, { ...ctx, scope }, state);\n } else if (mode === 'all' && node.type === 'ExpressionStatement') {\n collectFromRequireExpressionStatement(node, scope, state);\n } else if (mode === 'all' && node.type === 'AssignmentExpression') {\n collectFromAssignmentExpression(node, { ...ctx, scope }, state);\n } else if (node.type === 'Identifier') {\n collectFromNamespaceReference(node, ctx.parent, { ...ctx, scope }, state);\n }\n\n for (const child of getChildren(node)) {\n visit(child.node, { key: child.key, parent: node, scope }, state, mode);\n }\n};\n\nconst getChildren = (node: Node): { key: string; node: Node }[] => {\n const result: { key: string; node: 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({ key, node: value });\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (isNode(item)) {\n result.push({ key, node: item });\n }\n });\n }\n });\n\n return result;\n};\n\nconst precollectRequireSources = (node: Node, state: AnalyzerState): void => {\n if (node.type === 'VariableDeclarator' && node.id.type === 'Identifier') {\n const source = node.init ? sourceFromRequireSyntax(node.init) : null;\n if (source) {\n state.requireSources.set(node.id.name, source);\n }\n }\n\n getChildren(node).forEach((child) =>\n precollectRequireSources(child.node, state)\n );\n};\n\nconst addUnusedNamespaceSideEffects = (state: AnalyzerState): void => {\n state.namespaces.forEach((binding) => {\n if (!binding.used) {\n state.result.imports.push({\n imported: 'side-effect',\n local: binding.local,\n source: binding.source,\n type: binding.type,\n });\n }\n });\n};\n\nexport function collectOxcExportsAndImportsFromProgram(\n program: Program,\n code: string,\n isEsModule: boolean\n): OxcCollectedState {\n const rootScope = createScope(null);\n const state: AnalyzerState = {\n code,\n namespaces: [],\n requireSources: new Map(),\n result: {\n deadExports: [],\n exports: {},\n imports: [],\n isEsModule,\n reexports: [],\n },\n };\n\n precollectRequireSources(program, state);\n visit(\n program,\n { key: 'program', parent: null, scope: rootScope },\n state,\n 'all'\n );\n addUnusedNamespaceSideEffects(state);\n\n return state.result;\n}\n\nexport function collectOxcProcessorImportsFromProgram(\n program: Program,\n code: string\n): OxcCollectedImport[] {\n const rootScope = createScope(null);\n const state: AnalyzerState = {\n code,\n namespaces: [],\n requireSources: new Map(),\n result: {\n deadExports: [],\n exports: {},\n imports: [],\n isEsModule: true,\n reexports: [],\n },\n };\n\n precollectRequireSources(program, state);\n visit(\n program,\n { key: 'program', parent: null, scope: rootScope },\n state,\n 'importsOnly'\n );\n\n return state.result.imports;\n}\n\nexport function collectOxcExportsAndImports(\n code: string,\n filename: string\n): OxcCollectedState {\n const parsed = parseOxcCached(filename, code, 'unambiguous');\n\n return collectOxcExportsAndImportsFromProgram(\n parsed.program,\n code,\n parsed.module.hasModuleSyntax\n );\n}\n"],"file":"collectOxcExportsAndImports.js"}
|
|
1
|
+
{"mappings":"AA2BA,SAAS,sBAAsB;AAsF/B,MAAM,eAAe,YAAiC;CACpD,UAAU,IAAI,KAAK;CACnB;CACD;AAED,MAAM,UAAU,UACd,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,UAAU,SACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,iBAAiB,MAAY,MAAc,UAA6B;CAC5E,MAAM,KAAK,MAAM,KAAK,OAAO,KAAK,IAAI;CACtC,KAAK,KAAK;CACV,MAAM,SAAS,KAAK,SAAS,eAAe,KAAK,OAAO;CACxD,OAAO,KAAK;CACb;AAED,MAAM,wBAAwB,SAC5B,KAAK,SAAS,YAAY,KAAK,QAAQ,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ACzB,QAAQ;GACN,aAAa,EAAE;GACf,SAAS,EAAE;GACX,SAAS,EAAE;GACX;GACA,WAAW,EAAE;GACd;EACF;AAED,0BAAyB,SAAS,MAAM;AACxC,OACE,SACA;EAAE,KAAK;EAAW,QAAQ;EAAM,OAAO;EAAW,EAClD,OACA,MACD;AACD,+BAA8B,MAAM;AAEpC,QAAO,MAAM;;AAGf,OAAO,SAAS,sCACd,SACA,MACsB;CACtB,MAAM,YAAY,YAAY,KAAK;CACnC,MAAM,QAAuB;EAC3B;EACA,YAAY,EAAE;EACd,gBAAgB,IAAI,KAAK;EACzB,QAAQ;GACN,aAAa,EAAE;GACf,SAAS,EAAE;GACX,SAAS,EAAE;GACX,YAAY;GACZ,WAAW,EAAE;GACd;EACF;AAED,0BAAyB,SAAS,MAAM;AACxC,OACE,SACA;EAAE,KAAK;EAAW,QAAQ;EAAM,OAAO;EAAW,EAClD,OACA,cACD;AAED,QAAO,MAAM,OAAO;;AAGtB,OAAO,SAAS,4BACd,MACA,UACmB;CACnB,MAAM,SAAS,eAAe,UAAU,MAAM,cAAc;AAE5D,QAAO,uCACL,OAAO,SACP,MACA,OAAO,OAAO,gBACf","names":[],"sources":["../../src/utils/collectOxcExportsAndImports.ts"],"version":3,"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define,no-restricted-syntax,no-continue */\n\nimport type {\n AssignmentExpression,\n BindingPattern,\n CallExpression,\n Class as OxcClass,\n ExportAllDeclaration,\n ExportDefaultDeclaration,\n ExportNamedDeclaration,\n ExportSpecifier,\n Expression,\n ExpressionStatement,\n Function as OxcFunction,\n ImportDeclaration,\n ImportExpression,\n ImportSpecifier,\n MemberExpression,\n ModuleExportName,\n Node,\n ObjectExpression,\n ObjectPattern,\n Program,\n PropertyKey,\n VariableDeclarator,\n} from 'oxc-parser';\n\nimport { parseOxcCached } from './parseOxc';\n\ntype ImportKind = 'cjs' | 'dynamic' | 'esm';\n\nexport type OxcLocal = {\n code: string;\n end: number;\n name?: string;\n start: number;\n};\n\nexport type OxcCollectedImport = {\n imported: string | 'default' | '*' | 'side-effect';\n local: OxcLocal;\n source: string;\n type: ImportKind;\n};\n\nexport type OxcCollectedExport = {\n exported: string | 'default' | '*';\n local: OxcLocal;\n};\n\nexport type OxcCollectedReexport = {\n exported: string | 'default' | '*';\n imported: string | 'default' | '*';\n local: OxcLocal;\n source: string;\n};\n\nexport type OxcCollectedState = {\n deadExports: string[];\n exports: Record<string | 'default' | '*', OxcLocal>;\n imports: OxcCollectedImport[];\n isEsModule: boolean;\n reexports: OxcCollectedReexport[];\n};\n\ntype VisitMode = 'all' | 'importsOnly';\n\ntype NamespaceBinding = {\n kind: 'namespace';\n local: OxcLocal;\n name: string;\n source: string;\n type: ImportKind;\n used: boolean;\n};\n\ntype LocalBinding = {\n kind: 'local';\n name: string;\n};\n\ntype Binding = LocalBinding | NamespaceBinding;\n\ntype Scope = {\n bindings: Map<string, Binding>;\n parent: Scope | null;\n};\n\ntype ChildContext = {\n key: string;\n parent: Node | null;\n};\n\ntype VisitContext = ChildContext & {\n scope: Scope;\n};\n\ntype AnyNode = Node & Record<string, unknown>;\n\ntype OxcIdentifier = Node & { name: string; type: 'Identifier' };\n\ntype Destructed = {\n as: Node;\n what: string | '*';\n};\n\ntype AnalyzerState = {\n code: string;\n namespaces: NamespaceBinding[];\n requireSources: Map<string, string>;\n result: OxcCollectedState;\n};\n\nconst createScope = (parent: Scope | null): Scope => ({\n bindings: new Map(),\n parent,\n});\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 localFromNode = (node: Node, code: string, name?: string): OxcLocal => ({\n code: code.slice(node.start, node.end),\n end: node.end,\n name: name ?? (node.type === 'Identifier' ? node.name : undefined),\n start: node.start,\n});\n\nconst nameFromModuleExport = (node: ModuleExportName): string =>\n node.type === 'Literal' ? node.value : node.name;\n\nconst nameFromPropertyKey = (key: PropertyKey): string | null => {\n if (key.type === 'Identifier') {\n return key.name;\n }\n\n if (key.type === 'Literal' && typeof key.value === 'string') {\n return key.value;\n }\n\n return null;\n};\n\nconst nameFromMemberProperty = (node: MemberExpression): string | null => {\n if (node.computed) {\n return node.property.type === 'Literal' &&\n typeof node.property.value === 'string'\n ? node.property.value\n : null;\n }\n\n return node.property.type === 'Identifier' ? node.property.name : null;\n};\n\nconst defineBinding = (scope: Scope, binding: Binding): void => {\n scope.bindings.set(binding.name, binding);\n};\n\nconst lookupBinding = (scope: Scope, name: string): Binding | null => {\n let current: Scope | null = scope;\n while (current) {\n const binding = current.bindings.get(name);\n if (binding) {\n return binding;\n }\n\n current = current.parent;\n }\n\n return null;\n};\n\nconst collectBindingNames = (pattern: BindingPattern): string[] => {\n if (pattern.type === 'Identifier') {\n return [pattern.name];\n }\n\n if (pattern.type === 'AssignmentPattern') {\n return collectBindingNames(pattern.left);\n }\n\n if (pattern.type === 'ObjectPattern') {\n return pattern.properties.flatMap((property) =>\n property.type === 'RestElement'\n ? collectBindingNames(property.argument)\n : collectBindingNames(property.value)\n );\n }\n\n if (pattern.type === 'ArrayPattern') {\n return pattern.elements.flatMap((element) =>\n element ? collectBindingLikeNames(element) : []\n );\n }\n\n return [];\n};\n\nconst collectBindingLikeNames = (node: Node): string[] => {\n if (node.type === 'RestElement') {\n return collectBindingLikeNames(node.argument);\n }\n\n if (node.type === 'TSParameterProperty') {\n return collectBindingLikeNames(node.parameter);\n }\n\n return collectBindingNames(node as BindingPattern);\n};\n\nconst declareLocalPattern = (scope: Scope, pattern: BindingPattern): void => {\n collectBindingNames(pattern).forEach((name) =>\n defineBinding(scope, { kind: 'local', name })\n );\n};\n\nconst declareLocalBindingLike = (scope: Scope, node: Node): void => {\n collectBindingLikeNames(node).forEach((name) =>\n defineBinding(scope, { kind: 'local', name })\n );\n};\n\nconst isTypeOnlyImport = (\n declaration: ImportDeclaration,\n specifier?: ImportSpecifier\n): boolean =>\n declaration.importKind === 'type' || specifier?.importKind === 'type';\n\nconst isTypeOnlyExport = (\n declaration:\n | ExportAllDeclaration\n | ExportDefaultDeclaration\n | ExportNamedDeclaration\n | ExportSpecifier\n): boolean => 'exportKind' in declaration && declaration.exportKind === 'type';\n\nconst addImport = (\n state: AnalyzerState,\n item: Omit<OxcCollectedImport, 'local'> & { local: Node; name?: string }\n): void => {\n state.result.imports.push({\n imported: item.imported,\n local: localFromNode(item.local, state.code, item.name),\n source: item.source,\n type: item.type,\n });\n};\n\nconst addExport = (\n state: AnalyzerState,\n exported: string | 'default' | '*',\n local: Node,\n name?: string\n): void => {\n const { result } = state;\n result.exports[exported] = localFromNode(local, state.code, name);\n};\n\nconst addReexport = (\n state: AnalyzerState,\n item: Omit<OxcCollectedReexport, 'local'> & { local: Node }\n): void => {\n state.result.reexports.push({\n exported: item.exported,\n imported: item.imported,\n local: localFromNode(item.local, state.code),\n source: item.source,\n });\n};\n\nconst collectDestructed = (pattern: ObjectPattern): Destructed[] =>\n pattern.properties.flatMap((property) => {\n if (property.type === 'RestElement') {\n return collectBindingNames(property.argument).map(() => ({\n as: property.argument,\n what: '*' as const,\n }));\n }\n\n const firstKey = nameFromPropertyKey(property.key);\n if (!firstKey) {\n return [];\n }\n\n if (property.value.type === 'ObjectPattern') {\n return collectBindingNames(property.value).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n }\n\n if (property.value.type === 'ArrayPattern') {\n return collectBindingNames(property.value).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n }\n\n if (property.value.type === 'AssignmentPattern') {\n return collectBindingNames(property.value.left).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n }\n\n return collectBindingNames(property.value).map(() => ({\n as: property.value,\n what: firstKey,\n }));\n });\n\nconst getStringConstant = (expression: Expression): string | null => {\n if (expression.type === 'Literal' && typeof expression.value === 'string') {\n return expression.value;\n }\n\n if (\n expression.type === 'TemplateLiteral' &&\n expression.expressions.length === 0\n ) {\n return expression.quasis[0]?.value.cooked ?? null;\n }\n\n if (expression.type === 'BinaryExpression' && expression.operator === '+') {\n const left = getStringConstant(expression.left);\n const right = getStringConstant(expression.right);\n return left === null || right === null ? null : left + right;\n }\n\n if (\n expression.type === 'CallExpression' &&\n expression.callee.type === 'MemberExpression' &&\n nameFromMemberProperty(expression.callee) === 'concat'\n ) {\n const base = getStringConstant(expression.callee.object);\n if (base === null) {\n return null;\n }\n\n const parts = expression.arguments.map((arg) =>\n arg.type === 'SpreadElement' ? null : getStringConstant(arg)\n );\n if (parts.some((part) => part === null)) {\n return null;\n }\n\n return [base, ...(parts as string[])].join('');\n }\n\n if (\n expression.type === 'TSAsExpression' ||\n expression.type === 'TSSatisfiesExpression' ||\n expression.type === 'TSNonNullExpression' ||\n expression.type === 'TSTypeAssertion' ||\n expression.type === 'ParenthesizedExpression'\n ) {\n return getStringConstant(expression.expression);\n }\n\n return null;\n};\n\nconst isRequireCall = (node: Node, scope: Scope): boolean =>\n node.type === 'CallExpression' &&\n node.callee.type === 'Identifier' &&\n node.callee.name === 'require' &&\n lookupBinding(scope, 'require') === null;\n\nconst sourceFromRequireLike = (\n node: Node,\n scope: Scope,\n state: AnalyzerState\n): string | null => {\n if (isRequireCall(node, scope)) {\n const call = node as CallExpression;\n const [sourceArg] = call.arguments;\n if (!sourceArg || sourceArg.type === 'SpreadElement') {\n return null;\n }\n\n return getStringConstant(sourceArg);\n }\n\n if (node.type === 'Identifier') {\n return state.requireSources.get(node.name) ?? null;\n }\n\n if (node.type === 'CallExpression') {\n for (const arg of node.arguments) {\n if (arg.type === 'SpreadElement') {\n continue;\n }\n\n const source = sourceFromRequireLike(arg, scope, state);\n if (source) {\n return source;\n }\n }\n }\n\n return null;\n};\n\nconst sourceFromDirectRequireBinding = (\n node: Node,\n scope: Scope,\n state: AnalyzerState\n): string | null => {\n if (isRequireCall(node, scope)) {\n const call = node as CallExpression;\n const [sourceArg] = call.arguments;\n if (!sourceArg || sourceArg.type === 'SpreadElement') {\n return null;\n }\n\n return getStringConstant(sourceArg);\n }\n\n if (node.type === 'Identifier') {\n return state.requireSources.get(node.name) ?? null;\n }\n\n return null;\n};\n\nconst sourceFromRequireSyntax = (node: Node): string | null => {\n if (\n node.type === 'CallExpression' &&\n node.callee.type === 'Identifier' &&\n node.callee.name === 'require'\n ) {\n const [sourceArg] = node.arguments;\n return sourceArg && sourceArg.type !== 'SpreadElement'\n ? getStringConstant(sourceArg)\n : null;\n }\n\n if (node.type === 'CallExpression') {\n for (const arg of node.arguments) {\n if (arg.type === 'SpreadElement') {\n continue;\n }\n\n const source = sourceFromRequireSyntax(arg);\n if (source) {\n return source;\n }\n }\n }\n\n return null;\n};\n\nconst sourceFromImportedMember = (\n node: Node,\n scope: Scope,\n state: AnalyzerState\n): { imported: string | '*' | 'default'; source: string } | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n const source = sourceFromRequireLike(node.object, scope, state);\n const imported = nameFromMemberProperty(node);\n if (!source || !imported) {\n return null;\n }\n\n return { imported, source };\n};\n\nconst isExportsObject = (node: Node): boolean =>\n node.type === 'Identifier' && node.name === 'exports';\n\nconst getExportAssignmentName = (node: Node): string | 'default' | null => {\n if (node.type !== 'MemberExpression') {\n return null;\n }\n\n if (isExportsObject(node.object)) {\n return nameFromMemberProperty(node);\n }\n\n if (\n node.object.type === 'Identifier' &&\n node.object.name === 'module' &&\n nameFromMemberProperty(node) === 'exports'\n ) {\n return 'default';\n }\n\n return null;\n};\n\nconst getCalleeName = (node: Expression): string | null => {\n if (node.type === 'Identifier') {\n return node.name;\n }\n\n if (node.type === 'MemberExpression') {\n return nameFromMemberProperty(node);\n }\n\n return null;\n};\n\nconst getObjectProperty = (\n objectExpression: ObjectExpression,\n name: string\n): Node | null => {\n for (const property of objectExpression.properties) {\n if (property.type === 'SpreadElement') {\n continue;\n }\n\n if (nameFromPropertyKey(property.key) === name) {\n return property.value;\n }\n }\n\n return null;\n};\n\nconst getReturnedExpression = (node: Node): Expression | null => {\n if (node.type === 'ArrowFunctionExpression') {\n return node.body.type === 'BlockStatement'\n ? getReturnedExpression(node.body)\n : node.body;\n }\n\n if (\n node.type === 'FunctionExpression' ||\n node.type === 'FunctionDeclaration'\n ) {\n return node.body ? getReturnedExpression(node.body) : null;\n }\n\n if (node.type === 'BlockStatement') {\n const returned = node.body.find(\n (statement) => statement.type === 'ReturnStatement'\n );\n return returned?.type === 'ReturnStatement' ? returned.argument : null;\n }\n\n return null;\n};\n\nconst collectFromImportDeclaration = (\n node: ImportDeclaration,\n scope: Scope,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyImport(node)) {\n return;\n }\n\n const source = node.source.value;\n if (node.specifiers.length === 0) {\n addImport(state, {\n imported: 'side-effect',\n local: node,\n source,\n type: 'esm',\n });\n return;\n }\n\n node.specifiers.forEach((specifier) => {\n if (\n specifier.type === 'ImportSpecifier' &&\n isTypeOnlyImport(node, specifier)\n ) {\n return;\n }\n\n if (specifier.type === 'ImportNamespaceSpecifier') {\n const binding: NamespaceBinding = {\n kind: 'namespace',\n local: localFromNode(specifier.local, state.code, specifier.local.name),\n name: specifier.local.name,\n source,\n type: 'esm',\n used: false,\n };\n defineBinding(scope, binding);\n state.namespaces.push(binding);\n return;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier') {\n defineBinding(scope, { kind: 'local', name: specifier.local.name });\n addImport(state, {\n imported: 'default',\n local: specifier.local,\n name: specifier.local.name,\n source,\n type: 'esm',\n });\n return;\n }\n\n defineBinding(scope, { kind: 'local', name: specifier.local.name });\n addImport(state, {\n imported: nameFromModuleExport(specifier.imported),\n local: specifier.local,\n name: specifier.local.name,\n source,\n type: 'esm',\n });\n });\n};\n\nconst collectExportedDeclaration = (\n declaration: ExportNamedDeclaration['declaration'],\n state: AnalyzerState\n): void => {\n if (!declaration) {\n return;\n }\n\n if (declaration.type === 'VariableDeclaration') {\n declaration.declarations.forEach((declarator) => {\n exportFromVariableDeclarator(declarator, state);\n });\n return;\n }\n\n if (declaration.type === 'TSEnumDeclaration') {\n addExport(state, declaration.id.name, declaration.id, declaration.id.name);\n return;\n }\n\n if (\n declaration.type === 'FunctionDeclaration' ||\n declaration.type === 'ClassDeclaration'\n ) {\n const { id } = declaration as OxcFunction | OxcClass;\n if (id) {\n addExport(state, id.name, id, id.name);\n }\n }\n};\n\nconst collectFromExportNamedDeclaration = (\n node: ExportNamedDeclaration,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyExport(node)) {\n return;\n }\n\n const source = node.source?.value;\n node.specifiers.forEach((specifier) => {\n if (isTypeOnlyExport(specifier)) {\n return;\n }\n\n const exported = nameFromModuleExport(specifier.exported);\n const imported = nameFromModuleExport(specifier.local);\n\n if (source) {\n addReexport(state, {\n exported,\n imported,\n local: specifier,\n source,\n });\n return;\n }\n\n addExport(state, exported, specifier.local, imported);\n });\n\n collectExportedDeclaration(node.declaration, state);\n};\n\nconst collectFromExportAllDeclaration = (\n node: ExportAllDeclaration,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyExport(node)) {\n return;\n }\n\n addReexport(state, {\n exported: node.exported ? nameFromModuleExport(node.exported) : '*',\n imported: '*',\n local: node,\n source: node.source.value,\n });\n};\n\nconst collectFromExportDefaultDeclaration = (\n node: ExportDefaultDeclaration,\n state: AnalyzerState\n): void => {\n if (isTypeOnlyExport(node)) {\n return;\n }\n\n addExport(state, 'default', node.declaration);\n};\n\nconst exportFromVariableDeclarator = (\n node: VariableDeclarator,\n state: AnalyzerState\n): void => {\n if (node.id.type === 'Identifier') {\n addExport(state, node.id.name, node.init ?? node.id, node.id.name);\n return;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectDestructed(node.id).forEach((destructed) => {\n if (destructed.as.type === 'Identifier') {\n addExport(\n state,\n destructed.as.name,\n node.init ?? destructed.as,\n destructed.as.name\n );\n }\n });\n return;\n }\n\n if (node.id.type === 'ArrayPattern') {\n collectBindingNames(node.id).forEach((name) =>\n addExport(state, name, node.init ?? node.id, name)\n );\n }\n};\n\nconst collectFromImportExpression = (\n node: ImportExpression,\n parent: Node | null,\n state: AnalyzerState\n): void => {\n const source = getStringConstant(node.source);\n if (!source) {\n return;\n }\n\n let container = parent;\n let awaited = false;\n if (container?.type === 'AwaitExpression') {\n awaited = true;\n container = findParentContainer(container);\n }\n\n if (container?.type === 'VariableDeclarator') {\n importFromVariableDeclarator(container, awaited, source, 'dynamic', state);\n }\n};\n\nconst collectFromWywDynamicImport = (\n node: CallExpression,\n parent: Node | null,\n state: AnalyzerState\n): void => {\n if (\n node.callee.type !== 'Identifier' ||\n node.callee.name !== '__wyw_dynamic_import'\n ) {\n return;\n }\n\n const [sourceArg] = node.arguments;\n if (!sourceArg || sourceArg.type === 'SpreadElement') {\n return;\n }\n\n const source = getStringConstant(sourceArg);\n if (!source) {\n return;\n }\n\n let container = parent;\n let awaited = false;\n if (container?.type === 'AwaitExpression') {\n awaited = true;\n container = findParentContainer(container);\n }\n\n if (container?.type === 'VariableDeclarator') {\n importFromVariableDeclarator(container, awaited, source, 'dynamic', state);\n return;\n }\n\n addImport(state, {\n imported: '*',\n local: node,\n source,\n type: 'dynamic',\n });\n};\n\nconst parentContainers = new WeakMap<Node, Node | null>();\n\nconst findParentContainer = (node: Node): Node | null =>\n parentContainers.get(node) ?? null;\n\nconst importFromVariableDeclarator = (\n node: VariableDeclarator,\n isSync: boolean,\n source: string,\n type: ImportKind,\n state: AnalyzerState\n): void => {\n if (node.id.type === 'Identifier') {\n addImport(state, {\n imported: '*',\n local: node.id,\n name: node.id.name,\n source,\n type,\n });\n return;\n }\n\n if (!isSync || node.id.type !== 'ObjectPattern') {\n return;\n }\n\n collectDestructed(node.id).forEach((destructed) => {\n addImport(state, {\n imported: destructed.what,\n local: destructed.as,\n source,\n type,\n });\n });\n};\n\nconst collectFromRequireDeclarator = (\n node: VariableDeclarator,\n scope: Scope,\n state: AnalyzerState\n): boolean => {\n if (!node.init) {\n return false;\n }\n\n const memberImport = sourceFromImportedMember(node.init, scope, state);\n if (memberImport) {\n if (node.id.type === 'Identifier') {\n defineBinding(scope, { kind: 'local', name: node.id.name });\n addImport(state, {\n imported: memberImport.imported,\n local: node.id,\n name: node.id.name,\n source: memberImport.source,\n type: 'cjs',\n });\n }\n return true;\n }\n\n const source = sourceFromRequireLike(node.init, scope, state);\n if (!source) {\n return false;\n }\n\n if (node.id.type === 'Identifier') {\n state.requireSources.set(node.id.name, source);\n const binding: NamespaceBinding = {\n kind: 'namespace',\n local: localFromNode(node.id, state.code, node.id.name),\n name: node.id.name,\n source,\n type: 'cjs',\n used: false,\n };\n defineBinding(scope, binding);\n state.namespaces.push(binding);\n return true;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectDestructed(node.id).forEach((destructed) => {\n addImport(state, {\n imported: destructed.what,\n local: destructed.as,\n source,\n type: 'cjs',\n });\n });\n return true;\n }\n\n return false;\n};\n\nconst collectFromNamespaceReference = (\n node: OxcIdentifier,\n parent: Node | null,\n ctx: VisitContext,\n state: AnalyzerState\n): void => {\n const binding = lookupBinding(ctx.scope, node.name);\n if (!binding || binding.kind !== 'namespace') {\n return;\n }\n\n if (isBindingPosition(node, parent, ctx.key)) {\n return;\n }\n\n if (isTypeNode(parent)) {\n return;\n }\n\n binding.used = true;\n\n if (parent?.type === 'MemberExpression' && parent.object === node) {\n const imported = nameFromMemberProperty(parent);\n addImport(state, {\n imported: imported ?? '*',\n local: imported ? parent : node,\n source: binding.source,\n type: binding.type,\n });\n return;\n }\n\n if (parent?.type === 'VariableDeclarator' && parent.init === node) {\n if (parent.id.type === 'ObjectPattern') {\n collectDestructed(parent.id).forEach((destructed) => {\n addImport(state, {\n imported: destructed.what,\n local: destructed.as,\n source: binding.source,\n type: binding.type,\n });\n });\n return;\n }\n }\n\n addImport(state, {\n imported: '*',\n local: node,\n name: node.name,\n source: binding.source,\n type: binding.type,\n });\n};\n\nconst isBindingPosition = (\n node: Node,\n parent: Node | null,\n key: string\n): boolean => {\n if (!parent) {\n return false;\n }\n\n if (parent.type === 'ImportNamespaceSpecifier' && key === 'local') {\n return true;\n }\n\n if (\n (parent.type === 'ImportSpecifier' ||\n parent.type === 'ImportDefaultSpecifier') &&\n key === 'local'\n ) {\n return true;\n }\n\n if (parent.type === 'VariableDeclarator' && key === 'id') {\n return true;\n }\n\n if (parent.type === 'FunctionDeclaration' && key === 'id') {\n return true;\n }\n\n if (parent.type === 'ClassDeclaration' && key === 'id') {\n return true;\n }\n\n if (\n parent.type === 'Property' &&\n parent.value === node &&\n parent.key !== node\n ) {\n return true;\n }\n\n return false;\n};\n\nconst isTypeNode = (node: Node | null): boolean =>\n !!node && (node.type.startsWith('TS') || node.type.startsWith('JSDoc'));\n\nconst collectFromAssignmentExpression = (\n node: AssignmentExpression,\n ctx: VisitContext,\n state: AnalyzerState\n): void => {\n if (node.operator !== '=') {\n return;\n }\n\n const exported = getExportAssignmentName(node.left);\n if (!exported || exported === '__esModule') {\n return;\n }\n\n const imported = sourceFromImportedMember(node.right, ctx.scope, state);\n if (imported) {\n addReexport(state, {\n exported,\n imported: imported.imported,\n local: node,\n source: imported.source,\n });\n return;\n }\n\n const directRequireSource = sourceFromDirectRequireBinding(\n node.right,\n ctx.scope,\n state\n );\n if (directRequireSource) {\n addReexport(state, {\n exported,\n imported: '*',\n local: node,\n source: directRequireSource,\n });\n return;\n }\n\n addExport(state, exported, node.right);\n};\n\nconst collectFromRequireExpressionStatement = (\n node: ExpressionStatement,\n scope: Scope,\n state: AnalyzerState\n): void => {\n const source = sourceFromDirectRequireBinding(node.expression, scope, state);\n if (!source) {\n return;\n }\n\n addImport(state, {\n imported: 'side-effect',\n local: node.expression,\n source,\n type: 'cjs',\n });\n};\n\nconst collectFromDefineProperty = (\n node: CallExpression,\n ctx: VisitContext,\n state: AnalyzerState\n): boolean => {\n if (\n node.callee.type !== 'MemberExpression' ||\n node.callee.object.type !== 'Identifier' ||\n node.callee.object.name !== 'Object' ||\n nameFromMemberProperty(node.callee) !== 'defineProperty'\n ) {\n return false;\n }\n\n const [target, nameArg, descriptor] = node.arguments;\n if (\n !target ||\n !nameArg ||\n !descriptor ||\n target.type === 'SpreadElement' ||\n nameArg.type === 'SpreadElement' ||\n descriptor.type === 'SpreadElement' ||\n !isExportsObject(target)\n ) {\n return false;\n }\n\n const exported = getStringConstant(nameArg);\n if (!exported || exported === '__esModule') {\n return true;\n }\n\n if (descriptor.type === 'ObjectExpression') {\n const getter = getObjectProperty(descriptor, 'get');\n const returned = getter ? getReturnedExpression(getter) : null;\n const imported = returned\n ? sourceFromImportedMember(returned, ctx.scope, state)\n : null;\n\n if (imported) {\n addReexport(state, {\n exported,\n imported: imported.imported,\n local: node,\n source: imported.source,\n });\n return true;\n }\n\n const directRequireSource = returned\n ? sourceFromDirectRequireBinding(returned, ctx.scope, state)\n : null;\n if (directRequireSource) {\n addReexport(state, {\n exported,\n imported: '*',\n local: node,\n source: directRequireSource,\n });\n return true;\n }\n\n if (returned) {\n addExport(state, exported, returned);\n return true;\n }\n }\n\n addExport(state, exported, node);\n return true;\n};\n\nconst collectFromHelperCall = (\n node: CallExpression,\n ctx: VisitContext,\n state: AnalyzerState\n): void => {\n const callee = getCalleeName(node.callee);\n if (!callee) {\n return;\n }\n\n if (collectFromDefineProperty(node, ctx, state)) {\n return;\n }\n\n if (callee === 'forEach' && node.callee.type === 'MemberExpression') {\n const { object } = node.callee;\n if (\n object.type === 'CallExpression' &&\n object.callee.type === 'MemberExpression' &&\n object.callee.object.type === 'Identifier' &&\n object.callee.object.name === 'Object' &&\n nameFromMemberProperty(object.callee) === 'keys'\n ) {\n const [keysArg] = object.arguments;\n if (keysArg && keysArg.type !== 'SpreadElement') {\n const source = sourceFromRequireLike(keysArg, ctx.scope, state);\n if (source) {\n addReexport(state, {\n exported: '*',\n imported: '*',\n local: node,\n source,\n });\n }\n }\n }\n return;\n }\n\n if (\n /(?:^|_)exportStar$/i.test(callee) ||\n callee === '_export_star' ||\n callee === '__reExport'\n ) {\n for (const arg of node.arguments) {\n if (arg.type === 'SpreadElement') {\n continue;\n }\n\n const source = sourceFromRequireLike(arg, ctx.scope, state);\n if (source) {\n addReexport(state, {\n exported: '*',\n imported: '*',\n local: node,\n source,\n });\n return;\n }\n }\n }\n\n if (callee === '__export' || callee === '_export') {\n const [firstArg, secondArg] = node.arguments;\n if (firstArg && firstArg.type !== 'SpreadElement') {\n const source = sourceFromRequireLike(firstArg, ctx.scope, state);\n if (source) {\n addReexport(state, {\n exported: '*',\n imported: '*',\n local: node,\n source,\n });\n return;\n }\n }\n\n if (secondArg?.type === 'ObjectExpression') {\n secondArg.properties.forEach((property) => {\n if (property.type === 'SpreadElement') {\n return;\n }\n\n const exported = nameFromPropertyKey(property.key);\n const returned = getReturnedExpression(property.value);\n if (!exported || !returned) {\n return;\n }\n\n const imported = sourceFromImportedMember(returned, ctx.scope, state);\n if (imported) {\n addReexport(state, {\n exported,\n imported: imported.imported,\n local: property,\n source: imported.source,\n });\n return;\n }\n\n const directRequireSource = sourceFromDirectRequireBinding(\n returned,\n ctx.scope,\n state\n );\n if (directRequireSource) {\n addReexport(state, {\n exported,\n imported: '*',\n local: property,\n source: directRequireSource,\n });\n return;\n }\n\n addExport(state, exported, returned);\n });\n }\n }\n};\n\nconst visit = (\n node: Node,\n ctx: VisitContext,\n state: AnalyzerState,\n mode: VisitMode = 'all'\n): void => {\n if (mode === 'all') {\n parentContainers.set(node, ctx.parent);\n }\n\n let { scope } = ctx;\n if (\n node.type === 'Program' ||\n node.type === 'BlockStatement' ||\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n scope = createScope(ctx.scope);\n }\n\n if (\n node.type === 'FunctionDeclaration' ||\n node.type === 'FunctionExpression' ||\n node.type === 'ArrowFunctionExpression'\n ) {\n node.params.forEach((param) => declareLocalBindingLike(scope, param));\n }\n\n if (node.type === 'ImportDeclaration') {\n collectFromImportDeclaration(node, scope, state);\n } else if (mode === 'all' && node.type === 'ExportNamedDeclaration') {\n collectFromExportNamedDeclaration(node, state);\n } else if (mode === 'all' && node.type === 'ExportAllDeclaration') {\n collectFromExportAllDeclaration(node, state);\n } else if (mode === 'all' && node.type === 'ExportDefaultDeclaration') {\n collectFromExportDefaultDeclaration(node, state);\n } else if (node.type === 'VariableDeclarator') {\n if (!collectFromRequireDeclarator(node, scope, state)) {\n declareLocalPattern(scope, node.id);\n }\n } else if (mode === 'all' && node.type === 'ImportExpression') {\n collectFromImportExpression(node, ctx.parent, state);\n } else if (mode === 'all' && node.type === 'CallExpression') {\n collectFromWywDynamicImport(node, ctx.parent, state);\n collectFromHelperCall(node, { ...ctx, scope }, state);\n } else if (mode === 'all' && node.type === 'ExpressionStatement') {\n collectFromRequireExpressionStatement(node, scope, state);\n } else if (mode === 'all' && node.type === 'AssignmentExpression') {\n collectFromAssignmentExpression(node, { ...ctx, scope }, state);\n } else if (node.type === 'Identifier') {\n collectFromNamespaceReference(node, ctx.parent, { ...ctx, scope }, state);\n }\n\n for (const child of getChildren(node)) {\n visit(child.node, { key: child.key, parent: node, scope }, state, mode);\n }\n};\n\nconst getChildren = (node: Node): { key: string; node: Node }[] => {\n const result: { key: string; node: 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({ key, node: value });\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (isNode(item)) {\n result.push({ key, node: item });\n }\n });\n }\n });\n\n return result;\n};\n\nconst precollectRequireSources = (node: Node, state: AnalyzerState): void => {\n // Cheap text precheck at the Program entry: if the file body has no\n // 'require(' substring there can be no CommonJS require() init to collect.\n // Skip the full AST walk — meaningful saving on ESM-only modules in large\n // monorepos. Done at Program-level only so nested recursion doesn't pay\n // the indexOf cost per node.\n if (node.type === 'Program' && state.code.indexOf('require(') === -1) {\n return;\n }\n\n if (node.type === 'VariableDeclarator' && node.id.type === 'Identifier') {\n const source = node.init ? sourceFromRequireSyntax(node.init) : null;\n if (source) {\n state.requireSources.set(node.id.name, source);\n }\n }\n\n getChildren(node).forEach((child) =>\n precollectRequireSources(child.node, state)\n );\n};\n\nconst addUnusedNamespaceSideEffects = (state: AnalyzerState): void => {\n state.namespaces.forEach((binding) => {\n if (!binding.used) {\n state.result.imports.push({\n imported: 'side-effect',\n local: binding.local,\n source: binding.source,\n type: binding.type,\n });\n }\n });\n};\n\nexport function collectOxcExportsAndImportsFromProgram(\n program: Program,\n code: string,\n isEsModule: boolean\n): OxcCollectedState {\n const rootScope = createScope(null);\n const state: AnalyzerState = {\n code,\n namespaces: [],\n requireSources: new Map(),\n result: {\n deadExports: [],\n exports: {},\n imports: [],\n isEsModule,\n reexports: [],\n },\n };\n\n precollectRequireSources(program, state);\n visit(\n program,\n { key: 'program', parent: null, scope: rootScope },\n state,\n 'all'\n );\n addUnusedNamespaceSideEffects(state);\n\n return state.result;\n}\n\nexport function collectOxcProcessorImportsFromProgram(\n program: Program,\n code: string\n): OxcCollectedImport[] {\n const rootScope = createScope(null);\n const state: AnalyzerState = {\n code,\n namespaces: [],\n requireSources: new Map(),\n result: {\n deadExports: [],\n exports: {},\n imports: [],\n isEsModule: true,\n reexports: [],\n },\n };\n\n precollectRequireSources(program, state);\n visit(\n program,\n { key: 'program', parent: null, scope: rootScope },\n state,\n 'importsOnly'\n );\n\n return state.result.imports;\n}\n\nexport function collectOxcExportsAndImports(\n code: string,\n filename: string\n): OxcCollectedState {\n const parsed = parseOxcCached(filename, code, 'unambiguous');\n\n return collectOxcExportsAndImportsFromProgram(\n parsed.program,\n code,\n parsed.module.hasModuleSyntax\n );\n}\n"],"file":"collectOxcExportsAndImports.js"}
|