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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) 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/processEntrypoint.js +35 -20
  14. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  15. package/esm/transform/generators/resolveImports.js +48 -2
  16. package/esm/transform/generators/resolveImports.js.map +1 -1
  17. package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  18. package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
  19. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
  20. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
  21. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
  22. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
  23. package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
  24. package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
  25. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
  26. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
  27. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
  28. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
  29. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
  30. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
  31. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
  32. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
  33. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
  34. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
  35. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
  36. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
  37. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
  38. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
  39. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
  40. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
  41. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
  42. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
  43. package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
  44. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
  45. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
  46. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
  47. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
  48. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
  49. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
  50. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
  51. package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
  52. package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
  53. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
  54. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
  55. package/esm/transform/generators/resolveStaticOxcValues.js +1 -2910
  56. package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -1
  57. package/esm/transform/generators/transform.js +57 -45
  58. package/esm/transform/generators/transform.js.map +1 -1
  59. package/esm/transform/helpers/loadWywOptions.js +33 -4
  60. package/esm/transform/helpers/loadWywOptions.js.map +1 -1
  61. package/esm/transform.js +3 -1
  62. package/esm/transform.js.map +1 -1
  63. package/esm/utils/EventEmitter.js +42 -9
  64. package/esm/utils/EventEmitter.js.map +1 -1
  65. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
  66. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
  67. package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
  68. package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
  69. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
  70. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
  71. package/esm/utils/applyOxcProcessors/displayName.js +93 -0
  72. package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
  73. package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
  74. package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
  75. package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
  76. package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
  77. package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
  78. package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
  79. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
  80. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
  81. package/esm/utils/applyOxcProcessors/shared.js +29 -0
  82. package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
  83. package/esm/utils/applyOxcProcessors/types.js +2 -0
  84. package/esm/utils/applyOxcProcessors/types.js.map +1 -0
  85. package/esm/utils/applyOxcProcessors.js +1 -1216
  86. package/esm/utils/applyOxcProcessors.js.map +1 -1
  87. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
  88. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
  89. package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
  90. package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
  91. package/esm/utils/collectOxcRuntime/types.js +2 -0
  92. package/esm/utils/collectOxcRuntime/types.js.map +1 -0
  93. package/esm/utils/collectOxcRuntime.js +5 -193
  94. package/esm/utils/collectOxcRuntime.js.map +1 -1
  95. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
  96. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
  97. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
  98. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
  99. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
  100. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
  101. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
  102. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
  103. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
  104. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
  105. package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
  106. package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
  107. package/esm/utils/collectOxcTemplateDependencies.js +3 -1397
  108. package/esm/utils/collectOxcTemplateDependencies.js.map +1 -1
  109. package/esm/utils/nativeResolver.js +93 -0
  110. package/esm/utils/nativeResolver.js.map +1 -0
  111. package/esm/utils/oxc/ast.js +28 -0
  112. package/esm/utils/oxc/ast.js.map +1 -0
  113. package/esm/utils/oxc/parse.js +3 -0
  114. package/esm/utils/oxc/parse.js.map +1 -0
  115. package/esm/utils/oxc/replacements.js +14 -0
  116. package/esm/utils/oxc/replacements.js.map +1 -0
  117. package/esm/utils/oxc/sourceLocations.js +59 -0
  118. package/esm/utils/oxc/sourceLocations.js.map +1 -0
  119. package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
  120. package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
  121. package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
  122. package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
  123. package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
  124. package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
  125. package/esm/utils/oxcPreevalStage/processors.js +17 -0
  126. package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
  127. package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
  128. package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
  129. package/esm/utils/oxcPreevalStage/types.js +2 -0
  130. package/esm/utils/oxcPreevalStage/types.js.map +1 -0
  131. package/esm/utils/oxcPreevalStage.js +17 -73
  132. package/esm/utils/oxcPreevalStage.js.map +1 -1
  133. package/esm/utils/oxcPreevalTransforms.js +12 -1
  134. package/esm/utils/oxcPreevalTransforms.js.map +1 -1
  135. package/esm/utils/processorStaticSemantics.js +157 -0
  136. package/esm/utils/processorStaticSemantics.js.map +1 -0
  137. package/esm/utils/resolveWithConditions.js +3 -3
  138. package/esm/utils/resolveWithConditions.js.map +1 -1
  139. package/package.json +4 -3
  140. package/types/cache.js +8 -0
  141. package/types/debug/fileReporter.js +46 -1
  142. package/types/eval/broker.d.ts +6 -2
  143. package/types/eval/broker.js +244 -95
  144. package/types/eval/protocol.d.ts +15 -1
  145. package/types/module.d.ts +4 -1
  146. package/types/module.js +97 -48
  147. package/types/transform/Entrypoint.types.d.ts +3 -0
  148. package/types/transform/generators/resolveImports.d.ts +3 -1
  149. package/types/transform/generators/resolveImports.js +49 -2
  150. package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
  151. package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  152. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
  153. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
  154. package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
  155. package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
  156. package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
  157. package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
  158. package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
  159. package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
  160. package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
  161. package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
  162. package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
  163. package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
  164. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
  165. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
  166. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
  167. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
  168. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
  169. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
  170. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
  171. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
  172. package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
  173. package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
  174. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
  175. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
  176. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
  177. package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
  178. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
  179. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
  180. package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
  181. package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
  182. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
  183. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
  184. package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
  185. package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
  186. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
  187. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
  188. package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -2
  189. package/types/transform/generators/resolveStaticOxcValues.js +1 -3235
  190. package/types/transform/generators/transform.js +63 -49
  191. package/types/transform/helpers/loadWywOptions.js +23 -3
  192. package/types/transform.js +3 -1
  193. package/types/utils/EventEmitter.d.ts +16 -1
  194. package/types/utils/EventEmitter.js +44 -9
  195. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
  196. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
  197. package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
  198. package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
  199. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
  200. package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
  201. package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
  202. package/types/utils/applyOxcProcessors/displayName.js +113 -0
  203. package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
  204. package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
  205. package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
  206. package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
  207. package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
  208. package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
  209. package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
  210. package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
  211. package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
  212. package/types/utils/applyOxcProcessors/shared.js +37 -0
  213. package/types/utils/applyOxcProcessors/types.d.ts +88 -0
  214. package/types/utils/applyOxcProcessors/types.js +1 -0
  215. package/types/utils/applyOxcProcessors.d.ts +1 -16
  216. package/types/utils/applyOxcProcessors.js +1 -1391
  217. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
  218. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
  219. package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
  220. package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
  221. package/types/utils/collectOxcRuntime/types.d.ts +16 -0
  222. package/types/utils/collectOxcRuntime/types.js +1 -0
  223. package/types/utils/collectOxcRuntime.d.ts +2 -12
  224. package/types/utils/collectOxcRuntime.js +5 -224
  225. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
  226. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
  227. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
  228. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
  229. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
  230. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
  231. package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
  232. package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
  233. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
  234. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
  235. package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
  236. package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
  237. package/types/utils/collectOxcTemplateDependencies.d.ts +4 -38
  238. package/types/utils/collectOxcTemplateDependencies.js +3 -1580
  239. package/types/utils/nativeResolver.d.ts +13 -0
  240. package/types/utils/nativeResolver.js +91 -0
  241. package/types/utils/oxc/ast.d.ts +4 -0
  242. package/types/utils/oxc/ast.js +37 -0
  243. package/types/utils/oxc/parse.d.ts +3 -0
  244. package/types/utils/oxc/parse.js +2 -0
  245. package/types/utils/oxc/replacements.d.ts +12 -0
  246. package/types/utils/oxc/replacements.js +18 -0
  247. package/types/utils/oxc/sourceLocations.d.ts +5 -0
  248. package/types/utils/oxc/sourceLocations.js +63 -0
  249. package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
  250. package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
  251. package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
  252. package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
  253. package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
  254. package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
  255. package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
  256. package/types/utils/oxcPreevalStage/processors.js +16 -0
  257. package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
  258. package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
  259. package/types/utils/oxcPreevalStage/types.d.ts +22 -0
  260. package/types/utils/oxcPreevalStage/types.js +1 -0
  261. package/types/utils/oxcPreevalStage.d.ts +2 -18
  262. package/types/utils/oxcPreevalStage.js +17 -79
  263. package/types/utils/oxcPreevalTransforms.js +14 -1
  264. package/types/utils/processorStaticSemantics.d.ts +13 -0
  265. package/types/utils/processorStaticSemantics.js +191 -0
  266. package/types/utils/resolveWithConditions.js +3 -3
  267. package/esm/eval/resolverStrategy.js +0 -51
  268. package/esm/eval/resolverStrategy.js.map +0 -1
  269. package/types/eval/resolverStrategy.d.ts +0 -13
  270. package/types/eval/resolverStrategy.js +0 -46
