@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
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-restricted-syntax,no-continue */
2
2
  import { collectOxcExportsAndImports } from './collectOxcExportsAndImports';
3
3
  import { EventEmitter } from './EventEmitter';
4
+ import { getOxcNodeChildren } from './oxc/ast';
4
5
  import { parseOxcProgramCached } from './parseOxc';
5
6
  const ssrCheckFields = new Set([
6
7
  '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/;
@@ -103,28 +105,11 @@ const isNode = (value) => !!value &&
103
105
  typeof value === 'object' &&
104
106
  'type' in value &&
105
107
  typeof value.type === 'string';
106
- const getChildren = (node) => {
107
- const result = [];
108
- const record = node;
109
- Object.keys(record).forEach((key) => {
110
- if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {
111
- return;
112
- }
113
- const value = record[key];
114
- if (isNode(value)) {
115
- result.push(value);
116
- return;
117
- }
118
- if (Array.isArray(value)) {
119
- value.forEach((item) => {
120
- if (isNode(item)) {
121
- result.push(item);
122
- }
123
- });
124
- }
125
- });
126
- return result;
127
- };
108
+ // Reuses the per-node.type visitor-key cache in utils/oxc/ast.ts. This file's
109
+ // getChildren shape historically diverged from the canonical one (a smaller
110
+ // metadata-key skip set), but the produced children list is identical in
111
+ // practice because oxc-parser nodes don't carry the extra metadata fields.
112
+ const getChildren = getOxcNodeChildren;
128
113
  const parseOxc = (code, filename) => {
129
114
  return parseOxcProgramCached(filename, code, 'unambiguous');
130
115
  };
@@ -347,66 +332,95 @@ const predeclareScopeNames = (node, scope) => {
347
332
  });
348
333
  }
349
334
  const visitScopeDescendants = (child) => {
350
- if (child.type === 'VariableDeclarator') {
351
- collectBindingNames(child.id).forEach((name) => {
352
- scope.names.add(name);
353
- });
354
- }
355
- else if (child.type === 'FunctionDeclaration' && child.id) {
356
- scope.names.add(child.id.name);
357
- }
358
- else if (child.type === 'ClassDeclaration' && child.id) {
359
- scope.names.add(child.id.name);
360
- }
361
- else if (child.type === 'ImportDefaultSpecifier' ||
362
- child.type === 'ImportNamespaceSpecifier' ||
363
- child.type === 'ImportSpecifier') {
364
- scope.names.add(child.local.name);
335
+ switch (child.type) {
336
+ case 'VariableDeclarator': {
337
+ const names = collectBindingNames(child.id);
338
+ for (let i = 0; i < names.length; i += 1) {
339
+ scope.names.add(names[i]);
340
+ }
341
+ break;
342
+ }
343
+ case 'FunctionDeclaration':
344
+ case 'ClassDeclaration':
345
+ if (child.id) {
346
+ scope.names.add(child.id.name);
347
+ }
348
+ break;
349
+ case 'ImportDefaultSpecifier':
350
+ case 'ImportNamespaceSpecifier':
351
+ case 'ImportSpecifier':
352
+ scope.names.add(child.local.name);
353
+ break;
354
+ default:
355
+ break;
365
356
  }
366
357
  if (createsScope(child)) {
367
358
  return;
368
359
  }
369
- getChildren(child).forEach(visitScopeDescendants);
360
+ const children = getChildren(child);
361
+ for (let i = 0; i < children.length; i += 1) {
362
+ visitScopeDescendants(children[i]);
363
+ }
370
364
  };
371
- getChildren(node).forEach(visitScopeDescendants);
365
+ const rootChildren = getChildren(node);
366
+ for (let i = 0; i < rootChildren.length; i += 1) {
367
+ visitScopeDescendants(rootChildren[i]);
368
+ }
372
369
  };
