@wyw-in-js/transform 2.0.0-alpha.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/esm/cache.js +7 -0
  2. package/esm/cache.js.map +1 -1
  3. package/esm/debug/fileReporter.js +35 -1
  4. package/esm/debug/fileReporter.js.map +1 -1
  5. package/esm/eval/broker.js +230 -89
  6. package/esm/eval/broker.js.map +1 -1
  7. package/esm/eval/protocol.js.map +1 -1
  8. package/esm/eval/runner.js +143 -24
  9. package/esm/eval/runner.js.map +1 -1
  10. package/esm/module.js +70 -43
  11. package/esm/module.js.map +1 -1
  12. package/esm/transform/Entrypoint.types.js.map +1 -1
  13. package/esm/transform/generators/collect.js +1 -0
  14. package/esm/transform/generators/collect.js.map +1 -1
  15. package/esm/transform/generators/processEntrypoint.js +35 -20
  16. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  17. package/esm/transform/generators/resolveImports.js +48 -2
  18. package/esm/transform/generators/resolveImports.js.map +1 -1
  19. package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  20. package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
  21. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
  22. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
  23. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
  24. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
  25. package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
  26. package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
  27. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
  28. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
  29. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
  30. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
  31. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
  32. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
  33. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
  34. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
  35. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
  36. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
  37. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
  38. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
  39. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
  40. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
  41. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
  42. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
  43. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
  44. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
  45. package/esm/transform/generators/resolveStaticOxcValues/prune.js +272 -0
  46. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
  47. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +184 -0
  48. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
  49. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
  50. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
  51. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
  52. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
  53. package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
  54. package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
  55. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
  56. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
  57. package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
  58. package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
  59. package/esm/transform/generators/transform.js +58 -45
  60. package/esm/transform/generators/transform.js.map +1 -1
  61. package/esm/transform/helpers/loadWywOptions.js +33 -4
  62. package/esm/transform/helpers/loadWywOptions.js.map +1 -1
  63. package/esm/transform.js +3 -1
  64. package/esm/transform.js.map +1 -1
  65. package/esm/utils/EventEmitter.js +55 -9
  66. package/esm/utils/EventEmitter.js.map +1 -1
  67. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
  68. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
  69. package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
  70. package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
  71. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +517 -0
  72. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
  73. package/esm/utils/applyOxcProcessors/displayName.js +93 -0
  74. package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
  75. package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
  76. package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
  77. package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
  78. package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
  79. package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
  80. package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
  81. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
  82. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
  83. package/esm/utils/applyOxcProcessors/shared.js +29 -0
  84. package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
  85. package/esm/utils/applyOxcProcessors/types.js +2 -0
  86. package/esm/utils/applyOxcProcessors/types.js.map +1 -0
  87. package/esm/utils/applyOxcProcessors.js +1 -1216
  88. package/esm/utils/applyOxcProcessors.js.map +1 -1
  89. package/esm/utils/collectOxcExportsAndImports.js +8 -0
  90. package/esm/utils/collectOxcExportsAndImports.js.map +1 -1
  91. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
  92. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
  93. package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
  94. package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
  95. package/esm/utils/collectOxcRuntime/types.js +2 -0
  96. package/esm/utils/collectOxcRuntime/types.js.map +1 -0
  97. package/esm/utils/collectOxcRuntime.js +5 -193
  98. package/esm/utils/collectOxcRuntime.js.map +1 -1
  99. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
  100. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
  101. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
  102. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
  103. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
  104. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
  105. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
  106. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
  107. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
  108. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
  109. package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
  110. package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
  111. package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
  112. package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
  113. package/esm/utils/nativeResolver.js +93 -0
  114. package/esm/utils/nativeResolver.js.map +1 -0
  115. package/esm/utils/oxc/ast.js +58 -0
  116. package/esm/utils/oxc/ast.js.map +1 -0
  117. package/esm/utils/oxc/parse.js +3 -0
  118. package/esm/utils/oxc/parse.js.map +1 -0
  119. package/esm/utils/oxc/replacements.js +14 -0
  120. package/esm/utils/oxc/replacements.js.map +1 -0
  121. package/esm/utils/oxc/sourceLocations.js +59 -0
  122. package/esm/utils/oxc/sourceLocations.js.map +1 -0
  123. package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
  124. package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
  125. package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
  126. package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
  127. package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
  128. package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
  129. package/esm/utils/oxcPreevalStage/processors.js +17 -0
  130. package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
  131. package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
  132. package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
  133. package/esm/utils/oxcPreevalStage/types.js +2 -0
  134. package/esm/utils/oxcPreevalStage/types.js.map +1 -0
  135. package/esm/utils/oxcPreevalStage.js +17 -73
  136. package/esm/utils/oxcPreevalStage.js.map +1 -1
  137. package/esm/utils/oxcPreevalTransforms.js +106 -66
  138. package/esm/utils/oxcPreevalTransforms.js.map +1 -1
  139. package/esm/utils/parseOxc.js +6 -1
  140. package/esm/utils/parseOxc.js.map +1 -1
  141. package/esm/utils/processorStaticSemantics.js +157 -0
  142. package/esm/utils/processorStaticSemantics.js.map +1 -0
  143. package/esm/utils/resolveWithConditions.js +3 -3
  144. package/esm/utils/resolveWithConditions.js.map +1 -1
  145. package/package.json +6 -5
  146. package/types/cache.js +8 -0
  147. package/types/debug/fileReporter.js +46 -1
  148. package/types/eval/broker.d.ts +6 -2
  149. package/types/eval/broker.js +244 -95
  150. package/types/eval/protocol.d.ts +15 -1
  151. package/types/module.d.ts +4 -1
  152. package/types/module.js +97 -48
  153. package/types/transform/Entrypoint.types.d.ts +4 -0
  154. package/types/transform/generators/collect.js +1 -0
  155. package/types/transform/generators/resolveImports.d.ts +3 -1
  156. package/types/transform/generators/resolveImports.js +49 -2
  157. package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
  158. package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  159. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
  160. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
  161. package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
  162. package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
  163. package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
  164. package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
  165. package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
  166. package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
  167. package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
  168. package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
  169. package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
  170. package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
  171. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
  172. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
  173. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
  174. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
  175. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
  176. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
  177. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
  178. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
  179. package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
  180. package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
  181. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
  182. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
  183. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
  184. package/types/transform/generators/resolveStaticOxcValues/prune.js +312 -0
  185. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
  186. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +198 -0
  187. package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
  188. package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
  189. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
  190. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
  191. package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
  192. package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
  193. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
  194. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
  195. package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
  196. package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
  197. package/types/transform/generators/transform.js +64 -49
  198. package/types/transform/helpers/loadWywOptions.js +23 -3
  199. package/types/transform.js +3 -1
  200. package/types/utils/EventEmitter.d.ts +16 -1
  201. package/types/utils/EventEmitter.js +57 -9
  202. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +9 -0
  203. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +169 -0
  204. package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
  205. package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
  206. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
  207. package/types/utils/applyOxcProcessors/cleanupRemovals.js +567 -0
  208. package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
  209. package/types/utils/applyOxcProcessors/displayName.js +113 -0
  210. package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
  211. package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
  212. package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
  213. package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
  214. package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
  215. package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
  216. package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
  217. package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
  218. package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
  219. package/types/utils/applyOxcProcessors/shared.js +37 -0
  220. package/types/utils/applyOxcProcessors/types.d.ts +88 -0
  221. package/types/utils/applyOxcProcessors/types.js +1 -0
  222. package/types/utils/applyOxcProcessors.d.ts +1 -16
  223. package/types/utils/applyOxcProcessors.js +1 -1391
  224. package/types/utils/collectOxcExportsAndImports.js +8 -0
  225. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
  226. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
  227. package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
  228. package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
  229. package/types/utils/collectOxcRuntime/types.d.ts +17 -0
  230. package/types/utils/collectOxcRuntime/types.js +1 -0
  231. package/types/utils/collectOxcRuntime.d.ts +2 -12
  232. package/types/utils/collectOxcRuntime.js +5 -224
  233. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
  234. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
  235. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
  236. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
  237. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
  238. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
  239. package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
  240. package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
  241. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
  242. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
  243. package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
  244. package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
  245. package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
  246. package/types/utils/collectOxcTemplateDependencies.js +3 -1580
  247. package/types/utils/nativeResolver.d.ts +13 -0
  248. package/types/utils/nativeResolver.js +91 -0
  249. package/types/utils/oxc/ast.d.ts +4 -0
  250. package/types/utils/oxc/ast.js +61 -0
  251. package/types/utils/oxc/parse.d.ts +3 -0
  252. package/types/utils/oxc/parse.js +2 -0
  253. package/types/utils/oxc/replacements.d.ts +12 -0
  254. package/types/utils/oxc/replacements.js +18 -0
  255. package/types/utils/oxc/sourceLocations.d.ts +5 -0
  256. package/types/utils/oxc/sourceLocations.js +63 -0
  257. package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
  258. package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
  259. package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
  260. package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
  261. package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
  262. package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
  263. package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
  264. package/types/utils/oxcPreevalStage/processors.js +16 -0
  265. package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
  266. package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
  267. package/types/utils/oxcPreevalStage/types.d.ts +22 -0
  268. package/types/utils/oxcPreevalStage/types.js +1 -0
  269. package/types/utils/oxcPreevalStage.d.ts +2 -18
  270. package/types/utils/oxcPreevalStage.js +17 -79
  271. package/types/utils/oxcPreevalTransforms.js +111 -75
  272. package/types/utils/parseOxc.js +6 -1
  273. package/types/utils/processorStaticSemantics.d.ts +13 -0
  274. package/types/utils/processorStaticSemantics.js +191 -0
  275. package/types/utils/resolveWithConditions.js +3 -3
  276. package/esm/eval/resolverStrategy.js +0 -51
  277. package/esm/eval/resolverStrategy.js.map +0 -1
  278. package/types/eval/resolverStrategy.d.ts +0 -13
  279. package/types/eval/resolverStrategy.js +0 -46
