@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/cache.js +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/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 +186 -0
- package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
- package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
- package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
- package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
- package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
- package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
- package/esm/transform/generators/transform.js +57 -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 +42 -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 +431 -0
- package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
- package/esm/utils/applyOxcProcessors/displayName.js +93 -0
- package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
- package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
- package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
- package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
- package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
- package/esm/utils/applyOxcProcessors/shared.js +29 -0
- package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
- package/esm/utils/applyOxcProcessors/types.js +2 -0
- package/esm/utils/applyOxcProcessors/types.js.map +1 -0
- package/esm/utils/applyOxcProcessors.js +1 -1216
- package/esm/utils/applyOxcProcessors.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 +28 -0
- package/esm/utils/oxc/ast.js.map +1 -0
- package/esm/utils/oxc/parse.js +3 -0
- package/esm/utils/oxc/parse.js.map +1 -0
- package/esm/utils/oxc/replacements.js +14 -0
- package/esm/utils/oxc/replacements.js.map +1 -0
- package/esm/utils/oxc/sourceLocations.js +59 -0
- package/esm/utils/oxc/sourceLocations.js.map +1 -0
- package/esm/utils/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 +12 -1
- package/esm/utils/oxcPreevalTransforms.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 +4 -3
- 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 +3 -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 +220 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
- package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
- package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
- package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
- package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
- package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
- package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
- package/types/transform/generators/transform.js +63 -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 +44 -9
- package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
- package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
- package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
- package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
- package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
- package/types/utils/applyOxcProcessors/displayName.js +113 -0
- package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
- package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
- package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
- package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
- package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
- package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
- package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
- package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
- package/types/utils/applyOxcProcessors/shared.js +37 -0
- package/types/utils/applyOxcProcessors/types.d.ts +88 -0
- package/types/utils/applyOxcProcessors/types.js +1 -0
- package/types/utils/applyOxcProcessors.d.ts +1 -16
- package/types/utils/applyOxcProcessors.js +1 -1391
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
- package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
- package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
- package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
- package/types/utils/collectOxcRuntime/types.d.ts +16 -0
- package/types/utils/collectOxcRuntime/types.js +1 -0
- package/types/utils/collectOxcRuntime.d.ts +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 +37 -0
- package/types/utils/oxc/parse.d.ts +3 -0
- package/types/utils/oxc/parse.js +2 -0
- package/types/utils/oxc/replacements.d.ts +12 -0
- package/types/utils/oxc/replacements.js +18 -0
- package/types/utils/oxc/sourceLocations.d.ts +5 -0
- package/types/utils/oxc/sourceLocations.js +63 -0
- package/types/utils/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 +14 -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;AAChC,MAAM,2BAA2B;AAEjC,MAAM,UAAU,UACd,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,UAAU,SACV,OAAQ,MAA6B,SAAS;AAEhD,MAAM,eAAe,SAAuB;CAC1C,MAAM,SAAiB,EAAE;CACzB,MAAM,SAAS;AAEf,QAAO,KAAK,OAAO,CAAC,SAAS,QAAQ;AACnC,MAAI,QAAQ,UAAU,QAAQ,W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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"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
import { parseSync } from "oxc-parser";
|
|
3
|
+
const parseOxc = (code, filename) => {
|
|
4
|
+
const parsed = parseSync(filename, code, {
|
|
5
|
+
astType: filename.endsWith(".ts") || filename.endsWith(".tsx") ? "ts" : "js",
|
|
6
|
+
range: true,
|
|
7
|
+
sourceType: "module"
|
|
8
|
+
});
|
|
9
|
+
const fatalError = parsed.errors.find((error) => error.severity === "Error");
|
|
10
|
+
if (fatalError) {
|
|
11
|
+
throw new Error(fatalError.message);
|
|
12
|
+
}
|
|
13
|
+
return parsed.program;
|
|
14
|
+
};
|
|
15
|
+
const applyReplacements = (code, replacements) => {
|
|
16
|
+
let result = code;
|
|
17
|
+
replacements.sort((a, b) => b.start - a.start).forEach((replacement) => {
|
|
18
|
+
result = result.slice(0, replacement.start) + replacement.value + result.slice(replacement.end);
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
const shouldTerminateWithSemicolon = (node, parent, key) => {
|
|
23
|
+
if (node.type === "VariableDeclaration" && parent) {
|
|
24
|
+
if ((parent.type === "ForStatement" || parent.type === "ForInStatement" || parent.type === "ForOfStatement") && key && ["init", "left"].includes(key)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (parent.type === "ExportNamedDeclaration") {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (node.type === "ImportDeclaration" || node.type === "ExpressionStatement" || node.type === "ReturnStatement" || node.type === "ThrowStatement" || node.type === "VariableDeclaration") {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
35
|
+
if (node.declaration) {
|
|
36
|
+
return node.declaration.type === "VariableDeclaration";
|
|
37
|
+
}
|
|
38
|
+
return Array.isArray(node.specifiers) && node.specifiers.length > 0;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
const getChildren = (node) => {
|
|
43
|
+
const result = [];
|
|
44
|
+
const record = node;
|
|
45
|
+
Object.keys(record).forEach((key) => {
|
|
46
|
+
if (key === "type" || key === "start" || key === "end" || key === "range") {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const value = record[key];
|
|
50
|
+
if (value && typeof value === "object" && "type" in value) {
|
|
51
|
+
result.push({
|
|
52
|
+
key,
|
|
53
|
+
node: value
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
value.forEach((item) => {
|
|
59
|
+
if (item && typeof item === "object" && "type" in item) {
|
|
60
|
+
result.push({
|
|
61
|
+
key,
|
|
62
|
+
node: item
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
const getLineIndent = (code, offset) => {
|
|
71
|
+
const lineStart = code.lastIndexOf("\n", offset - 1) + 1;
|
|
72
|
+
let idx = lineStart;
|
|
73
|
+
while (idx < code.length && (code[idx] === " " || code[idx] === " ")) {
|
|
74
|
+
idx += 1;
|
|
75
|
+
}
|
|
76
|
+
return code.slice(lineStart, idx).replace(/\t/g, " ");
|
|
77
|
+
};
|
|
78
|
+
const isPlainObjectProperty = (property) => property.type === "Property" && property.kind === "init" && property.method !== true;
|
|
79
|
+
const isFormattableObjectExpression = (node) => node.type === "ObjectExpression" && node.properties.every((property) => property.type === "SpreadElement" || isPlainObjectProperty(property));
|
|
80
|
+
const hasNestedObjectValue = (node) => node.type === "ObjectExpression" && node.properties.some((property) => isPlainObjectProperty(property) && property.value.type === "ObjectExpression");
|
|
81
|
+
const printFormattedObjectExpression = (node, code, baseIndent) => {
|
|
82
|
+
if (node.type !== "ObjectExpression" || node.properties.length === 0 || !isFormattableObjectExpression(node)) {
|
|
83
|
+
return code.slice(node.start, node.end);
|
|
84
|
+
}
|
|
85
|
+
const lines = node.properties.map((property) => {
|
|
86
|
+
if (property.type === "SpreadElement") {
|
|
87
|
+
return `${baseIndent} ...${code.slice(property.argument.start, property.argument.end)}`;
|
|
88
|
+
}
|
|
89
|
+
const keySource = property.computed ? `[${code.slice(property.key.start, property.key.end)}]` : code.slice(property.key.start, property.key.end);
|
|
90
|
+
const valueSource = property.value.type === "ObjectExpression" ? printFormattedObjectExpression(property.value, code, `${baseIndent} `) : code.slice(property.value.start, property.value.end).trim();
|
|
91
|
+
return `${baseIndent} ${keySource}: ${valueSource}`;
|
|
92
|
+
});
|
|
93
|
+
return `{\n${lines.join(",\n")}\n${baseIndent}}`;
|
|
94
|
+
};
|
|
95
|
+
const formatRuntimeObjectLiterals = (code, filename) => {
|
|
96
|
+
const replacements = [];
|
|
97
|
+
const walk = (node, parent = null) => {
|
|
98
|
+
if (node.type === "ObjectExpression") {
|
|
99
|
+
const shouldFormat = parent?.type === "VariableDeclarator" && hasNestedObjectValue(node) || parent?.type === "CallExpression";
|
|
100
|
+
if (shouldFormat) {
|
|
101
|
+
replacements.push({
|
|
102
|
+
end: node.end,
|
|
103
|
+
start: node.start,
|
|
104
|
+
value: printFormattedObjectExpression(node, code, getLineIndent(code, node.start))
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
getChildren(node).forEach((child) => walk(child.node, node));
|
|
110
|
+
};
|
|
111
|
+
walk(parseOxc(code, filename));
|
|
112
|
+
return replacements.length > 0 ? applyReplacements(code, replacements) : code;
|
|
113
|
+
};
|
|
114
|
+
const collapseRuntimeBlankLines = (code) => {
|
|
115
|
+
const lines = code.split("\n");
|
|
116
|
+
const result = [];
|
|
117
|
+
for (let idx = 0; idx < lines.length; idx += 1) {
|
|
118
|
+
const line = lines[idx];
|
|
119
|
+
if (line.trim() !== "") {
|
|
120
|
+
result.push(line);
|
|
121
|
+
} else {
|
|
122
|
+
let nextIdx = idx;
|
|
123
|
+
while (nextIdx < lines.length && lines[nextIdx]?.trim() === "") {
|
|
124
|
+
nextIdx += 1;
|
|
125
|
+
}
|
|
126
|
+
const previousNonEmpty = [...result].reverse().find((entry) => entry.trim() !== "");
|
|
127
|
+
const nextNonEmpty = lines.slice(nextIdx).find((entry) => entry.trim() !== "");
|
|
128
|
+
if (previousNonEmpty && nextNonEmpty) {
|
|
129
|
+
const trimmedPrevious = previousNonEmpty.trim();
|
|
130
|
+
if (trimmedPrevious.startsWith("//") || trimmedPrevious.endsWith("*/")) {
|
|
131
|
+
result.push("");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
idx = nextIdx - 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return result.join("\n");
|
|
138
|
+
};
|
|
139
|
+
const ensureBlankLineAfterLeadingBlockComment = (code) => code.replace(/^(\/\*[\s\S]*?\*\/)\n(?!\n)/, "$1\n\n");
|
|
140
|
+
const insertMissingSemicolons = (code, filename) => {
|
|
141
|
+
const replacements = [];
|
|
142
|
+
const hasTrailingSemicolon = (node) => code.slice(node.start, node.end).trimEnd().endsWith(";");
|
|
143
|
+
const walk = (node, parent = null, key = null) => {
|
|
144
|
+
if (shouldTerminateWithSemicolon(node, parent, key) && !hasTrailingSemicolon(node)) {
|
|
145
|
+
replacements.push({
|
|
146
|
+
end: node.end,
|
|
147
|
+
start: node.end,
|
|
148
|
+
value: ";"
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
getChildren(node).forEach((child) => walk(child.node, node, child.key));
|
|
152
|
+
};
|
|
153
|
+
walk(parseOxc(code, filename));
|
|
154
|
+
return replacements.length > 0 ? applyReplacements(code, replacements) : code;
|
|
155
|
+
};
|
|
156
|
+
export const normalizeRuntimeCode = (code, filename) => insertMissingSemicolons(ensureBlankLineAfterLeadingBlockComment(collapseRuntimeBlankLines(formatRuntimeObjectLiterals(code.replace(/^\n+/, "").replace(/\n+$/, "").replace(/[ \t]+\n/g, "\n"), filename))), filename);
|
|
157
|
+
//# sourceMappingURL=normalizeRuntimeCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAEA,SAAS,iBAAiB;AAc1B,MAAM,YAAY,MAAc,aAA8B;CAC5D,MAAM,SAAS,UAAU,UAAU,MAAM;EACvC,SACE,SAAS,SAAS,MAAM,IAAI,SAAS,SAAS,OAAO,GAAG,OAAO;EACjE,OAAO;EACP,YAAY;EACb,CAAC;CACF,MAAM,aAAa,OAAO,OAAO,MAAM,UAAU,MAAM,aAAa,QAAQ;AAC5E,KAAI,YAAY;AACd,QAAM,IAAI,MAAM,WAAW,QAAQ;;AAGrC,QAAO,OAAO;;AAGhB,MAAM,qBACJ,MACA,iBACW;CACX,IAAI,SAAS;AACb,cACG,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,CACjC,SAAS,gBAAgB;AACxB,WACE,OAAO,MAAM,GAAG,YAAY,MAAM,GAClC,YAAY,QACZ,OAAO,MAAM,YAAY,IAAI;GAC/B;AAEJ,QAAO;;AAGT,MAAM,gCACJ,MACA,QACA,QACY;AACZ,KAAI,KAAK,SAAS,yBAAyB,QAAQ;AACjD,OACG,OAAO,SAAS,kBACf,OAAO,SAAS,oBAChB,OAAO,SAAS,qBAClB,OACA,CAAC,QAAQ,OAAO,CAAC,SAAS,IAAI,EAC9B;AACA,UAAO;;AAGT,MAAI,OAAO,SAAS,0BAA0B;AAC5C,UAAO;;;AAIX,KACE,KAAK,SAAS,uBACd,KAAK,SAAS,yBACd,KAAK,SAAS,qBACd,KAAK,SAAS,oBACd,KAAK,SAAS,uBACd;AACA,SAAO;;AAGT,KAAI,KAAK,SAAS,0BAA0B;AAC1C,MAAI,KAAK,aAAa;AACpB,UAAO,KAAK,YAAY,SAAS;;AAG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Ac,aACjD,wBACE,wCACE,0BACE,4BACE,KACG,QAAQ,QAAQ,GAAG,CACnB,QAAQ,QAAQ,GAAG,CACnB,QAAQ,aAAa,KAAK,EAC7B,SACD,CACF,CACF,EACD,SACD","names":[],"sources":["../../../src/utils/collectOxcRuntime/normalizeRuntimeCode.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport { parseSync } from 'oxc-parser';\nimport type { Node, Program } from 'oxc-parser';\n\nimport type { RuntimeReplacement } from './types';\n\ntype AnyNode = Node & Record<string, unknown>;\ntype AnyProperty = AnyNode & {\n computed?: boolean;\n key: Node;\n kind?: string;\n method?: boolean;\n value: Node;\n};\n\nconst parseOxc = (code: string, filename: string): Program => {\n const parsed = parseSync(filename, code, {\n astType:\n filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js',\n range: true,\n sourceType: 'module',\n });\n const fatalError = parsed.errors.find((error) => error.severity === 'Error');\n if (fatalError) {\n throw new Error(fatalError.message);\n }\n\n return parsed.program as Program;\n};\n\nconst applyReplacements = (\n code: string,\n replacements: RuntimeReplacement[]\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 shouldTerminateWithSemicolon = (\n node: Node,\n parent: Node | null,\n key: string | null\n): boolean => {\n if (node.type === 'VariableDeclaration' && parent) {\n if (\n (parent.type === 'ForStatement' ||\n parent.type === 'ForInStatement' ||\n parent.type === 'ForOfStatement') &&\n key &&\n ['init', 'left'].includes(key)\n ) {\n return false;\n }\n\n if (parent.type === 'ExportNamedDeclaration') {\n return false;\n }\n }\n\n if (\n node.type === 'ImportDeclaration' ||\n node.type === 'ExpressionStatement' ||\n node.type === 'ReturnStatement' ||\n node.type === 'ThrowStatement' ||\n node.type === 'VariableDeclaration'\n ) {\n return true;\n }\n\n if (node.type === 'ExportNamedDeclaration') {\n if (node.declaration) {\n return node.declaration.type === 'VariableDeclaration';\n }\n\n return Array.isArray(node.specifiers) && node.specifiers.length > 0;\n }\n\n return false;\n};\n\nconst getChildren = (node: Node): Array<{ key: string | null; node: Node }> => {\n const result: Array<{ key: string | null; node: Node }> = [];\n const record = node as Node & Record<string, unknown>;\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 (value && typeof value === 'object' && 'type' in (value as object)) {\n result.push({ key, node: value as Node });\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach((item) => {\n if (item && typeof item === 'object' && 'type' in (item as object)) {\n result.push({ key, node: item as Node });\n }\n });\n }\n });\n\n return result;\n};\n\nconst getLineIndent = (code: string, offset: number): string => {\n const lineStart = code.lastIndexOf('\\n', offset - 1) + 1;\n let idx = lineStart;\n while (idx < code.length && (code[idx] === ' ' || code[idx] === '\\t')) {\n idx += 1;\n }\n\n return code.slice(lineStart, idx).replace(/\\t/g, ' ');\n};\n\nconst isPlainObjectProperty = (property: Node): property is AnyProperty =>\n property.type === 'Property' &&\n (property as AnyProperty).kind === 'init' &&\n (property as AnyProperty).method !== true;\n\nconst isFormattableObjectExpression = (node: Node): boolean =>\n node.type === 'ObjectExpression' &&\n node.properties.every(\n (property) =>\n property.type === 'SpreadElement' || isPlainObjectProperty(property)\n );\n\nconst hasNestedObjectValue = (node: Node): boolean =>\n node.type === 'ObjectExpression' &&\n node.properties.some(\n (property) =>\n isPlainObjectProperty(property) &&\n property.value.type === 'ObjectExpression'\n );\n\nconst printFormattedObjectExpression = (\n node: Node,\n code: string,\n baseIndent: string\n): string => {\n if (\n node.type !== 'ObjectExpression' ||\n node.properties.length === 0 ||\n !isFormattableObjectExpression(node)\n ) {\n return code.slice(node.start, node.end);\n }\n\n const lines = node.properties.map((property) => {\n if (property.type === 'SpreadElement') {\n return `${baseIndent} ...${code.slice(\n property.argument.start,\n property.argument.end\n )}`;\n }\n\n const keySource = property.computed\n ? `[${code.slice(property.key.start, property.key.end)}]`\n : code.slice(property.key.start, property.key.end);\n const valueSource =\n property.value.type === 'ObjectExpression'\n ? printFormattedObjectExpression(\n property.value,\n code,\n `${baseIndent} `\n )\n : code.slice(property.value.start, property.value.end).trim();\n\n return `${baseIndent} ${keySource}: ${valueSource}`;\n });\n\n return `{\\n${lines.join(',\\n')}\\n${baseIndent}}`;\n};\n\nconst formatRuntimeObjectLiterals = (\n code: string,\n filename: string\n): string => {\n const replacements: RuntimeReplacement[] = [];\n\n const walk = (node: Node, parent: Node | null = null): void => {\n if (node.type === 'ObjectExpression') {\n const shouldFormat =\n (parent?.type === 'VariableDeclarator' && hasNestedObjectValue(node)) ||\n parent?.type === 'CallExpression';\n\n if (shouldFormat) {\n replacements.push({\n end: node.end,\n start: node.start,\n value: printFormattedObjectExpression(\n node,\n code,\n getLineIndent(code, node.start)\n ),\n });\n return;\n }\n }\n\n getChildren(node).forEach((child) => walk(child.node, node));\n };\n\n walk(parseOxc(code, filename));\n return replacements.length > 0 ? applyReplacements(code, replacements) : code;\n};\n\nconst collapseRuntimeBlankLines = (code: string): string => {\n const lines = code.split('\\n');\n const result: string[] = [];\n\n for (let idx = 0; idx < lines.length; idx += 1) {\n const line = lines[idx]!;\n if (line.trim() !== '') {\n result.push(line);\n } else {\n let nextIdx = idx;\n while (nextIdx < lines.length && lines[nextIdx]?.trim() === '') {\n nextIdx += 1;\n }\n\n const previousNonEmpty = [...result]\n .reverse()\n .find((entry) => entry.trim() !== '');\n const nextNonEmpty = lines\n .slice(nextIdx)\n .find((entry) => entry.trim() !== '');\n\n if (previousNonEmpty && nextNonEmpty) {\n const trimmedPrevious = previousNonEmpty.trim();\n if (\n trimmedPrevious.startsWith('//') ||\n trimmedPrevious.endsWith('*/')\n ) {\n result.push('');\n }\n }\n\n idx = nextIdx - 1;\n }\n }\n\n return result.join('\\n');\n};\n\nconst ensureBlankLineAfterLeadingBlockComment = (code: string): string =>\n code.replace(/^(\\/\\*[\\s\\S]*?\\*\\/)\\n(?!\\n)/, '$1\\n\\n');\n\nconst insertMissingSemicolons = (code: string, filename: string): string => {\n const replacements: RuntimeReplacement[] = [];\n const hasTrailingSemicolon = (node: Node): boolean =>\n code.slice(node.start, node.end).trimEnd().endsWith(';');\n\n const walk = (\n node: Node,\n parent: Node | null = null,\n key: string | null = null\n ): void => {\n if (\n shouldTerminateWithSemicolon(node, parent, key) &&\n !hasTrailingSemicolon(node)\n ) {\n replacements.push({\n end: node.end,\n start: node.end,\n value: ';',\n });\n }\n\n getChildren(node).forEach((child) => walk(child.node, node, child.key));\n };\n\n walk(parseOxc(code, filename));\n return replacements.length > 0 ? applyReplacements(code, replacements) : code;\n};\n\nexport const normalizeRuntimeCode = (code: string, filename: string): string =>\n insertMissingSemicolons(\n ensureBlankLineAfterLeadingBlockComment(\n collapseRuntimeBlankLines(\n formatRuntimeObjectLiterals(\n code\n .replace(/^\\n+/, '')\n .replace(/\\n+$/, '')\n .replace(/[ \\t]+\\n/g, '\\n'),\n filename\n )\n )\n ),\n filename\n );\n"],"file":"normalizeRuntimeCode.js"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { SourceMapGenerator } from "source-map";
|
|
3
|
+
const remapping = createRequire(import.meta.url)("@jridgewell/remapping");
|
|
4
|
+
const countLines = (code) => code.split("\n").length;
|
|
5
|
+
const createLineSourceMap = (generatedCode, originalCode, filename) => {
|
|
6
|
+
const generator = new SourceMapGenerator({ file: filename });
|
|
7
|
+
const generatedLines = countLines(generatedCode);
|
|
8
|
+
const originalLines = countLines(originalCode);
|
|
9
|
+
for (let line = 1; line <= generatedLines; line += 1) {
|
|
10
|
+
generator.addMapping({
|
|
11
|
+
generated: {
|
|
12
|
+
column: 0,
|
|
13
|
+
line
|
|
14
|
+
},
|
|
15
|
+
original: {
|
|
16
|
+
column: 0,
|
|
17
|
+
line: Math.min(line, originalLines)
|
|
18
|
+
},
|
|
19
|
+
source: filename
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
generator.setSourceContent(filename, originalCode);
|
|
23
|
+
return generator.toJSON();
|
|
24
|
+
};
|
|
25
|
+
export const createComposedRuntimeSourceMap = (generatedCode, originalCode, filename, inputSourceMap) => {
|
|
26
|
+
const runtimeMap = createLineSourceMap(generatedCode, originalCode, filename);
|
|
27
|
+
if (!inputSourceMap) {
|
|
28
|
+
return runtimeMap;
|
|
29
|
+
}
|
|
30
|
+
const composed = remapping([runtimeMap, inputSourceMap], () => null);
|
|
31
|
+
return {
|
|
32
|
+
...composed,
|
|
33
|
+
file: runtimeMap.file
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=sourceMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAAA,SAAS,qBAAqB;AAE9B,SAAS,0BAA6C;AAOtD,MAAM,YAAY,cAAc,OAAO,KAAK,IAAI,CAC9C,wBACD;AAED,MAAM,cAAc,SAAyB,KAAK,MAAM,KAAK,CAAC;AAE9D,MAAM,uBACJ,eACA,cACA,aACiB;CACjB,MAAM,YAAY,IAAI,mBAAmB,EACvC,MAAM,UACP,CAAC;CACF,MAAM,iBAAiB,WAAW,cAAc;CAChD,MAAM,gBAAgB,WAAW,aAAa;AAE9C,MAAK,IAAI,OAAO,GAAG,QAAQ,gBAAgB,QAAQ,GAAG;AACpD,YAAU,WAAW;GACnB,WAAW;IACT,QAAQ;IACR;IACD;GACD,UAAU;IACR,QAAQ;IACR,MAAM,KAAK,IAAI,MAAM,cAAc;IACpC;GACD,QAAQ;GACT,CAAC;;AAGJ,WAAU,iBAAiB,UAAU,aAAa;AAElD,QAAO,UAAU,QAAQ;;AAG3B,OAAO,MAAM,kCACX,eACA,cACA,UACA,mBACiB;CACjB,MAAM,aAAa,oBAAoB,eAAe,cAAc,SAAS;AAC7E,KAAI,CAAC,gBAAgB;AACnB,SAAO;;CAGT,MAAM,WAAW,UAAU,CAAC,YAAY,eAAe,QAAQ,KAAK;AACpE,QAAO;EACL,GAAG;EACH,MAAM,WAAW;EAClB","names":[],"sources":["../../../src/utils/collectOxcRuntime/sourceMap.ts"],"version":3,"sourcesContent":["import { createRequire } from 'node:module';\n\nimport { SourceMapGenerator, type RawSourceMap } from 'source-map';\n\ntype RemappingFn = (\n input: RawSourceMap | RawSourceMap[],\n loader: (source: string, context: unknown) => RawSourceMap | null | undefined\n) => RawSourceMap;\n\nconst remapping = createRequire(import.meta.url)(\n '@jridgewell/remapping'\n) as RemappingFn;\n\nconst countLines = (code: string): number => code.split('\\n').length;\n\nconst createLineSourceMap = (\n generatedCode: string,\n originalCode: string,\n filename: string\n): RawSourceMap => {\n const generator = new SourceMapGenerator({\n file: filename,\n });\n const generatedLines = countLines(generatedCode);\n const originalLines = countLines(originalCode);\n\n for (let line = 1; line <= generatedLines; line += 1) {\n generator.addMapping({\n generated: {\n column: 0,\n line,\n },\n original: {\n column: 0,\n line: Math.min(line, originalLines),\n },\n source: filename,\n });\n }\n\n generator.setSourceContent(filename, originalCode);\n\n return generator.toJSON() as RawSourceMap;\n};\n\nexport const createComposedRuntimeSourceMap = (\n generatedCode: string,\n originalCode: string,\n filename: string,\n inputSourceMap?: RawSourceMap\n): RawSourceMap => {\n const runtimeMap = createLineSourceMap(generatedCode, originalCode, filename);\n if (!inputSourceMap) {\n return runtimeMap;\n }\n\n const composed = remapping([runtimeMap, inputSourceMap], () => null);\n return {\n ...composed,\n file: runtimeMap.file,\n } as RawSourceMap;\n};\n"],"file":"sourceMap.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/utils/collectOxcRuntime/types.ts"],"version":3,"sourcesContent":["import type { StrictOptions } from '@wyw-in-js/shared';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { WYWTransformMetadata } from '../TransformMetadata';\n\nexport type OxcCollectOptions = Pick<\n StrictOptions,\n | 'classNameSlug'\n | 'displayName'\n | 'eval'\n | 'extensions'\n | 'tagResolver'\n | 'variableNameConfig'\n> & {\n preserveSideEffectImportLocals?: Set<string>;\n};\n\nexport type OxcCollectResult = {\n code: string;\n map: RawSourceMap;\n metadata: WYWTransformMetadata | null;\n};\n\nexport type RuntimeReplacement = {\n end: number;\n start: number;\n value: string;\n};\n"],"file":"types.js"}
|