@@ -0,0 +1,13 @@
1
+ import type { EvalResolverKind, OxcOptions, StrictOptions } from '@wyw-in-js/shared';
2
+ export type NativeResolverParams = {
3
+ conditionNames?: string[];
4
+ extensions: StrictOptions['extensions'];
5
+ importer: string;
6
+ kind: EvalResolverKind;
7
+ oxcOptions?: OxcOptions;
8
+ specifier: string;
9
+ };
10
+ export declare const expandNativeResolverConditions: (kind: EvalResolverKind, conditionNames?: readonly string[]) => string[];
11
+ export declare const clearNativeResolverCacheForTest: () => void;
12
+ export declare const getNativeResolverCacheSizeForTest: () => number;
13
+ export declare const resolveWithNativeResolver: ({ conditionNames, extensions, importer, kind, oxcOptions, specifier, }: NativeResolverParams) => string;
@@ -0,0 +1,91 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { ResolverFactory } from 'oxc-resolver';
4
+ import { parseRequest } from './parseRequest';
5
+ const CJS_DEFAULT_CONDITIONS = ['require', 'node', 'default'];
6
+ const ESM_DEFAULT_CONDITIONS = ['node', 'import', 'default'];
7
+ const FALLBACK_EXTENSIONS = ['.json', '.node'];
8
+ const MAX_RESOLVER_CACHE_SIZE = 64;
9
+ const resolverCache = new Map();
10
+ const unique = (items) => Array.from(new Set(items));
11
+ export const expandNativeResolverConditions = (kind, conditionNames) => {
12
+ const defaults = kind === 'require' ? CJS_DEFAULT_CONDITIONS : ESM_DEFAULT_CONDITIONS;
13
+ const names = conditionNames?.length ? conditionNames : ['...'];
14
+ const result = [];
15
+ names.forEach((name) => {
16
+ if (name === '...') {
17
+ defaults.forEach((condition) => result.push(condition));
18
+ return;
19
+ }
20
+ result.push(name);
21
+ });
22
+ return unique(result);
23
+ };
24
+ const createResolverOptions = ({ conditionNames, extensions, kind, oxcOptions, }) => {
25
+ const configuredResolver = (oxcOptions?.resolver ?? {});
26
+ const hasConfiguredTsconfig = Object.prototype.hasOwnProperty.call(configuredResolver, 'tsconfig');
27
+ const configuredConditionNames = Array.isArray(configuredResolver.conditionNames)
28
+ ? configuredResolver.conditionNames
29
+ : undefined;
30
+ const configuredExtensions = Array.isArray(configuredResolver.extensions)
31
+ ? configuredResolver.extensions
32
+ : [];
33
+ return {
34
+ ...configuredResolver,
35
+ ...(hasConfiguredTsconfig ? {} : { tsconfig: 'auto' }),
36
+ conditionNames: expandNativeResolverConditions(kind, conditionNames ?? configuredConditionNames),
37
+ extensions: unique([
38
+ ...configuredExtensions,
39
+ ...extensions,
40
+ ...FALLBACK_EXTENSIONS,
41
+ ]),
42
+ };
43
+ };
44
+ const getResolver = (options) => {
45
+ const key = JSON.stringify(options);
46
+ const cached = resolverCache.get(key);
47
+ if (cached) {
48
+ resolverCache.delete(key);
49
+ resolverCache.set(key, cached);
50
+ return cached;
51
+ }
52
+ const resolver = new ResolverFactory(options);
53
+ if (resolverCache.size >= MAX_RESOLVER_CACHE_SIZE) {
54
+ const oldestKey = resolverCache.keys().next().value;
55
+ if (oldestKey !== undefined) {
56
+ resolverCache.delete(oldestKey);
57
+ }
58
+ }
59
+ resolverCache.set(key, resolver);
60
+ return resolver;
61
+ };
62
+ export const clearNativeResolverCacheForTest = () => {
63
+ resolverCache.clear();
64
+ };
65
+ export const getNativeResolverCacheSizeForTest = () => resolverCache.size;
66
+ const preferJsOverCjsForExtensionlessFileSpecifier = (specifier, resolved) => {
67
+ if ((specifier.startsWith('.') || path.isAbsolute(specifier)) &&
68
+ path.extname(specifier) === '' &&
69
+ resolved.endsWith('.cjs') &&
70
+ fs.existsSync(`${resolved.slice(0, -4)}.js`)) {
71
+ return `${resolved.slice(0, -4)}.js`;
72
+ }
73
+ return resolved;
74
+ };
75
+ export const resolveWithNativeResolver = ({ conditionNames, extensions, importer, kind, oxcOptions, specifier, }) => {
76
+ const { filename, query, hash } = parseRequest(specifier);
77
+ const options = createResolverOptions({
78
+ conditionNames,
79
+ extensions,
80
+ kind,
81
+ oxcOptions,
82
+ });
83
+ const resolver = getResolver(options);
84
+ const result = resolver.resolveFileSync(importer, filename);
85
+ if (!result.path) {
86
+ throw new Error(result.error ?? `Cannot resolve module ${specifier}`);
87
+ }
88
+ const resolved = preferJsOverCjsForExtensionlessFileSpecifier(filename, result.path);
89
+ const suffix = `${query ? `?${query}` : ''}${hash ? `#${hash}` : ''}`;
90
+ return `${resolved}${suffix}`;
91
+ };
@@ -0,0 +1,4 @@
1
+ import type { Node } from 'oxc-parser';
2
+ export declare const isOxcNode: (value: unknown) => value is Node;
3
+ export declare const getOxcNodeChildren: (node: Node) => Node[];
4
+ export declare const walkOxc: (node: Node, enter: (node: Node, parent: Node | null) => void, parent?: Node | null) => void;
@@ -0,0 +1,37 @@
1
+ export const isOxcNode = (value) => !!value &&
2
+ typeof value === 'object' &&
3
+ 'type' in value &&
4
+ typeof value.type === 'string';
5
+ export const getOxcNodeChildren = (node) => {
6
+ const result = [];
7
+ const record = node;
8
+ Object.keys(record).forEach((key) => {
9
+ if (key === 'comments' ||
10
+ key === 'end' ||
11
+ key === 'errors' ||
12
+ key === 'parent' ||
13
+ key === 'range' ||
14
+ key === 'span' ||
15
+ key === 'start' ||
16
+ key === 'type') {
17
+ return;
18
+ }
19
+ const value = record[key];
20
+ if (isOxcNode(value)) {
21
+ result.push(value);
22
+ return;
23
+ }
24
+ if (Array.isArray(value)) {
25
+ value.forEach((item) => {
26
+ if (isOxcNode(item)) {
27
+ result.push(item);
28
+ }
29
+ });
30
+ }
31
+ });
32
+ return result;
33
+ };
34
+ export const walkOxc = (node, enter, parent = null) => {
35
+ enter(node, parent);
36
+ getOxcNodeChildren(node).forEach((child) => walkOxc(child, enter, node));
37
+ };
@@ -0,0 +1,3 @@
1
+ import type { Program } from 'oxc-parser';
2
+ export type OxcSourceType = 'module' | 'unambiguous';
3
+ export declare const parseOxcProgram: (code: string, filename: string, sourceType?: OxcSourceType) => Program;
@@ -0,0 +1,2 @@
1
+ import { parseOxcProgramCached } from '../parseOxc';
2
+ export const parseOxcProgram = (code, filename, sourceType = 'unambiguous') => parseOxcProgramCached(filename, code, sourceType);
@@ -0,0 +1,12 @@
1
+ export type OxcValueReplacement = {
2
+ end: number;
3
+ start: number;
4
+ value: string;
5
+ };
6
+ export type OxcTextReplacement = {
7
+ end: number;
8
+ start: number;
9
+ text: string;
10
+ };
11
+ export type OxcReplacement = OxcTextReplacement | OxcValueReplacement;
12
+ export declare const applyOxcReplacements: (code: string, replacements: OxcReplacement[]) => string;
@@ -0,0 +1,18 @@
1
+ const getReplacementValue = (replacement) => {
2
+ if ('value' in replacement) {
3
+ return replacement.value;
4
+ }
5
+ return replacement.text;
6
+ };
7
+ export const applyOxcReplacements = (code, replacements) => {
8
+ let result = code;
9
+ [...replacements]
10
+ .sort((a, b) => b.start - a.start)
11
+ .forEach((replacement) => {
12
+ result =
13
+ result.slice(0, replacement.start) +
14
+ getReplacementValue(replacement) +
15
+ result.slice(replacement.end);
16
+ });
17
+ return result;
18
+ };
@@ -0,0 +1,5 @@
1
+ import type { SourceLocation } from '@wyw-in-js/shared';
2
+ export type OxcLocationLookup = (offset: number) => SourceLocation['start'];
3
+ export declare const createOxcLocationLookup: (code: string) => OxcLocationLookup;
4
+ export declare const createOxcSourceLocation: (start: number, end: number, loc: OxcLocationLookup, filename?: string | null, identifierName?: string | null) => SourceLocation;
5
+ export declare const buildOxcCodeFrameError: (code: string, location: SourceLocation, message: string) => Error;
@@ -0,0 +1,63 @@
1
+ export const createOxcLocationLookup = (code) => {
2
+ const lineStarts = [0];
3
+ for (let idx = 0; idx < code.length; idx += 1) {
4
+ if (code[idx] === '\n') {
5
+ lineStarts.push(idx + 1);
6
+ }
7
+ }
8
+ return (offset) => {
9
+ let low = 0;
10
+ let high = lineStarts.length - 1;
11
+ while (low <= high) {
12
+ const mid = Math.floor((low + high) / 2);
13
+ const next = lineStarts[mid + 1] ?? Infinity;
14
+ if (lineStarts[mid] <= offset && offset < next) {
15
+ return {
16
+ column: offset - lineStarts[mid],
17
+ line: mid + 1,
18
+ };
19
+ }
20
+ if (offset < lineStarts[mid]) {
21
+ high = mid - 1;
22
+ }
23
+ else {
24
+ low = mid + 1;
25
+ }
26
+ }
27
+ const lastLine = lineStarts.length - 1;
28
+ return {
29
+ column: Math.max(0, offset - lineStarts[lastLine]),
30
+ line: lastLine + 1,
31
+ };
32
+ };
33
+ };
34
+ export const createOxcSourceLocation = (start, end, loc, filename, identifierName) => ({
35
+ end: loc(end),
36
+ filename: filename ?? undefined,
37
+ identifierName,
38
+ start: loc(start),
39
+ });
40
+ export const buildOxcCodeFrameError = (code, location, message) => {
41
+ const lines = code.split('\n');
42
+ const startLine = location.start.line;
43
+ const endLine = location.end.line;
44
+ const frameStart = Math.max(1, startLine - 2);
45
+ const frameEnd = Math.min(lines.length, endLine + 2);
46
+ const lineNoWidth = String(frameEnd).length;
47
+ const frame = [];
48
+ for (let lineNo = frameStart; lineNo <= frameEnd; lineNo += 1) {
49
+ const marker = lineNo === startLine ? '>' : ' ';
50
+ const line = lines[lineNo - 1] ?? '';
51
+ frame.push(line.length > 0
52
+ ? `${marker} ${String(lineNo).padStart(lineNoWidth)} | ${line}`
53
+ : `${marker} ${String(lineNo).padStart(lineNoWidth)} |`);
54
+ if (lineNo === startLine) {
55
+ const pointerLength = startLine === endLine
56
+ ? Math.max(1, location.end.column - location.start.column)
57
+ : 1;
58
+ frame.push(` ${' '.repeat(lineNoWidth)} | ${' '.repeat(location.start.column)}${'^'.repeat(pointerLength)}`);
59
+ }
60
+ }
61
+ const prefix = location.filename ? `${location.filename}: ` : '';
62
+ return new Error(`${prefix}${message}\n${frame.join('\n')}`);
63
+ };
@@ -0,0 +1,3 @@
1
+ import type { OxcPreevalOptions } from './types';
2
+ export declare const getEvalStrategy: (options: OxcPreevalOptions) => import("@wyw-in-js/shared").EvalStrategy;
3
+ export declare const usesStaticEvaluation: (options: OxcPreevalOptions) => boolean;
@@ -0,0 +1,2 @@
1
+ export const getEvalStrategy = (options) => options.eval?.strategy ?? 'hybrid';
2
+ export const usesStaticEvaluation = (options) => getEvalStrategy(options) !== 'execute';
@@ -0,0 +1,3 @@
1
+ import type { EventEmitter } from '../EventEmitter';
2
+ import type { OxcPreevalOptions } from './types';
3
+ export declare const prepareOxcPreevalCode: (code: string, filename: string, options: OxcPreevalOptions, eventEmitter: EventEmitter) => string;
@@ -0,0 +1,20 @@
1
+ import { isFeatureEnabled } from '@wyw-in-js/shared';
2
+ import { removeDangerousCodeWithOxc, replaceImportMetaEnvWithOxc, rewriteDynamicImportsAndAddRequireFallbackWithOxc, } from '../oxcPreevalTransforms';
3
+ const DYNAMIC_IMPORT_RE = /\bimport(?:\s|\/\*[\s\S]*?\*\/)*\(/;
4
+ const REQUIRE_CALL_RE = /\brequire(?:\s|\/\*[\s\S]*?\*\/)*\(/;
5
+ export const prepareOxcPreevalCode = (code, filename, options, eventEmitter) => {
6
+ let nextCode = eventEmitter.perf('transform:preeval:importMetaEnv', () => replaceImportMetaEnvWithOxc(code, filename));
7
+ if (isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)) {
8
+ nextCode = eventEmitter.perf('transform:preeval:removeDangerousCode', () => removeDangerousCodeWithOxc(nextCode, filename, options.codeRemover));
9
+ }
10
+ const shouldRewriteDynamicImports = DYNAMIC_IMPORT_RE.test(nextCode);
11
+ const shouldAddRequireFallback = REQUIRE_CALL_RE.test(nextCode);
12
+ if (shouldRewriteDynamicImports || shouldAddRequireFallback) {
13
+ nextCode = rewriteDynamicImportsAndAddRequireFallbackWithOxc(nextCode, filename, {
14
+ addRequireFallback: shouldAddRequireFallback,
15
+ eventEmitter,
16
+ rewriteDynamicImports: shouldRewriteDynamicImports,
17
+ });
18
+ }
19
+ return nextCode;
20
+ };
@@ -0,0 +1 @@
1
+ export declare const appendOxcWywPreval: (code: string, filename: string, dependencyNames: string[]) => string;
@@ -0,0 +1,22 @@
1
+ import { parseSync } from 'oxc-parser';
2
+ const parseSourceType = (code, filename) => {
3
+ const parsed = parseSync(filename, code, {
4
+ astType: filename.endsWith('.ts') || filename.endsWith('.tsx') ? 'ts' : 'js',
5
+ range: true,
6
+ sourceType: 'unambiguous',
7
+ });
8
+ const fatalError = parsed.errors.find((error) => error.severity === 'Error');
9
+ if (fatalError) {
10
+ throw new Error(fatalError.message);
11
+ }
12
+ return parsed.program.sourceType === 'script' ? 'script' : 'module';
13
+ };
14
+ export const appendOxcWywPreval = (code, filename, dependencyNames) => {
15
+ const uniqueNames = [...new Set(dependencyNames)];
16
+ const properties = uniqueNames.map((name) => `${name}: ${name}`).join(', ');
17
+ const object = uniqueNames.length > 0 ? `{ ${properties} }` : '{}';
18
+ if (parseSourceType(code, filename) === 'script') {
19
+ return `${code}\nexports.__wywPreval = ${object};`;
20
+ }
21
+ return `${code}\nexport const __wywPreval = ${object};`;
22
+ };
@@ -0,0 +1,10 @@
1
+ import type { IFileContext } from '@wyw-in-js/processor-utils';
2
+ import type { EventEmitter } from '../EventEmitter';
3
+ import type { ApplyOxcProcessorsResult } from '../applyOxcProcessors/types';
4
+ import type { OxcPreevalOptions } from './types';
5
+ type PreevalProcessorCollection = {
6
+ dependencyNames: string[];
7
+ processed: ApplyOxcProcessorsResult;
8
+ };
9
+ export declare const collectPreevalProcessors: (code: string, fileContext: IFileContext, options: OxcPreevalOptions, eventEmitter: EventEmitter) => PreevalProcessorCollection;
10
+ export {};
@@ -0,0 +1,16 @@
1
+ import { applyOxcProcessors } from '../applyOxcProcessors';
2
+ export const collectPreevalProcessors = (code, fileContext, options, eventEmitter) => {
3
+ const dependencyNames = [];
4
+ const processed = eventEmitter.perf('transform:preeval:processTemplate', () => applyOxcProcessors(code, fileContext, options, (processor) => {
5
+ processor.dependencies.forEach((dependency) => {
6
+ if (dependency.ex.type === 'Identifier') {
7
+ dependencyNames.push(dependency.ex.name);
8
+ }
9
+ });
10
+ processor.doEvaltimeReplacement();
11
+ }));
12
+ return {
13
+ dependencyNames,
14
+ processed,
15
+ };
16
+ };
@@ -0,0 +1,3 @@
1
+ import type { ApplyOxcProcessorsResult } from '../applyOxcProcessors/types';
2
+ import type { OxcPreevalOptions, StaticPreevalOverlay } from './types';
3
+ export declare const createStaticPreevalOverlay: (processed: ApplyOxcProcessorsResult, dependencyNames: string[], options: OxcPreevalOptions) => StaticPreevalOverlay;
@@ -0,0 +1,23 @@
1
+ import { usesStaticEvaluation } from './evalStrategy';
2
+ export const createStaticPreevalOverlay = (processed, dependencyNames, options) => {
3
+ const staticValuesEnabled = usesStaticEvaluation(options);
4
+ const staticValueNames = staticValuesEnabled
5
+ ? new Set(processed.staticValues.map((item) => item.name))
6
+ : null;
7
+ const evalDependencyNames = staticValuesEnabled
8
+ ? dependencyNames.filter((name) => !staticValueNames.has(name))
9
+ : dependencyNames;
10
+ const staticValueCache = new Map();
11
+ if (staticValuesEnabled) {
12
+ processed.staticValues.forEach(({ name, value }) => {
13
+ staticValueCache.set(name, value);
14
+ });
15
+ }
16
+ return {
17
+ evalDependencyNames,
18
+ staticValueCache,
19
+ staticValueCandidates: staticValuesEnabled
20
+ ? processed.staticValueCandidates
21
+ : [],
22
+ };
23
+ };
@@ -0,0 +1,22 @@
1
+ import type { StrictOptions } from '@wyw-in-js/shared';
2
+ import type { EventEmitter } from '../EventEmitter';
3
+ import type { WYWTransformMetadata } from '../TransformMetadata';
4
+ import type { OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';
5
+ export type OxcPreevalOptions = Pick<StrictOptions, 'classNameSlug' | 'codeRemover' | 'displayName' | 'eval' | 'extensions' | 'features' | 'staticBindings' | 'tagResolver'> & {
6
+ eventEmitter?: EventEmitter;
7
+ };
8
+ export type OxcPreevalResult = {
9
+ baseCode: string;
10
+ code: string;
11
+ dependencyNames: string[];
12
+ metadata: WYWTransformMetadata | null;
13
+ processorClassNames: Record<string, string>;
14
+ staticDependencies: string[];
15
+ staticValueCache: Map<string, unknown>;
16
+ staticValueCandidates: OxcStaticValueCandidate[];
17
+ };
18
+ export type StaticPreevalOverlay = {
19
+ evalDependencyNames: string[];
20
+ staticValueCache: Map<string, unknown>;
21
+ staticValueCandidates: OxcStaticValueCandidate[];
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,20 +1,4 @@
1
1
  import type { IFileContext } from '@wyw-in-js/processor-utils';
2
- import type { StrictOptions } from '@wyw-in-js/shared';
3
- import { EventEmitter } from './EventEmitter';
4
- import type { WYWTransformMetadata } from './TransformMetadata';
5
- import type { OxcStaticValueCandidate } from './collectOxcTemplateDependencies';
6
- type OxcPreevalOptions = Pick<StrictOptions, 'classNameSlug' | 'codeRemover' | 'displayName' | 'evaluate' | 'extensions' | 'features' | 'tagResolver'> & {
7
- eventEmitter?: EventEmitter;
8
- };
9
- type OxcPreevalResult = {
10
- baseCode: string;
11
- code: string;
12
- dependencyNames: string[];
13
- metadata: WYWTransformMetadata | null;
14
- staticDependencies: string[];
15
- staticValueCache: Map<string, unknown>;
16
- staticValueCandidates: OxcStaticValueCandidate[];
17
- };
18
- export declare const appendOxcWywPreval: (code: string, filename: string, dependencyNames: string[]) => string;
2
+ import type { OxcPreevalOptions, OxcPreevalResult } from './oxcPreevalStage/types';
3
+ export { appendOxcWywPreval } from './oxcPreevalStage/prevalExport';
19
4
  export declare const runOxcPreevalStage: (code: string, fileContext: IFileContext, options: OxcPreevalOptions) => OxcPreevalResult;
20
- export {};
@@ -1,102 +1,40 @@
1
- import { parseSync } from 'oxc-parser';
2
- import { isFeatureEnabled } from '@wyw-in-js/shared';
3
1
  import { EventEmitter } from './EventEmitter';
4
- import { applyOxcProcessors } from './applyOxcProcessors';
5
- import { removeDangerousCodeWithOxc, replaceImportMetaEnvWithOxc, rewriteDynamicImportsAndAddRequireFallbackWithOxc, } from './oxcPreevalTransforms';
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';
3
+ import { prepareOxcPreevalCode } from './oxcPreevalStage/prepareCode';
4
+ import { collectPreevalProcessors } from './oxcPreevalStage/processors';
5
+ import { createStaticPreevalOverlay } from './oxcPreevalStage/staticOverlay';
6
+ export { appendOxcWywPreval } from './oxcPreevalStage/prevalExport';
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
51
- ? new Set(processed.staticValues.map((item) => item.name))
52
- : null;
53
- const evalDependencyNames = staticValuesEnabled
54
- ? dependencyNames.filter((name) => !staticValueNames.has(name))
55
- : dependencyNames;
56
- let nextCode = eventEmitter.perf('transform:preeval:importMetaEnv', () => replaceImportMetaEnvWithOxc(processed.code, filename));
57
- if (isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)) {
58
- nextCode = eventEmitter.perf('transform:preeval:removeDangerousCode', () => removeDangerousCodeWithOxc(nextCode, filename, options.codeRemover));
59
- }
60
- const shouldRewriteDynamicImports = DYNAMIC_IMPORT_RE.test(nextCode);
61
- const shouldAddRequireFallback = REQUIRE_CALL_RE.test(nextCode);
62
- if (shouldRewriteDynamicImports || shouldAddRequireFallback) {
63
- nextCode = rewriteDynamicImportsAndAddRequireFallbackWithOxc(nextCode, filename, {
64
- addRequireFallback: shouldAddRequireFallback,
65
- eventEmitter,
66
- rewriteDynamicImports: shouldRewriteDynamicImports,
67
- });
68
- }
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);
69
13
  if (processed.processors.length === 0) {
70
14
  return {
71
- baseCode: nextCode,
72
- code: nextCode,
15
+ baseCode,
16
+ code: baseCode,
73
17
  dependencyNames: [],
74
18
  metadata: null,
19
+ processorClassNames: {},
75
20
  staticDependencies: [],
76
21
  staticValueCandidates: [],
77
22
  staticValueCache: new Map(),
78
23
  };
79
24
  }
80
- const staticValueCache = new Map();
81
- if (staticValuesEnabled) {
82
- processed.staticValues.forEach(({ name, value }) => {
83
- staticValueCache.set(name, value);
84
- });
85
- }
86
25
  return {
87
- baseCode: nextCode,
88
- code: appendOxcWywPreval(nextCode, filename, evalDependencyNames),
89
- dependencyNames: evalDependencyNames,
26
+ baseCode,
27
+ code: appendOxcWywPreval(baseCode, filename, staticOverlay.evalDependencyNames),
28
+ dependencyNames: staticOverlay.evalDependencyNames,
90
29
  metadata: {
91
30
  dependencies: [],
92
31
  processors: processed.processors,
93
32
  replacements: [],
94
33
  rules: {},
95
34
  },
35
+ processorClassNames: Object.fromEntries(processed.processorClassNamesByLocal),
96
36
  staticDependencies: [],
97
- staticValueCandidates: staticValuesEnabled
98
- ? processed.staticValueCandidates
99
- : [],
100
- staticValueCache,
37
+ staticValueCache: staticOverlay.staticValueCache,
38
+ staticValueCandidates: staticOverlay.staticValueCandidates,
101
39
  };
102
40
  };