@@ -0,0 +1,18 @@
1
+ import { usesStaticEvaluation } from "./evalStrategy.js";
2
+ export const createStaticPreevalOverlay = (processed, dependencyNames, options) => {
3
+ const staticValuesEnabled = usesStaticEvaluation(options);
4
+ const staticValueNames = staticValuesEnabled ? new Set(processed.staticValues.map((item) => item.name)) : null;
5
+ const evalDependencyNames = staticValuesEnabled ? dependencyNames.filter((name) => !staticValueNames.has(name)) : dependencyNames;
6
+ const staticValueCache = new Map();
7
+ if (staticValuesEnabled) {
8
+ processed.staticValues.forEach(({ name, value }) => {
9
+ staticValueCache.set(name, value);
10
+ });
11
+ }
12
+ return {
13
+ evalDependencyNames,
14
+ staticValueCache,
15
+ staticValueCandidates: staticValuesEnabled ? processed.staticValueCandidates : []
16
+ };
17
+ };
18
+ //# sourceMappingURL=staticOverlay.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AACA,SAAS,4BAA4B;AAGrC,OAAO,MAAM,8BACX,WACA,iBACA,YACyB;CACzB,MAAM,sBAAsB,qBAAqB,QAAQ;CACzD,MAAM,mBAAmB,sBACrB,IAAI,IAAI,UAAU,aAAa,KAAK,SAAS,KAAK,KAAK,CAAC,GACxD;CACJ,MAAM,sBAAsB,sBACxB,gBAAgB,QAAQ,SAAS,CAAC,iBAAkB,IAAI,KAAK,CAAC,GAC9D;CACJ,MAAM,mBAAmB,IAAI,KAAsB;AAEnD,KAAI,qBAAqB;AACvB,YAAU,aAAa,SAAS,EAAE,MAAM,YAAY;AAClD,oBAAiB,IAAI,MAAM,MAAM;IACjC;;AAGJ,QAAO;EACL;EACA;EACA,uBAAuB,sBACnB,UAAU,wBACV,EAAE;EACP","names":[],"sources":["../../../src/utils/oxcPreevalStage/staticOverlay.ts"],"version":3,"sourcesContent":["import type { ApplyOxcProcessorsResult } from '../applyOxcProcessors/types';\nimport { usesStaticEvaluation } from './evalStrategy';\nimport type { OxcPreevalOptions, StaticPreevalOverlay } from './types';\n\nexport const createStaticPreevalOverlay = (\n processed: ApplyOxcProcessorsResult,\n dependencyNames: string[],\n options: OxcPreevalOptions\n): StaticPreevalOverlay => {\n const staticValuesEnabled = usesStaticEvaluation(options);\n const staticValueNames = staticValuesEnabled\n ? new Set(processed.staticValues.map((item) => item.name))\n : null;\n const evalDependencyNames = staticValuesEnabled\n ? dependencyNames.filter((name) => !staticValueNames!.has(name))\n : dependencyNames;\n const staticValueCache = new Map<string, unknown>();\n\n if (staticValuesEnabled) {\n processed.staticValues.forEach(({ name, value }) => {\n staticValueCache.set(name, value);\n });\n }\n\n return {\n evalDependencyNames,\n staticValueCache,\n staticValueCandidates: staticValuesEnabled\n ? processed.staticValueCandidates\n : [],\n };\n};\n"],"file":"staticOverlay.js"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"","names":[],"sources":["../../../src/utils/oxcPreevalStage/types.ts"],"version":3,"sourcesContent":["import type { StrictOptions } from '@wyw-in-js/shared';\n\nimport type { EventEmitter } from '../EventEmitter';\nimport type { WYWTransformMetadata } from '../TransformMetadata';\nimport type { OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';\n\nexport type OxcPreevalOptions = Pick<\n StrictOptions,\n | 'classNameSlug'\n | 'codeRemover'\n | 'displayName'\n | 'eval'\n | 'extensions'\n | 'features'\n | 'staticBindings'\n | 'tagResolver'\n> & { eventEmitter?: EventEmitter };\n\nexport type OxcPreevalResult = {\n baseCode: string;\n code: string;\n dependencyNames: string[];\n metadata: WYWTransformMetadata | null;\n processorClassNames: Record<string, string>;\n staticDependencies: string[];\n staticValueCache: Map<string, unknown>;\n staticValueCandidates: OxcStaticValueCandidate[];\n};\n\nexport type StaticPreevalOverlay = {\n evalDependencyNames: string[];\n staticValueCache: Map<string, unknown>;\n staticValueCandidates: OxcStaticValueCandidate[];\n};\n"],"file":"types.js"}
@@ -1,97 +1,41 @@
1
- import { parseSync } from "oxc-parser";
2
- import { isFeatureEnabled } from "@wyw-in-js/shared";
3
1
  import { EventEmitter } from "./EventEmitter.js";
