@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,123 @@
1
+ import { collectImportBindings, isSafeLiteral, unwrapExpression } from "./staticExpression.js";
2
+ export const collectLocalConstExpressions = (program) => {
3
+ const result = new Map();
4
+ const collect = (declaration) => {
5
+ if (declaration.kind !== "const") {
6
+ return;
7
+ }
8
+ declaration.declarations.forEach((declarator) => {
9
+ if (declarator.id.type === "Identifier" && declarator.init) {
10
+ result.set(declarator.id.name, declarator.init);
11
+ }
12
+ });
13
+ };
14
+ program.body.forEach((statement) => {
15
+ if (statement.type === "VariableDeclaration") {
16
+ collect(statement);
17
+ return;
18
+ }
19
+ if (statement.type === "ExportNamedDeclaration" && statement.declaration?.type === "VariableDeclaration") {
20
+ collect(statement.declaration);
21
+ }
22
+ });
23
+ return result;
24
+ };
25
+ export const objectPropertyKeyName = (node) => {
26
+ const unwrapped = unwrapExpression(node);
27
+ if (unwrapped.type === "Identifier") {
28
+ return unwrapped.name;
29
+ }
30
+ if (isSafeLiteral(unwrapped) && typeof unwrapped.value === "string") {
31
+ return unwrapped.value;
32
+ }
33
+ return null;
34
+ };
35
+ export const findObjectPropertyValue = (expr, name) => {
36
+ const unwrapped = unwrapExpression(expr);
37
+ if (unwrapped.type !== "ObjectExpression") {
38
+ return null;
39
+ }
40
+ for (const property of unwrapped.properties) {
41
+ if (property.type === "SpreadElement") {
42
+ continue;
43
+ }
44
+ const propertyNode = property;
45
+ if (propertyNode.computed) {
46
+ continue;
47
+ }
48
+ const key = propertyNode.key;
49
+ const value = propertyNode.value;
50
+ if (key && value && objectPropertyKeyName(key) === name) {
51
+ return value;
52
+ }
53
+ }
54
+ return null;
55
+ };
56
+ export const topLevelStatements = (program) => {
57
+ const result = [];
58
+ program.body.forEach((statement) => {
59
+ if (statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration") {
60
+ result.push(statement.declaration ?? statement);
61
+ return;
62
+ }
63
+ result.push(statement);
64
+ });
65
+ return result;
66
+ };
67
+ export const findTopLevelConstExpression = (program, name) => {
68
+ for (const statement of topLevelStatements(program)) {
69
+ if (statement.type !== "VariableDeclaration" || statement.kind !== "const") {
70
+ continue;
71
+ }
72
+ for (const declarator of statement.declarations) {
73
+ if (declarator.id.type === "Identifier" && declarator.id.name === name && declarator.init) {
74
+ return declarator.init;
75
+ }
76
+ }
77
+ }
78
+ return null;
79
+ };
80
+ export const hasTopLevelBinding = (program, name) => {
81
+ if (collectImportBindings(program).has(name)) {
82
+ return true;
83
+ }
84
+ return topLevelStatements(program).some((statement) => {
85
+ if (statement.type === "VariableDeclaration") {
86
+ return statement.declarations.some((declarator) => declarator.id.type === "Identifier" && declarator.id.name === name);
87
+ }
88
+ if (statement.type === "FunctionDeclaration") {
89
+ return statement.id?.name === name;
90
+ }
91
+ if (statement.type === "ClassDeclaration") {
92
+ return statement.id?.name === name;
93
+ }
94
+ return false;
95
+ });
96
+ };
97
+ export const isTopLevelFunctionOrClass = (program, name) => topLevelStatements(program).some((statement) => {
98
+ if (statement.type === "FunctionDeclaration") {
99
+ return statement.id?.name === name;
100
+ }
101
+ if (statement.type === "ClassDeclaration") {
102
+ return statement.id?.name === name;
103
+ }
104
+ return false;
105
+ });
106
+ export const functionReturnExpression = (expr, options = {}) => {
107
+ const unwrapped = unwrapExpression(expr);
108
+ if (unwrapped.type !== "ArrowFunctionExpression" && unwrapped.type !== "FunctionExpression") {
109
+ return null;
110
+ }
111
+ if (unwrapped.async || !options.allowParams && unwrapped.params.length > 0 || !unwrapped.body) {
112
+ return null;
113
+ }
114
+ if (unwrapped.body.type !== "BlockStatement") {
115
+ return unwrapped.body;
116
+ }
117
+ if (unwrapped.body.body.length !== 1) {
118
+ return null;
119
+ }
120
+ const [statement] = unwrapped.body.body;
121
+ return statement.type === "ReturnStatement" && statement.argument ? statement.argument : null;
122
+ };
123
+ //# sourceMappingURL=programAnalysis.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AASA,SACE,uBACA,eACA,wBACK;AAGP,OAAO,MAAM,gCACX,YAC4B;CAC5B,MAAM,SAAS,IAAI,KAAyB;CAE5C,MAAM,WAAW,gBAA2C;AAC1D,MAAI,YAAY,SAAS,SAAS;AAChC;;AAGF,cAAY,aAAa,SAAS,eAAe;AAC/C,OAAI,WAAW,GAAG,SAAS,gBAAgB,WAAW,MAAM;AAC1D,WAAO,IAAI,WAAW,GAAG,MAAM,WAAW,KAAK;;IAEjD;;AAGJ,SAAQ,KAAK,SAAS,cAAc;AAClC,MAAI,UAAU,SAAS,uBAAuB;AAC5C,WA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A0B;AAC7E,KAAI,sBAAsB,QAAQ,CAAC,IAAI,KAAK,EAAE;AAC5C,SAAO;;AAGT,QAAO,mBAAmB,QAAQ,CAAC,MAAM,cAAc;AACrD,MAAI,UAAU,SAAS,uBAAuB;AAC5C,UAAO,UAAU,aAAa,MAC3B,eACC,WAAW,GAAG,SAAS,gBAAgB,WAAW,GAAG,SAAS,KACjE;;AAGH,MAAI,UAAU,SAAS,uBAAuB;AAC5C,UAAO,UAAU,IAAI,SAAS;;AAGhC,MAAI,UAAU,SAAS,oBAAoB;AACzC,UAAO,UAAU,IAAI,SAAS;;AAGhC,SAAO;GACP;;AAGJ,OAAO,MAAM,6BACX,SACA,SAEA,mBAAmB,QAAQ,CAAC,MAAM,cAAc;AAC9C,KAAI,UAAU,SAAS,uBAAuB;AAC5C,SAAO,UAAU,IAAI,SAAS;;AAGhC,KAAI,UAAU,SAAS,oBAAoB;AACzC,SAAO,UAAU,IAAI,SAAS;;AAGhC,QAAO;EACP;AAEJ,OAAO,MAAM,4BACX,MACA,UAAqC,EAAE,KACjB;CACtB,MAAM,YAAY,iBAAiB,KAAK;AACxC,KACE,UAAU,SAAS,6BACnB,UAAU,SAAS,sBACnB;AACA,SAAO;;AAGT,KACE,UAAU,SACT,CAAC,QAAQ,eAAe,UAAU,OAAO,SAAS,KACnD,CAAC,UAAU,MACX;AACA,SAAO;;AAGT,KAAI,UAAU,KAAK,SAAS,kBAAkB;AAC5C,SAAO,UAAU;;AAGnB,KAAI,UAAU,KAAK,KAAK,WAAW,GAAG;AACpC,SAAO;;CAGT,MAAM,CAAC,aAAa,UAAU,KAAK;AACnC,QAAO,UAAU,SAAS,qBAAqB,UAAU,WACrD,UAAU,WACV","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/programAnalysis.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type {\n Expression,\n Node,\n Program,\n VariableDeclaration,\n} from 'oxc-parser';\n\nimport {\n collectImportBindings,\n isSafeLiteral,\n unwrapExpression,\n} from './staticExpression';\nimport type { AnyNode } from './types';\n\nexport const collectLocalConstExpressions = (\n program: Program\n): Map<string, Expression> => {\n const result = new Map<string, Expression>();\n\n const collect = (declaration: VariableDeclaration): void => {\n if (declaration.kind !== 'const') {\n return;\n }\n\n declaration.declarations.forEach((declarator) => {\n if (declarator.id.type === 'Identifier' && declarator.init) {\n result.set(declarator.id.name, declarator.init);\n }\n });\n };\n\n program.body.forEach((statement) => {\n if (statement.type === 'VariableDeclaration') {\n collect(statement);\n return;\n }\n\n if (\n statement.type === 'ExportNamedDeclaration' &&\n statement.declaration?.type === 'VariableDeclaration'\n ) {\n collect(statement.declaration);\n }\n });\n\n return result;\n};\nexport const objectPropertyKeyName = (node: Node): string | null => {\n const unwrapped = unwrapExpression(node);\n\n if (unwrapped.type === 'Identifier') {\n return unwrapped.name;\n }\n\n if (isSafeLiteral(unwrapped) && typeof unwrapped.value === 'string') {\n return unwrapped.value;\n }\n\n return null;\n};\n\nexport const findObjectPropertyValue = (\n expr: Node,\n name: string\n): Expression | null => {\n const unwrapped = unwrapExpression(expr);\n if (unwrapped.type !== 'ObjectExpression') {\n return null;\n }\n\n for (const property of unwrapped.properties) {\n if (property.type === 'SpreadElement') {\n continue;\n }\n\n const propertyNode = property as AnyNode;\n if (propertyNode.computed) {\n continue;\n }\n\n const key = propertyNode.key as Node | undefined;\n const value = propertyNode.value as Expression | undefined;\n if (key && value && objectPropertyKeyName(key) === name) {\n return value;\n }\n }\n\n return null;\n};\nexport const topLevelStatements = (program: Program): Node[] => {\n const result: Node[] = [];\n\n program.body.forEach((statement) => {\n if (\n statement.type === 'ExportNamedDeclaration' ||\n statement.type === 'ExportDefaultDeclaration'\n ) {\n result.push(statement.declaration ?? statement);\n return;\n }\n\n result.push(statement);\n });\n\n return result;\n};\n\nexport const findTopLevelConstExpression = (\n program: Program,\n name: string\n): Expression | null => {\n for (const statement of topLevelStatements(program)) {\n if (\n statement.type !== 'VariableDeclaration' ||\n statement.kind !== 'const'\n ) {\n continue;\n }\n\n for (const declarator of statement.declarations) {\n if (\n declarator.id.type === 'Identifier' &&\n declarator.id.name === name &&\n declarator.init\n ) {\n return declarator.init;\n }\n }\n }\n\n return null;\n};\n\nexport const hasTopLevelBinding = (program: Program, name: string): boolean => {\n if (collectImportBindings(program).has(name)) {\n return true;\n }\n\n return topLevelStatements(program).some((statement) => {\n if (statement.type === 'VariableDeclaration') {\n return statement.declarations.some(\n (declarator) =>\n declarator.id.type === 'Identifier' && declarator.id.name === name\n );\n }\n\n if (statement.type === 'FunctionDeclaration') {\n return statement.id?.name === name;\n }\n\n if (statement.type === 'ClassDeclaration') {\n return statement.id?.name === name;\n }\n\n return false;\n });\n};\n\nexport const isTopLevelFunctionOrClass = (\n program: Program,\n name: string\n): boolean =>\n topLevelStatements(program).some((statement) => {\n if (statement.type === 'FunctionDeclaration') {\n return statement.id?.name === name;\n }\n\n if (statement.type === 'ClassDeclaration') {\n return statement.id?.name === name;\n }\n\n return false;\n });\n\nexport const functionReturnExpression = (\n expr: Node,\n options: { allowParams?: boolean } = {}\n): Expression | null => {\n const unwrapped = unwrapExpression(expr);\n if (\n unwrapped.type !== 'ArrowFunctionExpression' &&\n unwrapped.type !== 'FunctionExpression'\n ) {\n return null;\n }\n\n if (\n unwrapped.async ||\n (!options.allowParams && unwrapped.params.length > 0) ||\n !unwrapped.body\n ) {\n return null;\n }\n\n if (unwrapped.body.type !== 'BlockStatement') {\n return unwrapped.body as Expression;\n }\n\n if (unwrapped.body.body.length !== 1) {\n return null;\n }\n\n const [statement] = unwrapped.body.body;\n return statement.type === 'ReturnStatement' && statement.argument\n ? statement.argument\n : null;\n};\n"],"file":"programAnalysis.js"}
@@ -0,0 +1,186 @@
1
+ import { getOxcNodeChildren } from "../../../utils/oxc/ast.js";
2
+ import { applyOxcReplacements } from "../../../utils/oxc/replacements.js";
3
+ import { parseProgram } from "./environment.js";
4
+ import { collectImportBindings, unwrapExpression } from "./staticExpression.js";
5
+ import { findWYWMetaExtendsExpression, staticWYWMetaExtendsReplacementCode } from "./processorStaticModel.js";
6
+ export const isIdentifierBindingPosition = (node, parent) => {
7
+ if (node.type !== "Identifier" || !parent) {
8
+ return false;
9
+ }
10
+ if (parent.type === "VariableDeclarator" && parent.id === node || parent.type === "FunctionDeclaration" && parent.id === node || parent.type === "FunctionExpression" && parent.id === node || parent.type === "ClassDeclaration" && parent.id === node || parent.type === "ClassExpression" && parent.id === node) {
11
+ return true;
12
+ }
13
+ if ((parent.type === "ArrowFunctionExpression" || parent.type === "FunctionDeclaration" || parent.type === "FunctionExpression") && parent.params.some((param) => param === node)) {
14
+ return true;
15
+ }
16
+ return parent.type === "ImportSpecifier" && parent.local === node || parent.type === "ImportDefaultSpecifier" && parent.local === node || parent.type === "ImportNamespaceSpecifier" && parent.local === node;
17
+ };
18
+ export const isPropertyKeyOnlyIdentifier = (node, parent) => node.type === "Identifier" && !!parent && (parent.type === "MemberExpression" && parent.property === node && !parent.computed || parent.type === "Property" && parent.key === node && !parent.computed && !parent.shorthand);
19
+ export const collectUsedIdentifierNames = (program) => {
20
+ const used = new Set();
21
+ const walk = (node, parent) => {
22
+ if (node.type === "ImportDeclaration") {
23
+ return;
24
+ }
25
+ if (node.type === "Identifier" && !isIdentifierBindingPosition(node, parent) && !isPropertyKeyOnlyIdentifier(node, parent)) {
26
+ used.add(node.name);
27
+ }
28
+ getOxcNodeChildren(node).forEach((child) => walk(child, node));
29
+ };
30
+ walk(program, null);
31
+ return used;
32
+ };
33
+ export const removableStaticHelperNames = (program, staticValueNames) => {
34
+ const used = collectUsedIdentifierNames(program);
35
+ const result = new Set();
36
+ program.body.forEach((statement) => {
37
+ if (statement.type !== "VariableDeclaration") {
38
+ return;
39
+ }
40
+ statement.declarations.forEach((declarator) => {
41
+ if (declarator.id.type === "Identifier" && staticValueNames.has(declarator.id.name) && !used.has(declarator.id.name)) {
42
+ result.add(declarator.id.name);
43
+ }
44
+ });
45
+ });
46
+ return result;
47
+ };
48
+ export const collectImportLocalReferences = (node, importLocals, result) => {
49
+ const walk = (item, parent) => {
50
+ if (item.type === "Identifier" && importLocals.has(item.name) && !isIdentifierBindingPosition(item, parent) && !isPropertyKeyOnlyIdentifier(item, parent)) {
51
+ result.add(item.name);
52
+ }
53
+ getOxcNodeChildren(item).forEach((child) => walk(child, item));
54
+ };
55
+ walk(node, null);
56
+ };
57
+ export const removeStaticHelperDeclarations = (code, filename, staticValueNames) => {
58
+ if (staticValueNames.size === 0) {
59
+ return {
60
+ code,
61
+ removed: new Set(),
62
+ removedImportLocals: new Set()
63
+ };
64
+ }
65
+ const program = parseProgram(code, filename);
66
+ const removableNames = removableStaticHelperNames(program, staticValueNames);
67
+ const importLocals = new Set();
68
+ collectImportBindings(program).forEach((_, local) => importLocals.add(local));
69
+ const removedImportLocals = new Set();
70
+ const ranges = [];
71
+ const replacements = [];
72
+ program.body.forEach((statement) => {
73
+ if (statement.type !== "VariableDeclaration" || statement.declarations.length === 0) {
74
+ return;
75
+ }
76
+ const removableIndexes = statement.declarations.flatMap((declarator, index) => declarator.id.type === "Identifier" && removableNames.has(declarator.id.name) ? [index] : []);
77
+ if (removableIndexes.length === 0) {
78
+ return;
79
+ }
80
+ removableIndexes.forEach((index) => {
81
+ collectImportLocalReferences(statement.declarations[index], importLocals, removedImportLocals);
82
+ });
83
+ if (removableIndexes.length === statement.declarations.length) {
84
+ ranges.push({
85
+ end: statement.end,
86
+ start: statement.start
87
+ });
88
+ return;
89
+ }
90
+ const keptDeclarations = statement.declarations.filter((_, index) => !removableIndexes.includes(index)).map((declarator) => code.slice(declarator.start, declarator.end));
91
+ replacements.push({
92
+ end: statement.end,
93
+ start: statement.start,
94
+ text: `${statement.kind} ${keptDeclarations.join(", ")};`
95
+ });
96
+ });
97
+ return {
98
+ code: applyOxcReplacements(code, [...ranges.map((range) => ({
99
+ ...range,
100
+ text: ""
101
+ })), ...replacements]),
102
+ removed: removableNames,
103
+ removedImportLocals
104
+ };
105
+ };
106
+ export const importSpecifierLocalName = (specifier) => specifier.local?.name ?? null;
107
+ export const removeUnusedStaticImports = (code, filename, staticImportLocals, sideEffectImportLocals) => {
108
+ if (staticImportLocals.size === 0) {
109
+ return code;
110
+ }
111
+ const program = parseProgram(code, filename);
112
+ const used = collectUsedIdentifierNames(program);
113
+ const ranges = [];
114
+ const replacements = [];
115
+ program.body.forEach((statement) => {
116
+ if (statement.type !== "ImportDeclaration" || statement.specifiers.length === 0) {
117
+ return;
118
+ }
119
+ const removable = statement.specifiers.flatMap((specifier, index) => {
120
+ const localName = importSpecifierLocalName(specifier);
121
+ return localName && staticImportLocals.has(localName) && !used.has(localName) ? [{
122
+ index,
123
+ localName
124
+ }] : [];
125
+ });
126
+ if (removable.length === 0) {
127
+ return;
128
+ }
129
+ if (removable.length === statement.specifiers.length) {
130
+ if (removable.some((item) => sideEffectImportLocals.has(item.localName))) {
131
+ replacements.push({
132
+ end: statement.end,
133
+ start: statement.start,
134
+ text: `import ${code.slice(statement.source.start, statement.source.end)};`
135
+ });
136
+ return;
137
+ }
138
+ ranges.push({
139
+ end: statement.end,
140
+ start: statement.start
141
+ });
142
+ }
143
+ });
144
+ return applyOxcReplacements(code, [...ranges.map((range) => ({
145
+ ...range,
146
+ text: ""
147
+ })), ...replacements]);
148
+ };
149
+ export const replaceStaticWYWMetaExtendsHelpers = (code, filename, helperValues) => {
150
+ if (helperValues.size === 0) {
151
+ return code;
152
+ }
153
+ const program = parseProgram(code, filename);
154
+ const replacements = [];
155
+ const visit = (node) => {
156
+ if (node.type === "ObjectExpression") {
157
+ const extendsExpression = findWYWMetaExtendsExpression(node);
158
+ if (extendsExpression) {
159
+ const unwrapped = unwrapExpression(extendsExpression);
160
+ if (unwrapped.type === "CallExpression" && unwrapped.callee.type === "Identifier" && unwrapped.arguments.length === 0 && helperValues.has(unwrapped.callee.name)) {
161
+ const replacement = staticWYWMetaExtendsReplacementCode(helperValues.get(unwrapped.callee.name));
162
+ if (replacement) {
163
+ replacements.push({
164
+ end: extendsExpression.end,
165
+ start: extendsExpression.start,
166
+ text: replacement
167
+ });
168
+ }
169
+ }
170
+ }
171
+ }
172
+ getOxcNodeChildren(node).forEach(visit);
173
+ };
174
+ visit(program);
175
+ return applyOxcReplacements(code, replacements);
176
+ };
177
+ export const pruneStaticPreevalCode = (code, filename, staticValueNames, staticImportLocals, staticExtendsHelperValues, sideEffectImportLocals) => {
178
+ const codeWithMetadataPruned = replaceStaticWYWMetaExtendsHelpers(code, filename, staticExtendsHelperValues);
179
+ const helpersRemoved = removeStaticHelperDeclarations(codeWithMetadataPruned, filename, staticValueNames);
180
+ if (helpersRemoved.removed.size === 0) {
181
+ return codeWithMetadataPruned;
182
+ }
183
+ const importLocalsToPrune = new Set([...staticImportLocals, ...helpersRemoved.removedImportLocals]);
184
+ return removeUnusedStaticImports(helpersRemoved.code, filename, importLocalsToPrune, sideEffectImportLocals);
185
+ };
186
+ //# sourceMappingURL=prune.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAIA,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB,wBAAwB;AACxD,SACE,8BACA,2CACK;AAGP,OAAO,MAAM,+BACX,MACA,WACY;AACZ,KAAI,KAAK,SAAS,gBAAgB,CAAC,QAAQ;AACzC,SAAO;;AAGT,KACG,OAAO,SAAS,wBAAwB,OAAO,OAAO,QACtD,OAAO,SAAS,yBAAyB,OAAO,OAAO,QACvD,OAAO,SAAS,wBAAwB,OAAO,OAAO,QACtD,OAAO,SAAS,sBAAsB,OAAO,OAAO,QACpD,OAAO,SAAS,qBAAqB,OAAO,OAAO,MACpD;AACA,SAAO;;AAGT,MACG,OAAO,SAAS,6BACf,OAAO,SAAS,yBAChB,OAAO,SAAS,yBAClB,OAAO,OAAO,MAAM,UAAU,UAAU,KAAK,EAC7C;AACA,SAAO;;AAGT,QACG,OAAO,SAAS,qBAAqB,OAAO,UAAU,QACtD,OAAO,SAA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MACA,UACA,iBACW;AACX,KAAI,aAAa,SAAS,GAAG;AAC3B,SAAO;;CAGT,MAAM,UAAU,aAAa,MAAM,SAAS;CAC5C,MAAM,eAA8B,EAAE;CAEtC,MAAM,SAAS,SAAqB;AAClC,MAAI,KAAK,SAAS,oBAAoB;GACpC,MAAM,oBAAoB,6BAA6B,KAAK;AAC5D,OAAI,mBAAmB;IACrB,MAAM,YAAY,iBAAiB,kBAAkB;AACrD,QACE,UAAU,SAAS,oBACnB,UAAU,OAAO,SAAS,gBAC1B,UAAU,UAAU,WAAW,KAC/B,aAAa,IAAI,UAAU,OAAO,KAAK,EACvC;KACA,MAAM,cAAc,oCAClB,aAAa,IAAI,UAAU,OAAO,KAAK,CACxC;AACD,SAAI,aAAa;AACf,mBAAa,KAAK;OAChB,KAAK,kBAAkB;OACvB,OAAO,kBAAkB;OACzB,MAAM;OACP,CAAC;;;;;AAMV,qBAAmB,KAAK,CAAC,QAAQ,MAAM;;AAGzC,OAAM,QAAQ;AACd,QAAO,qBAAqB,MAAM,aAAa;;AAGjD,OAAO,MAAM,0BACX,MACA,UACA,kBACA,oBACA,2BACA,2BACW;CACX,MAAM,yBAAyB,mCAC7B,MACA,UACA,0BACD;CACD,MAAM,iBAAiB,+BACrB,wBACA,UACA,iBACD;AACD,KAAI,eAAe,QAAQ,SAAS,GAAG;AACrC,SAAO;;CAGT,MAAM,sBAAsB,IAAI,IAAI,CAClC,GAAG,oBACH,GAAG,eAAe,oBACnB,CAAC;AAEF,QAAO,0BACL,eAAe,MACf,UACA,qBACA,uBACD","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/prune.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport type { ImportDeclaration, Node, Program } from 'oxc-parser';\n\nimport { getOxcNodeChildren } from '../../../utils/oxc/ast';\nimport { applyOxcReplacements } from '../../../utils/oxc/replacements';\nimport { parseProgram } from './environment';\nimport { collectImportBindings, unwrapExpression } from './staticExpression';\nimport {\n findWYWMetaExtendsExpression,\n staticWYWMetaExtendsReplacementCode,\n} from './processorStaticModel';\nimport type { Range, Replacement } from './types';\n\nexport const isIdentifierBindingPosition = (\n node: Node,\n parent: Node | null\n): boolean => {\n if (node.type !== 'Identifier' || !parent) {\n return false;\n }\n\n if (\n (parent.type === 'VariableDeclarator' && parent.id === node) ||\n (parent.type === 'FunctionDeclaration' && parent.id === node) ||\n (parent.type === 'FunctionExpression' && parent.id === node) ||\n (parent.type === 'ClassDeclaration' && parent.id === node) ||\n (parent.type === 'ClassExpression' && parent.id === node)\n ) {\n return true;\n }\n\n if (\n (parent.type === 'ArrowFunctionExpression' ||\n parent.type === 'FunctionDeclaration' ||\n parent.type === 'FunctionExpression') &&\n parent.params.some((param) => param === node)\n ) {\n return true;\n }\n\n return (\n (parent.type === 'ImportSpecifier' && parent.local === node) ||\n (parent.type === 'ImportDefaultSpecifier' && parent.local === node) ||\n (parent.type === 'ImportNamespaceSpecifier' && parent.local === node)\n );\n};\n\nexport const isPropertyKeyOnlyIdentifier = (\n node: Node,\n parent: Node | null\n): boolean =>\n node.type === 'Identifier' &&\n !!parent &&\n ((parent.type === 'MemberExpression' &&\n parent.property === node &&\n !parent.computed) ||\n (parent.type === 'Property' &&\n parent.key === node &&\n !parent.computed &&\n !parent.shorthand));\n\nexport const collectUsedIdentifierNames = (program: Program): Set<string> => {\n const used = new Set<string>();\n\n const walk = (node: Node, parent: Node | null): void => {\n if (node.type === 'ImportDeclaration') {\n return;\n }\n\n if (\n node.type === 'Identifier' &&\n !isIdentifierBindingPosition(node, parent) &&\n !isPropertyKeyOnlyIdentifier(node, parent)\n ) {\n used.add(node.name);\n }\n\n getOxcNodeChildren(node).forEach((child) => walk(child, node));\n };\n\n walk(program, null);\n return used;\n};\n\nexport const removableStaticHelperNames = (\n program: Program,\n staticValueNames: Set<string>\n): Set<string> => {\n const used = collectUsedIdentifierNames(program);\n const result = new Set<string>();\n\n program.body.forEach((statement) => {\n if (statement.type !== 'VariableDeclaration') {\n return;\n }\n\n statement.declarations.forEach((declarator) => {\n if (\n declarator.id.type === 'Identifier' &&\n staticValueNames.has(declarator.id.name) &&\n !used.has(declarator.id.name)\n ) {\n result.add(declarator.id.name);\n }\n });\n });\n\n return result;\n};\n\nexport const collectImportLocalReferences = (\n node: Node,\n importLocals: Set<string>,\n result: Set<string>\n): void => {\n const walk = (item: Node, parent: Node | null): void => {\n if (\n item.type === 'Identifier' &&\n importLocals.has(item.name) &&\n !isIdentifierBindingPosition(item, parent) &&\n !isPropertyKeyOnlyIdentifier(item, parent)\n ) {\n result.add(item.name);\n }\n\n getOxcNodeChildren(item).forEach((child) => walk(child, item));\n };\n\n walk(node, null);\n};\nexport const removeStaticHelperDeclarations = (\n code: string,\n filename: string,\n staticValueNames: Set<string>\n): { code: string; removed: Set<string>; removedImportLocals: Set<string> } => {\n if (staticValueNames.size === 0) {\n return { code, removed: new Set(), removedImportLocals: new Set() };\n }\n\n const program = parseProgram(code, filename);\n const removableNames = removableStaticHelperNames(program, staticValueNames);\n const importLocals = new Set<string>();\n collectImportBindings(program).forEach((_, local) => importLocals.add(local));\n const removedImportLocals = new Set<string>();\n const ranges: Range[] = [];\n const replacements: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (\n statement.type !== 'VariableDeclaration' ||\n statement.declarations.length === 0\n ) {\n return;\n }\n\n const removableIndexes = statement.declarations.flatMap(\n (declarator, index) =>\n declarator.id.type === 'Identifier' &&\n removableNames.has(declarator.id.name)\n ? [index]\n : []\n );\n if (removableIndexes.length === 0) {\n return;\n }\n\n removableIndexes.forEach((index) => {\n collectImportLocalReferences(\n statement.declarations[index],\n importLocals,\n removedImportLocals\n );\n });\n\n if (removableIndexes.length === statement.declarations.length) {\n ranges.push({\n end: statement.end,\n start: statement.start,\n });\n return;\n }\n\n const keptDeclarations = statement.declarations\n .filter((_, index) => !removableIndexes.includes(index))\n .map((declarator) => code.slice(declarator.start, declarator.end));\n replacements.push({\n end: statement.end,\n start: statement.start,\n text: `${statement.kind} ${keptDeclarations.join(', ')};`,\n });\n });\n\n return {\n code: applyOxcReplacements(code, [\n ...ranges.map((range) => ({ ...range, text: '' })),\n ...replacements,\n ]),\n removed: removableNames,\n removedImportLocals,\n };\n};\n\nexport const importSpecifierLocalName = (\n specifier: ImportDeclaration['specifiers'][number]\n): string | null => specifier.local?.name ?? null;\n\nexport const removeUnusedStaticImports = (\n code: string,\n filename: string,\n staticImportLocals: Set<string>,\n sideEffectImportLocals: Set<string>\n): string => {\n if (staticImportLocals.size === 0) {\n return code;\n }\n\n const program = parseProgram(code, filename);\n const used = collectUsedIdentifierNames(program);\n const ranges: Range[] = [];\n const replacements: Replacement[] = [];\n\n program.body.forEach((statement) => {\n if (\n statement.type !== 'ImportDeclaration' ||\n statement.specifiers.length === 0\n ) {\n return;\n }\n\n const removable = statement.specifiers.flatMap((specifier, index) => {\n const localName = importSpecifierLocalName(specifier);\n return localName &&\n staticImportLocals.has(localName) &&\n !used.has(localName)\n ? [{ index, localName }]\n : [];\n });\n\n if (removable.length === 0) {\n return;\n }\n\n if (removable.length === statement.specifiers.length) {\n if (\n removable.some((item) => sideEffectImportLocals.has(item.localName))\n ) {\n replacements.push({\n end: statement.end,\n start: statement.start,\n text: `import ${code.slice(\n statement.source.start,\n statement.source.end\n )};`,\n });\n return;\n }\n\n ranges.push({\n end: statement.end,\n start: statement.start,\n });\n }\n });\n\n return applyOxcReplacements(code, [\n ...ranges.map((range) => ({ ...range, text: '' })),\n ...replacements,\n ]);\n};\n\nexport const replaceStaticWYWMetaExtendsHelpers = (\n code: string,\n filename: string,\n helperValues: Map<string, unknown>\n): string => {\n if (helperValues.size === 0) {\n return code;\n }\n\n const program = parseProgram(code, filename);\n const replacements: Replacement[] = [];\n\n const visit = (node: Node): void => {\n if (node.type === 'ObjectExpression') {\n const extendsExpression = findWYWMetaExtendsExpression(node);\n if (extendsExpression) {\n const unwrapped = unwrapExpression(extendsExpression);\n if (\n unwrapped.type === 'CallExpression' &&\n unwrapped.callee.type === 'Identifier' &&\n unwrapped.arguments.length === 0 &&\n helperValues.has(unwrapped.callee.name)\n ) {\n const replacement = staticWYWMetaExtendsReplacementCode(\n helperValues.get(unwrapped.callee.name)\n );\n if (replacement) {\n replacements.push({\n end: extendsExpression.end,\n start: extendsExpression.start,\n text: replacement,\n });\n }\n }\n }\n }\n\n getOxcNodeChildren(node).forEach(visit);\n };\n\n visit(program);\n return applyOxcReplacements(code, replacements);\n};\n\nexport const pruneStaticPreevalCode = (\n code: string,\n filename: string,\n staticValueNames: Set<string>,\n staticImportLocals: Set<string>,\n staticExtendsHelperValues: Map<string, unknown>,\n sideEffectImportLocals: Set<string>\n): string => {\n const codeWithMetadataPruned = replaceStaticWYWMetaExtendsHelpers(\n code,\n filename,\n staticExtendsHelperValues\n );\n const helpersRemoved = removeStaticHelperDeclarations(\n codeWithMetadataPruned,\n filename,\n staticValueNames\n );\n if (helpersRemoved.removed.size === 0) {\n return codeWithMetadataPruned;\n }\n\n const importLocalsToPrune = new Set([\n ...staticImportLocals,\n ...helpersRemoved.removedImportLocals,\n ]);\n\n return removeUnusedStaticImports(\n helpersRemoved.code,\n filename,\n importLocalsToPrune,\n sideEffectImportLocals\n );\n};\n"],"file":"prune.js"}
@@ -0,0 +1,183 @@
1
+ /* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
2
+ import { isAbsolute } from "path";
3
+ import { appendOxcWywPreval } from "../../../utils/oxcPreevalStage.js";
4
+ import { stripQueryAndHash } from "../../../utils/parseRequest.js";
5
+ import { resolveCandidateValue, resolveOpaqueRuntimeCandidateValue } from "./candidateResolver.js";
6
+ import { debugStaticResolve, getEvalStrategy, getStaticStrategyFailure, parseProgram } from "./environment.js";
7
+ import { collectWYWMetaExtendsHelperNames, createSameFileStaticWYWMetaHelperResolver } from "./processorStaticModel.js";
8
+ import { pruneStaticPreevalCode } from "./prune.js";
9
+ import { runtimeCallbackPlaceholder } from "./staticExpression.js";
10
+ export function* resolveStaticOxcPreevalValues() {
11
+ const preevalResult = this.entrypoint.getPreevalResult();
12
+ if (!preevalResult) {
13
+ return false;
14
+ }
15
+ const candidates = preevalResult.staticValueCandidates ?? [];
16
+ const evalDependencyNames = new Set(preevalResult.dependencyNames ?? []);
17
+ if (candidates.length === 0 && evalDependencyNames.size === 0) {
18
+ return false;
19
+ }
20
+ const filename = this.entrypoint.loadedAndParsed.evaluator === "ignored" ? this.entrypoint.name : this.entrypoint.loadedAndParsed.evalConfig.filename ?? this.entrypoint.name;
21
+ const evalStrategy = getEvalStrategy(this);
22
+ if (evalStrategy === "execute") {
23
+ return false;
24
+ }
25
+ const staticOnly = evalStrategy === "static";
26
+ const staticValueCache = preevalResult.staticValueCache ?? new Map();
27
+ const staticDependencies = new Set(preevalResult.staticDependencies ?? []);
28
+ const staticImportLocals = new Set();
29
+ const sideEffectImportLocals = new Set();
30
+ const staticNullWYWMetaExtendsHelpers = new Set(preevalResult.staticNullWYWMetaExtendsHelpers ?? []);
31
+ const memo = new Map();
32
+ const opaqueRuntimeBaseHelpers = collectWYWMetaExtendsHelperNames(parseProgram(preevalResult.baseCode ?? preevalResult.code, filename));
33
+ // Names of candidates resolved to runtime callbacks (function values).
34
+ // They keep the file out of evalFile but their helper declarations must
35
+ // not be pruned — the runtime call site relies on them.
36
+ const runtimeOnlyCandidateNames = new Set(preevalResult.runtimeOnlyStaticValueNames ?? []);
37
+ let changed = false;
38
+ let hasKnownStaticCandidate = false;
39
+ const resolveSameFileStaticWYWMetaHelpers = createSameFileStaticWYWMetaHelperResolver(preevalResult.baseCode ?? preevalResult.code, filename);
40
+ const applySameFileStaticWYWMetaHelpers = () => {
41
+ let appliedAny = false;
42
+ for (;;) {
43
+ let applied = false;
44
+ const values = resolveSameFileStaticWYWMetaHelpers(staticValueCache);
45
+ values.forEach((value, name) => {
46
+ if (staticValueCache.has(name) || !evalDependencyNames.has(name) && !opaqueRuntimeBaseHelpers.has(name)) {
47
+ return;
48
+ }
49
+ staticValueCache.set(name, value);
50
+ debugStaticResolve(this, {
51
+ candidate: name,
52
+ filename,
53
+ phase: "candidate",
54
+ reason: "same-file-static-metadata",
55
+ status: "resolved"
56
+ });
57
+ applied = true;
58
+ });
59
+ if (!applied) {
60
+ break;
61
+ }
62
+ appliedAny = true;
63
+ }
64
+ if (appliedAny) {
65
+ changed = true;
66
+ hasKnownStaticCandidate = true;
67
+ }
68
+ return appliedAny;
69
+ };
70
+ applySameFileStaticWYWMetaHelpers();
71
+ for (const candidate of candidates) {
72
+ applySameFileStaticWYWMetaHelpers();
73
+ const isOpaqueRuntimeBaseHelper = opaqueRuntimeBaseHelpers.has(candidate.name);
74
+ if (!evalDependencyNames.has(candidate.name) && !isOpaqueRuntimeBaseHelper && !staticValueCache.has(candidate.name)) {
75
+ debugStaticResolve(this, {
76
+ candidate: candidate.name,
77
+ filename,
78
+ phase: "candidate",
79
+ reason: "not-eval-dependency",
80
+ status: "skipped"
81
+ });
82
+ continue;
83
+ }
84
+ if (staticValueCache.has(candidate.name)) {
85
+ hasKnownStaticCandidate = true;
86
+ candidate.imports.forEach((item) => staticImportLocals.add(item.importLocal ?? item.local));
87
+ if (isOpaqueRuntimeBaseHelper && staticValueCache.get(candidate.name) === null) {
88
+ staticNullWYWMetaExtendsHelpers.add(candidate.name);
89
+ }
90
+ debugStaticResolve(this, {
91
+ candidate: candidate.name,
92
+ filename,
93
+ phase: "candidate",
94
+ reason: "already-static",
95
+ status: "skipped"
96
+ });
97
+ continue;
98
+ }
99
+ let resolved;
100
+ let resolvedOpaqueRuntimeBase = false;
101
+ if (isOpaqueRuntimeBaseHelper) {
102
+ resolved = yield* resolveOpaqueRuntimeCandidateValue(this, candidate, filename);
103
+ resolvedOpaqueRuntimeBase = !!resolved;
104
+ if (!resolved) {
105
+ resolved = yield* resolveCandidateValue(this, candidate, filename, memo);
106
+ }
107
+ } else {
108
+ resolved = yield* resolveCandidateValue(this, candidate, filename, memo);
109
+ }
110
+ if (!resolved) {
111
+ continue;
112
+ }
113
+ if (resolvedOpaqueRuntimeBase) {
114
+ debugStaticResolve(this, {
115
+ candidate: candidate.name,
116
+ filename,
117
+ phase: "candidate",
118
+ reason: "opaque-runtime-component",
119
+ status: "resolved"
120
+ });
121
+ staticNullWYWMetaExtendsHelpers.add(candidate.name);
122
+ }
123
+ if (resolved.runtimeOnly) {
124
+ // Runtime callback — seed a callable placeholder for collect() but
125
+ // track it separately so the `_exp = () => target` helper survives
126
+ // pruning. The runtime call site relies on that helper declaration.
127
+ runtimeOnlyCandidateNames.add(candidate.name);
128
+ staticValueCache.set(candidate.name, runtimeCallbackPlaceholder);
129
+ } else {
130
+ staticValueCache.set(candidate.name, resolved.value);
131
+ }
132
+ hasKnownStaticCandidate = true;
133
+ candidate.imports.forEach((item) => staticImportLocals.add(item.importLocal ?? item.local));
134
+ resolved.dependencies.forEach((dependency) => staticDependencies.add(dependency));
135
+ resolved.sideEffectImportLocals?.forEach((local) => sideEffectImportLocals.add(local));
136
+ changed = true;
137
+ applySameFileStaticWYWMetaHelpers();
138
+ }
139
+ if (!changed && (!hasKnownStaticCandidate || preevalResult.staticValuesApplied)) {
140
+ if (staticOnly && evalDependencyNames.size > 0) {
141
+ throw getStaticStrategyFailure(filename, evalDependencyNames);
142
+ }
143
+ return false;
144
+ }
145
+ const dependencyNames = (preevalResult.dependencyNames ?? []).filter((name) => !staticValueCache.has(name) && !runtimeOnlyCandidateNames.has(name));
146
+ if (staticOnly && dependencyNames.length > 0) {
147
+ throw getStaticStrategyFailure(filename, dependencyNames);
148
+ }
149
+ preevalResult.dependencyNames = dependencyNames;
150
+ preevalResult.staticValueCache = staticValueCache;
151
+ preevalResult.staticDependencies = [...staticDependencies];
152
+ preevalResult.staticNullWYWMetaExtendsHelpers = [...staticNullWYWMetaExtendsHelpers];
153
+ preevalResult.runtimeOnlyStaticValueNames = [...runtimeOnlyCandidateNames];
154
+ preevalResult.staticValuesApplied = true;
155
+ const originalBaseCode = preevalResult.baseCode ?? preevalResult.code;
156
+ const prunableStaticValueNames = new Set([...staticValueCache.keys()].filter((name) => !runtimeOnlyCandidateNames.has(name)));
157
+ const staticExtendsHelperValues = new Map([...staticValueCache].filter(([name]) => !runtimeOnlyCandidateNames.has(name)));
158
+ staticNullWYWMetaExtendsHelpers.forEach((name) => {
159
+ if (!staticExtendsHelperValues.has(name)) {
160
+ staticExtendsHelperValues.set(name, null);
161
+ }
162
+ });
163
+ const baseCode = pruneStaticPreevalCode(originalBaseCode, filename, prunableStaticValueNames, staticImportLocals, staticExtendsHelperValues, sideEffectImportLocals);
164
+ const evalBaseCode = sideEffectImportLocals.size > 0 ? pruneStaticPreevalCode(originalBaseCode, filename, prunableStaticValueNames, staticImportLocals, staticExtendsHelperValues, new Set()) : baseCode;
165
+ preevalResult.baseCode = baseCode;
166
+ preevalResult.code = appendOxcWywPreval(baseCode, filename, dependencyNames);
167
+ preevalResult.evalCode = appendOxcWywPreval(evalBaseCode, filename, dependencyNames);
168
+ preevalResult.staticSideEffectImportLocals = [...sideEffectImportLocals];
169
+ for (const dependency of staticDependencies) {
170
+ const strippedDependency = stripQueryAndHash(dependency);
171
+ if (isAbsolute(strippedDependency)) {
172
+ this.services.cache.checkFreshness(dependency, strippedDependency);
173
+ }
174
+ this.entrypoint.addInvalidationDependency({
175
+ only: ["*"],
176
+ resolved: dependency,
177
+ source: dependency
178
+ });
179
+ this.entrypoint.markInvalidateOnDependencyChange(dependency);
180
+ }
181
+ return true;
182
+ }
183
+ //# sourceMappingURL=resolveStaticOxcPreevalValues.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAEA,SAAS,kBAAkB;AAE3B,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAElC,SACE,uBACA,0CACK;AACP,SACE,oBACA,iBACA,0BACA,oBACK;AACP,SACE,kCACA,iDACK;AACP,SAAS,8BAA8B;AACvC,SAAS,kCAAkC;AAG3C,OAAO,UAAU,gCAEW;CAC1B,MAAM,gBAAgB,KAAK,WAAW,kBAAkB;AACxD,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MAAM,KAAK;;GAE3C;CACF,MAAM,WAAW,uBACf,kBACA,UACA,0BACA,oBACA,2BACA,uBACD;CACD,MAAM,eACJ,uBAAuB,OAAO,IAC1B,uBACE,kBACA,UACA,0BACA,oBACA,2BACA,IAAI,KAAK,CACV,GACD;AACN,eAAc,WAAW;AACzB,eAAc,OAAO,mBAAmB,UAAU,UAAU,gBAAgB;AAC5E,eAAc,WAAW,mBACvB,cACA,UACA,gBACD;AACD,eAAc,+BAA+B,CAAC,GAAG,uBAAuB;AAExE,MAAK,MAAM,cAAc,oBAAoB;EAC3C,MAAM,qBAAqB,kBAAkB,WAAW;AACxD,MAAI,WAAW,mBAAmB,EAAE;AAClC,QAAK,SAAS,MAAM,eAAe,YAAY,mBAAmB;;AAGpE,OAAK,WAAW,0BAA0B;GACxC,MAAM,CAAC,IAAI;GACX,UAAU;GACV,QAAQ;GACT,CAAC;AACF,OAAK,WAAW,iCAAiC,WAAW;;AAG9D,QAAO","names":[],"sources":["../../../../src/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */\n\nimport { isAbsolute } from 'path';\n\nimport { appendOxcWywPreval } from '../../../utils/oxcPreevalStage';\nimport { stripQueryAndHash } from '../../../utils/parseRequest';\nimport type { ITransformAction, SyncScenarioFor } from '../../types';\nimport {\n resolveCandidateValue,\n resolveOpaqueRuntimeCandidateValue,\n} from './candidateResolver';\nimport {\n debugStaticResolve,\n getEvalStrategy,\n getStaticStrategyFailure,\n parseProgram,\n} from './environment';\nimport {\n collectWYWMetaExtendsHelperNames,\n createSameFileStaticWYWMetaHelperResolver,\n} from './processorStaticModel';\nimport { pruneStaticPreevalCode } from './prune';\nimport { runtimeCallbackPlaceholder } from './staticExpression';\nimport type { StaticExportResult } from './types';\n\nexport function* resolveStaticOxcPreevalValues(\n this: ITransformAction\n): SyncScenarioFor<boolean> {\n const preevalResult = this.entrypoint.getPreevalResult();\n if (!preevalResult) {\n return false;\n }\n\n const candidates = preevalResult.staticValueCandidates ?? [];\n const evalDependencyNames = new Set(preevalResult.dependencyNames ?? []);\n if (candidates.length === 0 && evalDependencyNames.size === 0) {\n return false;\n }\n\n const filename =\n this.entrypoint.loadedAndParsed.evaluator === 'ignored'\n ? this.entrypoint.name\n : this.entrypoint.loadedAndParsed.evalConfig.filename ??\n this.entrypoint.name;\n const evalStrategy = getEvalStrategy(this);\n if (evalStrategy === 'execute') {\n return false;\n }\n const staticOnly = evalStrategy === 'static';\n\n const staticValueCache =\n preevalResult.staticValueCache ?? new Map<string, unknown>();\n const staticDependencies = new Set(preevalResult.staticDependencies ?? []);\n const staticImportLocals = new Set<string>();\n const sideEffectImportLocals = new Set<string>();\n const staticNullWYWMetaExtendsHelpers = new Set(\n preevalResult.staticNullWYWMetaExtendsHelpers ?? []\n );\n const memo = new Map<string, StaticExportResult | null>();\n const opaqueRuntimeBaseHelpers = collectWYWMetaExtendsHelperNames(\n parseProgram(preevalResult.baseCode ?? preevalResult.code, filename)\n );\n // Names of candidates resolved to runtime callbacks (function values).\n // They keep the file out of evalFile but their helper declarations must\n // not be pruned — the runtime call site relies on them.\n const runtimeOnlyCandidateNames = new Set<string>(\n preevalResult.runtimeOnlyStaticValueNames ?? []\n );\n let changed = false;\n let hasKnownStaticCandidate = false;\n const resolveSameFileStaticWYWMetaHelpers =\n createSameFileStaticWYWMetaHelperResolver(\n preevalResult.baseCode ?? preevalResult.code,\n filename\n );\n const applySameFileStaticWYWMetaHelpers = (): boolean => {\n let appliedAny = false;\n\n for (;;) {\n let applied = false;\n const values = resolveSameFileStaticWYWMetaHelpers(staticValueCache);\n values.forEach((value, name) => {\n if (\n staticValueCache.has(name) ||\n (!evalDependencyNames.has(name) &&\n !opaqueRuntimeBaseHelpers.has(name))\n ) {\n return;\n }\n\n staticValueCache.set(name, value);\n debugStaticResolve(this, {\n candidate: name,\n filename,\n phase: 'candidate',\n reason: 'same-file-static-metadata',\n status: 'resolved',\n });\n applied = true;\n });\n\n if (!applied) {\n break;\n }\n\n appliedAny = true;\n }\n\n if (appliedAny) {\n changed = true;\n hasKnownStaticCandidate = true;\n }\n\n return appliedAny;\n };\n\n applySameFileStaticWYWMetaHelpers();\n\n for (const candidate of candidates) {\n applySameFileStaticWYWMetaHelpers();\n\n const isOpaqueRuntimeBaseHelper = opaqueRuntimeBaseHelpers.has(\n candidate.name\n );\n if (\n !evalDependencyNames.has(candidate.name) &&\n !isOpaqueRuntimeBaseHelper &&\n !staticValueCache.has(candidate.name)\n ) {\n debugStaticResolve(this, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'not-eval-dependency',\n status: 'skipped',\n });\n continue;\n }\n\n if (staticValueCache.has(candidate.name)) {\n hasKnownStaticCandidate = true;\n candidate.imports.forEach((item) =>\n staticImportLocals.add(item.importLocal ?? item.local)\n );\n if (\n isOpaqueRuntimeBaseHelper &&\n staticValueCache.get(candidate.name) === null\n ) {\n staticNullWYWMetaExtendsHelpers.add(candidate.name);\n }\n debugStaticResolve(this, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'already-static',\n status: 'skipped',\n });\n continue;\n }\n\n let resolved: StaticExportResult | null;\n let resolvedOpaqueRuntimeBase = false;\n if (isOpaqueRuntimeBaseHelper) {\n resolved = yield* resolveOpaqueRuntimeCandidateValue(\n this,\n candidate,\n filename\n );\n resolvedOpaqueRuntimeBase = !!resolved;\n if (!resolved) {\n resolved = yield* resolveCandidateValue(\n this,\n candidate,\n filename,\n memo\n );\n }\n } else {\n resolved = yield* resolveCandidateValue(this, candidate, filename, memo);\n }\n if (!resolved) {\n continue;\n }\n\n if (resolvedOpaqueRuntimeBase) {\n debugStaticResolve(this, {\n candidate: candidate.name,\n filename,\n phase: 'candidate',\n reason: 'opaque-runtime-component',\n status: 'resolved',\n });\n staticNullWYWMetaExtendsHelpers.add(candidate.name);\n }\n\n if (resolved.runtimeOnly) {\n // Runtime callback — seed a callable placeholder for collect() but\n // track it separately so the `_exp = () => target` helper survives\n // pruning. The runtime call site relies on that helper declaration.\n runtimeOnlyCandidateNames.add(candidate.name);\n staticValueCache.set(candidate.name, runtimeCallbackPlaceholder);\n } else {\n staticValueCache.set(candidate.name, resolved.value);\n }\n hasKnownStaticCandidate = true;\n candidate.imports.forEach((item) =>\n staticImportLocals.add(item.importLocal ?? item.local)\n );\n resolved.dependencies.forEach((dependency) =>\n staticDependencies.add(dependency)\n );\n resolved.sideEffectImportLocals?.forEach((local) =>\n sideEffectImportLocals.add(local)\n );\n changed = true;\n applySameFileStaticWYWMetaHelpers();\n }\n\n if (\n !changed &&\n (!hasKnownStaticCandidate || preevalResult.staticValuesApplied)\n ) {\n if (staticOnly && evalDependencyNames.size > 0) {\n throw getStaticStrategyFailure(filename, evalDependencyNames);\n }\n return false;\n }\n\n const dependencyNames = (preevalResult.dependencyNames ?? []).filter(\n (name) =>\n !staticValueCache.has(name) && !runtimeOnlyCandidateNames.has(name)\n );\n if (staticOnly && dependencyNames.length > 0) {\n throw getStaticStrategyFailure(filename, dependencyNames);\n }\n preevalResult.dependencyNames = dependencyNames;\n preevalResult.staticValueCache = staticValueCache;\n preevalResult.staticDependencies = [...staticDependencies];\n preevalResult.staticNullWYWMetaExtendsHelpers = [\n ...staticNullWYWMetaExtendsHelpers,\n ];\n preevalResult.runtimeOnlyStaticValueNames = [...runtimeOnlyCandidateNames];\n preevalResult.staticValuesApplied = true;\n const originalBaseCode = preevalResult.baseCode ?? preevalResult.code;\n const prunableStaticValueNames = new Set(\n [...staticValueCache.keys()].filter(\n (name) => !runtimeOnlyCandidateNames.has(name)\n )\n );\n const staticExtendsHelperValues = new Map(\n [...staticValueCache].filter(\n ([name]) => !runtimeOnlyCandidateNames.has(name)\n )\n );\n staticNullWYWMetaExtendsHelpers.forEach((name) => {\n if (!staticExtendsHelperValues.has(name)) {\n staticExtendsHelperValues.set(name, null);\n }\n });\n const baseCode = pruneStaticPreevalCode(\n originalBaseCode,\n filename,\n prunableStaticValueNames,\n staticImportLocals,\n staticExtendsHelperValues,\n sideEffectImportLocals\n );\n const evalBaseCode =\n sideEffectImportLocals.size > 0\n ? pruneStaticPreevalCode(\n originalBaseCode,\n filename,\n prunableStaticValueNames,\n staticImportLocals,\n staticExtendsHelperValues,\n new Set()\n )\n : baseCode;\n preevalResult.baseCode = baseCode;\n preevalResult.code = appendOxcWywPreval(baseCode, filename, dependencyNames);\n preevalResult.evalCode = appendOxcWywPreval(\n evalBaseCode,\n filename,\n dependencyNames\n );\n preevalResult.staticSideEffectImportLocals = [...sideEffectImportLocals];\n\n for (const dependency of staticDependencies) {\n const strippedDependency = stripQueryAndHash(dependency);\n if (isAbsolute(strippedDependency)) {\n this.services.cache.checkFreshness(dependency, strippedDependency);\n }\n\n this.entrypoint.addInvalidationDependency({\n only: ['*'],\n resolved: dependency,\n source: dependency,\n });\n this.entrypoint.markInvalidateOnDependencyChange(dependency);\n }\n\n return true;\n}\n"],"file":"resolveStaticOxcPreevalValues.js"}