@@ -40,6 +40,7 @@ const defaultReactComponentTypes = [
40
40
  'MemoExoticComponent',
41
41
  'NamedExoticComponent',
42
42
  ];
43
+ const defaultReactHocs = ['forwardRef', 'memo'];
43
44
  const generatedProcessorHelperNameRe = /^_exp\d*$/;
44
45
  const requireCallRe = /\brequire\s*\(/;
45
46
  const windowTokenRe = /\bwindow\b/;
@@ -876,6 +877,7 @@ const isHocCall = (call, hocs, imports) => {
876
877
  const matched = getImportForExpression(getInnermostCallee(call), imports);
877
878
  return !!matched && hocs[matched[0]]?.includes(matched[1]);
878
879
  };
880
+ const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports));
879
881
  const getComponentTypes = (options) => {
880
882
  const componentTypes = {
881
883
  ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),
@@ -888,6 +890,14 @@ const getComponentTypes = (options) => {
888
890
  }
889
891
  return componentTypes;
890
892
  };
893
+ const getHocs = (options) => {
894
+ const hocs = {
895
+ ...(options?.hocs ?? {}),
896
+ };
897
+ const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);
898
+ hocs.react = [...reactHocs];
899
+ return hocs;
900
+ };
891
901
  const getTypeImport = (node, imports) => {
892
902
  if (node.type === 'Identifier') {
893
903
  const matched = getImportBinding(imports, node.name);
@@ -1019,7 +1029,7 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
1019
1029
  const program = parseOxc(code, filename);
1020
1030
  const imports = collectImportBindings(code, filename, program);
1021
1031
  const componentTypes = getComponentTypes(options);
1022
- const hocs = options?.hocs ?? {};
1032
+ const hocs = getHocs(options);
1023
1033
  const hasHocs = Object.keys(hocs).length > 0;
1024
1034
  const windowScopedNames = windowTokenRe.test(code)
1025
1035
  ? collectWindowScopedNames(program)
@@ -1122,6 +1132,9 @@ export const removeDangerousCodeWithOxc = (code, filename, options) => {
1122
1132
  if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
1123
1133
  return;
1124
1134
  }
1135
+ if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
1136
+ return;
1137
+ }
1125
1138
  if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
1126
1139
  return;
1127
1140
  }
@@ -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;