373
370
  const declareBindings = (node, scope) => {
374
- if (node.type === 'VariableDeclarator') {
375
- const names = collectBindingNames(node.id);
376
- names.forEach((name) => {
377
- scope.names.add(name);
378
- scope.bindings.set(name, null);
379
- });
380
- if (node.id.type === 'Identifier' && node.init) {
381
- scope.bindings.set(node.id.name, node.init);
382
- }
383
- return;
384
- }
385
- if (node.type === 'FunctionDeclaration' && node.id) {
386
- scope.names.add(node.id.name);
387
- scope.bindings.set(node.id.name, null);
388
- }
389
- if (node.type === 'ClassDeclaration' && node.id) {
390
- scope.names.add(node.id.name);
391
- scope.bindings.set(node.id.name, null);
392
- return;
393
- }
394
- if (node.type === 'ImportDefaultSpecifier' ||
395
- node.type === 'ImportNamespaceSpecifier' ||
396
- node.type === 'ImportSpecifier') {
397
- scope.names.add(node.local.name);
398
- scope.bindings.set(node.local.name, null);
399
- return;
400
- }
401
- if (node.type === 'FunctionDeclaration' ||
402
- node.type === 'FunctionExpression' ||
403
- node.type === 'ArrowFunctionExpression') {
404
- node.params.forEach((param) => {
405
- collectBindingNames(param).forEach((name) => {
371
+ // Called for every visited AST node, so the dispatch is hot. A switch lets
372
+ // V8 generate a jump table on node.type; the previous chained `if`s walked
373
+ // each branch's string-compare for every non-matching node.
374
+ switch (node.type) {
375
+ case 'VariableDeclarator': {
376
+ const names = collectBindingNames(node.id);
377
+ for (let i = 0; i < names.length; i += 1) {
378
+ const name = names[i];
406
379
  scope.names.add(name);
407
380
  scope.bindings.set(name, null);
408
- });
409
- });
381
+ }
382
+ if (node.id.type === 'Identifier' && node.init) {
383
+ scope.bindings.set(node.id.name, node.init);
384
+ }
385
+ return;
386
+ }
387
+ case 'ClassDeclaration': {
388
+ if (node.id) {
389
+ scope.names.add(node.id.name);
390
+ scope.bindings.set(node.id.name, null);
391
+ }
392
+ return;
393
+ }
394
+ case 'ImportDefaultSpecifier':
395
+ case 'ImportNamespaceSpecifier':
396
+ case 'ImportSpecifier': {
397
+ scope.names.add(node.local.name);
398
+ scope.bindings.set(node.local.name, null);
399
+ return;
400
+ }
401
+ case 'FunctionDeclaration': {
402
+ if (node.id) {
403
+ scope.names.add(node.id.name);
404
+ scope.bindings.set(node.id.name, null);
405
+ }
406
+ // Fall through to declare params.
407
+ }
408
+ // eslint-disable-next-line no-fallthrough
409
+ case 'FunctionExpression':
410
+ case 'ArrowFunctionExpression': {
411
+ const { params } = node;
412
+ for (let i = 0; i < params.length; i += 1) {
413
+ const names = collectBindingNames(params[i]);
414
+ for (let j = 0; j < names.length; j += 1) {
415
+ const name = names[j];
416
+ scope.names.add(name);
417
+ scope.bindings.set(name, null);
418
+ }
419
+ }
420
+ break;
421
+ }
422
+ default:
423
+ break;
410
424
  }
411
425
  };
412
426
  const visit = (node, scope, enter, parent = null, ancestors = []) => {
@@ -417,7 +431,17 @@ const visit = (node, scope, enter, parent = null, ancestors = []) => {
417
431
  }
418
432
  declareBindings(node, currentScope);
419
433
  enter(node, currentScope, parent, ancestors);
420
- getChildren(node).forEach((child) => visit(child, currentScope, enter, node, [...ancestors, node]));
434
+ // Push onto a shared ancestors stack instead of allocating `[...ancestors,
435
+ // node]` per child step (O(n × depth) extra allocation on deep ASTs).
436
+ // Every consumer of `ancestors` in this file reads it synchronously inside
437
+ // the enter callback; future callers that need to retain the reference
438
+ // must .slice() it themselves.
439
+ ancestors.push(node);
440
+ const children = getChildren(node);
441
+ for (let i = 0; i < children.length; i += 1) {
442
+ visit(children[i], currentScope, enter, node, ancestors);
443
+ }
444
+ ancestors.pop();
421
445
  };
422
446
  export const replaceImportMetaEnvWithOxc = (code, filename) => {
423
447
  if (!importMetaEnvRe.test(code)) {
@@ -876,6 +900,7 @@ const isHocCall = (call, hocs, imports) => {
876
900
  const matched = getImportForExpression(getInnermostCallee(call), imports);
877
901
  return !!matched && hocs[matched[0]]?.includes(matched[1]);
878
902
  };
903
+ const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports));
879
904
  const getComponentTypes = (options) => {
880
905
  const componentTypes = {
881
906
  ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),
@@ -888,6 +913,14 @@ const getComponentTypes = (options) => {
888
913
  }
889
914
  return componentTypes;
890
915
  };
916
+ const getHocs = (options) => {
917
+ const hocs = {
918
+ ...(options?.hocs ?? {}),
919
+ };
920
+ const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);
921
+ hocs.react = [...reactHocs];
922
+ return hocs;
923
+ };
891
924
  const getTypeImport = (node, imports) => {
892
925
  if (node.type === 'Identifier') {
893
926
  const matched = getImportBinding(imports, node.name);
@@ -1019,7 +1052,7 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
1019
1052
  const program = parseOxc(code, filename);
1020
1053
  const imports = collectImportBindings(code, filename, program);
1021
1054
  const componentTypes = getComponentTypes(options);
1022
- const hocs = options?.hocs ?? {};
1055
+ const hocs = getHocs(options);
1023
1056
  const hasHocs = Object.keys(hocs).length > 0;
1024
1057
  const windowScopedNames = windowTokenRe.test(code)
1025
1058
  ? collectWindowScopedNames(program)
@@ -1122,6 +1155,9 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
1122
1155
  if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
1123
1156
  return;
1124
1157
  }
1158
+ if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
1159
+ return;
1160
+ }
1125
1161
  if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
