@wyw-in-js/transform 1.1.0 → 2.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (801) hide show
  1. package/esm/cache.js +433 -289
  2. package/esm/cache.js.map +1 -1
  3. package/esm/debug/fileReporter.js +171 -134
  4. package/esm/debug/fileReporter.js.map +1 -1
  5. package/esm/eval/broker.js +2275 -0
  6. package/esm/eval/broker.js.map +1 -0
  7. package/esm/eval/lru.js +36 -0
  8. package/esm/eval/lru.js.map +1 -0
  9. package/esm/eval/prepareModuleOnDemand.js +21 -0
  10. package/esm/eval/prepareModuleOnDemand.js.map +1 -0
  11. package/esm/eval/protocol.js +2 -0
  12. package/esm/eval/protocol.js.map +1 -0
  13. package/esm/eval/runner.js +1878 -0
  14. package/esm/eval/runner.js.map +1 -0
  15. package/esm/eval/serialize.js +333 -0
  16. package/esm/eval/serialize.js.map +1 -0
  17. package/esm/eval/writeQueue.js +81 -0
  18. package/esm/eval/writeQueue.js.map +1 -0
  19. package/esm/evaluators/index.js +11 -12
  20. package/esm/evaluators/index.js.map +1 -1
  21. package/esm/index.js +25 -29
  22. package/esm/index.js.map +1 -1
  23. package/esm/module.js +923 -520
  24. package/esm/module.js.map +1 -1
  25. package/esm/shaker.js +14 -80
  26. package/esm/shaker.js.map +1 -1
  27. package/esm/transform/BaseEntrypoint.js +162 -164
  28. package/esm/transform/BaseEntrypoint.js.map +1 -1
  29. package/esm/transform/Entrypoint.helpers.js +96 -253
  30. package/esm/transform/Entrypoint.helpers.js.map +1 -1
  31. package/esm/transform/Entrypoint.js +336 -270
  32. package/esm/transform/Entrypoint.js.map +1 -1
  33. package/esm/transform/Entrypoint.types.js +1 -1
  34. package/esm/transform/Entrypoint.types.js.map +1 -1
  35. package/esm/transform/EvaluatedEntrypoint.js +10 -4
  36. package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
  37. package/esm/transform/actions/AbortError.js +6 -6
  38. package/esm/transform/actions/AbortError.js.map +1 -1
  39. package/esm/transform/actions/BaseAction.js +140 -136
  40. package/esm/transform/actions/BaseAction.js.map +1 -1
  41. package/esm/transform/actions/UnprocessedEntrypointError.js +6 -6
  42. package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
  43. package/esm/transform/actions/actionRunner.js +63 -66
  44. package/esm/transform/actions/actionRunner.js.map +1 -1
  45. package/esm/transform/actions/types.js +1 -1
  46. package/esm/transform/actions/types.js.map +1 -1
  47. package/esm/transform/barrelManifest.types.js +2 -0
  48. package/esm/transform/barrelManifest.types.js.map +1 -0
  49. package/esm/transform/generators/baseProcessingHandlers.js +15 -17
  50. package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
  51. package/esm/transform/generators/collect.js +27 -55
  52. package/esm/transform/generators/collect.js.map +1 -1
  53. package/esm/transform/generators/createStylisPreprocessor.js +353 -321
  54. package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
  55. package/esm/transform/generators/evalFile.js +48 -47
  56. package/esm/transform/generators/evalFile.js.map +1 -1
  57. package/esm/transform/generators/extract.js +78 -90
  58. package/esm/transform/generators/extract.js.map +1 -1
  59. package/esm/transform/generators/getExports.js +57 -74
  60. package/esm/transform/generators/getExports.js.map +1 -1
  61. package/esm/transform/generators/index.js +11 -11
  62. package/esm/transform/generators/index.js.map +1 -1
  63. package/esm/transform/generators/processEntrypoint.js +93 -67
  64. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  65. package/esm/transform/generators/processImports.js +102 -67
  66. package/esm/transform/generators/processImports.js.map +1 -1
  67. package/esm/transform/generators/resolveImports.js +212 -197
  68. package/esm/transform/generators/resolveImports.js.map +1 -1
  69. package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  70. package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
  71. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
  72. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
  73. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
  74. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
  75. package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
  76. package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
  77. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
  78. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
  79. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
  80. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
  81. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
  82. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
  83. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
  84. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
  85. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
  86. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
  87. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
  88. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
  89. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
  90. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
  91. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
  92. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
  93. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
  94. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
  95. package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
  96. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
  97. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
  98. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
  99. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
  100. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
  101. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
  102. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
  103. package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
  104. package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
  105. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
  106. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
  107. package/esm/transform/generators/resolveStaticOxcValues.js +2 -0
  108. package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -0
  109. package/esm/transform/generators/rewriteOxcBarrelImports.js +822 -0
  110. package/esm/transform/generators/rewriteOxcBarrelImports.js.map +1 -0
  111. package/esm/transform/generators/transform.js +251 -248
  112. package/esm/transform/generators/transform.js.map +1 -1
  113. package/esm/transform/generators/workflow.js +87 -90
  114. package/esm/transform/generators/workflow.js.map +1 -1
  115. package/esm/transform/helpers/loadWywOptions.js +183 -74
  116. package/esm/transform/helpers/loadWywOptions.js.map +1 -1
  117. package/esm/transform/helpers/withDefaultServices.js +13 -22
  118. package/esm/transform/helpers/withDefaultServices.js.map +1 -1
  119. package/esm/transform/isStaticallyEvaluatableModule.js +140 -152
  120. package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -1
  121. package/esm/transform/oxcBarrelManifest.js +349 -0
  122. package/esm/transform/oxcBarrelManifest.js.map +1 -0
  123. package/esm/transform/rootLog.js +3 -3
  124. package/esm/transform/rootLog.js.map +1 -1
  125. package/esm/transform/syntax.js +2 -0
  126. package/esm/transform/syntax.js.map +1 -0
  127. package/esm/transform/types.js +2 -2
  128. package/esm/transform/types.js.map +1 -1
  129. package/esm/transform.js +125 -147
  130. package/esm/transform.js.map +1 -1
  131. package/esm/types.js +4 -1
  132. package/esm/types.js.map +1 -1
  133. package/esm/utils/EventEmitter.js +79 -48
  134. package/esm/utils/EventEmitter.js.map +1 -1
  135. package/esm/utils/ShakerMetadata.js +2 -2
  136. package/esm/utils/ShakerMetadata.js.map +1 -1
  137. package/esm/utils/TransformDiagnostics.js +9 -9
  138. package/esm/utils/TransformDiagnostics.js.map +1 -1
  139. package/esm/utils/TransformMetadata.js +24 -26
  140. package/esm/utils/TransformMetadata.js.map +1 -1
  141. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
  142. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
  143. package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
  144. package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
  145. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
  146. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
  147. package/esm/utils/applyOxcProcessors/displayName.js +93 -0
  148. package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
  149. package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
  150. package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
  151. package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
  152. package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
  153. package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
  154. package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
  155. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
  156. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
  157. package/esm/utils/applyOxcProcessors/shared.js +29 -0
  158. package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
  159. package/esm/utils/applyOxcProcessors/types.js +2 -0
  160. package/esm/utils/applyOxcProcessors/types.js.map +1 -0
  161. package/esm/utils/applyOxcProcessors.js +2 -0
  162. package/esm/utils/applyOxcProcessors.js.map +1 -0
  163. package/esm/utils/collectOxcExportsAndImports.js +934 -0
  164. package/esm/utils/collectOxcExportsAndImports.js.map +1 -0
  165. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
  166. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
  167. package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
  168. package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
  169. package/esm/utils/collectOxcRuntime/types.js +2 -0
  170. package/esm/utils/collectOxcRuntime/types.js.map +1 -0
  171. package/esm/utils/collectOxcRuntime.js +32 -0
  172. package/esm/utils/collectOxcRuntime.js.map +1 -0
  173. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
  174. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
  175. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
  176. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
  177. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
  178. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
  179. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
  180. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
  181. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
  182. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
  183. package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
  184. package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
  185. package/esm/utils/collectOxcTemplateDependencies.js +4 -0
  186. package/esm/utils/collectOxcTemplateDependencies.js.map +1 -0
  187. package/esm/utils/dispose-polyfill.js +3 -4
  188. package/esm/utils/dispose-polyfill.js.map +1 -1
  189. package/esm/utils/getFileIdx.js +6 -6
  190. package/esm/utils/getFileIdx.js.map +1 -1
  191. package/esm/utils/getPluginKey.js +12 -12
  192. package/esm/utils/getPluginKey.js.map +1 -1
  193. package/esm/utils/getVisitorKeys.js +9 -3
  194. package/esm/utils/getVisitorKeys.js.map +1 -1
  195. package/esm/utils/hasCachedWywPrevalExport.js +23 -0
  196. package/esm/utils/hasCachedWywPrevalExport.js.map +1 -0
  197. package/esm/utils/hasWywPreval.js +5 -5
  198. package/esm/utils/hasWywPreval.js.map +1 -1
  199. package/esm/utils/importOverrides.js +75 -90
  200. package/esm/utils/importOverrides.js.map +1 -1
  201. package/esm/utils/isNode.js +2 -2
  202. package/esm/utils/isNode.js.map +1 -1
  203. package/esm/utils/isNotNull.js +2 -2
  204. package/esm/utils/isNotNull.js.map +1 -1
  205. package/esm/utils/isSerializable.js +11 -11
  206. package/esm/utils/isSerializable.js.map +1 -1
  207. package/esm/utils/nativeResolver.js +93 -0
  208. package/esm/utils/nativeResolver.js.map +1 -0
  209. package/esm/utils/oxc/ast.js +28 -0
  210. package/esm/utils/oxc/ast.js.map +1 -0
  211. package/esm/utils/oxc/parse.js +3 -0
  212. package/esm/utils/oxc/parse.js.map +1 -0
  213. package/esm/utils/oxc/replacements.js +14 -0
  214. package/esm/utils/oxc/replacements.js.map +1 -0
  215. package/esm/utils/oxc/sourceLocations.js +59 -0
  216. package/esm/utils/oxc/sourceLocations.js.map +1 -0
  217. package/esm/utils/oxcAstService.js +121 -0
  218. package/esm/utils/oxcAstService.js.map +1 -0
  219. package/esm/utils/oxcEmit.js +447 -0
  220. package/esm/utils/oxcEmit.js.map +1 -0
  221. package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
  222. package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
  223. package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
  224. package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
  225. package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
  226. package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
  227. package/esm/utils/oxcPreevalStage/processors.js +17 -0
  228. package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
  229. package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
  230. package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
  231. package/esm/utils/oxcPreevalStage/types.js +2 -0
  232. package/esm/utils/oxcPreevalStage/types.js.map +1 -0
  233. package/esm/utils/oxcPreevalStage.js +41 -0
  234. package/esm/utils/oxcPreevalStage.js.map +1 -0
  235. package/esm/utils/oxcPreevalTransforms.js +1065 -0
  236. package/esm/utils/oxcPreevalTransforms.js.map +1 -0
  237. package/esm/utils/oxcShaker.js +662 -0
  238. package/esm/utils/oxcShaker.js.map +1 -0
  239. package/esm/utils/parseOxc.js +37 -0
  240. package/esm/utils/parseOxc.js.map +1 -0
  241. package/esm/utils/parseRequest.js +27 -27
  242. package/esm/utils/parseRequest.js.map +1 -1
  243. package/esm/utils/peek.js +1 -1
  244. package/esm/utils/peek.js.map +1 -1
  245. package/esm/utils/processorLookup.js +125 -0
  246. package/esm/utils/processorLookup.js.map +1 -0
  247. package/esm/utils/processorStaticSemantics.js +157 -0
  248. package/esm/utils/processorStaticSemantics.js.map +1 -0
  249. package/esm/utils/resolveWithConditions.js +99 -0
  250. package/esm/utils/resolveWithConditions.js.map +1 -0
  251. package/esm/vm/createVmContext.js +140 -141
  252. package/esm/vm/createVmContext.js.map +1 -1
  253. package/esm/vm/process.js +11 -13
  254. package/esm/vm/process.js.map +1 -1
  255. package/package.json +19 -26
  256. package/types/cache.d.ts +17 -8
  257. package/types/cache.js +245 -95
  258. package/types/debug/fileReporter.js +68 -23
  259. package/types/eval/broker.d.ts +92 -0
  260. package/types/eval/broker.js +2411 -0
  261. package/types/eval/lru.d.ts +10 -0
  262. package/types/eval/lru.js +36 -0
  263. package/types/eval/prepareModuleOnDemand.d.ts +7 -0
  264. package/types/eval/prepareModuleOnDemand.js +24 -0
  265. package/types/eval/protocol.d.ts +111 -0
  266. package/types/eval/protocol.js +1 -0
  267. package/types/eval/serialize.d.ts +78 -0
  268. package/types/eval/serialize.js +357 -0
  269. package/types/eval/writeQueue.d.ts +13 -0
  270. package/types/eval/writeQueue.js +80 -0
  271. package/types/evaluators/index.d.ts +2 -2
  272. package/types/evaluators/index.js +6 -9
  273. package/types/index.d.ts +3 -6
  274. package/types/index.js +24 -82
  275. package/types/module.d.ts +38 -7
  276. package/types/module.js +613 -192
  277. package/types/shaker.d.ts +2 -10
  278. package/types/shaker.js +10 -100
  279. package/types/transform/BaseEntrypoint.js +6 -11
  280. package/types/transform/Entrypoint.d.ts +15 -15
  281. package/types/transform/Entrypoint.helpers.d.ts +2 -5
  282. package/types/transform/Entrypoint.helpers.js +43 -203
  283. package/types/transform/Entrypoint.js +130 -53
  284. package/types/transform/Entrypoint.types.d.ts +31 -6
  285. package/types/transform/Entrypoint.types.js +1 -2
  286. package/types/transform/EvaluatedEntrypoint.d.ts +13 -2
  287. package/types/transform/EvaluatedEntrypoint.js +7 -6
  288. package/types/transform/actions/AbortError.js +2 -7
  289. package/types/transform/actions/BaseAction.js +4 -8
  290. package/types/transform/actions/UnprocessedEntrypointError.js +2 -7
  291. package/types/transform/actions/actionRunner.js +8 -12
  292. package/types/transform/actions/types.d.ts +2 -2
  293. package/types/transform/actions/types.js +1 -2
  294. package/types/transform/{barrelManifest.d.ts → barrelManifest.types.d.ts} +0 -2
  295. package/types/transform/barrelManifest.types.js +1 -0
  296. package/types/transform/generators/baseProcessingHandlers.d.ts +4 -5
  297. package/types/transform/generators/baseProcessingHandlers.js +10 -14
  298. package/types/transform/generators/collect.js +13 -39
  299. package/types/transform/generators/createStylisPreprocessor.js +19 -60
  300. package/types/transform/generators/evalFile.d.ts +2 -2
  301. package/types/transform/generators/evalFile.js +26 -28
  302. package/types/transform/generators/extract.js +5 -8
  303. package/types/transform/generators/getExports.js +23 -30
  304. package/types/transform/generators/index.d.ts +2 -2
  305. package/types/transform/generators/index.js +11 -14
  306. package/types/transform/generators/processEntrypoint.d.ts +2 -2
  307. package/types/transform/generators/processEntrypoint.js +60 -26
  308. package/types/transform/generators/processImports.d.ts +0 -3
  309. package/types/transform/generators/processImports.js +60 -20
  310. package/types/transform/generators/resolveImports.d.ts +3 -1
  311. package/types/transform/generators/resolveImports.js +66 -23
  312. package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
  313. package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  314. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
  315. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
  316. package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
  317. package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
  318. package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
  319. package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
  320. package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
  321. package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
  322. package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
  323. package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
  324. package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
  325. package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
  326. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
  327. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
  328. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
  329. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
  330. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
  331. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
  332. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
  333. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
  334. package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
  335. package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
  336. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
  337. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
  338. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
  339. package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
  340. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
  341. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
  342. package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
  343. package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
  344. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
  345. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
  346. package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
  347. package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
  348. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
  349. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
  350. package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -0
  351. package/types/transform/generators/resolveStaticOxcValues.js +1 -0
  352. package/types/transform/generators/{rewriteBarrelImports.d.ts → rewriteOxcBarrelImports.d.ts} +2 -3
  353. package/types/transform/generators/{rewriteBarrelImports.js → rewriteOxcBarrelImports.js} +282 -225
  354. package/types/transform/generators/transform.d.ts +3 -7
  355. package/types/transform/generators/transform.js +217 -199
  356. package/types/transform/generators/workflow.js +62 -45
  357. package/types/transform/helpers/loadWywOptions.js +115 -21
  358. package/types/transform/helpers/withDefaultServices.d.ts +1 -1
  359. package/types/transform/helpers/withDefaultServices.js +6 -44
  360. package/types/transform/isStaticallyEvaluatableModule.d.ts +1 -2
  361. package/types/transform/isStaticallyEvaluatableModule.js +125 -126
  362. package/types/transform/oxcBarrelManifest.d.ts +2 -0
  363. package/types/transform/{barrelManifest.js → oxcBarrelManifest.js} +156 -97
  364. package/types/transform/rootLog.js +2 -5
  365. package/types/transform/syntax.d.ts +38 -0
  366. package/types/transform/syntax.js +1 -0
  367. package/types/transform/types.d.ts +9 -6
  368. package/types/transform/types.js +1 -4
  369. package/types/transform.d.ts +2 -2
  370. package/types/transform.js +90 -101
  371. package/types/types.d.ts +0 -23
  372. package/types/types.js +1 -2
  373. package/types/utils/EventEmitter.d.ts +16 -1
  374. package/types/utils/EventEmitter.js +47 -18
  375. package/types/utils/ShakerMetadata.js +1 -5
  376. package/types/utils/TransformDiagnostics.js +3 -7
  377. package/types/utils/TransformMetadata.js +8 -16
  378. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
  379. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
  380. package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
  381. package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
  382. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
  383. package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
  384. package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
  385. package/types/utils/applyOxcProcessors/displayName.js +113 -0
  386. package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
  387. package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
  388. package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
  389. package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
  390. package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
  391. package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
  392. package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
  393. package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
  394. package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
  395. package/types/utils/applyOxcProcessors/shared.js +37 -0
  396. package/types/utils/applyOxcProcessors/types.d.ts +88 -0
  397. package/types/utils/applyOxcProcessors/types.js +1 -0
  398. package/types/utils/applyOxcProcessors.d.ts +1 -0
  399. package/types/utils/applyOxcProcessors.js +1 -0
  400. package/types/utils/collectOxcExportsAndImports.d.ts +35 -0
  401. package/types/utils/collectOxcExportsAndImports.js +957 -0
  402. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
  403. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
  404. package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
  405. package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
  406. package/types/utils/collectOxcRuntime/types.d.ts +16 -0
  407. package/types/utils/collectOxcRuntime/types.js +1 -0
  408. package/types/utils/collectOxcRuntime.d.ts +4 -0
  409. package/types/utils/collectOxcRuntime.js +31 -0
  410. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
  411. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
  412. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
  413. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
  414. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
  415. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
  416. package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
  417. package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
  418. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
  419. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
  420. package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
  421. package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
  422. package/types/utils/collectOxcTemplateDependencies.d.ts +4 -0
  423. package/types/utils/collectOxcTemplateDependencies.js +3 -0
  424. package/types/utils/getFileIdx.js +1 -4
  425. package/types/utils/getPluginKey.d.ts +5 -2
  426. package/types/utils/getPluginKey.js +2 -6
  427. package/types/utils/getVisitorKeys.d.ts +4 -4
  428. package/types/utils/getVisitorKeys.js +9 -6
  429. package/types/utils/hasCachedWywPrevalExport.d.ts +14 -0
  430. package/types/utils/hasCachedWywPrevalExport.js +30 -0
  431. package/types/utils/hasWywPreval.js +1 -4
  432. package/types/utils/importOverrides.js +17 -27
  433. package/types/utils/isNode.d.ts +2 -2
  434. package/types/utils/isNode.js +2 -6
  435. package/types/utils/isNotNull.js +1 -4
  436. package/types/utils/isSerializable.js +3 -6
  437. package/types/utils/nativeResolver.d.ts +13 -0
  438. package/types/utils/nativeResolver.js +91 -0
  439. package/types/utils/oxc/ast.d.ts +4 -0
  440. package/types/utils/oxc/ast.js +37 -0
  441. package/types/utils/oxc/parse.d.ts +3 -0
  442. package/types/utils/oxc/parse.js +2 -0
  443. package/types/utils/oxc/replacements.d.ts +12 -0
  444. package/types/utils/oxc/replacements.js +18 -0
  445. package/types/utils/oxc/sourceLocations.d.ts +5 -0
  446. package/types/utils/oxc/sourceLocations.js +63 -0
  447. package/types/utils/oxcAstService.d.ts +11 -0
  448. package/types/utils/oxcAstService.js +79 -0
  449. package/types/utils/oxcEmit.d.ts +19 -0
  450. package/types/utils/oxcEmit.js +506 -0
  451. package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
  452. package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
  453. package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
  454. package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
  455. package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
  456. package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
  457. package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
  458. package/types/utils/oxcPreevalStage/processors.js +16 -0
  459. package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
  460. package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
  461. package/types/utils/oxcPreevalStage/types.d.ts +22 -0
  462. package/types/utils/oxcPreevalStage/types.js +1 -0
  463. package/types/utils/oxcPreevalStage.d.ts +4 -0
  464. package/types/utils/oxcPreevalStage.js +40 -0
  465. package/types/utils/oxcPreevalTransforms.d.ts +13 -0
  466. package/types/utils/oxcPreevalTransforms.js +1192 -0
  467. package/types/utils/oxcShaker.d.ts +13 -0
  468. package/types/utils/oxcShaker.js +751 -0
  469. package/types/utils/parseOxc.d.ts +11 -0
  470. package/types/utils/parseOxc.js +38 -0
  471. package/types/utils/parseRequest.js +2 -7
  472. package/types/utils/peek.js +1 -5
  473. package/types/utils/processorLookup.d.ts +8 -0
  474. package/types/utils/processorLookup.js +135 -0
  475. package/types/utils/processorStaticSemantics.d.ts +13 -0
  476. package/types/utils/processorStaticSemantics.js +191 -0
  477. package/types/utils/resolveWithConditions.d.ts +12 -0
  478. package/types/utils/resolveWithConditions.js +103 -0
  479. package/types/vm/createVmContext.d.ts +2 -2
  480. package/types/vm/createVmContext.js +25 -62
  481. package/types/vm/process.js +20 -26
  482. package/esm/babel.js +0 -2
  483. package/esm/babel.js.map +0 -1
  484. package/esm/options/buildOptions.js +0 -168
  485. package/esm/options/buildOptions.js.map +0 -1
  486. package/esm/options/buildOptions.test.js +0 -138
  487. package/esm/options/buildOptions.test.js.map +0 -1
  488. package/esm/options/loadBabelOptions.js +0 -24
  489. package/esm/options/loadBabelOptions.js.map +0 -1
  490. package/esm/plugins/babel-transform.js +0 -53
  491. package/esm/plugins/babel-transform.js.map +0 -1
  492. package/esm/plugins/collector.js +0 -60
  493. package/esm/plugins/collector.js.map +0 -1
  494. package/esm/plugins/dynamic-import.js +0 -56
  495. package/esm/plugins/dynamic-import.js.map +0 -1
  496. package/esm/plugins/preeval.js +0 -73
  497. package/esm/plugins/preeval.js.map +0 -1
  498. package/esm/plugins/shaker.js +0 -680
  499. package/esm/plugins/shaker.js.map +0 -1
  500. package/esm/transform/barrelManifest.js +0 -291
  501. package/esm/transform/barrelManifest.js.map +0 -1
  502. package/esm/transform/generators/explodeReexports.js +0 -64
  503. package/esm/transform/generators/explodeReexports.js.map +0 -1
  504. package/esm/transform/generators/rewriteBarrelImports.js +0 -733
  505. package/esm/transform/generators/rewriteBarrelImports.js.map +0 -1
  506. package/esm/utils/addIdentifierToWywPreval.js +0 -68
  507. package/esm/utils/addIdentifierToWywPreval.js.map +0 -1
  508. package/esm/utils/collectExportsAndImports.js +0 -1157
  509. package/esm/utils/collectExportsAndImports.js.map +0 -1
  510. package/esm/utils/collectTemplateDependencies.js +0 -228
  511. package/esm/utils/collectTemplateDependencies.js.map +0 -1
  512. package/esm/utils/createId.js +0 -6
  513. package/esm/utils/createId.js.map +0 -1
  514. package/esm/utils/findIdentifiers.js +0 -62
  515. package/esm/utils/findIdentifiers.js.map +0 -1
  516. package/esm/utils/getConstantStringValue.js +0 -58
  517. package/esm/utils/getConstantStringValue.js.map +0 -1
  518. package/esm/utils/getMemberExpressionPropertyName.js +0 -11
  519. package/esm/utils/getMemberExpressionPropertyName.js.map +0 -1
  520. package/esm/utils/getScope.js +0 -6
  521. package/esm/utils/getScope.js.map +0 -1
  522. package/esm/utils/getSource.js +0 -15
  523. package/esm/utils/getSource.js.map +0 -1
  524. package/esm/utils/getTagProcessor.js +0 -404
  525. package/esm/utils/getTagProcessor.js.map +0 -1
  526. package/esm/utils/isExports.js +0 -22
  527. package/esm/utils/isExports.js.map +0 -1
  528. package/esm/utils/isGlobal.js +0 -6
  529. package/esm/utils/isGlobal.js.map +0 -1
  530. package/esm/utils/isNodePath.js +0 -4
  531. package/esm/utils/isNodePath.js.map +0 -1
  532. package/esm/utils/isRemoved.js +0 -46
  533. package/esm/utils/isRemoved.js.map +0 -1
  534. package/esm/utils/isRequire.js +0 -13
  535. package/esm/utils/isRequire.js.map +0 -1
  536. package/esm/utils/isTypedNode.js +0 -6
  537. package/esm/utils/isTypedNode.js.map +0 -1
  538. package/esm/utils/isUnnecessaryReactCall.js +0 -72
  539. package/esm/utils/isUnnecessaryReactCall.js.map +0 -1
  540. package/esm/utils/removeDangerousCode.js +0 -276
  541. package/esm/utils/removeDangerousCode.js.map +0 -1
  542. package/esm/utils/replaceImportMetaEnv.js +0 -44
  543. package/esm/utils/replaceImportMetaEnv.js.map +0 -1
  544. package/esm/utils/scopeHelpers.js +0 -527
  545. package/esm/utils/scopeHelpers.js.map +0 -1
  546. package/esm/utils/traversalCache.js +0 -23
  547. package/esm/utils/traversalCache.js.map +0 -1
  548. package/esm/utils/unwrapExpression.js +0 -18
  549. package/esm/utils/unwrapExpression.js.map +0 -1
  550. package/esm/utils/unwrapSequence.js +0 -14
  551. package/esm/utils/unwrapSequence.js.map +0 -1
  552. package/esm/utils/valueToLiteral.js +0 -59
  553. package/esm/utils/valueToLiteral.js.map +0 -1
  554. package/esm/utils/visitors/JSXElementsRemover.js +0 -51
  555. package/esm/utils/visitors/JSXElementsRemover.js.map +0 -1
  556. package/lib/babel.js +0 -2
  557. package/lib/babel.js.map +0 -1
  558. package/lib/cache.js +0 -308
  559. package/lib/cache.js.map +0 -1
  560. package/lib/debug/fileReporter.js +0 -153
  561. package/lib/debug/fileReporter.js.map +0 -1
  562. package/lib/evaluators/index.js +0 -20
  563. package/lib/evaluators/index.js.map +0 -1
  564. package/lib/index.js +0 -286
  565. package/lib/index.js.map +0 -1
  566. package/lib/module.js +0 -552
  567. package/lib/module.js.map +0 -1
  568. package/lib/options/buildOptions.js +0 -176
  569. package/lib/options/buildOptions.js.map +0 -1
  570. package/lib/options/buildOptions.test.js +0 -141
  571. package/lib/options/buildOptions.test.js.map +0 -1
  572. package/lib/options/loadBabelOptions.js +0 -31
  573. package/lib/options/loadBabelOptions.js.map +0 -1
  574. package/lib/plugins/babel-transform.js +0 -60
  575. package/lib/plugins/babel-transform.js.map +0 -1
  576. package/lib/plugins/collector.js +0 -70
  577. package/lib/plugins/collector.js.map +0 -1
  578. package/lib/plugins/dynamic-import.js +0 -61
  579. package/lib/plugins/dynamic-import.js.map +0 -1
  580. package/lib/plugins/preeval.js +0 -81
  581. package/lib/plugins/preeval.js.map +0 -1
  582. package/lib/plugins/shaker.js +0 -691
  583. package/lib/plugins/shaker.js.map +0 -1
  584. package/lib/shaker.js +0 -95
  585. package/lib/shaker.js.map +0 -1
  586. package/lib/transform/BaseEntrypoint.js +0 -179
  587. package/lib/transform/BaseEntrypoint.js.map +0 -1
  588. package/lib/transform/Entrypoint.helpers.js +0 -279
  589. package/lib/transform/Entrypoint.helpers.js.map +0 -1
  590. package/lib/transform/Entrypoint.js +0 -289
  591. package/lib/transform/Entrypoint.js.map +0 -1
  592. package/lib/transform/Entrypoint.types.js +0 -2
  593. package/lib/transform/Entrypoint.types.js.map +0 -1
  594. package/lib/transform/EvaluatedEntrypoint.js +0 -13
  595. package/lib/transform/EvaluatedEntrypoint.js.map +0 -1
  596. package/lib/transform/actions/AbortError.js +0 -16
  597. package/lib/transform/actions/AbortError.js.map +0 -1
  598. package/lib/transform/actions/BaseAction.js +0 -150
  599. package/lib/transform/actions/BaseAction.js.map +0 -1
  600. package/lib/transform/actions/UnprocessedEntrypointError.js +0 -16
  601. package/lib/transform/actions/UnprocessedEntrypointError.js.map +0 -1
  602. package/lib/transform/actions/actionRunner.js +0 -82
  603. package/lib/transform/actions/actionRunner.js.map +0 -1
  604. package/lib/transform/actions/types.js +0 -2
  605. package/lib/transform/actions/types.js.map +0 -1
  606. package/lib/transform/barrelManifest.js +0 -300
  607. package/lib/transform/barrelManifest.js.map +0 -1
  608. package/lib/transform/generators/baseProcessingHandlers.js +0 -27
  609. package/lib/transform/generators/baseProcessingHandlers.js.map +0 -1
  610. package/lib/transform/generators/collect.js +0 -66
  611. package/lib/transform/generators/collect.js.map +0 -1
  612. package/lib/transform/generators/createStylisPreprocessor.js +0 -372
  613. package/lib/transform/generators/createStylisPreprocessor.js.map +0 -1
  614. package/lib/transform/generators/evalFile.js +0 -57
  615. package/lib/transform/generators/evalFile.js.map +0 -1
  616. package/lib/transform/generators/explodeReexports.js +0 -71
  617. package/lib/transform/generators/explodeReexports.js.map +0 -1
  618. package/lib/transform/generators/extract.js +0 -102
  619. package/lib/transform/generators/extract.js.map +0 -1
  620. package/lib/transform/generators/getExports.js +0 -85
  621. package/lib/transform/generators/getExports.js.map +0 -1
  622. package/lib/transform/generators/index.js +0 -19
  623. package/lib/transform/generators/index.js.map +0 -1
  624. package/lib/transform/generators/processEntrypoint.js +0 -76
  625. package/lib/transform/generators/processEntrypoint.js.map +0 -1
  626. package/lib/transform/generators/processImports.js +0 -82
  627. package/lib/transform/generators/processImports.js.map +0 -1
  628. package/lib/transform/generators/resolveImports.js +0 -221
  629. package/lib/transform/generators/resolveImports.js.map +0 -1
  630. package/lib/transform/generators/rewriteBarrelImports.js +0 -743
  631. package/lib/transform/generators/rewriteBarrelImports.js.map +0 -1
  632. package/lib/transform/generators/transform.js +0 -272
  633. package/lib/transform/generators/transform.js.map +0 -1
  634. package/lib/transform/generators/workflow.js +0 -100
  635. package/lib/transform/generators/workflow.js.map +0 -1
  636. package/lib/transform/helpers/loadWywOptions.js +0 -88
  637. package/lib/transform/helpers/loadWywOptions.js.map +0 -1
  638. package/lib/transform/helpers/withDefaultServices.js +0 -31
  639. package/lib/transform/helpers/withDefaultServices.js.map +0 -1
  640. package/lib/transform/isStaticallyEvaluatableModule.js +0 -159
  641. package/lib/transform/isStaticallyEvaluatableModule.js.map +0 -1
  642. package/lib/transform/rootLog.js +0 -9
  643. package/lib/transform/rootLog.js.map +0 -1
  644. package/lib/transform/types.js +0 -8
  645. package/lib/transform/types.js.map +0 -1
  646. package/lib/transform.js +0 -160
  647. package/lib/transform.js.map +0 -1
  648. package/lib/types.js +0 -2
  649. package/lib/types.js.map +0 -1
  650. package/lib/utils/EventEmitter.js +0 -61
  651. package/lib/utils/EventEmitter.js.map +0 -1
  652. package/lib/utils/ShakerMetadata.js +0 -9
  653. package/lib/utils/ShakerMetadata.js.map +0 -1
  654. package/lib/utils/TransformDiagnostics.js +0 -20
  655. package/lib/utils/TransformDiagnostics.js.map +0 -1
  656. package/lib/utils/TransformMetadata.js +0 -45
  657. package/lib/utils/TransformMetadata.js.map +0 -1
  658. package/lib/utils/addIdentifierToWywPreval.js +0 -75
  659. package/lib/utils/addIdentifierToWywPreval.js.map +0 -1
  660. package/lib/utils/collectExportsAndImports.js +0 -1173
  661. package/lib/utils/collectExportsAndImports.js.map +0 -1
  662. package/lib/utils/collectTemplateDependencies.js +0 -242
  663. package/lib/utils/collectTemplateDependencies.js.map +0 -1
  664. package/lib/utils/createId.js +0 -13
  665. package/lib/utils/createId.js.map +0 -1
  666. package/lib/utils/dispose-polyfill.js +0 -9
  667. package/lib/utils/dispose-polyfill.js.map +0 -1
  668. package/lib/utils/findIdentifiers.js +0 -73
  669. package/lib/utils/findIdentifiers.js.map +0 -1
  670. package/lib/utils/getConstantStringValue.js +0 -66
  671. package/lib/utils/getConstantStringValue.js.map +0 -1
  672. package/lib/utils/getFileIdx.js +0 -16
  673. package/lib/utils/getFileIdx.js.map +0 -1
  674. package/lib/utils/getMemberExpressionPropertyName.js +0 -18
  675. package/lib/utils/getMemberExpressionPropertyName.js.map +0 -1
  676. package/lib/utils/getPluginKey.js +0 -21
  677. package/lib/utils/getPluginKey.js.map +0 -1
  678. package/lib/utils/getScope.js +0 -12
  679. package/lib/utils/getScope.js.map +0 -1
  680. package/lib/utils/getSource.js +0 -24
  681. package/lib/utils/getSource.js.map +0 -1
  682. package/lib/utils/getTagProcessor.js +0 -424
  683. package/lib/utils/getTagProcessor.js.map +0 -1
  684. package/lib/utils/getVisitorKeys.js +0 -11
  685. package/lib/utils/getVisitorKeys.js.map +0 -1
  686. package/lib/utils/hasWywPreval.js +0 -13
  687. package/lib/utils/hasWywPreval.js.map +0 -1
  688. package/lib/utils/importOverrides.js +0 -119
  689. package/lib/utils/importOverrides.js.map +0 -1
  690. package/lib/utils/isExports.js +0 -27
  691. package/lib/utils/isExports.js.map +0 -1
  692. package/lib/utils/isGlobal.js +0 -13
  693. package/lib/utils/isGlobal.js.map +0 -1
  694. package/lib/utils/isNode.js +0 -9
  695. package/lib/utils/isNode.js.map +0 -1
  696. package/lib/utils/isNodePath.js +0 -10
  697. package/lib/utils/isNodePath.js.map +0 -1
  698. package/lib/utils/isNotNull.js +0 -10
  699. package/lib/utils/isNotNull.js.map +0 -1
  700. package/lib/utils/isRemoved.js +0 -52
  701. package/lib/utils/isRemoved.js.map +0 -1
  702. package/lib/utils/isRequire.js +0 -18
  703. package/lib/utils/isRequire.js.map +0 -1
  704. package/lib/utils/isSerializable.js +0 -19
  705. package/lib/utils/isSerializable.js.map +0 -1
  706. package/lib/utils/isTypedNode.js +0 -13
  707. package/lib/utils/isTypedNode.js.map +0 -1
  708. package/lib/utils/isUnnecessaryReactCall.js +0 -81
  709. package/lib/utils/isUnnecessaryReactCall.js.map +0 -1
  710. package/lib/utils/parseRequest.js +0 -37
  711. package/lib/utils/parseRequest.js.map +0 -1
  712. package/lib/utils/peek.js +0 -9
  713. package/lib/utils/peek.js.map +0 -1
  714. package/lib/utils/removeDangerousCode.js +0 -284
  715. package/lib/utils/removeDangerousCode.js.map +0 -1
  716. package/lib/utils/replaceImportMetaEnv.js +0 -50
  717. package/lib/utils/replaceImportMetaEnv.js.map +0 -1
  718. package/lib/utils/scopeHelpers.js +0 -557
  719. package/lib/utils/scopeHelpers.js.map +0 -1
  720. package/lib/utils/traversalCache.js +0 -31
  721. package/lib/utils/traversalCache.js.map +0 -1
  722. package/lib/utils/unwrapExpression.js +0 -25
  723. package/lib/utils/unwrapExpression.js.map +0 -1
  724. package/lib/utils/unwrapSequence.js +0 -20
  725. package/lib/utils/unwrapSequence.js.map +0 -1
  726. package/lib/utils/valueToLiteral.js +0 -65
  727. package/lib/utils/valueToLiteral.js.map +0 -1
  728. package/lib/utils/visitors/JSXElementsRemover.js +0 -57
  729. package/lib/utils/visitors/JSXElementsRemover.js.map +0 -1
  730. package/lib/vm/createVmContext.js +0 -166
  731. package/lib/vm/createVmContext.js.map +0 -1
  732. package/lib/vm/process.js +0 -38
  733. package/lib/vm/process.js.map +0 -1
  734. package/types/babel.d.ts +0 -2
  735. package/types/babel.js +0 -2
  736. package/types/options/buildOptions.d.ts +0 -6
  737. package/types/options/buildOptions.js +0 -178
  738. package/types/options/loadBabelOptions.d.ts +0 -3
  739. package/types/options/loadBabelOptions.js +0 -26
  740. package/types/plugins/babel-transform.d.ts +0 -4
  741. package/types/plugins/babel-transform.js +0 -49
  742. package/types/plugins/collector.d.ts +0 -23
  743. package/types/plugins/collector.js +0 -62
  744. package/types/plugins/dynamic-import.d.ts +0 -6
  745. package/types/plugins/dynamic-import.js +0 -60
  746. package/types/plugins/preeval.d.ts +0 -16
  747. package/types/plugins/preeval.js +0 -69
  748. package/types/plugins/shaker.d.ts +0 -14
  749. package/types/plugins/shaker.js +0 -724
  750. package/types/transform/generators/explodeReexports.d.ts +0 -7
  751. package/types/transform/generators/explodeReexports.js +0 -65
  752. package/types/utils/addIdentifierToWywPreval.d.ts +0 -4
  753. package/types/utils/addIdentifierToWywPreval.js +0 -74
  754. package/types/utils/collectExportsAndImports.d.ts +0 -31
  755. package/types/utils/collectExportsAndImports.js +0 -1147
  756. package/types/utils/collectTemplateDependencies.d.ts +0 -17
  757. package/types/utils/collectTemplateDependencies.js +0 -220
  758. package/types/utils/createId.d.ts +0 -2
  759. package/types/utils/createId.js +0 -9
  760. package/types/utils/findIdentifiers.d.ts +0 -6
  761. package/types/utils/findIdentifiers.js +0 -67
  762. package/types/utils/getConstantStringValue.d.ts +0 -2
  763. package/types/utils/getConstantStringValue.js +0 -94
  764. package/types/utils/getMemberExpressionPropertyName.d.ts +0 -2
  765. package/types/utils/getMemberExpressionPropertyName.js +0 -46
  766. package/types/utils/getScope.d.ts +0 -2
  767. package/types/utils/getScope.js +0 -10
  768. package/types/utils/getSource.d.ts +0 -2
  769. package/types/utils/getSource.js +0 -22
  770. package/types/utils/getTagProcessor.d.ts +0 -13
  771. package/types/utils/getTagProcessor.js +0 -411
  772. package/types/utils/isExports.d.ts +0 -6
  773. package/types/utils/isExports.js +0 -19
  774. package/types/utils/isGlobal.d.ts +0 -2
  775. package/types/utils/isGlobal.js +0 -9
  776. package/types/utils/isNodePath.d.ts +0 -3
  777. package/types/utils/isNodePath.js +0 -6
  778. package/types/utils/isRemoved.d.ts +0 -5
  779. package/types/utils/isRemoved.js +0 -41
  780. package/types/utils/isRequire.d.ts +0 -6
  781. package/types/utils/isRequire.js +0 -14
  782. package/types/utils/isTypedNode.d.ts +0 -5
  783. package/types/utils/isTypedNode.js +0 -9
  784. package/types/utils/isUnnecessaryReactCall.d.ts +0 -3
  785. package/types/utils/isUnnecessaryReactCall.js +0 -75
  786. package/types/utils/removeDangerousCode.d.ts +0 -4
  787. package/types/utils/removeDangerousCode.js +0 -326
  788. package/types/utils/replaceImportMetaEnv.d.ts +0 -3
  789. package/types/utils/replaceImportMetaEnv.js +0 -39
  790. package/types/utils/scopeHelpers.d.ts +0 -12
  791. package/types/utils/scopeHelpers.js +0 -580
  792. package/types/utils/traversalCache.d.ts +0 -4
  793. package/types/utils/traversalCache.js +0 -27
  794. package/types/utils/unwrapExpression.d.ts +0 -2
  795. package/types/utils/unwrapExpression.js +0 -57
  796. package/types/utils/unwrapSequence.d.ts +0 -8
  797. package/types/utils/unwrapSequence.js +0 -16
  798. package/types/utils/valueToLiteral.d.ts +0 -3
  799. package/types/utils/valueToLiteral.js +0 -63
  800. package/types/utils/visitors/JSXElementsRemover.d.ts +0 -3
  801. package/types/utils/visitors/JSXElementsRemover.js +0 -51
