@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,304 @@
1
+ /* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
2
+ import { collectLocalConstExpressions } from './programAnalysis';
3
+ import { collectImportBindings, collectStaticExpressionReferences, isSafeLiteral, isSafeStaticExpression, unwrapExpression, } from './staticExpression';
4
+ export const mutatingMethodNames = new Set([
5
+ 'add',
6
+ 'clear',
7
+ 'copyWithin',
8
+ 'delete',
9
+ 'fill',
10
+ 'pop',
11
+ 'push',
12
+ 'reverse',
13
+ 'set',
14
+ 'shift',
15
+ 'sort',
16
+ 'splice',
17
+ 'unshift',
18
+ ]);
19
+ export const rootIdentifierName = (expr) => {
20
+ const unwrapped = unwrapExpression(expr);
21
+ if (unwrapped.type === 'Identifier') {
22
+ return unwrapped.name;
23
+ }
24
+ if (unwrapped.type === 'MemberExpression') {
25
+ return rootIdentifierName(unwrapped.object);
26
+ }
27
+ if (unwrapped.type === 'ChainExpression') {
28
+ return rootIdentifierName(unwrapped.expression);
29
+ }
30
+ return null;
31
+ };
32
+ export const staticMemberName = (expr) => {
33
+ const unwrapped = unwrapExpression(expr);
34
+ if (unwrapped.type === 'Identifier') {
35
+ return unwrapped.name;
36
+ }
37
+ if (isSafeLiteral(unwrapped) && typeof unwrapped.value === 'string') {
38
+ return unwrapped.value;
39
+ }
40
+ return null;
41
+ };
42
+ export const expressionMayProduceMutableValue = (expr, locals, visiting) => {
43
+ const unwrapped = unwrapExpression(expr);
44
+ if (unwrapped.type === 'ObjectExpression' ||
45
+ unwrapped.type === 'ArrayExpression') {
46
+ return true;
47
+ }
48
+ if (unwrapped.type === 'Identifier') {
49
+ const local = locals.get(unwrapped.name);
50
+ if (!local || visiting.has(unwrapped.name)) {
51
+ return true;
52
+ }
53
+ visiting.add(unwrapped.name);
54
+ const result = expressionMayProduceMutableValue(local, locals, visiting);
55
+ visiting.delete(unwrapped.name);
56
+ return result;
57
+ }
58
+ if (unwrapped.type === 'ConditionalExpression') {
59
+ return (expressionMayProduceMutableValue(unwrapped.consequent, locals, visiting) ||
60
+ expressionMayProduceMutableValue(unwrapped.alternate, locals, visiting));
61
+ }
62
+ if (unwrapped.type === 'LogicalExpression' ||
63
+ unwrapped.type === 'MemberExpression') {
64
+ return true;
65
+ }
66
+ return false;
67
+ };
68
+ export const collectExpressionMutationHints = (expr, mutatedNames, callArgumentNames) => {
69
+ const unwrapped = unwrapExpression(expr);
70
+ if (unwrapped.type === 'AssignmentExpression') {
71
+ const rootName = rootIdentifierName(unwrapped.left);
72
+ if (rootName) {
73
+ mutatedNames.add(rootName);
74
+ }
75
+ collectExpressionMutationHints(unwrapped.right, mutatedNames, callArgumentNames);
76
+ return;
77
+ }
78
+ if (unwrapped.type === 'UpdateExpression') {
79
+ const rootName = rootIdentifierName(unwrapped.argument);
80
+ if (rootName) {
81
+ mutatedNames.add(rootName);
82
+ }
83
+ return;
84
+ }
85
+ if (unwrapped.type === 'UnaryExpression') {
86
+ if (unwrapped.operator === 'delete') {
87
+ const rootName = rootIdentifierName(unwrapped.argument);
88
+ if (rootName) {
89
+ mutatedNames.add(rootName);
90
+ }
91
+ }
92
+ collectExpressionMutationHints(unwrapped.argument, mutatedNames, callArgumentNames);
93
+ return;
94
+ }
95
+ if (unwrapped.type === 'CallExpression') {
96
+ const callee = unwrapExpression(unwrapped.callee);
97
+ if (callee.type === 'MemberExpression') {
98
+ const methodName = staticMemberName(callee.property);
99
+ const rootName = rootIdentifierName(callee.object);
100
+ if (rootName && methodName && mutatingMethodNames.has(methodName)) {
101
+ mutatedNames.add(rootName);
102
+ }
103
+ collectExpressionMutationHints(callee.object, mutatedNames, callArgumentNames);
104
+ if (callee.computed) {
105
+ collectExpressionMutationHints(callee.property, mutatedNames, callArgumentNames);
106
+ }
107
+ }
108
+ else {
109
+ collectExpressionMutationHints(unwrapped.callee, mutatedNames, callArgumentNames);
110
+ }
111
+ unwrapped.arguments.forEach((argument) => {
112
+ const argumentNode = argument.type === 'SpreadElement' ? argument.argument : argument;
113
+ const rootName = rootIdentifierName(argumentNode);
114
+ if (rootName) {
115
+ callArgumentNames.add(rootName);
116
+ }
117
+ collectExpressionMutationHints(argumentNode, mutatedNames, callArgumentNames);
118
+ });
119
+ return;
120
+ }
121
+ if (unwrapped.type === 'TaggedTemplateExpression') {
122
+ collectExpressionMutationHints(unwrapped.tag, mutatedNames, callArgumentNames);
123
+ unwrapped.quasi.expressions.forEach((item) => collectExpressionMutationHints(item, mutatedNames, callArgumentNames));
124
+ return;
125
+ }
126
+ if (unwrapped.type === 'ConditionalExpression') {
127
+ collectExpressionMutationHints(unwrapped.test, mutatedNames, callArgumentNames);
128
+ collectExpressionMutationHints(unwrapped.consequent, mutatedNames, callArgumentNames);
129
+ collectExpressionMutationHints(unwrapped.alternate, mutatedNames, callArgumentNames);
130
+ return;
131
+ }
132
+ if (unwrapped.type === 'BinaryExpression' ||
133
+ unwrapped.type === 'LogicalExpression') {
134
+ collectExpressionMutationHints(unwrapped.left, mutatedNames, callArgumentNames);
135
+ collectExpressionMutationHints(unwrapped.right, mutatedNames, callArgumentNames);
136
+ return;
137
+ }
138
+ if (unwrapped.type === 'MemberExpression') {
139
+ collectExpressionMutationHints(unwrapped.object, mutatedNames, callArgumentNames);
140
+ if (unwrapped.computed) {
141
+ collectExpressionMutationHints(unwrapped.property, mutatedNames, callArgumentNames);
142
+ }
143
+ return;
144
+ }
145
+ if (unwrapped.type === 'ArrayExpression') {
146
+ unwrapped.elements.forEach((item) => {
147
+ if (!item) {
148
+ return;
149
+ }
150
+ collectExpressionMutationHints(item.type === 'SpreadElement' ? item.argument : item, mutatedNames, callArgumentNames);
151
+ });
152
+ return;
153
+ }
154
+ if (unwrapped.type === 'ObjectExpression') {
155
+ unwrapped.properties.forEach((property) => {
156
+ if (property.type === 'SpreadElement') {
157
+ collectExpressionMutationHints(property.argument, mutatedNames, callArgumentNames);
158
+ return;
159
+ }
160
+ const propertyNode = property;
161
+ if (propertyNode.computed && propertyNode.key) {
162
+ collectExpressionMutationHints(propertyNode.key, mutatedNames, callArgumentNames);
163
+ }
164
+ if (propertyNode.value && typeof propertyNode.value === 'object') {
165
+ collectExpressionMutationHints(propertyNode.value, mutatedNames, callArgumentNames);
166
+ }
167
+ });
168
+ }
169
+ };
170
+ export const collectTopLevelMutationHints = (program, closureNames = null) => {
171
+ const callArgumentNames = new Set();
172
+ const mutatedNames = new Set();
173
+ const collectDeclaration = (declaration) => {
174
+ declaration.declarations.forEach((declarator) => {
175
+ if (closureNames) {
176
+ const declaredName = declarator.id.type === 'Identifier' ? declarator.id.name : null;
177
+ if (!declaredName || !closureNames.has(declaredName)) {
178
+ return;
179
+ }
180
+ }
181
+ if (declarator.init) {
182
+ collectExpressionMutationHints(declarator.init, mutatedNames, callArgumentNames);
183
+ }
184
+ });
185
+ };
186
+ program.body.forEach((statement) => {
187
+ if (statement.type === 'VariableDeclaration') {
188
+ collectDeclaration(statement);
189
+ return;
190
+ }
191
+ if (statement.type === 'ExpressionStatement') {
192
+ collectExpressionMutationHints(statement.expression, mutatedNames, callArgumentNames);
193
+ return;
194
+ }
195
+ if (statement.type === 'ExportNamedDeclaration') {
196
+ if (statement.declaration?.type === 'VariableDeclaration') {
197
+ collectDeclaration(statement.declaration);
198
+ }
199
+ return;
200
+ }
201
+ if (statement.type === 'ExportDefaultDeclaration') {
202
+ if (statement.declaration.type !== 'FunctionDeclaration' &&
203
+ statement.declaration.type !== 'ClassDeclaration') {
204
+ collectExpressionMutationHints(statement.declaration, mutatedNames, callArgumentNames);
205
+ }
206
+ }
207
+ });
208
+ return { callArgumentNames, mutatedNames };
209
+ };
210
+ export const collectStaticExpressionDependencies = (program, target, options = {}) => {
211
+ const imports = collectImportBindings(program);
212
+ const locals = collectLocalConstExpressions(program);
213
+ const collectedImports = new Map();
214
+ const referencedNames = new Set();
215
+ const mutableReferencedNames = new Set();
216
+ const visitedLocals = new Set();
217
+ const visitingLocals = new Set();
218
+ const markMutable = (name, expression) => {
219
+ if (expressionMayProduceMutableValue(expression, locals, new Set())) {
220
+ mutableReferencedNames.add(name);
221
+ }
222
+ };
223
+ const collectLocal = (name) => {
224
+ // Pre-resolved locals (e.g. `const x = css\`\``) have a known value
225
+ // (the className string). Skip walking their init — its
226
+ // TaggedTemplateExpression isn't safe-static by itself, but the
227
+ // value is already determined.
228
+ if (options.preResolvedLocals?.has(name)) {
229
+ referencedNames.add(name);
230
+ visitedLocals.add(name);
231
+ return true;
232
+ }
233
+ const expression = locals.get(name);
234
+ if (!expression || visitingLocals.has(name)) {
235
+ return false;
236
+ }
237
+ referencedNames.add(name);
238
+ markMutable(name, expression);
239
+ if (visitedLocals.has(name)) {
240
+ return true;
241
+ }
242
+ visitingLocals.add(name);
243
+ const result = collectExpression(expression);
244
+ visitingLocals.delete(name);
245
+ if (result) {
246
+ visitedLocals.add(name);
247
+ }
248
+ return result;
249
+ };
250
+ const collectExpression = (expr) => {
251
+ if (!isSafeStaticExpression(expr, options)) {
252
+ return false;
253
+ }
254
+ const references = new Set();
255
+ if (!collectStaticExpressionReferences(expr, references, options)) {
256
+ return false;
257
+ }
258
+ for (const reference of references) {
259
+ referencedNames.add(reference);
260
+ const importBinding = imports.get(reference);
261
+ if (importBinding) {
262
+ collectedImports.set(`${importBinding.source}\0${importBinding.imported}\0${importBinding.local}`, importBinding);
263
+ mutableReferencedNames.add(reference);
264
+ continue;
265
+ }
266
+ if (!collectLocal(reference)) {
267
+ // Unknown identifier — neither an import nor a same-file local.
268
+ // Common case: undeclared globals like __DEV__ used in
269
+ // `typeof __DEV__ !== "undefined"` short-circuit guards. The
270
+ // evaluator returns undefined for unknowns, which the outer
271
+ // expression's logical short-circuits handle correctly. Don't
272
+ // reject the whole walk upfront — let the evaluator decide.
273
+ continue;
274
+ }
275
+ }
276
+ return true;
277
+ };
278
+ if (target.localName) {
279
+ referencedNames.add(target.localName);
280
+ markMutable(target.localName, target.expression);
281
+ }
282
+ if (!collectExpression(target.expression)) {
283
+ return null;
284
+ }
285
+ const closureNames = new Set(referencedNames);
286
+ if (target.localName) {
287
+ closureNames.add(target.localName);
288
+ }
289
+ const mutationHints = collectTopLevelMutationHints(program, closureNames);
290
+ for (const name of referencedNames) {
291
+ if (mutationHints.mutatedNames.has(name)) {
292
+ return null;
293
+ }
294
+ }
295
+ for (const name of mutableReferencedNames) {
296
+ if (mutationHints.callArgumentNames.has(name) &&
297
+ !options.ignoredMutableCallArgumentNames?.has(name)) {
298
+ return null;
299
+ }
300
+ }
301
+ return {
302
+ imports: [...collectedImports.values()],
303
+ };
304
+ };
@@ -0,0 +1,99 @@
1
+ import type { Expression, Node, Program } from 'oxc-parser';
2
+ import type { OxcTextReplacement } from '../../../utils/oxc/replacements';
3
+ import type { runOxcPreevalStage } from '../../../utils/oxcPreevalStage';
4
+ import type { ITransformAction, SyncScenarioFor } from '../../types';
5
+ export type AnyNode = Node & Record<string, unknown>;
6
+ export type ImportBinding = {
7
+ imported: '*' | 'default' | string;
8
+ local: string;
9
+ source: string;
10
+ };
11
+ export type CollectImportBindingsOptions = {
12
+ includeNamespace?: boolean;
13
+ };
14
+ export type ExportTarget = {
15
+ expression: Expression;
16
+ kind: 'expression';
17
+ localName?: string;
18
+ } | {
19
+ imported: 'default' | string;
20
+ kind: 'import';
21
+ source: string;
22
+ };
23
+ export type StaticExportResult = {
24
+ callable?: 'zero-arg';
25
+ dependencies: string[];
26
+ runtimeOnly?: boolean;
27
+ sideEffectDependencies?: string[];
28
+ sideEffectImportLocals?: string[];
29
+ value: unknown;
30
+ };
31
+ export type StaticFileAnalysis = {
32
+ code: string;
33
+ codeHash: string;
34
+ program: Program;
35
+ };
36
+ export type StaticFileHashCacheEntry = {
37
+ hash: string;
38
+ mtimeMs: number;
39
+ size: number;
40
+ };
41
+ export type StaticMetadataPreevalCacheEntry = {
42
+ result: null;
43
+ } | {
44
+ result: ReturnType<typeof runOxcPreevalStage>;
45
+ };
46
+ export type StaticExportCacheEntry = {
47
+ attempts: number;
48
+ result: null;
49
+ } | {
50
+ dependencyHashes: Map<string, string>;
51
+ result: StaticExportResult;
52
+ };
53
+ export declare const STATIC_EXPORT_MAX_NULL_ATTEMPTS = 2;
54
+ export declare const GENERATED_HELPER_NAME_RE: RegExp;
55
+ export type StaticExpressionOptions = {
56
+ allowMetadataCalls?: boolean;
57
+ ignoredMutableCallArgumentNames?: Set<string>;
58
+ preResolvedLocals?: ReadonlySet<string>;
59
+ staticHelperLocals?: ReadonlySet<string>;
60
+ };
61
+ export type StaticResolveDebugPhase = 'candidate' | 'entrypoint' | 'export' | 'import' | 'processor-metadata';
62
+ export type StaticResolveDebugStatus = 'rejected' | 'resolved' | 'skipped';
63
+ export type StaticResolveDebugEvent = {
64
+ candidate?: string;
65
+ dependency?: string;
66
+ exported?: string;
67
+ filename: string;
68
+ imported?: string;
69
+ importer?: string;
70
+ phase: StaticResolveDebugPhase;
71
+ reason?: string;
72
+ source?: string;
73
+ status: StaticResolveDebugStatus;
74
+ };
75
+ export type Range = {
76
+ end: number;
77
+ start: number;
78
+ };
79
+ export type Replacement = Range & OxcTextReplacement;
80
+ export type StaticExpressionDependencies = {
81
+ imports: ImportBinding[];
82
+ };
83
+ export type PreparedProcessorTarget = {
84
+ dependencies: StaticExpressionDependencies;
85
+ evaluationCode?: string;
86
+ evaluationSpan?: Range;
87
+ expression: Expression;
88
+ opaqueRuntimeBase: boolean;
89
+ };
90
+ export type OpaqueRuntimeImportProof = {
91
+ dependencies: string[];
92
+ names: Set<string>;
93
+ };
94
+ export type ResolveStaticImportValue = (action: ITransformAction, importer: string, binding: Pick<ImportBinding, 'imported' | 'source'>, stack: Set<string>, memo: Map<string, StaticExportResult | null>) => SyncScenarioFor<StaticExportResult | null>;
95
+ export type ResolveStaticExportValue = (action: ITransformAction, filename: string, exportedName: string, stack: Set<string>, memo: Map<string, StaticExportResult | null>) => SyncScenarioFor<StaticExportResult | null>;
96
+ export type StaticExportResolverContext = {
97
+ resolveImportValue: ResolveStaticImportValue;
98
+ resolveStaticExport: ResolveStaticExportValue;
99
+ };
@@ -0,0 +1,2 @@
1
+ export const STATIC_EXPORT_MAX_NULL_ATTEMPTS = 2;
2
+ export const GENERATED_HELPER_NAME_RE = /^_exp\d*$/;
@@ -0,0 +1,7 @@
1
+ import type { Expression, Program } from 'oxc-parser';
2
+ import type { ITransformAction, SyncScenarioFor } from '../../types';
3
+ import type { ExportTarget, ResolveStaticImportValue, StaticExportResult } from './types';
4
+ export declare const zeroArgFunctionReturnExpression: (expression: Expression) => Expression | null;
5
+ export declare function resolveZeroArgFunctionStaticExport(action: ITransformAction, filename: string, code: string, program: Program, target: Extract<ExportTarget, {
6
+ kind: 'expression';
7
+ }>, stack: Set<string>, memo: Map<string, StaticExportResult | null>, resolveImportValue: ResolveStaticImportValue): SyncScenarioFor<StaticExportResult | null>;
@@ -0,0 +1,64 @@
1
+ /* eslint-disable no-restricted-syntax,no-continue,@typescript-eslint/no-use-before-define */
2
+ import { evaluateOxcStaticExpressionAt, isOxcStaticSerializableValue, } from '../../../utils/collectOxcTemplateDependencies';
3
+ import { getStaticBindings } from './environment';
4
+ import { bindStaticResolvedValue, unwrapExpression } from './staticExpression';
5
+ import { collectStaticExpressionDependencies } from './staticExpressionDependencies';
6
+ export const zeroArgFunctionReturnExpression = (expression) => {
7
+ const unwrapped = unwrapExpression(expression);
8
+ if (unwrapped.type !== 'ArrowFunctionExpression' &&
9
+ unwrapped.type !== 'FunctionExpression') {
10
+ return null;
11
+ }
12
+ if (unwrapped.async || unwrapped.params.length !== 0 || !unwrapped.body) {
13
+ return null;
14
+ }
15
+ if (unwrapped.body.type !== 'BlockStatement') {
16
+ return unwrapped.body;
17
+ }
18
+ if (unwrapped.body.body.length !== 1) {
19
+ return null;
20
+ }
21
+ const [statement] = unwrapped.body.body;
22
+ return statement?.type === 'ReturnStatement' && statement.argument
23
+ ? statement.argument
24
+ : null;
25
+ };
26
+ export function* resolveZeroArgFunctionStaticExport(action, filename, code, program, target, stack, memo, resolveImportValue) {
27
+ const returnExpression = zeroArgFunctionReturnExpression(target.expression);
28
+ if (!returnExpression) {
29
+ return null;
30
+ }
31
+ const staticDependencies = collectStaticExpressionDependencies(program, {
32
+ ...target,
33
+ expression: returnExpression,
34
+ }, { allowMetadataCalls: true });
35
+ if (!staticDependencies) {
36
+ return null;
37
+ }
38
+ const env = new Map();
39
+ const dependencies = new Set([filename]);
40
+ const sideEffectDependencies = new Set();
41
+ for (const binding of staticDependencies.imports) {
42
+ const resolved = yield* resolveImportValue(action, filename, binding, stack, memo);
43
+ if (!resolved) {
44
+ return null;
45
+ }
46
+ if (!bindStaticResolvedValue(env, returnExpression, binding.local, resolved)) {
47
+ return null;
48
+ }
49
+ resolved.dependencies.forEach((item) => dependencies.add(item));
50
+ resolved.sideEffectDependencies?.forEach((item) => sideEffectDependencies.add(item));
51
+ }
52
+ const value = evaluateOxcStaticExpressionAt(code, filename, {
53
+ end: returnExpression.end,
54
+ start: returnExpression.start,
55
+ }, env, getStaticBindings(action));
56
+ return isOxcStaticSerializableValue(value)
57
+ ? {
58
+ callable: 'zero-arg',
59
+ dependencies: [...dependencies],
60
+ sideEffectDependencies: [...sideEffectDependencies],
61
+ value,
62
+ }
63
+ : null;
64
+ }
@@ -1,2 +1 @@
1
- import type { ITransformAction, SyncScenarioFor } from '../types';
2
- export declare function resolveStaticOxcPreevalValues(this: ITransformAction): SyncScenarioFor<boolean>;
1
+ export { resolveStaticOxcPreevalValues } from './resolveStaticOxcValues/resolveStaticOxcPreevalValues';