1126
1162
  return;
1127
1163
  }
@@ -1,5 +1,10 @@
1
1
  import { parseSync } from 'oxc-parser';
2
- const MAX_PARSE_CACHE_ENTRIES = 200;
2
+ // 200 evicts under sustained pressure on large monorepos — the
3
+ // removeUnusedAfterReplacement cleanup loop reparses on every iteration
4
+ // (new content -> new key) and applyOxcProcessors reparses after extraction.
5
+ // 1000 is still bounded (~50-100 MB worst case for an enormous build) and
6
+ // keeps every entry hot across the actions for a single file.
7
+ const MAX_PARSE_CACHE_ENTRIES = 1000;
3
8
  const parseCache = new Map();
4
9
  const getAstType = (filename) => filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js';
5
10
  const makeCacheKey = (filename, code, sourceType) => `${sourceType}\0${filename}\0${code}`;
@@ -0,0 +1,13 @@
1
+ import type { BaseProcessor, Expression as ProcessorExpression, ProcessorStaticContext, ProcessorStaticValue } from '@wyw-in-js/processor-utils';
2
+ export declare const unknownProcessorStaticValue: unique symbol;
3
+ export type UnknownProcessorStaticValue = typeof unknownProcessorStaticValue;
4
+ export declare const createProcessorStaticContext: (processor: BaseProcessor) => ProcessorStaticContext;
5
+ export declare const isProcessorStaticValue: (value: unknown) => value is ProcessorStaticValue;
6
+ export declare const getProcessorStaticValue: (processor: BaseProcessor) => ProcessorStaticValue | null;
7
+ export declare const processorStaticValueToRuntimeValue: (value: ProcessorStaticValue) => unknown | UnknownProcessorStaticValue;
8
+ export declare const resolveProcessorStaticRuntimeValue: (processor: BaseProcessor) => unknown | UnknownProcessorStaticValue;
9
+ export declare const resolveProcessorStaticClassName: (processor: BaseProcessor) => string | null;
10
+ export declare const processorLiteralValue: (expression: ProcessorExpression) => unknown | UnknownProcessorStaticValue;
11
+ export declare const processorPropertyKeyName: (key: ProcessorExpression) => string | null;
12
+ export declare const processorObjectPropertyValue: (expression: ProcessorExpression, name: string) => ProcessorExpression | null;
13
+ export declare const processorExpressionToStaticValue: (expression: ProcessorExpression, resolveHelperCall: (name: string) => unknown | UnknownProcessorStaticValue) => unknown | UnknownProcessorStaticValue;
@@ -0,0 +1,191 @@
1
+ export const unknownProcessorStaticValue = Symbol('unknownProcessorStaticValue');
2
+ export const createProcessorStaticContext = (processor) => {
3
+ const processorWithInternals = processor;
4
+ return {
5
+ addDependency: () => { },
6
+ debug: () => { },
7
+ fileContext: processorWithInternals.context ??
8
+ {},
9
+ metadata: {
10
+ className: processor.className,
11
+ displayName: processor.displayName,
12
+ isReferenced: processor.isReferenced,
13
+ location: processor.location,
14
+ slug: processor.slug,
15
+ tagSource: processor.tagSource,
16
+ },
17
+ options: processorWithInternals.options ??
18
+ {},
19
+ unresolved: (reason, details) => ({
20
+ ...(details ? { details } : {}),
21
+ kind: 'unresolved',
22
+ reason,
23
+ }),
24
+ };
25
+ };
26
+ export const isProcessorStaticValue = (value) => {
27
+ if (typeof value !== 'object' || value === null || !('kind' in value)) {
28
+ return false;
29
+ }
30
+ const candidate = value;
31
+ switch (candidate.kind) {
32
+ case 'class-name':
33
+ return typeof candidate.className === 'string';
34
+ case 'opaque-component':
35
+ return (candidate.className === undefined ||
36
+ typeof candidate.className === 'string');
37
+ case 'runtime-callback':
38
+ case 'serializable':
39
+ return true;
40
+ case 'selector-chain':
41
+ return (typeof candidate.className === 'string' &&
42
+ Array.isArray(candidate.selectors) &&
43
+ candidate.selectors.every((selector) => typeof selector === 'string'));
44
+ case 'unresolved':
45
+ return typeof candidate.reason === 'string';
46
+ default:
47
+ return false;
48
+ }
49
+ };
50
+ export const getProcessorStaticValue = (processor) => {
51
+ if (!processor.getStaticValue) {
52
+ return null;
53
+ }
54
+ try {
55
+ const value = processor.getStaticValue(createProcessorStaticContext(processor));
56
+ return isProcessorStaticValue(value) ? value : null;
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ };
62
+ export const processorStaticValueToRuntimeValue = (value) => {
63
+ switch (value.kind) {
64
+ case 'class-name':
65
+ return value.value === undefined ? value.className : value.value;
66
+ case 'opaque-component':
67
+ case 'runtime-callback':
68
+ return value.value === undefined
69
+ ? unknownProcessorStaticValue
70
+ : value.value;
71
+ case 'selector-chain':
72
+ case 'serializable':
73
+ return value.value;
74
+ case 'unresolved':
75
+ return unknownProcessorStaticValue;
76
+ default:
77
+ return unknownProcessorStaticValue;
78
+ }
79
+ };
80
+ export const resolveProcessorStaticRuntimeValue = (processor) => {
81
+ const staticValue = getProcessorStaticValue(processor);
82
+ return staticValue
83
+ ? processorStaticValueToRuntimeValue(staticValue)
84
+ : unknownProcessorStaticValue;
85
+ };
86
+ export const resolveProcessorStaticClassName = (processor) => {
87
+ const staticValue = getProcessorStaticValue(processor);
88
+ if (staticValue?.kind !== 'class-name') {
89
+ return null;
90
+ }
91
+ const runtimeValue = processorStaticValueToRuntimeValue(staticValue);
92
+ return typeof runtimeValue === 'string'
93
+ ? runtimeValue
94
+ : staticValue.className;
95
+ };
96
+ export const processorLiteralValue = (expression) => {
97
+ const expressionWithValue = expression;
98
+ if (expression.type === 'StringLiteral' ||
99
+ expression.type === 'NumericLiteral' ||
100
+ expression.type === 'BooleanLiteral' ||
101
+ expression.type === 'Literal') {
102
+ return expressionWithValue.value;
103
+ }
104
+ if (expression.type === 'NullLiteral') {
105
+ return null;
106
+ }
107
+ return unknownProcessorStaticValue;
108
+ };
109
+ export const processorPropertyKeyName = (key) => {
110
+ if (key.type === 'Identifier') {
111
+ return key.name;
112
+ }
113
+ const value = processorLiteralValue(key);
114
+ return typeof value === 'string' ? value : null;
115
+ };
116
+ export const processorObjectPropertyValue = (expression, name) => {
117
+ if (expression.type !== 'ObjectExpression') {
118
+ return null;
119
+ }
120
+ const { properties } = expression;
121
+ if (!properties) {
122
+ return null;
123
+ }
124
+ for (const property of properties) {
125
+ if ((property.type === 'ObjectProperty' || property.type === 'Property') &&
126
+ property.key &&
127
+ processorPropertyKeyName(property.key) === name) {
128
+ return property.value ?? null;
129
+ }
130
+ }
131
+ return null;
132
+ };
133
+ export const processorExpressionToStaticValue = (expression, resolveHelperCall) => {
134
+ const literal = processorLiteralValue(expression);
135
+ if (literal !== unknownProcessorStaticValue) {
136
+ return literal;
137
+ }
138
+ if (expression.type === 'ArrayExpression') {
139
+ const { elements } = expression;
140
+ if (!elements) {
141
+ return unknownProcessorStaticValue;
142
+ }
143
+ const result = [];
144
+ for (const element of elements) {
145
+ if (element === null) {
146
+ result.push(null);
147
+ }
148
+ else {
149
+ const value = processorExpressionToStaticValue(element, resolveHelperCall);
150
+ if (value === unknownProcessorStaticValue) {
151
+ return unknownProcessorStaticValue;
152
+ }
153
+ result.push(value);
154
+ }
155
+ }
156
+ return result;
157
+ }
158
+ if (expression.type === 'ObjectExpression') {
159
+ const metaExpression = processorObjectPropertyValue(expression, '__wyw_meta');
160
+ if (!metaExpression || metaExpression.type !== 'ObjectExpression') {
161
+ return unknownProcessorStaticValue;
162
+ }
163
+ const classNameExpression = processorObjectPropertyValue(metaExpression, 'className');
164
+ const className = classNameExpression
165
+ ? processorLiteralValue(classNameExpression)
166
+ : unknownProcessorStaticValue;
167
+ if (typeof className !== 'string') {
168
+ return unknownProcessorStaticValue;
169
+ }
170
+ const extendsExpression = processorObjectPropertyValue(metaExpression, 'extends');
171
+ const extended = extendsExpression
172
+ ? processorExpressionToStaticValue(extendsExpression, resolveHelperCall)
173
+ : null;
174
+ if (extended === unknownProcessorStaticValue) {
175
+ return unknownProcessorStaticValue;
176
+ }
177
+ return {
178
+ __wyw_meta: {
179
+ className,
180
+ extends: extended,
181
+ },
182
+ };
183
+ }
184
+ if (expression.type === 'CallExpression') {
185
+ const call = expression;
186
+ if (call.arguments?.length === 0 && call.callee?.type === 'Identifier') {
187
+ return resolveHelperCall(call.callee.name);
188
+ }
189
+ }
190
+ return unknownProcessorStaticValue;
191
+ };
@@ -54,7 +54,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
54
54
  }