@@ -0,0 +1,496 @@
1
+ import { ValueType } from "@wyw-in-js/shared";
2
+ import { applyOxcReplacements } from "../oxc/replacements.js";
3
+ import { createOxcLocationLookup } from "../oxc/sourceLocations.js";
4
+ import { analyzeProgram, containsTaggedTemplateExpression, createSpanLookup, findReferences, getSourceLocation, isBindingDeclaredWithin, parseOxc, resolveBindingAt } from "./scopeAnalysis.js";
5
+ import { applyExpressionReplacements, collectIdentifierReferenceReplacements, collectStaticNamespaceMemberReferences, getConstantReplacement, replaceIdentifierReferences } from "./expressionReplacements.js";
6
+ import { cloneStaticValue, evaluateStatic, isStaticSerializableValue, literalCode } from "./staticEvaluator.js";
7
+ const allocateExpressionName = (ctx) => {
8
+ let base = "_exp";
9
+ let idx = 1;
10
+ while (ctx.usedNames.has(base)) {
11
+ idx += 1;
12
+ base = `_exp${idx}`;
13
+ }
14
+ ctx.usedNames.add(base);
15
+ return base;
16
+ };
17
+ const hoistedBindingKey = (binding) => `${binding.scope.start}:${binding.scope.end}:${binding.declaredAt}:${binding.name}`;
18
+ const allocateHoistedBindingName = (originalName, ctx) => {
19
+ const sanitized = originalName.replace(/[^A-Za-z0-9_$]/g, "_") || "hoisted";
20
+ const base = /^[A-Za-z_$]/.test(sanitized) ? `_${sanitized}` : "_hoisted";
21
+ let candidate = base;
22
+ let idx = 2;
23
+ while (ctx.usedNames.has(candidate)) {
24
+ candidate = `${base}${idx}`;
25
+ idx += 1;
26
+ }
27
+ ctx.usedNames.add(candidate);
28
+ return candidate;
29
+ };
30
+ const getHoistedBindingName = (binding, ctx) => {
31
+ const key = hoistedBindingKey(binding);
32
+ const existing = ctx.hoistedBindingNames.get(key);
33
+ if (existing) {
34
+ return existing;
35
+ }
36
+ const next = allocateHoistedBindingName(binding.name, ctx);
37
+ ctx.hoistedBindingNames.set(key, next);
38
+ return next;
39
+ };
40
+ const parenthesizeStaticReplacement = (source) => `(${source})`;
41
+ const replaceStaticLocalReferences = (expression, replacements, ctx, extraReplacements = []) => {
42
+ if (expression.type === "Identifier" && extraReplacements.length === 0) {
43
+ return replacements.get(expression.name) ?? ctx.code.slice(expression.start, expression.end);
44
+ }
45
+ const parenthesized = new Map();
46
+ replacements.forEach((value, key) => {
47
+ parenthesized.set(key, parenthesizeStaticReplacement(value));
48
+ });
49
+ return applyExpressionReplacements(expression, [...extraReplacements, ...collectIdentifierReferenceReplacements(expression, parenthesized)], ctx.code);
50
+ };
51
+ const collectStaticLocalExpression = (expression, ctx, stack = []) => {
52
+ const replacements = new Map();
53
+ const importedFrom = new Set();
54
+ const imports = [];
55
+ for (const { name, start } of findReferences(expression, ctx.referencesByNode)) {
56
+ const binding = resolveBindingAt(ctx, name, start);
57
+ if (!binding) {
58
+ return null;
59
+ }
60
+ if (binding.importedFrom) {
61
+ importedFrom.add(binding.importedFrom);
62
+ if (binding.imported && binding.imported !== "*") {
63
+ imports.push({
64
+ imported: binding.imported,
65
+ local: binding.name,
66
+ source: binding.importedFrom
67
+ });
68
+ continue;
69
+ }
70
+ return null;
71
+ }
72
+ const replacement = getConstantReplacement(binding, ctx);
73
+ if (replacement) {
74
+ replacements.set(name, replacement);
75
+ continue;
76
+ }
77
+ if (binding.kind === "param" || binding.declarationKind !== "const" || !binding.declarator?.init || binding.declarator.id.type !== "Identifier") {
78
+ return null;
79
+ }
80
+ // Processor-managed bindings (const x = css``) carry their value
81
+ // (the generated className string) via inlineConstants at candidate
82
+ // evaluation time. Walking the TaggedTemplateExpression here would
83
+ // pull the processor's tag import (e.g. `css` from '@linaria/core')
84
+ // into the candidate's static imports, where it fails to resolve.
85
+ // Leave the identifier as a free reference; the candidate-side env
86
+ // supplies the className.
87
+ if (binding.declarator.init.type === "TaggedTemplateExpression") {
88
+ continue;
89
+ }
90
+ const key = hoistedBindingKey(binding);
91
+ if (stack.includes(key)) {
92
+ return null;
93
+ }
94
+ const nested = collectStaticLocalExpression(binding.declarator.init, ctx, [...stack, key]);
95
+ if (!nested) {
96
+ return null;
97
+ }
98
+ replacements.set(name, nested.source);
99
+ nested.importedFrom.forEach((source) => importedFrom.add(source));
100
+ imports.push(...nested.imports);
101
+ }
102
+ return {
103
+ importedFrom: [...importedFrom],
104
+ imports,
105
+ source: replacements.size > 0 ? replaceStaticLocalReferences(expression, replacements, ctx) : ctx.code.slice(expression.start, expression.end)
106
+ };
107
+ };
108
+ const declarationInitCode = (init, ctx) => {
109
+ const renamedDependencies = new Map();
110
+ findReferences(init, ctx.referencesByNode).forEach(({ name, start }) => {
111
+ const dependency = resolveBindingAt(ctx, name, start);
112
+ if (!dependency || dependency.importedFrom || dependency.isRoot || dependency.declarator?.id.type !== "Identifier") {
113
+ return;
114
+ }
115
+ renamedDependencies.set(name, getHoistedBindingName(dependency, ctx));
116
+ });
117
+ return renamedDependencies.size > 0 ? replaceIdentifierReferences(init, renamedDependencies, ctx.code) : ctx.code.slice(init.start, init.end);
118
+ };
119
+ const addHoistedCode = (key, code, ctx) => {
120
+ if (ctx.hoistedDeclarations.has(key)) {
121
+ return;
122
+ }
123
+ ctx.hoistedDeclarations.set(key, code);
124
+ const declarations = ctx.hoistedDeclarationsByInsertionPoint.get(ctx.currentInsertionPoint) ?? [];
125
+ declarations.push(code);
126
+ ctx.hoistedDeclarationsByInsertionPoint.set(ctx.currentInsertionPoint, declarations);
127
+ };
128
+ const declarationCode = (binding, ctx) => {
129
+ const { declarator } = binding;
130
+ if (!declarator) {
131
+ return "";
132
+ }
133
+ const { id } = declarator;
134
+ if (id.type !== "Identifier") {
135
+ const idCode = ctx.code.slice(id.start, id.end);
136
+ if (!declarator.init) {
137
+ return `let ${idCode};`;
138
+ }
139
+ return `let ${idCode} = ${declarationInitCode(declarator.init, ctx)};`;
140
+ }
141
+ const hoistedName = getHoistedBindingName(binding, ctx);
142
+ if (!declarator.init) {
143
+ return `let ${hoistedName};`;
144
+ }
145
+ return `let ${hoistedName} = ${declarationInitCode(declarator.init, ctx)};`;
146
+ };
147
+ const assertHoistable = (binding, ctx, stack = []) => {
148
+ if (!binding.declarator?.init || binding.importedFrom || binding.isRoot) {
149
+ return;
150
+ }
151
+ if (stack.includes(binding.name)) {
152
+ return;
153
+ }
154
+ const refs = findReferences(binding.declarator.init, ctx.referencesByNode);
155
+ refs.forEach(({ name, start }) => {
156
+ const nextBinding = resolveBindingAt(ctx, name, start);
157
+ if (!nextBinding) {
158
+ return;
159
+ }
160
+ if (nextBinding.kind === "param") {
161
+ throw new Error(`This identifier cannot be used in the template, because it is a function parameter.`);
162
+ }
163
+ assertHoistable(nextBinding, ctx, [...stack, binding.name]);
164
+ });
165
+ };
166
+ const addHoistedDeclaration = (binding, ctx, stack = []) => {
167
+ if (!binding.declaration || !binding.declarator || binding.importedFrom || binding.isRoot || stack.includes(binding.name)) {
168
+ return;
169
+ }
170
+ const hoistSource = binding.declarator.init ?? binding.declarator;
171
+ findReferences(hoistSource, ctx.referencesByNode).forEach(({ name, start }) => {
172
+ const dependency = resolveBindingAt(ctx, name, start);
173
+ if (dependency) {
174
+ addHoistedDeclaration(dependency, ctx, [...stack, binding.name]);
175
+ }
176
+ });
177
+ if (!ctx.hoistedDeclarations.has(binding.name)) {
178
+ addHoistedCode(binding.name, declarationCode(binding, ctx), ctx);
179
+ }
180
+ };
181
+ const literalExpressionValue = (expression, ctx) => {
182
+ if (expression.type !== "Literal") {
183
+ return null;
184
+ }
185
+ if (expression.value !== null && typeof expression.value !== "string" && typeof expression.value !== "number" && typeof expression.value !== "boolean") {
186
+ return null;
187
+ }
188
+ let type;
189
+ if (expression.value === null) {
190
+ type = "NullLiteral";
191
+ } else if (typeof expression.value === "string") {
192
+ type = "StringLiteral";
193
+ } else if (typeof expression.value === "number") {
194
+ type = "NumericLiteral";
195
+ } else {
196
+ type = "BooleanLiteral";
197
+ }
198
+ const loc = getSourceLocation(expression.start, expression.end, ctx);
199
+ const ex = expression.value === null ? {
200
+ loc,
201
+ type
202
+ } : {
203
+ loc,
204
+ type,
205
+ value: expression.value
206
+ };
207
+ return {
208
+ ex,
209
+ kind: ValueType.CONST,
210
+ source: ctx.code.slice(expression.start, expression.end),
211
+ value: expression.value
212
+ };
213
+ };
214
+ const extractExpression = (expression, ctx, evaluate) => {
215
+ const source = ctx.code.slice(expression.start, expression.end);
216
+ // Only inline function expressions are function-valued here. A bare
217
+ // identifier that points to a local function may be a styled runtime
218
+ // component, so it has to stay as a lazy `_exp()` reference.
219
+ const isFunction = expression.type === "FunctionExpression" || expression.type === "ArrowFunctionExpression";
220
+ if (evaluate) {
221
+ const evaluated = evaluateStatic(expression, ctx);
222
+ const literal = literalCode(evaluated);
223
+ if (literal) {
224
+ findReferences(expression, ctx.referencesByNode).forEach(({ name }) => ctx.dependencyNames.add(name));
225
+ return {
226
+ expressionCode: literal,
227
+ importedFrom: [],
228
+ kind: isFunction ? ValueType.FUNCTION : ValueType.LAZY,
229
+ staticImports: [],
230
+ staticValue: isStaticSerializableValue(evaluated) ? cloneStaticValue(evaluated) : undefined
231
+ };
232
+ }
233
+ }
234
+ const identifierReplacements = new Map();
235
+ const importedFrom = [];
236
+ const namespaceStatic = collectStaticNamespaceMemberReferences(expression, ctx);
237
+ const staticIdentifierReplacements = new Map();
238
+ const staticImports = [...namespaceStatic.imports];
239
+ let hasNonStaticLocalReference = false;
240
+ let hasInlinableLocalReference = false;
241
+ findReferences(expression, ctx.referencesByNode).forEach(({ name, start }) => {
242
+ const binding = resolveBindingAt(ctx, name, start);
243
+ if (!binding) {
244
+ return;
245
+ }
246
+ if (isFunction && isBindingDeclaredWithin(binding, expression)) {
247
+ return;
248
+ }
249
+ ctx.dependencyNames.add(name);
250
+ if (binding.importedFrom) {
251
+ importedFrom.push(binding.importedFrom);
252
+ if (binding.imported && binding.imported !== "*") {
253
+ staticImports.push({
254
+ imported: binding.imported,
255
+ local: binding.name,
256
+ source: binding.importedFrom
257
+ });
258
+ } else if (binding.imported === "*" && namespaceStatic.coveredReferenceStarts.has(start)) {} else {
259
+ hasNonStaticLocalReference = true;
260
+ }
261
+ return;
262
+ }
263
+ const replacement = getConstantReplacement(binding, ctx);
264
+ if (evaluate && replacement) {
265
+ identifierReplacements.set(name, replacement);
266
+ return;
267
+ }
268
+ const init = binding.declarator?.init;
269
+ // Processor-managed bindings (`const x = css```, or object literals
270
+ // containing processor tags) carry values that only become known after
271
+ // processors run. Leave the identifier free in the candidate source so
272
+ // the resolver can supply it via inlineConstants at evaluation time.
273
+ const isProcessorManagedLocal = !!evaluate && !!init && containsTaggedTemplateExpression(init);
274
+ const staticLocalExpression = evaluate && init && !isProcessorManagedLocal ? collectStaticLocalExpression(init, ctx, [hoistedBindingKey(binding)]) : null;
275
+ if (staticLocalExpression) {
276
+ staticIdentifierReplacements.set(name, staticLocalExpression.source);
277
+ importedFrom.push(...staticLocalExpression.importedFrom);
278
+ staticImports.push(...staticLocalExpression.imports);
279
+ } else if (isProcessorManagedLocal) {
280
+ hasInlinableLocalReference = true;
281
+ } else {
282
+ hasNonStaticLocalReference = true;
283
+ }
284
+ assertHoistable(binding, ctx);
285
+ addHoistedDeclaration(binding, ctx);
286
+ if (!binding.isRoot && binding.declarator?.id.type === "Identifier") {
287
+ identifierReplacements.set(name, getHoistedBindingName(binding, ctx));
288
+ }
289
+ });
290
+ // Merge literal-const inlines (e.g. `const A = 32` -> "32") with
291
+ // local-to-imported substitutions (e.g. `const X = imp.y` -> "imp.y").
292
+ // Both must reach the candidate source so the resolver's evaluator
293
+ // can fold every Identifier in the expression; env only carries
294
+ // imported bindings, never same-file locals.
295
+ const mergedReplacements = new Map(staticIdentifierReplacements);
296
+ identifierReplacements.forEach((value, key) => {
297
+ if (!mergedReplacements.has(key)) {
298
+ mergedReplacements.set(key, value);
299
+ }
300
+ });
301
+ let staticExpressionCode;
302
+ if (mergedReplacements.size > 0) {
303
+ staticExpressionCode = replaceStaticLocalReferences(expression, mergedReplacements, ctx, namespaceStatic.replacements);
304
+ } else if (namespaceStatic.replacements.length > 0) {
305
+ staticExpressionCode = applyExpressionReplacements(expression, namespaceStatic.replacements, ctx.code);
306
+ }
307
+ return {
308
+ expressionCode: identifierReplacements.size > 0 ? replaceIdentifierReferences(expression, identifierReplacements, ctx.code) : source,
309
+ importedFrom,
310
+ kind: isFunction ? ValueType.FUNCTION : ValueType.LAZY,
311
+ staticExpressionCode,
312
+ hasInlinableLocalReference: !hasNonStaticLocalReference && hasInlinableLocalReference,
313
+ staticImports: hasNonStaticLocalReference ? [] : staticImports
314
+ };
315
+ };
316
+ const getInsertionPoints = (program, expressions) => {
317
+ if (expressions.length === 0) {
318
+ return [];
319
+ }
320
+ if (program.body.length === 0) {
321
+ return expressions.map(() => 0);
322
+ }
323
+ const insertionPoints = [];
324
+ let ownerIndex = 0;
325
+ expressions.forEach((expression) => {
326
+ while (ownerIndex < program.body.length - 1 && program.body[ownerIndex].end < expression.start) {
327
+ ownerIndex += 1;
328
+ }
329
+ let owner = program.body[ownerIndex];
330
+ if (!owner || owner.start > expression.start || owner.end < expression.end) {
331
+ owner = program.body.find((statement) => statement.start <= expression.start && statement.end >= expression.end);
332
+ }
333
+ insertionPoints.push(owner?.start ?? 0);
334
+ });
335
+ return insertionPoints;
336
+ };
337
+ const extractExpressions = (code, filename, evaluate, program, analysis, expressions, staticBindings) => {
338
+ if (expressions.length === 0) {
339
+ return {
340
+ code,
341
+ dependencyNames: [],
342
+ expressionValues: [],
343
+ staticValueCandidates: [],
344
+ staticValues: []
345
+ };
346
+ }
347
+ const insertionPoints = getInsertionPoints(program, expressions);
348
+ const ctx = {
349
+ bindingResolutionCache: new Map(),
350
+ bindingsByName: analysis.bindingsByName,
351
+ code,
352
+ currentInsertionPoint: insertionPoints[0] ?? 0,
353
+ currentExpressionStart: expressions[0].start,
354
+ dependencyNames: new Set(),
355
+ expressionValues: [],
356
+ filename,
357
+ hoistedBindingNames: new Map(),
358
+ hoistedDeclarations: new Map(),
359
+ hoistedDeclarationsByInsertionPoint: new Map(),
360
+ loc: createOxcLocationLookup(code),
361
+ referencesByNode: new WeakMap(),
362
+ replacements: [],
363
+ rootMutationsByBinding: analysis.rootMutationsByBinding,
364
+ staticBindings,
365
+ staticImportAliases: new Map(),
366
+ staticValueCandidates: [],
367
+ staticValues: [],
368
+ usedNames: new Set(analysis.usedNames)
369
+ };
370
+ expressions.forEach((expression, index) => {
371
+ ctx.currentInsertionPoint = insertionPoints[index] ?? 0;
372
+ ctx.currentExpressionStart = expression.start;
373
+ const literal = literalExpressionValue(expression, ctx);
374
+ if (literal) {
375
+ ctx.expressionValues.push(literal);
376
+ return;
377
+ }
378
+ const { expressionCode, hasInlinableLocalReference, importedFrom, kind, staticExpressionCode, staticImports, staticValue } = extractExpression(expression, ctx, evaluate);
379
+ const expName = allocateExpressionName(ctx);
380
+ addHoistedCode(expName, `const ${expName} = () => (${expressionCode});`, ctx);
381
+ if (staticValue !== undefined && kind !== ValueType.FUNCTION) {
382
+ ctx.staticValues.push({
383
+ name: expName,
384
+ value: staticValue
385
+ });
386
+ } else if ((staticImports.length > 0 || hasInlinableLocalReference || staticExpressionCode !== undefined) && kind !== ValueType.FUNCTION) {
387
+ const uniqueImports = new Map();
388
+ staticImports.forEach((item) => {
389
+ uniqueImports.set(`${item.local}\0${item.importLocal ?? ""}\0${item.source}\0${item.imported}`, item);
390
+ });
391
+ ctx.staticValueCandidates.push({
392
+ imports: [...uniqueImports.values()],
393
+ name: expName,
394
+ source: staticExpressionCode ?? expressionCode
395
+ });
396
+ }
397
+ ctx.replacements.push({
398
+ start: expression.start,
399
+ end: expression.end,
400
+ value: `${expName}()`
401
+ });
402
+ ctx.expressionValues.push({
403
+ ex: {
404
+ loc: getSourceLocation(expression.start, expression.end, ctx),
405
+ name: expName,
406
+ type: "Identifier"
407
+ },
408
+ importedFrom,
409
+ kind,
410
+ source: ctx.code.slice(expression.start, expression.end)
411
+ });
412
+ });
413
+ ctx.hoistedDeclarationsByInsertionPoint.forEach((declarations, point) => {
414
+ ctx.replacements.push({
415
+ start: point,
416
+ end: point,
417
+ value: `${declarations.join("\n")}\n`
418
+ });
419
+ });
420
+ return {
421
+ code: applyOxcReplacements(code, ctx.replacements),
422
+ dependencyNames: [...ctx.dependencyNames],
423
+ expressionValues: ctx.expressionValues,
424
+ staticValueCandidates: ctx.staticValueCandidates,
425
+ staticValues: ctx.staticValues
426
+ };
427
+ };
428
+ export const isOxcStaticSerializableValue = (value) => isStaticSerializableValue(value);
429
+ export const evaluateOxcStaticExpressionAt = (code, filename, expressionSpan, env = new Map(), staticBindings) => {
430
+ const program = parseOxc(code, filename);
431
+ const analysis = analyzeProgram(program, {
432
+ collectTargetExpressions: true,
433
+ expressionSpanLookup: createSpanLookup([expressionSpan])
434
+ });
435
+ const [expression] = analysis.targetExpressions;
436
+ if (!expression) {
437
+ return undefined;
438
+ }
439
+ const ctx = {
440
+ bindingResolutionCache: new Map(),
441
+ bindingsByName: analysis.bindingsByName,
442
+ code,
443
+ currentInsertionPoint: 0,
444
+ currentExpressionStart: expression.start,
445
+ dependencyNames: new Set(),
446
+ expressionValues: [],
447
+ filename,
448
+ hoistedBindingNames: new Map(),
449
+ hoistedDeclarations: new Map(),
450
+ hoistedDeclarationsByInsertionPoint: new Map(),
451
+ loc: createOxcLocationLookup(code),
452
+ referencesByNode: new WeakMap(),
453
+ replacements: [],
454
+ rootMutationsByBinding: analysis.rootMutationsByBinding,
455
+ staticBindings,
456
+ staticImportAliases: new Map(),
457
+ staticValueCandidates: [],
458
+ staticValues: [],
459
+ usedNames: new Set(analysis.usedNames)
460
+ };
461
+ return evaluateStatic(expression, ctx, new Map(env));
462
+ };
463
+ export const evaluateOxcStaticExpression = (source, filename, env = new Map(), staticBindings) => {
464
+ const code = `const __wyw_static_value = ${source};`;
465
+ const program = parseOxc(code, filename);
466
+ const declaration = program.body[0];
467
+ if (declaration?.type !== "VariableDeclaration") {
468
+ return undefined;
469
+ }
470
+ const [declarator] = declaration.declarations;
471
+ if (!declarator?.init) {
472
+ return undefined;
473
+ }
474
+ return evaluateOxcStaticExpressionAt(code, filename, {
475
+ end: declarator.init.end,
476
+ start: declarator.init.start
477
+ }, env, staticBindings);
478
+ };
479
+ export const collectOxcExpressionDependencies = (code, filename, evaluate = false, targetExpressionSpans, staticBindings) => {
480
+ const program = parseOxc(code, filename);
481
+ const analysis = analyzeProgram(program, {
482
+ collectTargetExpressions: true,
483
+ expressionSpanLookup: createSpanLookup(targetExpressionSpans)
484
+ });
485
+ return extractExpressions(code, filename, evaluate, program, analysis, analysis.targetExpressions, staticBindings);
486
+ };
487
+ export const collectOxcTemplateDependencies = (code, filename, evaluate = false, targetTemplateSpans) => {
488
+ const program = parseOxc(code, filename);
489
+ const analysis = analyzeProgram(program, {
490
+ collectTemplateLiterals: true,
491
+ templateSpanLookup: createSpanLookup(targetTemplateSpans)
492
+ });
493
+ const expressions = analysis.templateLiterals.flatMap((template) => template.expressions);
494
+ return extractExpressions(code, filename, evaluate, program, analysis, expressions);
495
+ };
496
+ //# sourceMappingURL=expressionExtraction.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAGA,SAAS,iBAAiB;AAG1B,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AACxC,SACE,gBACA,kCACA,kBACA,gBACA,mBACA,yBACA,UACA,wBACK;AACP,SACE,6BACA,wCACA,wCACA,wBACA,mCACK;AACP,SACE,kBACA,gBACA,2BACA,mBACK;AAcP,MAAM,0BAA0B,QAAmC;CACjE,IAAI,OAAO;CACX,IAAI,MAAM;AACV,QAAO,IAAI,UAAU,IAAI,KAAK,EAAE;AAC9B,SAAO;AACP,SAAO,OAAO;;AAGhB,KAAI,UAAU,IAAI,KAAK;AACvB,QAAO;;AAGT,MAAM,qBAAqB,YACzB,GAAG,QAAQ,MAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,GAAG,QAAQ,WAAW,GAAG,QAAQ;AAE/E,MAAM,8BACJ,cACA,QACW;CACX,MAAM,YAAY,aAAa,QAAQ,mBAAmB,IAAI,IAAI;CAClE,MAAM,OAAO,cAAc,KAAK,UAAU,GAAG,IAAI,cAAc;CAC/D,IAAI,YAAY;CAChB,IAAI,MAAM;AAEV,QAAO,IAAI,UAAU,IAAI,UAAU,EAAE;AACnC,cAAY,GAAG,OAAO;AACtB,SAAO;;AAGT,KAAI,UAAU,IAAI,UAAU;AAC5B,QAAO;;AAGT,MAAM,yBACJ,SACA,QACW;CACX,MAAM,MAAM,kBAAkB,QAAQ;CACtC,MAAM,WAAW,IAAI,oBAAoB,IAAI,IAAI;AACjD,KAAI,UAAU;AACZ,SAAO;;CAGT,MAAM,OAAO,2BAA2B,QAAQ,MAAM,IAAI;AAC1D,KAAI,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,SAAS,mBACT,eACD;;AAGH,OAAO,MAAM,kCACX,MACA,UACA,WAAW,OACX,wBAC6B;CAC7B,MAAM,UAAU,SAAS,MAAM,SAAS;CACxC,MAAM,WAAW,eAAe,SAAS;EACvC,yBAAyB;EACzB,oBAAoB,iBAAiB,oBAAoB;EAC1D,CAAC;CACF,MAAM,cAAc,SAAS,iBAAiB,SAC3C,aAAa,SAAS,YACxB;AAED,QAAO,mBACL,MACA,UACA,UACA,SACA,UACA,YACD","names":[],"sources":["../../../src/utils/collectOxcTemplateDependencies/expressionExtraction.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport { ValueType } from '@wyw-in-js/shared';\nimport type { Expression, Program } from 'oxc-parser';\n\nimport { applyOxcReplacements } from '../oxc/replacements';\nimport { createOxcLocationLookup } from '../oxc/sourceLocations';\nimport {\n analyzeProgram,\n containsTaggedTemplateExpression,\n createSpanLookup,\n findReferences,\n getSourceLocation,\n isBindingDeclaredWithin,\n parseOxc,\n resolveBindingAt,\n} from './scopeAnalysis';\nimport {\n applyExpressionReplacements,\n collectIdentifierReferenceReplacements,\n collectStaticNamespaceMemberReferences,\n getConstantReplacement,\n replaceIdentifierReferences,\n} from './expressionReplacements';\nimport {\n cloneStaticValue,\n evaluateStatic,\n isStaticSerializableValue,\n literalCode,\n} from './staticEvaluator';\nimport type {\n Binding,\n ExtractedExpression,\n ExpressionSpan,\n ExtractionContext,\n OxcStaticImportReference,\n ProgramAnalysis,\n Replacement,\n StaticBindings,\n StaticLocalExpression,\n TemplateExtractionResult,\n} from './types';\n\nconst allocateExpressionName = (ctx: ExtractionContext): string => {\n let base = '_exp';\n let idx = 1;\n while (ctx.usedNames.has(base)) {\n idx += 1;\n base = `_exp${idx}`;\n }\n\n ctx.usedNames.add(base);\n return base;\n};\n\nconst hoistedBindingKey = (binding: Binding): string =>\n `${binding.scope.start}:${binding.scope.end}:${binding.declaredAt}:${binding.name}`;\n\nconst allocateHoistedBindingName = (\n originalName: string,\n ctx: ExtractionContext\n): string => {\n const sanitized = originalName.replace(/[^A-Za-z0-9_$]/g, '_') || 'hoisted';\n const base = /^[A-Za-z_$]/.test(sanitized) ? `_${sanitized}` : '_hoisted';\n let candidate = base;\n let idx = 2;\n\n while (ctx.usedNames.has(candidate)) {\n candidate = `${base}${idx}`;\n idx += 1;\n }\n\n ctx.usedNames.add(candidate);\n return candidate;\n};\n\nconst getHoistedBindingName = (\n binding: Binding,\n ctx: ExtractionContext\n): string => {\n const key = hoistedBindingKey(binding);\n const existing = ctx.hoistedBindingNames.get(key);\n if (existing) {\n return existing;\n }\n\n const next = allocateHoistedBindingName(binding.name, ctx);\n ctx.hoistedBindingNames.set(key, next);\n return next;\n};\n\nconst parenthesizeStaticReplacement = (source: string): string => `(${source})`;\n\nconst replaceStaticLocalReferences = (\n expression: Expression,\n replacements: Map<string, string>,\n ctx: ExtractionContext,\n extraReplacements: Replacement[] = []\n): string => {\n if (expression.type === 'Identifier' && extraReplacements.length === 0) {\n return (\n replacements.get(expression.name) ??\n ctx.code.slice(expression.start, expression.end)\n );\n }\n\n const parenthesized = new Map<string, string>();\n replacements.forEach((value, key) => {\n parenthesized.set(key, parenthesizeStaticReplacement(value));\n });\n\n return applyExpressionReplacements(\n expression,\n [\n ...extraReplacements,\n ...collectIdentifierReferenceReplacements(expression, parenthesized),\n ],\n ctx.code\n );\n};\n\nconst collectStaticLocalExpression = (\n expression: Expression,\n ctx: ExtractionContext,\n stack: string[] = []\n): StaticLocalExpression | null => {\n const replacements = new Map<string, string>();\n const importedFrom = new Set<string>();\n const imports: OxcStaticImportReference[] = [];\n\n for (const { name, start } of findReferences(\n expression,\n ctx.referencesByNode\n )) {\n const binding = resolveBindingAt(ctx, name, start);\n if (!binding) {\n return null;\n }\n\n if (binding.importedFrom) {\n importedFrom.add(binding.importedFrom);\n if (binding.imported && binding.imported !== '*') {\n imports.push({\n imported: binding.imported,\n local: binding.name,\n source: binding.importedFrom,\n });\n continue;\n }\n\n return null;\n }\n\n const replacement = getConstantReplacement(binding, ctx);\n if (replacement) {\n replacements.set(name, replacement);\n continue;\n }\n\n if (\n binding.kind === 'param' ||\n binding.declarationKind !== 'const' ||\n !binding.declarator?.init ||\n binding.declarator.id.type !== 'Identifier'\n ) {\n return null;\n }\n\n // Processor-managed bindings (const x = css``) carry their value\n // (the generated className string) via inlineConstants at candidate\n // evaluation time. Walking the TaggedTemplateExpression here would\n // pull the processor's tag import (e.g. `css` from '@linaria/core')\n // into the candidate's static imports, where it fails to resolve.\n // Leave the identifier as a free reference; the candidate-side env\n // supplies the className.\n if (binding.declarator.init.type === 'TaggedTemplateExpression') {\n continue;\n }\n\n const key = hoistedBindingKey(binding);\n if (stack.includes(key)) {\n return null;\n }\n\n const nested = collectStaticLocalExpression(binding.declarator.init, ctx, [\n ...stack,\n key,\n ]);\n if (!nested) {\n return null;\n }\n\n replacements.set(name, nested.source);\n nested.importedFrom.forEach((source) => importedFrom.add(source));\n imports.push(...nested.imports);\n }\n\n return {\n importedFrom: [...importedFrom],\n imports,\n source:\n replacements.size > 0\n ? replaceStaticLocalReferences(expression, replacements, ctx)\n : ctx.code.slice(expression.start, expression.end),\n };\n};\n\nconst declarationInitCode = (\n init: Expression,\n ctx: ExtractionContext\n): string => {\n const renamedDependencies = new Map<string, string>();\n findReferences(init, ctx.referencesByNode).forEach(({ name, start }) => {\n const dependency = resolveBindingAt(ctx, name, start);\n if (\n !dependency ||\n dependency.importedFrom ||\n dependency.isRoot ||\n dependency.declarator?.id.type !== 'Identifier'\n ) {\n return;\n }\n\n renamedDependencies.set(name, getHoistedBindingName(dependency, ctx));\n });\n\n return renamedDependencies.size > 0\n ? replaceIdentifierReferences(init, renamedDependencies, ctx.code)\n : ctx.code.slice(init.start, init.end);\n};\n\nconst addHoistedCode = (\n key: string,\n code: string,\n ctx: ExtractionContext\n): void => {\n if (ctx.hoistedDeclarations.has(key)) {\n return;\n }\n\n ctx.hoistedDeclarations.set(key, code);\n const declarations =\n ctx.hoistedDeclarationsByInsertionPoint.get(ctx.currentInsertionPoint) ??\n [];\n declarations.push(code);\n ctx.hoistedDeclarationsByInsertionPoint.set(\n ctx.currentInsertionPoint,\n declarations\n );\n};\n\nconst declarationCode = (binding: Binding, ctx: ExtractionContext): string => {\n const { declarator } = binding;\n if (!declarator) {\n return '';\n }\n\n const { id } = declarator;\n if (id.type !== 'Identifier') {\n const idCode = ctx.code.slice(id.start, id.end);\n if (!declarator.init) {\n return `let ${idCode};`;\n }\n\n return `let ${idCode} = ${declarationInitCode(declarator.init, ctx)};`;\n }\n\n const hoistedName = getHoistedBindingName(binding, ctx);\n if (!declarator.init) {\n return `let ${hoistedName};`;\n }\n\n return `let ${hoistedName} = ${declarationInitCode(declarator.init, ctx)};`;\n};\n\nconst assertHoistable = (\n binding: Binding,\n ctx: ExtractionContext,\n stack: string[] = []\n): void => {\n if (!binding.declarator?.init || binding.importedFrom || binding.isRoot) {\n return;\n }\n\n if (stack.includes(binding.name)) {\n return;\n }\n\n const refs = findReferences(binding.declarator.init, ctx.referencesByNode);\n refs.forEach(({ name, start }) => {\n const nextBinding = resolveBindingAt(ctx, name, start);\n if (!nextBinding) {\n return;\n }\n\n if (nextBinding.kind === 'param') {\n throw new Error(\n `This identifier cannot be used in the template, because it is a function parameter.`\n );\n }\n\n assertHoistable(nextBinding, ctx, [...stack, binding.name]);\n });\n};\n\nconst addHoistedDeclaration = (\n binding: Binding,\n ctx: ExtractionContext,\n stack: string[] = []\n): void => {\n if (\n !binding.declaration ||\n !binding.declarator ||\n binding.importedFrom ||\n binding.isRoot ||\n stack.includes(binding.name)\n ) {\n return;\n }\n\n const hoistSource = binding.declarator.init ?? binding.declarator;\n findReferences(hoistSource, ctx.referencesByNode).forEach(\n ({ name, start }) => {\n const dependency = resolveBindingAt(ctx, name, start);\n if (dependency) {\n addHoistedDeclaration(dependency, ctx, [...stack, binding.name]);\n }\n }\n );\n\n if (!ctx.hoistedDeclarations.has(binding.name)) {\n addHoistedCode(binding.name, declarationCode(binding, ctx), ctx);\n }\n};\n\nconst literalExpressionValue = (\n expression: Expression,\n ctx: ExtractionContext\n): Omit<ExpressionValue, 'buildCodeFrameError'> | 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 return null;\n }\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 loc = getSourceLocation(expression.start, expression.end, ctx);\n const ex =\n expression.value === null\n ? { loc, type }\n : {\n loc,\n type,\n value: expression.value,\n };\n\n return {\n ex,\n kind: ValueType.CONST,\n source: ctx.code.slice(expression.start, expression.end),\n value: expression.value,\n } as unknown as Omit<ExpressionValue, 'buildCodeFrameError'>;\n};\n\nconst extractExpression = (\n expression: Expression,\n ctx: ExtractionContext,\n evaluate: boolean\n): ExtractedExpression => {\n const source = ctx.code.slice(expression.start, expression.end);\n // Only inline function expressions are function-valued here. A bare\n // identifier that points to a local function may be a styled runtime\n // component, so it has to stay as a lazy `_exp()` reference.\n const isFunction =\n expression.type === 'FunctionExpression' ||\n expression.type === 'ArrowFunctionExpression';\n\n if (evaluate) {\n const evaluated = evaluateStatic(expression, ctx);\n const literal = literalCode(evaluated);\n if (literal) {\n findReferences(expression, ctx.referencesByNode).forEach(({ name }) =>\n ctx.dependencyNames.add(name)\n );\n return {\n expressionCode: literal,\n importedFrom: [],\n kind: isFunction ? ValueType.FUNCTION : ValueType.LAZY,\n staticImports: [],\n staticValue: isStaticSerializableValue(evaluated)\n ? cloneStaticValue(evaluated)\n : undefined,\n };\n }\n }\n\n const identifierReplacements = new Map<string, string>();\n const importedFrom: string[] = [];\n const namespaceStatic = collectStaticNamespaceMemberReferences(\n expression,\n ctx\n );\n const staticIdentifierReplacements = new Map<string, string>();\n const staticImports: OxcStaticImportReference[] = [\n ...namespaceStatic.imports,\n ];\n let hasNonStaticLocalReference = false;\n let hasInlinableLocalReference = false;\n\n findReferences(expression, ctx.referencesByNode).forEach(\n ({ name, start }) => {\n const binding = resolveBindingAt(ctx, name, start);\n if (!binding) {\n return;\n }\n\n if (isFunction && isBindingDeclaredWithin(binding, expression)) {\n return;\n }\n\n ctx.dependencyNames.add(name);\n\n if (binding.importedFrom) {\n importedFrom.push(binding.importedFrom);\n if (binding.imported && binding.imported !== '*') {\n staticImports.push({\n imported: binding.imported,\n local: binding.name,\n source: binding.importedFrom,\n });\n } else if (\n binding.imported === '*' &&\n namespaceStatic.coveredReferenceStarts.has(start)\n ) {\n // The static candidate source gets a synthetic named import alias,\n // while the eval fallback keeps the original namespace expression.\n } else {\n hasNonStaticLocalReference = true;\n }\n return;\n }\n\n const replacement = getConstantReplacement(binding, ctx);\n if (evaluate && replacement) {\n identifierReplacements.set(name, replacement);\n return;\n }\n\n const init = binding.declarator?.init;\n // Processor-managed bindings (`const x = css```, or object literals\n // containing processor tags) carry values that only become known after\n // processors run. Leave the identifier free in the candidate source so\n // the resolver can supply it via inlineConstants at evaluation time.\n const isProcessorManagedLocal =\n !!evaluate && !!init && containsTaggedTemplateExpression(init);\n const staticLocalExpression =\n evaluate && init && !isProcessorManagedLocal\n ? collectStaticLocalExpression(init, ctx, [\n hoistedBindingKey(binding),\n ])\n : null;\n if (staticLocalExpression) {\n staticIdentifierReplacements.set(name, staticLocalExpression.source);\n importedFrom.push(...staticLocalExpression.importedFrom);\n staticImports.push(...staticLocalExpression.imports);\n } else if (isProcessorManagedLocal) {\n hasInlinableLocalReference = true;\n } else {\n hasNonStaticLocalReference = true;\n }\n\n assertHoistable(binding, ctx);\n addHoistedDeclaration(binding, ctx);\n if (!binding.isRoot && binding.declarator?.id.type === 'Identifier') {\n identifierReplacements.set(name, getHoistedBindingName(binding, ctx));\n }\n }\n );\n\n // Merge literal-const inlines (e.g. `const A = 32` -> \"32\") with\n // local-to-imported substitutions (e.g. `const X = imp.y` -> \"imp.y\").\n // Both must reach the candidate source so the resolver's evaluator\n // can fold every Identifier in the expression; env only carries\n // imported bindings, never same-file locals.\n const mergedReplacements = new Map(staticIdentifierReplacements);\n identifierReplacements.forEach((value, key) => {\n if (!mergedReplacements.has(key)) {\n mergedReplacements.set(key, value);\n }\n });\n\n let staticExpressionCode: string | undefined;\n if (mergedReplacements.size > 0) {\n staticExpressionCode = replaceStaticLocalReferences(\n expression,\n mergedReplacements,\n ctx,\n namespaceStatic.replacements\n );\n } else if (namespaceStatic.replacements.length > 0) {\n staticExpressionCode = applyExpressionReplacements(\n expression,\n namespaceStatic.replacements,\n ctx.code\n );\n }\n\n return {\n expressionCode:\n identifierReplacements.size > 0\n ? replaceIdentifierReferences(\n expression,\n identifierReplacements,\n ctx.code\n )\n : source,\n importedFrom,\n kind: isFunction ? ValueType.FUNCTION : ValueType.LAZY,\n staticExpressionCode,\n hasInlinableLocalReference:\n !hasNonStaticLocalReference && hasInlinableLocalReference,\n staticImports: hasNonStaticLocalReference ? [] : staticImports,\n };\n};\n\nconst getInsertionPoints = (\n program: Program,\n expressions: Expression[]\n): number[] => {\n if (expressions.length === 0) {\n return [];\n }\n\n if (program.body.length === 0) {\n return expressions.map(() => 0);\n }\n\n const insertionPoints: number[] = [];\n let ownerIndex = 0;\n\n expressions.forEach((expression) => {\n while (\n ownerIndex < program.body.length - 1 &&\n program.body[ownerIndex]!.end < expression.start\n ) {\n ownerIndex += 1;\n }\n\n let owner: Program['body'][number] | undefined = program.body[ownerIndex];\n if (\n !owner ||\n owner.start > expression.start ||\n owner.end < expression.end\n ) {\n owner = program.body.find(\n (statement) =>\n statement.start <= expression.start && statement.end >= expression.end\n );\n }\n\n insertionPoints.push(owner?.start ?? 0);\n });\n\n return insertionPoints;\n};\n\nconst extractExpressions = (\n code: string,\n filename: string,\n evaluate: boolean,\n program: Program,\n analysis: Pick<\n ProgramAnalysis,\n 'bindingsByName' | 'rootMutationsByBinding' | 'usedNames'\n >,\n expressions: Expression[],\n staticBindings?: StaticBindings\n): TemplateExtractionResult => {\n if (expressions.length === 0) {\n return {\n code,\n dependencyNames: [],\n expressionValues: [],\n staticValueCandidates: [],\n staticValues: [],\n };\n }\n\n const insertionPoints = getInsertionPoints(program, expressions);\n const ctx: ExtractionContext = {\n bindingResolutionCache: new Map(),\n bindingsByName: analysis.bindingsByName,\n code,\n currentInsertionPoint: insertionPoints[0] ?? 0,\n currentExpressionStart: expressions[0].start,\n dependencyNames: new Set(),\n expressionValues: [],\n filename,\n hoistedBindingNames: new Map(),\n hoistedDeclarations: new Map(),\n hoistedDeclarationsByInsertionPoint: new Map(),\n loc: createOxcLocationLookup(code),\n referencesByNode: new WeakMap(),\n replacements: [],\n rootMutationsByBinding: analysis.rootMutationsByBinding,\n staticBindings,\n staticImportAliases: new Map(),\n staticValueCandidates: [],\n staticValues: [],\n usedNames: new Set(analysis.usedNames),\n };\n\n expressions.forEach((expression, index) => {\n ctx.currentInsertionPoint = insertionPoints[index] ?? 0;\n ctx.currentExpressionStart = expression.start;\n\n const literal = literalExpressionValue(expression, ctx);\n if (literal) {\n ctx.expressionValues.push(literal);\n return;\n }\n\n const {\n expressionCode,\n hasInlinableLocalReference,\n importedFrom,\n kind,\n staticExpressionCode,\n staticImports,\n staticValue,\n } = extractExpression(expression, ctx, evaluate);\n const expName = allocateExpressionName(ctx);\n\n addHoistedCode(\n expName,\n `const ${expName} = () => (${expressionCode});`,\n ctx\n );\n if (staticValue !== undefined && kind !== ValueType.FUNCTION) {\n ctx.staticValues.push({\n name: expName,\n value: staticValue,\n });\n } else if (\n (staticImports.length > 0 ||\n hasInlinableLocalReference ||\n staticExpressionCode !== undefined) &&\n kind !== ValueType.FUNCTION\n ) {\n const uniqueImports = new Map<string, OxcStaticImportReference>();\n staticImports.forEach((item) => {\n uniqueImports.set(\n `${item.local}\\0${item.importLocal ?? ''}\\0${item.source}\\0${\n item.imported\n }`,\n item\n );\n });\n ctx.staticValueCandidates.push({\n imports: [...uniqueImports.values()],\n name: expName,\n source: staticExpressionCode ?? expressionCode,\n });\n }\n ctx.replacements.push({\n start: expression.start,\n end: expression.end,\n value: `${expName}()`,\n });\n ctx.expressionValues.push({\n ex: {\n loc: getSourceLocation(expression.start, expression.end, ctx),\n name: expName,\n type: 'Identifier',\n },\n importedFrom,\n kind,\n source: ctx.code.slice(expression.start, expression.end),\n } as unknown as Omit<ExpressionValue, 'buildCodeFrameError'>);\n });\n\n ctx.hoistedDeclarationsByInsertionPoint.forEach((declarations, point) => {\n ctx.replacements.push({\n start: point,\n end: point,\n value: `${declarations.join('\\n')}\\n`,\n });\n });\n\n return {\n code: applyOxcReplacements(code, ctx.replacements),\n dependencyNames: [...ctx.dependencyNames],\n expressionValues: ctx.expressionValues,\n staticValueCandidates: ctx.staticValueCandidates,\n staticValues: ctx.staticValues,\n };\n};\n\nexport const isOxcStaticSerializableValue = (value: unknown): boolean =>\n isStaticSerializableValue(value);\n\nexport const evaluateOxcStaticExpressionAt = (\n code: string,\n filename: string,\n expressionSpan: ExpressionSpan,\n env: Map<string, unknown> = new Map(),\n staticBindings?: StaticBindings\n): unknown | undefined => {\n const program = parseOxc(code, filename);\n const analysis = analyzeProgram(program, {\n collectTargetExpressions: true,\n expressionSpanLookup: createSpanLookup([expressionSpan]),\n });\n const [expression] = analysis.targetExpressions;\n if (!expression) {\n return undefined;\n }\n\n const ctx: ExtractionContext = {\n bindingResolutionCache: new Map(),\n bindingsByName: analysis.bindingsByName,\n code,\n currentInsertionPoint: 0,\n currentExpressionStart: expression.start,\n dependencyNames: new Set(),\n expressionValues: [],\n filename,\n hoistedBindingNames: new Map(),\n hoistedDeclarations: new Map(),\n hoistedDeclarationsByInsertionPoint: new Map(),\n loc: createOxcLocationLookup(code),\n referencesByNode: new WeakMap(),\n replacements: [],\n rootMutationsByBinding: analysis.rootMutationsByBinding,\n staticBindings,\n staticImportAliases: new Map(),\n staticValueCandidates: [],\n staticValues: [],\n usedNames: new Set(analysis.usedNames),\n };\n\n return evaluateStatic(expression, ctx, new Map(env));\n};\n\nexport const evaluateOxcStaticExpression = (\n source: string,\n filename: string,\n env: Map<string, unknown> = new Map(),\n staticBindings?: StaticBindings\n): unknown | undefined => {\n const code = `const __wyw_static_value = ${source};`;\n const program = parseOxc(code, filename);\n const declaration = program.body[0];\n if (declaration?.type !== 'VariableDeclaration') {\n return undefined;\n }\n\n const [declarator] = declaration.declarations;\n if (!declarator?.init) {\n return undefined;\n }\n\n return evaluateOxcStaticExpressionAt(\n code,\n filename,\n {\n end: declarator.init.end,\n start: declarator.init.start,\n },\n env,\n staticBindings\n );\n};\n\nexport const collectOxcExpressionDependencies = (\n code: string,\n filename: string,\n evaluate = false,\n targetExpressionSpans?: ExpressionSpan[],\n staticBindings?: StaticBindings\n): TemplateExtractionResult => {\n const program = parseOxc(code, filename);\n const analysis = analyzeProgram(program, {\n collectTargetExpressions: true,\n expressionSpanLookup: createSpanLookup(targetExpressionSpans),\n });\n\n return extractExpressions(\n code,\n filename,\n evaluate,\n program,\n analysis,\n analysis.targetExpressions,\n staticBindings\n );\n};\n\nexport const collectOxcTemplateDependencies = (\n code: string,\n filename: string,\n evaluate = false,\n targetTemplateSpans?: ExpressionSpan[]\n): TemplateExtractionResult => {\n const program = parseOxc(code, filename);\n const analysis = analyzeProgram(program, {\n collectTemplateLiterals: true,\n templateSpanLookup: createSpanLookup(targetTemplateSpans),\n });\n const expressions = analysis.templateLiterals.flatMap(\n (template) => template.expressions\n );\n\n return extractExpressions(\n code,\n filename,\n evaluate,\n program,\n analysis,\n expressions\n );\n};\n"],"file":"expressionExtraction.js"}