@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AASA,SAAS,oCAAoC;AAC7C,SACE,uBACA,mCACA,eACA,wBACA,wBACK;AASP,OAAO,MAAM,sBAAsB,IAAI,IAAI;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,OAAO,MAAM,sBAAsB,SAA8B;CAC/D,MAAM,YAAY,iBAAiB,KAAK;AAExC,KAAI,UAAU,SAAS,cAAc;AACnC,SAAO,UAAU;;AAGnB,KAAI,UAAU,SAAS,oBAAoB;AACzC,SAAO,mBAAmB,UAAU,OAAO;;AAG7C,KAAI,UAAU,SAAS,mBAAmB;AACxC,SAAO,mBAAmB,UAAU,WAAW;;AAGjD,QAAO;;AAGT,OAAO,MAAM,oBAAoB,SAA8B;CAC7D,MAAM,YAAY,iBAA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,IAAI,cAAc,SAAS,IAAI,cAAc,SACrE,cACD;AACD,2BAAuB,IAAI,UAAU;AACrC;;AAGF,OAAI,CAAC,aAAa,UAAU,EAAE;;;;;;;AAO5B;;;AAIJ,SAAO;;AAGT,KAAI,OAAO,WAAW;AACpB,kBAAgB,IAAI,OAAO,UAAU;AACrC,cAAY,OAAO,WAAW,OAAO,WAAW;;AAGlD,KAAI,CAAC,kBAAkB,OAAO,WAAW,EAAE;AACzC,SAAO;;CAGT,MAAM,eAAe,IAAI,IAAI,gBAAgB;AAC7C,KAAI,OAAO,WAAW;AACpB,eAAa,IAAI,OAAO,UAAU;;CAEpC,MAAM,gBAAgB,6BAA6B,SAAS,aAAa;AACzE,MAAK,MAAM,QAAQ,iBAAiB;AAClC,MAAI,cAAc,aAAa,IAAI,KAAK,EAAE;AACxC,UAAO;;;AAIX,MAAK,MAAM,QAAQ,wBAAwB;AACzC,MACE,cAAc,kBAAkB,IAAI,KAAK,IACzC,CAAC,QAAQ,iCAAiC,IAAI,KAAK,EACnD;AACA,UAAO;;;AAIX,QAAO,EACL,SAAS,CAAC,GAAG,iBAAiB,QAAQ,CAAC,EACxC","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type {\n Expression,\n Node,\n Program,\n VariableDeclaration,\n} from 'oxc-parser';\n\nimport { collectLocalConstExpressions } from './programAnalysis';\nimport {\n collectImportBindings,\n collectStaticExpressionReferences,\n isSafeLiteral,\n isSafeStaticExpression,\n unwrapExpression,\n} from './staticExpression';\nimport type {\n AnyNode,\n ExportTarget,\n ImportBinding,\n StaticExpressionDependencies,\n StaticExpressionOptions,\n} from './types';\n\nexport const mutatingMethodNames = new Set([\n 'add',\n 'clear',\n 'copyWithin',\n 'delete',\n 'fill',\n 'pop',\n 'push',\n 'reverse',\n 'set',\n 'shift',\n 'sort',\n 'splice',\n 'unshift',\n]);\n\nexport const rootIdentifierName = (expr: Node): string | null => {\n const unwrapped = unwrapExpression(expr);\n\n if (unwrapped.type === 'Identifier') {\n return unwrapped.name;\n }\n\n if (unwrapped.type === 'MemberExpression') {\n return rootIdentifierName(unwrapped.object);\n }\n\n if (unwrapped.type === 'ChainExpression') {\n return rootIdentifierName(unwrapped.expression);\n }\n\n return null;\n};\n\nexport const staticMemberName = (expr: Node): string | null => {\n const unwrapped = unwrapExpression(expr);\n\n if (unwrapped.type === 'Identifier') {\n return unwrapped.name;\n }\n\n if (isSafeLiteral(unwrapped) && typeof unwrapped.value === 'string') {\n return unwrapped.value;\n }\n\n return null;\n};\n\nexport const expressionMayProduceMutableValue = (\n expr: Node,\n locals: Map<string, Expression>,\n visiting: Set<string>\n): boolean => {\n const unwrapped = unwrapExpression(expr);\n\n if (\n unwrapped.type === 'ObjectExpression' ||\n unwrapped.type === 'ArrayExpression'\n ) {\n return true;\n }\n\n if (unwrapped.type === 'Identifier') {\n const local = locals.get(unwrapped.name);\n if (!local || visiting.has(unwrapped.name)) {\n return true;\n }\n\n visiting.add(unwrapped.name);\n const result = expressionMayProduceMutableValue(local, locals, visiting);\n visiting.delete(unwrapped.name);\n return result;\n }\n\n if (unwrapped.type === 'ConditionalExpression') {\n return (\n expressionMayProduceMutableValue(\n unwrapped.consequent,\n locals,\n visiting\n ) ||\n expressionMayProduceMutableValue(unwrapped.alternate, locals, visiting)\n );\n }\n\n if (\n unwrapped.type === 'LogicalExpression' ||\n unwrapped.type === 'MemberExpression'\n ) {\n return true;\n }\n\n return false;\n};\nexport const collectExpressionMutationHints = (\n expr: Node,\n mutatedNames: Set<string>,\n callArgumentNames: Set<string>\n): void => {\n const unwrapped = unwrapExpression(expr);\n\n if (unwrapped.type === 'AssignmentExpression') {\n const rootName = rootIdentifierName(unwrapped.left);\n if (rootName) {\n mutatedNames.add(rootName);\n }\n\n collectExpressionMutationHints(\n unwrapped.right,\n mutatedNames,\n callArgumentNames\n );\n return;\n }\n\n if (unwrapped.type === 'UpdateExpression') {\n const rootName = rootIdentifierName(unwrapped.argument);\n if (rootName) {\n mutatedNames.add(rootName);\n }\n\n return;\n }\n\n if (unwrapped.type === 'UnaryExpression') {\n if (unwrapped.operator === 'delete') {\n const rootName = rootIdentifierName(unwrapped.argument);\n if (rootName) {\n mutatedNames.add(rootName);\n }\n }\n\n collectExpressionMutationHints(\n unwrapped.argument,\n mutatedNames,\n callArgumentNames\n );\n return;\n }\n\n if (unwrapped.type === 'CallExpression') {\n const callee = unwrapExpression(unwrapped.callee);\n if (callee.type === 'MemberExpression') {\n const methodName = staticMemberName(callee.property);\n const rootName = rootIdentifierName(callee.object);\n if (rootName && methodName && mutatingMethodNames.has(methodName)) {\n mutatedNames.add(rootName);\n }\n\n collectExpressionMutationHints(\n callee.object,\n mutatedNames,\n callArgumentNames\n );\n if (callee.computed) {\n collectExpressionMutationHints(\n callee.property,\n mutatedNames,\n callArgumentNames\n );\n }\n } else {\n collectExpressionMutationHints(\n unwrapped.callee,\n mutatedNames,\n callArgumentNames\n );\n }\n\n unwrapped.arguments.forEach((argument) => {\n const argumentNode =\n argument.type === 'SpreadElement' ? argument.argument : argument;\n const rootName = rootIdentifierName(argumentNode);\n if (rootName) {\n callArgumentNames.add(rootName);\n }\n\n collectExpressionMutationHints(\n argumentNode,\n mutatedNames,\n callArgumentNames\n );\n });\n return;\n }\n\n if (unwrapped.type === 'TaggedTemplateExpression') {\n collectExpressionMutationHints(\n unwrapped.tag,\n mutatedNames,\n callArgumentNames\n );\n unwrapped.quasi.expressions.forEach((item) =>\n collectExpressionMutationHints(item, mutatedNames, callArgumentNames)\n );\n return;\n }\n\n if (unwrapped.type === 'ConditionalExpression') {\n collectExpressionMutationHints(\n unwrapped.test,\n mutatedNames,\n callArgumentNames\n );\n collectExpressionMutationHints(\n unwrapped.consequent,\n mutatedNames,\n callArgumentNames\n );\n collectExpressionMutationHints(\n unwrapped.alternate,\n mutatedNames,\n callArgumentNames\n );\n return;\n }\n\n if (\n unwrapped.type === 'BinaryExpression' ||\n unwrapped.type === 'LogicalExpression'\n ) {\n collectExpressionMutationHints(\n unwrapped.left,\n mutatedNames,\n callArgumentNames\n );\n collectExpressionMutationHints(\n unwrapped.right,\n mutatedNames,\n callArgumentNames\n );\n return;\n }\n\n if (unwrapped.type === 'MemberExpression') {\n collectExpressionMutationHints(\n unwrapped.object,\n mutatedNames,\n callArgumentNames\n );\n if (unwrapped.computed) {\n collectExpressionMutationHints(\n unwrapped.property,\n mutatedNames,\n callArgumentNames\n );\n }\n return;\n }\n\n if (unwrapped.type === 'ArrayExpression') {\n unwrapped.elements.forEach((item) => {\n if (!item) {\n return;\n }\n\n collectExpressionMutationHints(\n item.type === 'SpreadElement' ? item.argument : item,\n mutatedNames,\n callArgumentNames\n );\n });\n return;\n }\n\n if (unwrapped.type === 'ObjectExpression') {\n unwrapped.properties.forEach((property) => {\n if (property.type === 'SpreadElement') {\n collectExpressionMutationHints(\n property.argument,\n mutatedNames,\n callArgumentNames\n );\n return;\n }\n\n const propertyNode = property as AnyNode;\n if (propertyNode.computed && propertyNode.key) {\n collectExpressionMutationHints(\n propertyNode.key as Node,\n mutatedNames,\n callArgumentNames\n );\n }\n\n if (propertyNode.value && typeof propertyNode.value === 'object') {\n collectExpressionMutationHints(\n propertyNode.value as Node,\n mutatedNames,\n callArgumentNames\n );\n }\n });\n }\n};\n\nexport const collectTopLevelMutationHints = (\n program: Program,\n closureNames: ReadonlySet<string> | null = null\n): { callArgumentNames: Set<string>; mutatedNames: Set<string> } => {\n const callArgumentNames = new Set<string>();\n const mutatedNames = new Set<string>();\n\n const collectDeclaration = (declaration: VariableDeclaration): void => {\n declaration.declarations.forEach((declarator) => {\n if (closureNames) {\n const declaredName =\n declarator.id.type === 'Identifier' ? declarator.id.name : null;\n if (!declaredName || !closureNames.has(declaredName)) {\n return;\n }\n }\n if (declarator.init) {\n collectExpressionMutationHints(\n declarator.init,\n mutatedNames,\n callArgumentNames\n );\n }\n });\n };\n\n program.body.forEach((statement) => {\n if (statement.type === 'VariableDeclaration') {\n collectDeclaration(statement);\n return;\n }\n\n if (statement.type === 'ExpressionStatement') {\n collectExpressionMutationHints(\n statement.expression,\n mutatedNames,\n callArgumentNames\n );\n return;\n }\n\n if (statement.type === 'ExportNamedDeclaration') {\n if (statement.declaration?.type === 'VariableDeclaration') {\n collectDeclaration(statement.declaration);\n }\n\n return;\n }\n\n if (statement.type === 'ExportDefaultDeclaration') {\n if (\n statement.declaration.type !== 'FunctionDeclaration' &&\n statement.declaration.type !== 'ClassDeclaration'\n ) {\n collectExpressionMutationHints(\n statement.declaration,\n mutatedNames,\n callArgumentNames\n );\n }\n }\n });\n\n return { callArgumentNames, mutatedNames };\n};\nexport const collectStaticExpressionDependencies = (\n program: Program,\n target: Extract<ExportTarget, { kind: 'expression' }>,\n options: StaticExpressionOptions = {}\n): StaticExpressionDependencies | null => {\n const imports = collectImportBindings(program);\n const locals = collectLocalConstExpressions(program);\n const collectedImports = new Map<string, ImportBinding>();\n const referencedNames = new Set<string>();\n const mutableReferencedNames = new Set<string>();\n const visitedLocals = new Set<string>();\n const visitingLocals = new Set<string>();\n\n const markMutable = (name: string, expression: Node): void => {\n if (expressionMayProduceMutableValue(expression, locals, new Set())) {\n mutableReferencedNames.add(name);\n }\n };\n\n const collectLocal = (name: string): boolean => {\n // Pre-resolved locals (e.g. `const x = css\\`\\``) have a known value\n // (the className string). Skip walking their init — its\n // TaggedTemplateExpression isn't safe-static by itself, but the\n // value is already determined.\n if (options.preResolvedLocals?.has(name)) {\n referencedNames.add(name);\n visitedLocals.add(name);\n return true;\n }\n\n const expression = locals.get(name);\n if (!expression || visitingLocals.has(name)) {\n return false;\n }\n\n referencedNames.add(name);\n markMutable(name, expression);\n\n if (visitedLocals.has(name)) {\n return true;\n }\n\n visitingLocals.add(name);\n const result = collectExpression(expression);\n visitingLocals.delete(name);\n\n if (result) {\n visitedLocals.add(name);\n }\n\n return result;\n };\n\n const collectExpression = (expr: Node): boolean => {\n if (!isSafeStaticExpression(expr, options)) {\n return false;\n }\n\n const references = new Set<string>();\n if (!collectStaticExpressionReferences(expr, references, options)) {\n return false;\n }\n\n for (const reference of references) {\n referencedNames.add(reference);\n\n const importBinding = imports.get(reference);\n if (importBinding) {\n collectedImports.set(\n `${importBinding.source}\\0${importBinding.imported}\\0${importBinding.local}`,\n importBinding\n );\n mutableReferencedNames.add(reference);\n continue;\n }\n\n if (!collectLocal(reference)) {\n // Unknown identifier — neither an import nor a same-file local.\n // Common case: undeclared globals like __DEV__ used in\n // `typeof __DEV__ !== \"undefined\"` short-circuit guards. The\n // evaluator returns undefined for unknowns, which the outer\n // expression's logical short-circuits handle correctly. Don't\n // reject the whole walk upfront — let the evaluator decide.\n continue;\n }\n }\n\n return true;\n };\n\n if (target.localName) {\n referencedNames.add(target.localName);\n markMutable(target.localName, target.expression);\n }\n\n if (!collectExpression(target.expression)) {\n return null;\n }\n\n const closureNames = new Set(referencedNames);\n if (target.localName) {\n closureNames.add(target.localName);\n }\n const mutationHints = collectTopLevelMutationHints(program, closureNames);\n for (const name of referencedNames) {\n if (mutationHints.mutatedNames.has(name)) {\n return null;\n }\n }\n\n for (const name of mutableReferencedNames) {\n if (\n mutationHints.callArgumentNames.has(name) &&\n !options.ignoredMutableCallArgumentNames?.has(name)\n ) {\n return null;\n }\n }\n\n return {\n imports: [...collectedImports.values()],\n };\n};\n"],"file":"staticExpressionDependencies.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AA8EA,OAAO,MAAM,kCAAkC;AAC/C,OAAO,MAAM,2BAA2B","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/types.ts"],"version":3,"sourcesContent":["import type { Expression, Node, Program } from 'oxc-parser';\n\nimport type { OxcTextReplacement } from '../../../utils/oxc/replacements';\nimport type { runOxcPreevalStage } from '../../../utils/oxcPreevalStage';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\n\nexport type AnyNode = Node & Record<string, unknown>;\n\nexport type ImportBinding = {\n imported: '*' | 'default' | string;\n local: string;\n source: string;\n};\n\nexport type CollectImportBindingsOptions = {\n includeNamespace?: boolean;\n};\n\nexport type ExportTarget =\n | {\n expression: Expression;\n kind: 'expression';\n localName?: string;\n }\n | {\n imported: 'default' | string;\n kind: 'import';\n source: string;\n };\n\nexport type StaticExportResult = {\n callable?: 'zero-arg';\n dependencies: string[];\n // True when the candidate's value is a runtime callback (function)\n // already represented in the bundle as the locally-defined `_exp =\n // () => ...` arrow. The file does not need evalFile because of this\n // candidate, but the helper declaration must NOT be pruned — the\n // runtime call site relies on it.\n runtimeOnly?: boolean;\n sideEffectDependencies?: string[];\n sideEffectImportLocals?: string[];\n value: unknown;\n};\n\nexport type StaticFileAnalysis = {\n code: string;\n codeHash: string;\n program: Program;\n};\n\nexport type StaticFileHashCacheEntry = {\n hash: string;\n mtimeMs: number;\n size: number;\n};\n\nexport type StaticMetadataPreevalCacheEntry =\n | {\n result: null;\n }\n | {\n result: ReturnType<typeof runOxcPreevalStage>;\n };\n\n// Null entries carry an attempt counter so we can retry a bounded number of\n// times before accepting the failure as stable. This avoids both:\n// (a) poisoning the cache forever from a transient resolver failure\n// (b) thundering-herd retries where every consumer re-walks a stable miss\nexport type StaticExportCacheEntry =\n | {\n attempts: number;\n result: null;\n }\n | {\n dependencyHashes: Map<string, string>;\n result: StaticExportResult;\n };\n\nexport const STATIC_EXPORT_MAX_NULL_ATTEMPTS = 2;\nexport const GENERATED_HELPER_NAME_RE = /^_exp\\d*$/;\n\nexport type StaticExpressionOptions = {\n allowMetadataCalls?: boolean;\n ignoredMutableCallArgumentNames?: Set<string>;\n // Names of same-file locals whose value the resolver already knows\n // out-of-band (e.g. processor className strings from\n // applyOxcProcessors). Skip walking into their inits during\n // dependency collection — `const x = css`...`` has a\n // TaggedTemplateExpression init that fails isSafeStaticExpression,\n // but we don't need to walk it because `x`'s value is already\n // resolved.\n preResolvedLocals?: ReadonlySet<string>;\n // Local names of imports registered as pure helpers via\n // pluginOptions.staticBindings (e.g. `cx` from '@linaria/core',\n // `isFlagPresent` from './flags'). CallExpressions whose callee is\n // in this set are admitted by isSafeStaticExpression provided every\n // arg is itself safe-static. The actual invocation happens in\n // evaluateStatic via the env-bound function.\n staticHelperLocals?: ReadonlySet<string>;\n};\n\nexport type StaticResolveDebugPhase =\n | 'candidate'\n | 'entrypoint'\n | 'export'\n | 'import'\n | 'processor-metadata';\n\nexport type StaticResolveDebugStatus = 'rejected' | 'resolved' | 'skipped';\n\nexport type StaticResolveDebugEvent = {\n candidate?: string;\n dependency?: string;\n exported?: string;\n filename: string;\n imported?: string;\n importer?: string;\n phase: StaticResolveDebugPhase;\n reason?: string;\n source?: string;\n status: StaticResolveDebugStatus;\n};\n\nexport type Range = {\n end: number;\n start: number;\n};\n\nexport type Replacement = Range & OxcTextReplacement;\n\nexport type StaticExpressionDependencies = {\n imports: ImportBinding[];\n};\n\nexport type PreparedProcessorTarget = {\n dependencies: StaticExpressionDependencies;\n evaluationCode?: string;\n evaluationSpan?: Range;\n expression: Expression;\n opaqueRuntimeBase: boolean;\n};\n\nexport type OpaqueRuntimeImportProof = {\n dependencies: string[];\n names: Set<string>;\n};\n\nexport type ResolveStaticImportValue = (\n action: ITransformAction,\n importer: string,\n binding: Pick<ImportBinding, 'imported' | 'source'>,\n stack: Set<string>,\n memo: Map<string, StaticExportResult | null>\n) => SyncScenarioFor<StaticExportResult | null>;\n\nexport type ResolveStaticExportValue = (\n action: ITransformAction,\n filename: string,\n exportedName: string,\n stack: Set<string>,\n memo: Map<string, StaticExportResult | null>\n) => SyncScenarioFor<StaticExportResult | null>;\n\nexport type StaticExportResolverContext = {\n resolveImportValue: ResolveStaticImportValue;\n resolveStaticExport: ResolveStaticExportValue;\n};\n"],"file":"types.js"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { evaluateOxcStaticExpressionAt, isOxcStaticSerializableValue } from "../../../utils/collectOxcTemplateDependencies.js";
|
|
2
|
+
import { getStaticBindings } from "./environment.js";
|
|
3
|
+
import { bindStaticResolvedValue, unwrapExpression } from "./staticExpression.js";
|
|
4
|
+
import { collectStaticExpressionDependencies } from "./staticExpressionDependencies.js";
|
|
5
|
+
export const zeroArgFunctionReturnExpression = (expression) => {
|
|
6
|
+
const unwrapped = unwrapExpression(expression);
|
|
7
|
+
if (unwrapped.type !== "ArrowFunctionExpression" && unwrapped.type !== "FunctionExpression") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (unwrapped.async || unwrapped.params.length !== 0 || !unwrapped.body) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (unwrapped.body.type !== "BlockStatement") {
|
|
14
|
+
return unwrapped.body;
|
|
15
|
+
}
|
|
16
|
+
if (unwrapped.body.body.length !== 1) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const [statement] = unwrapped.body.body;
|
|
20
|
+
return statement?.type === "ReturnStatement" && statement.argument ? statement.argument : null;
|
|
21
|
+
};
|
|
22
|
+
export function* resolveZeroArgFunctionStaticExport(action, filename, code, program, target, stack, memo, resolveImportValue) {
|
|
23
|
+
const returnExpression = zeroArgFunctionReturnExpression(target.expression);
|
|
24
|
+
if (!returnExpression) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const staticDependencies = collectStaticExpressionDependencies(program, {
|
|
28
|
+
...target,
|
|
29
|
+
expression: returnExpression
|
|
30
|
+
}, { allowMetadataCalls: true });
|
|
31
|
+
if (!staticDependencies) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const env = new Map();
|
|
35
|
+
const dependencies = new Set([filename]);
|
|
36
|
+
const sideEffectDependencies = new Set();
|
|
37
|
+
for (const binding of staticDependencies.imports) {
|
|
38
|
+
const resolved = yield* resolveImportValue(action, filename, binding, stack, memo);
|
|
39
|
+
if (!resolved) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (!bindStaticResolvedValue(env, returnExpression, binding.local, resolved)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
resolved.dependencies.forEach((item) => dependencies.add(item));
|
|
46
|
+
resolved.sideEffectDependencies?.forEach((item) => sideEffectDependencies.add(item));
|
|
47
|
+
}
|
|
48
|
+
const value = evaluateOxcStaticExpressionAt(code, filename, {
|
|
49
|
+
end: returnExpression.end,
|
|
50
|
+
start: returnExpression.start
|
|
51
|
+
}, env, getStaticBindings(action));
|
|
52
|
+
return isOxcStaticSerializableValue(value) ? {
|
|
53
|
+
callable: "zero-arg",
|
|
54
|
+
dependencies: [...dependencies],
|
|
55
|
+
sideEffectDependencies: [...sideEffectDependencies],
|
|
56
|
+
value
|
|
57
|
+
} : null;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=zeroArgFunctionStaticExport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAIA,SACE,+BACA,oCACK;AAEP,SAAS,yBAAyB;AAClC,SAAS,yBAAyB,wBAAwB;AAC1D,SAAS,2CAA2C;AAOpD,OAAO,MAAM,mCACX,eACsB;CACtB,MAAM,YAAY,iBAAiB,WAAW;AAC9C,KACE,UAAU,SAAS,6BACnB,UAAU,SAAS,sBACnB;AACA,SAAO;;AAGT,KAAI,UAAU,SAAS,UAAU,OAAO,WAAW,KAAK,CAAC,UAAU,MAAM;AACvE,SAAO;;AAGT,KAAI,UAAU,KAAK,SAAS,kBAAkB;AAC5C,SAAO,UAAU;;AAGnB,KAAI,UAAU,KAAK,KAAK,WAAW,GAAG;AACpC,SAAO;;CAGT,MAAM,CAAC,aAAa,UAAU,KAAK;AACnC,QAAO,WAAW,SAAS,qBAAqB,UAAU,WACtD,UAAU,WACV;;AAGN,OAAO,UAAU,mCACf,QACA,UACA,MACA,SACA,QACA,OACA,MACA,oBAC4C;CAC5C,MAAM,mBAAmB,gCAAgC,OAAO,WAAW;AAC3E,KAAI,CAAC,kBAAkB;AACrB,SAAO;;CAGT,MAAM,qBAAqB,oCACzB,SACA;EACE,GAAG;EACH,YAAY;EACb,EACD,EAAE,oBAAoB,MAAM,CAC7B;AACD,KAAI,CAAC,oBAAoB;AACvB,SAAO;;CAGT,MAAM,MAAM,IAAI,KAAsB;CACtC,MAAM,eAAe,IAAI,IAAY,CAAC,SAAS,CAAC;CAChD,MAAM,yBAAyB,IAAI,KAAa;AAEhD,MAAK,MAAM,WAAW,mBAAmB,SAAS;EAChD,MAAM,WAAW,OAAO,mBACtB,QACA,UACA,SACA,OACA,KACD;AACD,MAAI,CAAC,UAAU;AACb,UAAO;;AAGT,MACE,CAAC,wBAAwB,KAAK,kBAAkB,QAAQ,OAAO,SAAS,EACxE;AACA,UAAO;;AAGT,WAAS,aAAa,SAAS,SAAS,aAAa,IAAI,KAAK,CAAC;AAC/D,WAAS,wBAAwB,SAAS,SACxC,uBAAuB,IAAI,KAAK,CACjC;;CAGH,MAAM,QAAQ,8BACZ,MACA,UACA;EACE,KAAK,iBAAiB;EACtB,OAAO,iBAAiB;EACzB,EACD,KACA,kBAAkB,OAAO,CAC1B;AACD,QAAO,6BAA6B,MAAM,GACtC;EACE,UAAU;EACV,cAAc,CAAC,GAAG,aAAa;EAC/B,wBAAwB,CAAC,GAAG,uBAAuB;EACnD;EACD,GACD","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type { Expression, Program } from 'oxc-parser';\n\nimport {\n evaluateOxcStaticExpressionAt,\n isOxcStaticSerializableValue,\n} from '../../../utils/collectOxcTemplateDependencies';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport { getStaticBindings } from './environment';\nimport { bindStaticResolvedValue, unwrapExpression } from './staticExpression';\nimport { collectStaticExpressionDependencies } from './staticExpressionDependencies';\nimport type {\n ExportTarget,\n ResolveStaticImportValue,\n StaticExportResult,\n} from './types';\n\nexport const zeroArgFunctionReturnExpression = (\n expression: Expression\n): Expression | null => {\n const unwrapped = unwrapExpression(expression);\n if (\n unwrapped.type !== 'ArrowFunctionExpression' &&\n unwrapped.type !== 'FunctionExpression'\n ) {\n return null;\n }\n\n if (unwrapped.async || unwrapped.params.length !== 0 || !unwrapped.body) {\n return null;\n }\n\n if (unwrapped.body.type !== 'BlockStatement') {\n return unwrapped.body as Expression;\n }\n\n if (unwrapped.body.body.length !== 1) {\n return null;\n }\n\n const [statement] = unwrapped.body.body;\n return statement?.type === 'ReturnStatement' && statement.argument\n ? statement.argument\n : null;\n};\n\nexport function* resolveZeroArgFunctionStaticExport(\n action: ITransformAction,\n filename: string,\n code: string,\n program: Program,\n target: Extract<ExportTarget, { kind: 'expression' }>,\n stack: Set<string>,\n memo: Map<string, StaticExportResult | null>,\n resolveImportValue: ResolveStaticImportValue\n): SyncScenarioFor<StaticExportResult | null> {\n const returnExpression = zeroArgFunctionReturnExpression(target.expression);\n if (!returnExpression) {\n return null;\n }\n\n const staticDependencies = collectStaticExpressionDependencies(\n program,\n {\n ...target,\n expression: returnExpression,\n },\n { allowMetadataCalls: true }\n );\n if (!staticDependencies) {\n return null;\n }\n\n const env = new Map<string, unknown>();\n const dependencies = new Set<string>([filename]);\n const sideEffectDependencies = new Set<string>();\n\n for (const binding of staticDependencies.imports) {\n const resolved = yield* resolveImportValue(\n action,\n filename,\n binding,\n stack,\n memo\n );\n if (!resolved) {\n return null;\n }\n\n if (\n !bindStaticResolvedValue(env, returnExpression, binding.local, resolved)\n ) {\n return null;\n }\n\n resolved.dependencies.forEach((item) => dependencies.add(item));\n resolved.sideEffectDependencies?.forEach((item) =>\n sideEffectDependencies.add(item)\n );\n }\n\n const value = evaluateOxcStaticExpressionAt(\n code,\n filename,\n {\n end: returnExpression.end,\n start: returnExpression.start,\n },\n env,\n getStaticBindings(action)\n );\n return isOxcStaticSerializableValue(value)\n ? {\n callable: 'zero-arg',\n dependencies: [...dependencies],\n sideEffectDependencies: [...sideEffectDependencies],\n value,\n }\n : null;\n}\n"],"file":"zeroArgFunctionStaticExport.js"}
|