55
55
  catch {
56
56
  throw new Error([
57
- '[wyw-in-js] Failed to parse Node resolver fallback output.',
57
+ '[wyw-in-js] Failed to parse custom module resolver output.',
58
58
  `stdout: ${stdout}`,
59
59
  result.stderr ? `stderr: ${result.stderr.trim()}` : '',
60
60
  ]
@@ -69,7 +69,7 @@ const resolveWithNodeProcess = (id, parent, conditions) => {
69
69
  }
70
70
  if (result.status !== 0 || !parsed?.resolved) {
71
71
  throw new Error([
72
- '[wyw-in-js] Node resolver fallback failed.',
72
+ '[wyw-in-js] Custom module resolver fallback failed.',
73
73
  `status: ${result.status ?? 'null'}`,
74
74
  result.stderr ? `stderr: ${result.stderr.trim()}` : '',
75
75
  ]
@@ -87,7 +87,7 @@ export const resolveFilenameWithConditions = (moduleImpl, id, parent, conditions
87
87
  // Bun crashes on macOS/Silicon in this exact path:
88
88
  // Module._resolveFilename(specifier, parent, false, { conditions })
89
89
  // We reproduced it both with a tiny standalone script and through the
90
- // `EvalBroker > passes conditionNames to node fallback resolution` test,
90
+ // `EvalBroker > passes conditionNames to native fallback resolution` test,
91
91
  // including on Bun 1.3.13. Keep this fallback narrow: only conditioned
92
92
  // resolution under Bun goes through a short-lived Node subprocess.
93
93
  //
@@ -1,51 +0,0 @@
1
- export const defaultBundlerOwnedSpecifierPrefixes = [
2
- "\0",
3
- "/@",
4
- "virtual:"
5
- ];
6
- export const getResolverPrecedence = (mode) => {
7
- if (mode === "hybrid") {
8
- return [
9
- "customResolver",
10
- "safeOxcResolver",
11
- "bundlerResolver",
12
- "nodeFallback"
13
- ];
14
- }
15
- if (mode === "bundler") {
16
- return [
17
- "customResolver",
18
- "bundlerResolver",
19
- "nodeFallback"
20
- ];
21
- }
22
- if (mode === "custom") {
23
- return ["customResolver"];
24
- }
25
- return ["nodeFallback"];
26
- };
27
- export const classifyHybridResolverSpecifier = (specifier, { bundlerOwnedPrefixes = defaultBundlerOwnedSpecifierPrefixes } = {}) => {
28
- if (bundlerOwnedPrefixes.some((prefix) => specifier.startsWith(prefix))) {
29
- return {
30
- reason: "bundler-owned-prefix",
31
- route: "bundler"
32
- };
33
- }
34
- if (!specifier.startsWith("./") && !specifier.startsWith("../")) {
35
- return {
36
- reason: "ambiguous-specifier",
37
- route: "bundler"
38
- };
39
- }
40
- if (/[?#]/.test(specifier)) {
41
- return {
42
- reason: "query-or-hash",
43
- route: "bundler"
44
- };
45
- }
46
- return {
47
- reason: "safe-relative-specifier",
48
- route: "oxc"
49
- };
50
- };
51
- //# sourceMappingURL=resolverStrategy.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAmBA,OAAO,MAAM,uCAAuC;CAClD;CACA;CACA;CACD;AAED,OAAO,MAAM,yBACX,SACsB;AACtB,KAAI,SAAS,UAAU;AACrB,SAAO;GACL;GACA;GACA;GACA;GACD;;AAGH,KAAI,SAAS,WAAW;AACtB,SAAO;GAAC;GAAkB;GAAmB;GAAe;;AAG9D,KAAI,SAAS,UAAU;AACrB,SAAO,CAAC,iBAAiB;;AAG3B,QAAO,CAAC,eAAe;;AAGzB,OAAO,MAAM,mCACX,WACA,EACE,uBAAuB,yCACY,EAAE,KACZ;AAC3B,KAAI,qBAAqB,MAAM,WAAW,UAAU,WAAW,OAAO,CAAC,EAAE;AACvE,SAAO;GACL,QAAQ;GACR,OAAO;GACR;;AAGH,KAAI,CAAC,UAAU,WAAW,KAAK,IAAI,CAAC,UAAU,WAAW,MAAM,EAAE;AAC/D,SAAO;GACL,QAAQ;GACR,OAAO;GACR;;AAGH,KAAI,OAAO,KAAK,UAAU,EAAE;AAC1B,SAAO;GACL,QAAQ;GACR,OAAO;GACR;;AAGH,QAAO;EACL,QAAQ;EACR,OAAO;EACR","names":[],"sources":["../../src/eval/resolverStrategy.ts"],"version":3,"sourcesContent":["import type { EvalResolverMode } from '@wyw-in-js/shared';\n\nexport type HybridResolverRoute = 'bundler' | 'oxc';\n\nexport type HybridResolverReason =\n | 'ambiguous-specifier'\n | 'bundler-owned-prefix'\n | 'query-or-hash'\n | 'safe-relative-specifier';\n\nexport type HybridResolverDecision = {\n reason: HybridResolverReason;\n route: HybridResolverRoute;\n};\n\nexport type HybridResolverClassifierOptions = {\n bundlerOwnedPrefixes?: readonly string[];\n};\n\nexport const defaultBundlerOwnedSpecifierPrefixes = [\n '\\0',\n '/@',\n 'virtual:',\n] as const;\n\nexport const getResolverPrecedence = (\n mode: EvalResolverMode\n): readonly string[] => {\n if (mode === 'hybrid') {\n return [\n 'customResolver',\n 'safeOxcResolver',\n 'bundlerResolver',\n 'nodeFallback',\n ];\n }\n\n if (mode === 'bundler') {\n return ['customResolver', 'bundlerResolver', 'nodeFallback'];\n }\n\n if (mode === 'custom') {\n return ['customResolver'];\n }\n\n return ['nodeFallback'];\n};\n\nexport const classifyHybridResolverSpecifier = (\n specifier: string,\n {\n bundlerOwnedPrefixes = defaultBundlerOwnedSpecifierPrefixes,\n }: HybridResolverClassifierOptions = {}\n): HybridResolverDecision => {\n if (bundlerOwnedPrefixes.some((prefix) => specifier.startsWith(prefix))) {\n return {\n reason: 'bundler-owned-prefix',\n route: 'bundler',\n };\n }\n\n if (!specifier.startsWith('./') && !specifier.startsWith('../')) {\n return {\n reason: 'ambiguous-specifier',\n route: 'bundler',\n };\n }\n\n if (/[?#]/.test(specifier)) {\n return {\n reason: 'query-or-hash',\n route: 'bundler',\n };\n }\n\n return {\n reason: 'safe-relative-specifier',\n route: 'oxc',\n };\n};\n"],"file":"resolverStrategy.js"}
@@ -1,13 +0,0 @@
1
- import type { EvalResolverMode } from '@wyw-in-js/shared';
2
- export type HybridResolverRoute = 'bundler' | 'oxc';
3
- export type HybridResolverReason = 'ambiguous-specifier' | 'bundler-owned-prefix' | 'query-or-hash' | 'safe-relative-specifier';
4
- export type HybridResolverDecision = {
5
- reason: HybridResolverReason;
6
- route: HybridResolverRoute;
7
- };
8
- export type HybridResolverClassifierOptions = {
9
- bundlerOwnedPrefixes?: readonly string[];
10
- };
11
- export declare const defaultBundlerOwnedSpecifierPrefixes: readonly ["\0", "/@", "virtual:"];
12
- export declare const getResolverPrecedence: (mode: EvalResolverMode) => readonly string[];
13
- export declare const classifyHybridResolverSpecifier: (specifier: string, { bundlerOwnedPrefixes, }?: HybridResolverClassifierOptions) => HybridResolverDecision;
@@ -1,46 +0,0 @@
1
- export const defaultBundlerOwnedSpecifierPrefixes = [
2
- '\0',
3
- '/@',
4
- 'virtual:',
5
- ];
6
- export const getResolverPrecedence = (mode) => {
7
- if (mode === 'hybrid') {
8
- return [
9
- 'customResolver',
10
- 'safeOxcResolver',
11
- 'bundlerResolver',
12
- 'nodeFallback',
13
- ];
14
- }
15
- if (mode === 'bundler') {
16
- return ['customResolver', 'bundlerResolver', 'nodeFallback'];
17
- }
18
- if (mode === 'custom') {
19
- return ['customResolver'];
20
- }
21
- return ['nodeFallback'];
22
- };
23
- export const classifyHybridResolverSpecifier = (specifier, { bundlerOwnedPrefixes = defaultBundlerOwnedSpecifierPrefixes, } = {}) => {
24
- if (bundlerOwnedPrefixes.some((prefix) => specifier.startsWith(prefix))) {
25
- return {
26
- reason: 'bundler-owned-prefix',
27
- route: 'bundler',
28
- };
29
- }
30
- if (!specifier.startsWith('./') && !specifier.startsWith('../')) {
31
- return {
32
- reason: 'ambiguous-specifier',
33
- route: 'bundler',
34
- };
35
- }
36
- if (/[?#]/.test(specifier)) {
37
- return {
38
- reason: 'query-or-hash',
39
- route: 'bundler',
40
- };
41
- }
42
- return {
43
- reason: 'safe-relative-specifier',
44
- route: 'oxc',
45
- };
46
- };