4
- import { applyOxcProcessors } from "./applyOxcProcessors.js";
5
- import { removeDangerousCodeWithOxc, replaceImportMetaEnvWithOxc, rewriteDynamicImportsAndAddRequireFallbackWithOxc } from "./oxcPreevalTransforms.js";
6
- const DYNAMIC_IMPORT_RE = /\bimport(?:\s|\/\*[\s\S]*?\*\/)*\(/;
7
- const REQUIRE_CALL_RE = /\brequire(?:\s|\/\*[\s\S]*?\*\/)*\(/;
8
- const isEnvDisabled = (value) => value === "0" || value === "false" || value === "no" || value === "off";
9
- const isStaticImportValuesEnabled = (features, filename) => {
10
- const envValue = process.env.WYW_STATIC_IMPORT_VALUES?.trim().toLowerCase();
11
- if (envValue) {
12
- return !isEnvDisabled(envValue);
13
- }
14
- return isFeatureEnabled(features, "staticImportValues", filename);
15
- };
16
- const parseSourceType = (code, filename) => {
17
- const parsed = parseSync(filename, code, {
18
- astType: filename.endsWith(".ts") || filename.endsWith(".tsx") ? "ts" : "js",
19
- range: true,
20
- sourceType: "unambiguous"
21
- });
22
- const fatalError = parsed.errors.find((error) => error.severity === "Error");
23
- if (fatalError) {
24
- throw new Error(fatalError.message);
25
- }
26
- return parsed.program.sourceType === "script" ? "script" : "module";
27
- };
28
- export const appendOxcWywPreval = (code, filename, dependencyNames) => {
29
- const uniqueNames = [...new Set(dependencyNames)];
30
- const properties = uniqueNames.map((name) => `${name}: ${name}`).join(", ");
31
- const object = uniqueNames.length > 0 ? `{ ${properties} }` : "{}";
32
- if (parseSourceType(code, filename) === "script") {
33
- return `${code}\nexports.__wywPreval = ${object};`;
34
- }
35
- return `${code}\nexport const __wywPreval = ${object};`;
36
- };
2
+ import { appendOxcWywPreval } from "./oxcPreevalStage/prevalExport.js";
3
+ import { prepareOxcPreevalCode } from "./oxcPreevalStage/prepareCode.js";
4
+ import { collectPreevalProcessors } from "./oxcPreevalStage/processors.js";
5
+ import { createStaticPreevalOverlay } from "./oxcPreevalStage/staticOverlay.js";
6
+ export { appendOxcWywPreval } from "./oxcPreevalStage/prevalExport.js";
37
7
  export const runOxcPreevalStage = (code, fileContext, options) => {
38
8
  const filename = fileContext.filename ?? "unknown.js";
39
- const dependencyNames = [];
40
9
  const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;
41
- const processed = eventEmitter.perf("transform:preeval:processTemplate", () => applyOxcProcessors(code, fileContext, options, (processor) => {
42
- processor.dependencies.forEach((dependency) => {
43
- if (dependency.ex.type === "Identifier") {
44
- dependencyNames.push(dependency.ex.name);
45
- }
46
- });
47
- processor.doEvaltimeReplacement();
48
- }));
49
- const staticValuesEnabled = isStaticImportValuesEnabled(options.features, filename);
50
- const staticValueNames = staticValuesEnabled ? new Set(processed.staticValues.map((item) => item.name)) : null;
51
- const evalDependencyNames = staticValuesEnabled ? dependencyNames.filter((name) => !staticValueNames.has(name)) : dependencyNames;
52
- let nextCode = eventEmitter.perf("transform:preeval:importMetaEnv", () => replaceImportMetaEnvWithOxc(processed.code, filename));
53
- if (isFeatureEnabled(options.features, "dangerousCodeRemover", filename)) {
54
- nextCode = eventEmitter.perf("transform:preeval:removeDangerousCode", () => removeDangerousCodeWithOxc(nextCode, filename, options.codeRemover));
55
- }
56
- const shouldRewriteDynamicImports = DYNAMIC_IMPORT_RE.test(nextCode);
57
- const shouldAddRequireFallback = REQUIRE_CALL_RE.test(nextCode);
58
- if (shouldRewriteDynamicImports || shouldAddRequireFallback) {
59
- nextCode = rewriteDynamicImportsAndAddRequireFallbackWithOxc(nextCode, filename, {
60
- addRequireFallback: shouldAddRequireFallback,
61
- eventEmitter,
62
- rewriteDynamicImports: shouldRewriteDynamicImports
63
- });
64
- }
10
+ const { dependencyNames, processed } = collectPreevalProcessors(code, fileContext, options, eventEmitter);
11
+ const staticOverlay = createStaticPreevalOverlay(processed, dependencyNames, options);
12
+ const baseCode = prepareOxcPreevalCode(processed.code, filename, options, eventEmitter);
65
13
  if (processed.processors.length === 0) {
66
14
  return {
67
- baseCode: nextCode,
68
- code: nextCode,
15
+ baseCode,
16
+ code: baseCode,
69
17
  dependencyNames: [],
70
18
  metadata: null,
19
+ processorClassNames: {},
71
20
  staticDependencies: [],
72
21
  staticValueCandidates: [],
73
22
  staticValueCache: new Map()
74
23
  };
75
24
  }
76
- const staticValueCache = new Map();
77
- if (staticValuesEnabled) {
78
- processed.staticValues.forEach(({ name, value }) => {
79
- staticValueCache.set(name, value);
80
- });
81
- }
82
25
  return {
83
- baseCode: nextCode,
84
- code: appendOxcWywPreval(nextCode, filename, evalDependencyNames),
85
- dependencyNames: evalDependencyNames,
26
+ baseCode,
27
+ code: appendOxcWywPreval(baseCode, filename, staticOverlay.evalDependencyNames),
28
+ dependencyNames: staticOverlay.evalDependencyNames,
86
29
  metadata: {
87
30
  dependencies: [],
88
31
  processors: processed.processors,
89
32
  replacements: [],
90
33
  rules: {}
91
34
  },
35
+ processorClassNames: Object.fromEntries(processed.processorClassNamesByLocal),
92
36
  staticDependencies: [],
93
- staticValueCandidates: staticValuesEnabled ? processed.staticValueCandidates : [],
94
- staticValueCache
37
+ staticValueCache: staticOverlay.staticValueCache,
38
+ staticValueCandidates: staticOverlay.staticValueCandidates
95
39
  };
96
40
  };
97
41
  //# sourceMappingURL=oxcPreevalStage.js.map
@@ -1 +1 @@
1
- {"mappings":"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","names":[],"sources":["../../src/utils/oxcPreevalStage.ts"],"version":3,"sourcesContent":["import { parseSync } from 'oxc-parser';\n\nimport type { IFileContext } from '@wyw-in-js/processor-utils';\nimport type { StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport { EventEmitter } from './EventEmitter';\nimport type { WYWTransformMetadata } from './TransformMetadata';\nimport type { OxcStaticValueCandidate } from './collectOxcTemplateDependencies';\nimport { applyOxcProcessors } from './applyOxcProcessors';\nimport {\n removeDangerousCodeWithOxc,\n replaceImportMetaEnvWithOxc,\n rewriteDynamicImportsAndAddRequireFallbackWithOxc,\n} from './oxcPreevalTransforms';\n\ntype OxcPreevalOptions = Pick<\n StrictOptions,\n | 'classNameSlug'\n | 'codeRemover'\n | 'displayName'\n | 'evaluate'\n | 'extensions'\n | 'features'\n | 'tagResolver'\n> & { eventEmitter?: EventEmitter };\n\ntype OxcPreevalResult = {\n baseCode: string;\n code: string;\n dependencyNames: string[];\n metadata: WYWTransformMetadata | null;\n staticDependencies: string[];\n staticValueCache: Map<string, unknown>;\n staticValueCandidates: OxcStaticValueCandidate[];\n};\n\nconst DYNAMIC_IMPORT_RE = /\\bimport(?:\\s|\\/\\*[\\s\\S]*?\\*\\/)*\\(/;\nconst REQUIRE_CALL_RE = /\\brequire(?:\\s|\\/\\*[\\s\\S]*?\\*\\/)*\\(/;\n\nconst isEnvDisabled = (value: string): boolean =>\n value === '0' || value === 'false' || value === 'no' || value === 'off';\n\nconst isStaticImportValuesEnabled = (\n features: StrictOptions['features'],\n filename: string\n): boolean => {\n const envValue = process.env.WYW_STATIC_IMPORT_VALUES?.trim().toLowerCase();\n if (envValue) {\n return !isEnvDisabled(envValue);\n }\n\n return isFeatureEnabled(features, 'staticImportValues', filename);\n};\n\nconst parseSourceType = (\n code: string,\n filename: string\n): 'module' | 'script' => {\n const parsed = parseSync(filename, code, {\n astType:\n filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js',\n range: true,\n sourceType: 'unambiguous',\n });\n const fatalError = parsed.errors.find((error) => error.severity === 'Error');\n if (fatalError) {\n throw new Error(fatalError.message);\n }\n\n return parsed.program.sourceType === 'script' ? 'script' : 'module';\n};\n\nexport const appendOxcWywPreval = (\n code: string,\n filename: string,\n dependencyNames: string[]\n): string => {\n const uniqueNames = [...new Set(dependencyNames)];\n const properties = uniqueNames.map((name) => `${name}: ${name}`).join(', ');\n const object = uniqueNames.length > 0 ? `{ ${properties} }` : '{}';\n\n if (parseSourceType(code, filename) === 'script') {\n return `${code}\\nexports.__wywPreval = ${object};`;\n }\n\n return `${code}\\nexport const __wywPreval = ${object};`;\n};\n\nexport const runOxcPreevalStage = (\n code: string,\n fileContext: IFileContext,\n options: OxcPreevalOptions\n): OxcPreevalResult => {\n const filename = fileContext.filename ?? 'unknown.js';\n const dependencyNames: string[] = [];\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n\n const processed = eventEmitter.perf('transform:preeval:processTemplate', () =>\n applyOxcProcessors(code, fileContext, options, (processor) => {\n processor.dependencies.forEach((dependency) => {\n if (dependency.ex.type === 'Identifier') {\n dependencyNames.push(dependency.ex.name);\n }\n });\n\n processor.doEvaltimeReplacement();\n })\n );\n const staticValuesEnabled = isStaticImportValuesEnabled(\n options.features,\n filename\n );\n const staticValueNames = staticValuesEnabled\n ? new Set(processed.staticValues.map((item) => item.name))\n : null;\n const evalDependencyNames = staticValuesEnabled\n ? dependencyNames.filter((name) => !staticValueNames!.has(name))\n : dependencyNames;\n\n let nextCode = eventEmitter.perf('transform:preeval:importMetaEnv', () =>\n replaceImportMetaEnvWithOxc(processed.code, filename)\n );\n\n if (isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)) {\n nextCode = eventEmitter.perf('transform:preeval:removeDangerousCode', () =>\n removeDangerousCodeWithOxc(nextCode, filename, options.codeRemover)\n );\n }\n\n const shouldRewriteDynamicImports = DYNAMIC_IMPORT_RE.test(nextCode);\n const shouldAddRequireFallback = REQUIRE_CALL_RE.test(nextCode);\n if (shouldRewriteDynamicImports || shouldAddRequireFallback) {\n nextCode = rewriteDynamicImportsAndAddRequireFallbackWithOxc(\n nextCode,\n filename,\n {\n addRequireFallback: shouldAddRequireFallback,\n eventEmitter,\n rewriteDynamicImports: shouldRewriteDynamicImports,\n }\n );\n }\n\n if (processed.processors.length === 0) {\n return {\n baseCode: nextCode,\n code: nextCode,\n dependencyNames: [],\n metadata: null,\n staticDependencies: [],\n staticValueCandidates: [],\n staticValueCache: new Map(),\n };\n }\n\n const staticValueCache = new Map<string, unknown>();\n if (staticValuesEnabled) {\n processed.staticValues.forEach(({ name, value }) => {\n staticValueCache.set(name, value);\n });\n }\n\n return {\n baseCode: nextCode,\n code: appendOxcWywPreval(nextCode, filename, evalDependencyNames),\n dependencyNames: evalDependencyNames,\n metadata: {\n dependencies: [],\n processors: processed.processors,\n replacements: [],\n rules: {},\n },\n staticDependencies: [],\n staticValueCandidates: staticValuesEnabled\n ? processed.staticValueCandidates\n : [],\n staticValueCache,\n };\n};\n"],"file":"oxcPreevalStage.js"}
1
+ {"mappings":"AAEA,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAM3C,SAAS,0BAA0B;AAEnC,OAAO,MAAM,sBACX,MACA,aACA,YACqB;CACrB,MAAM,WAAW,YAAY,YAAY;CACzC,MAAM,eAAe,QAAQ,gBAAgB,aAAa;CAC1D,MAAM,EAAE,iBAAiB,cAAc,yBACrC,MACA,aACA,SACA,aACD;CACD,MAAM,gBAAgB,2BACpB,WACA,iBACA,QACD;CACD,MAAM,WAAW,sBACf,UAAU,MACV,UACA,SACA,aACD;AAED,KAAI,UAAU,WAAW,WAAW,GAAG;AACrC,SAAO;GACL;GACA,MAAM;GACN,iBAAiB,EAAE;GACnB,UAAU;GACV,qBAAqB,EAAE;GACvB,oBAAoB,EAAE;GACtB,uBAAuB,EAAE;GACzB,kBAAkB,IAAI,KAAK;GAC5B;;AAGH,QAAO;EACL;EACA,MAAM,mBACJ,UACA,UACA,cAAc,oBACf;EACD,iBAAiB,cAAc;EAC/B,UAAU;GACR,cAAc,EAAE;GAChB,YAAY,UAAU;GACtB,cAAc,EAAE;GAChB,OAAO,EAAE;GACV;EACD,qBAAqB,OAAO,YAC1B,UAAU,2BACX;EACD,oBAAoB,EAAE;EACtB,kBAAkB,cAAc;EAChC,uBAAuB,cAAc;EACtC","names":[],"sources":["../../src/utils/oxcPreevalStage.ts"],"version":3,"sourcesContent":["import type { IFileContext } from '@wyw-in-js/processor-utils';\n\nimport { EventEmitter } from './EventEmitter';\nimport { appendOxcWywPreval } from './oxcPreevalStage/prevalExport';\nimport { prepareOxcPreevalCode } from './oxcPreevalStage/prepareCode';\nimport { collectPreevalProcessors } from './oxcPreevalStage/processors';\nimport { createStaticPreevalOverlay } from './oxcPreevalStage/staticOverlay';\nimport type {\n OxcPreevalOptions,\n OxcPreevalResult,\n} from './oxcPreevalStage/types';\n\nexport { appendOxcWywPreval } from './oxcPreevalStage/prevalExport';\n\nexport const runOxcPreevalStage = (\n code: string,\n fileContext: IFileContext,\n options: OxcPreevalOptions\n): OxcPreevalResult => {\n const filename = fileContext.filename ?? 'unknown.js';\n const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;\n const { dependencyNames, processed } = collectPreevalProcessors(\n code,\n fileContext,\n options,\n eventEmitter\n );\n const staticOverlay = createStaticPreevalOverlay(\n processed,\n dependencyNames,\n options\n );\n const baseCode = prepareOxcPreevalCode(\n processed.code,\n filename,\n options,\n eventEmitter\n );\n\n if (processed.processors.length === 0) {\n return {\n baseCode,\n code: baseCode,\n dependencyNames: [],\n metadata: null,\n processorClassNames: {},\n staticDependencies: [],\n staticValueCandidates: [],\n staticValueCache: new Map(),\n };\n }\n\n return {\n baseCode,\n code: appendOxcWywPreval(\n baseCode,\n filename,\n staticOverlay.evalDependencyNames\n ),\n dependencyNames: staticOverlay.evalDependencyNames,\n metadata: {\n dependencies: [],\n processors: processed.processors,\n replacements: [],\n rules: {},\n },\n processorClassNames: Object.fromEntries(\n processed.processorClassNamesByLocal\n ),\n staticDependencies: [],\n staticValueCache: staticOverlay.staticValueCache,\n staticValueCandidates: staticOverlay.staticValueCandidates,\n };\n};\n"],"file":"oxcPreevalStage.js"}
@@ -1,5 +1,6 @@
1
1
  import { collectOxcExportsAndImports } from "./collectOxcExportsAndImports.js";
2
2
  import { EventEmitter } from "./EventEmitter.js";
3
+ import { getOxcNodeChildren } from "./oxc/ast.js";
3
4
  import { parseOxcProgramCached } from "./parseOxc.js";
4
5
  const ssrCheckFields = new Set([
5
6
  "document",
@@ -40,6 +41,7 @@ const defaultReactComponentTypes = [
40
41
  "MemoExoticComponent",
41
42
  "NamedExoticComponent"
42
43
  ];
44
+ const defaultReactHocs = ["forwardRef", "memo"];
43
45
  const generatedProcessorHelperNameRe = /^_exp\d*$/;
44
46
  const requireCallRe = /\brequire\s*\(/;
45
47
  const windowTokenRe = /\bwindow\b/;
@@ -96,28 +98,11 @@ const getStaticBinding = (scope, name) => {
96
98
  };
97
99
  const isFileLikeRequireSpecifier = (value) => value.startsWith(".") || value.startsWith("/") || value.startsWith("file:");
98
100
  const isNode = (value) => !!value && typeof value === "object" && "type" in value && typeof value.type === "string";
99
- const getChildren = (node) => {
100
- const result = [];
101
- const record = node;
102
- Object.keys(record).forEach((key) => {
103
- if (key === "type" || key === "start" || key === "end" || key === "range") {
104
- return;
105
- }
106
- const value = record[key];
107
- if (isNode(value)) {
108
- result.push(value);
109
- return;
110
- }
111
- if (Array.isArray(value)) {
112
- value.forEach((item) => {
113
- if (isNode(item)) {
114
- result.push(item);
115
- }
116
- });
117
- }
118
- });
119
- return result;
120
- };
101
+ // Reuses the per-node.type visitor-key cache in utils/oxc/ast.ts. This file's
102
+ // getChildren shape historically diverged from the canonical one (a smaller
103
+ // metadata-key skip set), but the produced children list is identical in
104
+ // practice because oxc-parser nodes don't carry the extra metadata fields.
105
+ const getChildren = getOxcNodeChildren;
121
106
  const parseOxc = (code, filename) => {
122
107
  return parseOxcProgramCached(filename, code, "unambiguous");
123
108
  };
@@ -313,57 +298,92 @@ const predeclareScopeNames = (node, scope) => {
313
298
  });
314
299
  }
315
300
  const visitScopeDescendants = (child) => {
316
- if (child.type === "VariableDeclarator") {
317
- collectBindingNames(child.id).forEach((name) => {
318
- scope.names.add(name);
319
- });
320
- } else if (child.type === "FunctionDeclaration" && child.id) {
321
- scope.names.add(child.id.name);
322
- } else if (child.type === "ClassDeclaration" && child.id) {
323
- scope.names.add(child.id.name);
324
- } else if (child.type === "ImportDefaultSpecifier" || child.type === "ImportNamespaceSpecifier" || child.type === "ImportSpecifier") {
325
- scope.names.add(child.local.name);
301
+ switch (child.type) {
302
+ case "VariableDeclarator": {
303
+ const names = collectBindingNames(child.id);
304
+ for (let i = 0; i < names.length; i += 1) {
305
+ scope.names.add(names[i]);
306
+ }
307
+ break;
308
+ }
309
+ case "FunctionDeclaration":
310
+ case "ClassDeclaration":
311
+ if (child.id) {
312
+ scope.names.add(child.id.name);
313
+ }
314
+ break;
315
+ case "ImportDefaultSpecifier":
316
+ case "ImportNamespaceSpecifier":
317
+ case "ImportSpecifier":
318
+ scope.names.add(child.local.name);
319
+ break;
320
+ default: break;
326
321
  }
327
322
  if (createsScope(child)) {
328
323
  return;
329
324
  }
330
- getChildren(child).forEach(visitScopeDescendants);
325
+ const children = getChildren(child);
326
+ for (let i = 0; i < children.length; i += 1) {
327
+ visitScopeDescendants(children[i]);
328
+ }
331
329
  };
332
- getChildren(node).forEach(visitScopeDescendants);
330
+ const rootChildren = getChildren(node);
331
+ for (let i = 0; i < rootChildren.length; i += 1) {
332
+ visitScopeDescendants(rootChildren[i]);
333
+ }
333
334
  };
334
335
  const declareBindings = (node, scope) => {
335
- if (node.type === "VariableDeclarator") {
336
- const names = collectBindingNames(node.id);
337
- names.forEach((name) => {
338
- scope.names.add(name);
339
- scope.bindings.set(name, null);
340
- });
341
- if (node.id.type === "Identifier" && node.init) {
342
- scope.bindings.set(node.id.name, node.init);
343
- }
344
- return;
345
- }
346
- if (node.type === "FunctionDeclaration" && node.id) {
347
- scope.names.add(node.id.name);
348
- scope.bindings.set(node.id.name, null);
349
- }
350
- if (node.type === "ClassDeclaration" && node.id) {
351
- scope.names.add(node.id.name);
352
- scope.bindings.set(node.id.name, null);
353
- return;
354
- }
355
- if (node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier" || node.type === "ImportSpecifier") {
356
- scope.names.add(node.local.name);
357
- scope.bindings.set(node.local.name, null);
358
- return;
359
- }
360
- if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
361
- node.params.forEach((param) => {
362
- collectBindingNames(param).forEach((name) => {
336
+ // Called for every visited AST node, so the dispatch is hot. A switch lets
337
+ // V8 generate a jump table on node.type; the previous chained `if`s walked
338
+ // each branch's string-compare for every non-matching node.
339
+ switch (node.type) {
340
+ case "VariableDeclarator": {
341
+ const names = collectBindingNames(node.id);
342
+ for (let i = 0; i < names.length; i += 1) {
343
+ const name = names[i];
363
344
  scope.names.add(name);
364
345
  scope.bindings.set(name, null);
365
- });
366
- });
346
+ }
347
+ if (node.id.type === "Identifier" && node.init) {
348
+ scope.bindings.set(node.id.name, node.init);
349
+ }
350
+ return;
351
+ }
352
+ case "ClassDeclaration": {
353
+ if (node.id) {
354
+ scope.names.add(node.id.name);
355
+ scope.bindings.set(node.id.name, null);
356
+ }
357
+ return;
358
+ }
359
+ case "ImportDefaultSpecifier":
360
+ case "ImportNamespaceSpecifier":
361
+ case "ImportSpecifier": {
362
+ scope.names.add(node.local.name);
363
+ scope.bindings.set(node.local.name, null);
364
+ return;
365
+ }
366
+ case "FunctionDeclaration": {
367
+ if (node.id) {
368
+ scope.names.add(node.id.name);
369
+ scope.bindings.set(node.id.name, null);
370
+ }
371
+ }
372
+ // eslint-disable-next-line no-fallthrough
373
+ case "FunctionExpression":
374
+ case "ArrowFunctionExpression": {
375
+ const { params } = node;
376
+ for (let i = 0; i < params.length; i += 1) {
377
+ const names = collectBindingNames(params[i]);
378
+ for (let j = 0; j < names.length; j += 1) {
379
+ const name = names[j];
380
+ scope.names.add(name);
381
+ scope.bindings.set(name, null);
382
+ }
383
+ }
384
+ break;
385
+ }
386
+ default: break;
367
387
  }
368
388
  };
369
389
  const visit = (node, scope, enter, parent = null, ancestors = []) => {
@@ -374,7 +394,17 @@ const visit = (node, scope, enter, parent = null, ancestors = []) => {
374
394
  }
375
395
  declareBindings(node, currentScope);
376
396
  enter(node, currentScope, parent, ancestors);
377
- getChildren(node).forEach((child) => visit(child, currentScope, enter, node, [...ancestors, node]));
397
+ // Push onto a shared ancestors stack instead of allocating `[...ancestors,
398
+ // node]` per child step (O(n × depth) extra allocation on deep ASTs).
399
+ // Every consumer of `ancestors` in this file reads it synchronously inside
400
+ // the enter callback; future callers that need to retain the reference
401
+ // must .slice() it themselves.
402
+ ancestors.push(node);
403
+ const children = getChildren(node);
404
+ for (let i = 0; i < children.length; i += 1) {
405
+ visit(children[i], currentScope, enter, node, ancestors);
406
+ }
407
+ ancestors.pop();
378
408
  };
379
409
  export const replaceImportMetaEnvWithOxc = (code, filename) => {
380
410
  if (!importMetaEnvRe.test(code)) {
@@ -785,6 +815,7 @@ const isHocCall = (call, hocs, imports) => {
785
815
  const matched = getImportForExpression(getInnermostCallee(call), imports);
786
816
  return !!matched && hocs[matched[0]]?.includes(matched[1]);
787
817
  };
818
+ const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === "CallExpression" && isHocCall(ancestor, hocs, imports));
788
819
  const getComponentTypes = (options) => {
789
820
  const componentTypes = { ...options?.componentTypes ?? { react: [defaultPlaceholder] } };
790
821
  const reactTypes = componentTypes.react;
@@ -795,6 +826,12 @@ const getComponentTypes = (options) => {
795
826
  }
796
827
  return componentTypes;
797
828
  };
829
+ const getHocs = (options) => {
830
+ const hocs = { ...options?.hocs ?? {} };
831
+ const reactHocs = new Set([...defaultReactHocs, ...hocs.react ?? []]);
832
+ hocs.react = [...reactHocs];
833
+ return hocs;
834
+ };
798
835
  const getTypeImport = (node, imports) => {
799
836
  if (node.type === "Identifier") {
800
837
  const matched = getImportBinding(imports, node.name);
@@ -914,7 +951,7 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
914
951
  const program = parseOxc(code, filename);
915
952
  const imports = collectImportBindings(code, filename, program);
916
953
  const componentTypes = getComponentTypes(options);
917
- const hocs = options?.hocs ?? {};
954
+ const hocs = getHocs(options);
918
955
  const hasHocs = Object.keys(hocs).length > 0;
919
956
  const windowScopedNames = windowTokenRe.test(code) ? collectWindowScopedNames(program) : new Set();
920
957
  const reExportedLocalNames = collectReExportedLocalNames(program);
@@ -1003,6 +1040,9 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
1003
1040
  if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
1004
1041
  return;
1005
1042
  }
1043
+ if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
1044
+ return;
1045
+ }
1006
1046
  if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
1007
1047
  return;
1008
1048
  }