@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,207 @@
1
+ import { isOxcNode } from "../oxc/ast.js";
2
+ import { processorExpressionToStaticValue, resolveProcessorStaticRuntimeValue, unknownProcessorStaticValue } from "../processorStaticSemantics.js";
3
+ import { GENERATED_HELPER_NAME_RE, JS_IDENTIFIER_RE, WYW_META_EXTENDS_HELPER_RE } from "./shared.js";
4
+ export const oxcLiteralValue = (expression) => {
5
+ const expressionWithValue = expression;
6
+ const expressionType = expression.type;
7
+ if (expressionType === "StringLiteral" || expressionType === "NumericLiteral" || expressionType === "BooleanLiteral" || expressionType === "Literal") {
8
+ return expressionWithValue.value;
9
+ }
10
+ if (expressionType === "NullLiteral") {
11
+ return null;
12
+ }
13
+ return unknownProcessorStaticValue;
14
+ };
15
+ export const oxcPropertyKeyName = (key) => {
16
+ if (key.type === "Identifier") {
17
+ return key.name;
18
+ }
19
+ const value = oxcLiteralValue(key);
20
+ return typeof value === "string" ? value : null;
21
+ };
22
+ export const collectStaticObjectPropertyNames = (objectExpression) => {
23
+ if (objectExpression.type !== "ObjectExpression") {
24
+ return null;
25
+ }
26
+ const { properties } = objectExpression;
27
+ if (!properties) {
28
+ return null;
29
+ }
30
+ const names = new Set();
31
+ for (const property of properties) {
32
+ const propertyType = property.type;
33
+ if (propertyType !== "ObjectProperty" && propertyType !== "Property") {
34
+ return null;
35
+ }
36
+ if (!property.key || !property.value) {
37
+ return null;
38
+ }
39
+ const name = oxcPropertyKeyName(property.key);
40
+ if (!name || names.has(name)) {
41
+ return null;
42
+ }
43
+ names.add(name);
44
+ }
45
+ return names;
46
+ };
47
+ export const getSameFileProcessorObjectProperty = (ancestors) => {
48
+ let propertyIndex = -1;
49
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
50
+ if (ancestors[idx].type === "Property") {
51
+ propertyIndex = idx;
52
+ break;
53
+ }
54
+ }
55
+ if (propertyIndex <= 0) {
56
+ return null;
57
+ }
58
+ const property = ancestors[propertyIndex];
59
+ const objectExpression = ancestors[propertyIndex - 1];
60
+ if (!property.key || objectExpression.type !== "ObjectExpression") {
61
+ return null;
62
+ }
63
+ const propertyName = oxcPropertyKeyName(property.key);
64
+ const propertyNames = collectStaticObjectPropertyNames(objectExpression);
65
+ if (!propertyName || !propertyNames) {
66
+ return null;
67
+ }
68
+ for (let idx = propertyIndex - 2; idx >= 0; idx -= 1) {
69
+ const ancestor = ancestors[idx];
70
+ if (ancestor.type === "VariableDeclarator") {
71
+ const { id, init } = ancestor;
72
+ if (isOxcNode(id) && id.type === "Identifier" && init === objectExpression) {
73
+ return {
74
+ localName: id.name,
75
+ propertyName,
76
+ propertyNames
77
+ };
78
+ }
79
+ }
80
+ }
81
+ return null;
82
+ };
83
+ export const createSameFileProcessorStaticValueResolver = (processorsByLocal, expressionValues) => {
84
+ const expressionSourceByName = new Map();
85
+ expressionValues.forEach((value) => {
86
+ if (value.ex.type === "Identifier") {
87
+ expressionSourceByName.set(value.ex.name, value.source);
88
+ }
89
+ });
90
+ const memo = new Map();
91
+ const resolving = new Set();
92
+ function resolveLocal(local) {
93
+ if (memo.has(local)) {
94
+ return memo.get(local);
95
+ }
96
+ const processor = processorsByLocal.get(local);
97
+ if (!processor || resolving.has(local)) {
98
+ return unknownProcessorStaticValue;
99
+ }
100
+ resolving.add(local);
101
+ const contractValue = resolveProcessorStaticRuntimeValue(processor);
102
+ const value = contractValue !== unknownProcessorStaticValue ? contractValue : processorExpressionToStaticValue(processor.value, (helperName) => {
103
+ const source = expressionSourceByName.get(helperName);
104
+ return source ? resolveLocal(source) : unknownProcessorStaticValue;
105
+ });
106
+ resolving.delete(local);
107
+ memo.set(local, value);
108
+ return value;
109
+ }
110
+ function resolveProcessor(processor) {
111
+ const contractValue = resolveProcessorStaticRuntimeValue(processor);
112
+ if (contractValue !== unknownProcessorStaticValue) {
113
+ return contractValue;
114
+ }
115
+ return processorExpressionToStaticValue(processor.value, (helperName) => {
116
+ const source = expressionSourceByName.get(helperName);
117
+ return source ? resolveLocal(source) : unknownProcessorStaticValue;
118
+ });
119
+ }
120
+ return {
121
+ resolveLocal,
122
+ resolveProcessor
123
+ };
124
+ };
125
+ export const collectSameFileProcessorStaticValuesByLocal = (processorsByLocal, expressionValues) => {
126
+ const { resolveLocal } = createSameFileProcessorStaticValueResolver(processorsByLocal, expressionValues);
127
+ const result = new Map();
128
+ processorsByLocal.forEach((_processor, local) => {
129
+ const value = resolveLocal(local);
130
+ if (value !== unknownProcessorStaticValue) {
131
+ result.set(local, value);
132
+ }
133
+ });
134
+ return result;
135
+ };
136
+ export const collectSameFileProcessorObjectStaticValuesByLocal = (processorObjectsByLocal, processorsByLocal, expressionValues) => {
137
+ const { resolveProcessor } = createSameFileProcessorStaticValueResolver(processorsByLocal, expressionValues);
138
+ const result = new Map();
139
+ for (const [local, object] of processorObjectsByLocal) {
140
+ if (object.properties.size === object.propertyNames.size) {
141
+ const value = {};
142
+ let complete = true;
143
+ for (const propertyName of object.propertyNames) {
144
+ const processor = object.properties.get(propertyName);
145
+ if (!processor) {
146
+ complete = false;
147
+ break;
148
+ }
149
+ const propertyValue = resolveProcessor(processor);
150
+ if (propertyValue === unknownProcessorStaticValue) {
151
+ complete = false;
152
+ break;
153
+ }
154
+ value[propertyName] = propertyValue;
155
+ }
156
+ if (complete) {
157
+ result.set(local, value);
158
+ }
159
+ }
160
+ }
161
+ return result;
162
+ };
163
+ export const collectWYWMetaExtendsHelperNames = (code) => {
164
+ const names = new Set();
165
+ let match = WYW_META_EXTENDS_HELPER_RE.exec(code);
166
+ while (match) {
167
+ const name = match[1];
168
+ if (name && GENERATED_HELPER_NAME_RE.test(name)) {
169
+ names.add(name);
170
+ }
171
+ match = WYW_META_EXTENDS_HELPER_RE.exec(code);
172
+ }
173
+ return names;
174
+ };
175
+ export const collectCandidateInlineConstants = (candidate, processorStaticValuesByLocal) => {
176
+ const inlineConstants = {};
177
+ let hasInlineConstant = false;
178
+ let match = JS_IDENTIFIER_RE.exec(candidate.source);
179
+ while (match) {
180
+ const name = match[0];
181
+ if (processorStaticValuesByLocal.has(name)) {
182
+ inlineConstants[name] = processorStaticValuesByLocal.get(name);
183
+ hasInlineConstant = true;
184
+ }
185
+ match = JS_IDENTIFIER_RE.exec(candidate.source);
186
+ }
187
+ return hasInlineConstant ? inlineConstants : null;
188
+ };
189
+ export const addCandidateInlineConstants = (candidates, processorStaticValuesByLocal) => {
190
+ if (processorStaticValuesByLocal.size === 0) {
191
+ return candidates;
192
+ }
193
+ return candidates.map((candidate) => {
194
+ const inlineConstants = collectCandidateInlineConstants(candidate, processorStaticValuesByLocal);
195
+ if (!inlineConstants) {
196
+ return candidate;
197
+ }
198
+ return {
199
+ ...candidate,
200
+ inlineConstants: {
201
+ ...candidate.inlineConstants,
202
+ ...inlineConstants
203
+ }
204
+ };
205
+ });
206
+ };
207
+ //# sourceMappingURL=sameFileStaticValues.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAOA,SAAS,iBAAiB;AAC1B,SACE,kCACA,oCAEA,mCACK;AACP,SACE,0BACA,kBACA,kCACK;AAGP,OAAO,MAAM,mBACX,eAC0C;CAC1C,MAAM,sBAAsB;CAG5B,MAAM,iBAAiB,WAAW;AAElC,KACE,mBAAmB,mBACnB,mBAAmB,oBACnB,mBAAmB,oBACnB,mBAAmB,WACnB;AACA,SAAO,oBAAoB;;AAG7B,KAAI,mBAAmB,eAAe;AACpC,SAAO;;AAGT,QAAO;;AAGT,OAAO,MAAM,sBAAsB,QAA6B;AAC9D,KAAI,IAAI,SAAS,cAAc;AAC7B,SAAQ,IAAgC;;CAG1C,MAAM,QAAQ,gBAAgB,IAAI;AAClC,QAAO,OAAO,UAAU,WAAW,QAAQ;;AAG7C,OAAO,MAAM,oCACX,qBACuB;AACvB,KAAI,iBAAiB,SAAS,oBAAoB;AAChD,SAAO;;CAGT,MAAM,EAAE,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ED,MAAI,CAAC,iBAAiB;AACpB,UAAO;;AAGT,SAAO;GACL,GAAG;GACH,iBAAiB;IACf,GAAG,UAAU;IACb,GAAG;IACJ;GACF;GACD","names":[],"sources":["../../../src/utils/applyOxcProcessors/sameFileStaticValues.ts"],"version":3,"sourcesContent":["/* eslint-disable no-restricted-syntax */\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type { ExpressionValue } from '@wyw-in-js/shared';\nimport type { Node } from 'oxc-parser';\n\nimport type { OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';\nimport { isOxcNode } from '../oxc/ast';\nimport {\n processorExpressionToStaticValue,\n resolveProcessorStaticRuntimeValue,\n type UnknownProcessorStaticValue,\n unknownProcessorStaticValue,\n} from '../processorStaticSemantics';\nimport {\n GENERATED_HELPER_NAME_RE,\n JS_IDENTIFIER_RE,\n WYW_META_EXTENDS_HELPER_RE,\n} from './shared';\nimport type { AnyNode, SameFileProcessorObject } from './types';\n\nexport const oxcLiteralValue = (\n expression: Node\n): unknown | UnknownProcessorStaticValue => {\n const expressionWithValue = expression as Node & {\n value?: unknown;\n };\n const expressionType = expression.type as string;\n\n if (\n expressionType === 'StringLiteral' ||\n expressionType === 'NumericLiteral' ||\n expressionType === 'BooleanLiteral' ||\n expressionType === 'Literal'\n ) {\n return expressionWithValue.value;\n }\n\n if (expressionType === 'NullLiteral') {\n return null;\n }\n\n return unknownProcessorStaticValue;\n};\n\nexport const oxcPropertyKeyName = (key: Node): string | null => {\n if (key.type === 'Identifier') {\n return (key as Node & { name: string }).name;\n }\n\n const value = oxcLiteralValue(key);\n return typeof value === 'string' ? value : null;\n};\n\nexport const collectStaticObjectPropertyNames = (\n objectExpression: Node\n): Set<string> | null => {\n if (objectExpression.type !== 'ObjectExpression') {\n return null;\n }\n\n const { properties } = objectExpression as Node & {\n properties?: Array<\n Node & {\n computed?: boolean;\n key?: Node;\n type: string;\n value?: Node;\n }\n >;\n };\n if (!properties) {\n return null;\n }\n\n const names = new Set<string>();\n for (const property of properties) {\n const propertyType = property.type as string;\n if (propertyType !== 'ObjectProperty' && propertyType !== 'Property') {\n return null;\n }\n\n if (!property.key || !property.value) {\n return null;\n }\n\n const name = oxcPropertyKeyName(property.key);\n if (!name || names.has(name)) {\n return null;\n }\n\n names.add(name);\n }\n\n return names;\n};\n\nexport const getSameFileProcessorObjectProperty = (\n ancestors: Node[]\n): {\n localName: string;\n propertyName: string;\n propertyNames: Set<string>;\n} | null => {\n let propertyIndex = -1;\n for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {\n if (ancestors[idx].type === 'Property') {\n propertyIndex = idx;\n break;\n }\n }\n\n if (propertyIndex <= 0) {\n return null;\n }\n\n const property = ancestors[propertyIndex] as Node & {\n key?: Node;\n };\n const objectExpression = ancestors[propertyIndex - 1];\n if (!property.key || objectExpression.type !== 'ObjectExpression') {\n return null;\n }\n\n const propertyName = oxcPropertyKeyName(property.key);\n const propertyNames = collectStaticObjectPropertyNames(objectExpression);\n if (!propertyName || !propertyNames) {\n return null;\n }\n\n for (let idx = propertyIndex - 2; idx >= 0; idx -= 1) {\n const ancestor = ancestors[idx] as AnyNode;\n if (ancestor.type === 'VariableDeclarator') {\n const { id, init } = ancestor;\n if (\n isOxcNode(id) &&\n id.type === 'Identifier' &&\n init === objectExpression\n ) {\n return {\n localName: id.name,\n propertyName,\n propertyNames,\n };\n }\n }\n }\n\n return null;\n};\n\nexport const createSameFileProcessorStaticValueResolver = (\n processorsByLocal: Map<string, BaseProcessor>,\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[]\n): {\n resolveLocal: (local: string) => unknown | UnknownProcessorStaticValue;\n resolveProcessor: (\n processor: BaseProcessor\n ) => unknown | UnknownProcessorStaticValue;\n} => {\n const expressionSourceByName = new Map<string, string>();\n expressionValues.forEach((value) => {\n if (value.ex.type === 'Identifier') {\n expressionSourceByName.set(value.ex.name, value.source);\n }\n });\n\n const memo = new Map<string, unknown | UnknownProcessorStaticValue>();\n const resolving = new Set<string>();\n\n function resolveLocal(local: string): unknown | UnknownProcessorStaticValue {\n if (memo.has(local)) {\n return memo.get(local)!;\n }\n\n const processor = processorsByLocal.get(local);\n if (!processor || resolving.has(local)) {\n return unknownProcessorStaticValue;\n }\n\n resolving.add(local);\n const contractValue = resolveProcessorStaticRuntimeValue(processor);\n const value =\n contractValue !== unknownProcessorStaticValue\n ? contractValue\n : processorExpressionToStaticValue(processor.value, (helperName) => {\n const source = expressionSourceByName.get(helperName);\n return source ? resolveLocal(source) : unknownProcessorStaticValue;\n });\n resolving.delete(local);\n memo.set(local, value);\n return value;\n }\n\n function resolveProcessor(\n processor: BaseProcessor\n ): unknown | UnknownProcessorStaticValue {\n const contractValue = resolveProcessorStaticRuntimeValue(processor);\n if (contractValue !== unknownProcessorStaticValue) {\n return contractValue;\n }\n\n return processorExpressionToStaticValue(processor.value, (helperName) => {\n const source = expressionSourceByName.get(helperName);\n return source ? resolveLocal(source) : unknownProcessorStaticValue;\n });\n }\n\n return { resolveLocal, resolveProcessor };\n};\n\nexport const collectSameFileProcessorStaticValuesByLocal = (\n processorsByLocal: Map<string, BaseProcessor>,\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[]\n): Map<string, unknown> => {\n const { resolveLocal } = createSameFileProcessorStaticValueResolver(\n processorsByLocal,\n expressionValues\n );\n\n const result = new Map<string, unknown>();\n processorsByLocal.forEach((_processor, local) => {\n const value = resolveLocal(local);\n if (value !== unknownProcessorStaticValue) {\n result.set(local, value);\n }\n });\n\n return result;\n};\n\nexport const collectSameFileProcessorObjectStaticValuesByLocal = (\n processorObjectsByLocal: Map<string, SameFileProcessorObject>,\n processorsByLocal: Map<string, BaseProcessor>,\n expressionValues: Omit<ExpressionValue, 'buildCodeFrameError'>[]\n): Map<string, unknown> => {\n const { resolveProcessor } = createSameFileProcessorStaticValueResolver(\n processorsByLocal,\n expressionValues\n );\n\n const result = new Map<string, unknown>();\n for (const [local, object] of processorObjectsByLocal) {\n if (object.properties.size === object.propertyNames.size) {\n const value: Record<string, unknown> = {};\n let complete = true;\n for (const propertyName of object.propertyNames) {\n const processor = object.properties.get(propertyName);\n if (!processor) {\n complete = false;\n break;\n }\n\n const propertyValue = resolveProcessor(processor);\n if (propertyValue === unknownProcessorStaticValue) {\n complete = false;\n break;\n }\n\n value[propertyName] = propertyValue;\n }\n\n if (complete) {\n result.set(local, value);\n }\n }\n }\n\n return result;\n};\n\nexport const collectWYWMetaExtendsHelperNames = (code: string): Set<string> => {\n const names = new Set<string>();\n\n let match = WYW_META_EXTENDS_HELPER_RE.exec(code);\n while (match) {\n const name = match[1];\n if (name && GENERATED_HELPER_NAME_RE.test(name)) {\n names.add(name);\n }\n match = WYW_META_EXTENDS_HELPER_RE.exec(code);\n }\n return names;\n};\n\nexport const collectCandidateInlineConstants = (\n candidate: OxcStaticValueCandidate,\n processorStaticValuesByLocal: Map<string, unknown>\n): Record<string, unknown> | null => {\n const inlineConstants: Record<string, unknown> = {};\n let hasInlineConstant = false;\n\n let match = JS_IDENTIFIER_RE.exec(candidate.source);\n while (match) {\n const name = match[0];\n if (processorStaticValuesByLocal.has(name)) {\n inlineConstants[name] = processorStaticValuesByLocal.get(name);\n hasInlineConstant = true;\n }\n match = JS_IDENTIFIER_RE.exec(candidate.source);\n }\n\n return hasInlineConstant ? inlineConstants : null;\n};\n\nexport const addCandidateInlineConstants = (\n candidates: OxcStaticValueCandidate[],\n processorStaticValuesByLocal: Map<string, unknown>\n): OxcStaticValueCandidate[] => {\n if (processorStaticValuesByLocal.size === 0) {\n return candidates;\n }\n\n return candidates.map((candidate) => {\n const inlineConstants = collectCandidateInlineConstants(\n candidate,\n processorStaticValuesByLocal\n );\n\n if (!inlineConstants) {\n return candidate;\n }\n\n return {\n ...candidate,\n inlineConstants: {\n ...candidate.inlineConstants,\n ...inlineConstants,\n },\n };\n });\n};\n"],"file":"sameFileStaticValues.js"}
@@ -0,0 +1,29 @@
1
+ import { printOxcAstServiceImport } from "../oxcAstService.js";
2
+ import { parseOxcProgram } from "../oxc/parse.js";
3
+ import { createOxcSourceLocation } from "../oxc/sourceLocations.js";
4
+ export const GENERATED_HELPER_NAME_RE = /^_exp\d*$/;
5
+ export const WYW_META_EXTENDS_HELPER_RE = /(?:\bextends|["']extends["'])\s*:\s*(_exp\d*)\s*\(\s*\)/g;
6
+ export const JS_IDENTIFIER_RE = /[$A-Z_a-z][$\w]*/g;
7
+ export const parseOxc = (code, filename) => {
8
+ return parseOxcProgram(code, filename, "module");
9
+ };
10
+ export const insertAddedImports = (code, program, addedImports) => {
11
+ if (addedImports.length === 0) {
12
+ return code;
13
+ }
14
+ const uniqueImports = [...new Map(addedImports.map((item) => [`${item.source}\0${item.imported}\0${item.local}`, item])).values()];
15
+ const importBlock = uniqueImports.map(printOxcAstServiceImport).join("\n");
16
+ const lastImport = [...program.body].reverse().find((statement) => statement.type === "ImportDeclaration");
17
+ const hashbangEnd = code.startsWith("#!") ? (() => {
18
+ const newline = code.indexOf("\n");
19
+ return newline === -1 ? code.length : newline + 1;
20
+ })() : 0;
21
+ const insertionPoint = lastImport?.end ?? hashbangEnd;
22
+ const prefix = code.slice(0, insertionPoint);
23
+ const suffix = code.slice(insertionPoint);
24
+ const leadingBreak = prefix.length > 0 && !prefix.endsWith("\n") ? "\n" : "";
25
+ const trailingBreak = suffix.length > 0 && !suffix.startsWith("\n") ? "\n" : "";
26
+ return `${prefix}${leadingBreak}${importBlock}${trailingBreak}${suffix}`;
27
+ };
28
+ export const getSourceLocation = (start, end, loc, filename) => createOxcSourceLocation(start, end, loc, filename);
29
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAGA,SAAS,gCAAkD;AAC3D,SAAS,uBAAuB;AAChC,SACE,+BAEK;AAEP,OAAO,MAAM,2BAA2B;AACxC,OAAO,MAAM,6BACX;AACF,OAAO,MAAM,mBAAmB;AAEhC,OAAO,MAAM,YAAY,MAAc,aAA8B;AACnE,QAAO,gBAAgB,MAAM,UAAU,SAAS;;AAGlD,OAAO,MAAM,sBACX,MACA,SACA,iBACW;AACX,KAAI,aAAa,WAAW,GAAG;AAC7B,SAAO;;CAGT,MAAM,gBAAgB,CACpB,GAAG,IAAI,IACL,aAAa,KAAK,SAAS,CACzB,GAAG,KAAK,OAAO,IAAI,KAAK,SAAS,IAAI,KAAK,SAC1C,KACD,CAAC,CACH,CAAC,QAAQ,CACX;CACD,MAAM,cAAc,cAAc,IAAI,yBAAyB,CAAC,KAAK,KAAK;CAC1E,MAAM,aAAa,CAAC,GAAG,QAAQ,KAAK,CACjC,SAAS,CACT,MAAM,cAAc,UAAU,SAAS,oBAAoB;CAC9D,MAAM,cAAc,KAAK,WAAW,KAAK,UAC9B;EACL,MAAM,UAAU,KAAK,QAAQ,KAAK;AAClC,SAAO,YAAY,CAAC,IAAI,KAAK,SAAS,UAAU;KAC9C,GACJ;CACJ,MAAM,iBAAiB,YAAY,OAAO;CAC1C,MAAM,SAAS,KAAK,MAAM,GAAG,eAAe;CAC5C,MAAM,SAAS,KAAK,MAAM,eAAe;CACzC,MAAM,eAAe,OAAO,SAAS,KAAK,CAAC,OAAO,SAAS,KAAK,GAAG,OAAO;CAC1E,MAAM,gBACJ,OAAO,SAAS,KAAK,CAAC,OAAO,WAAW,KAAK,GAAG,OAAO;AAEzD,QAAO,GAAG,SAAS,eAAe,cAAc,gBAAgB;;AAGlE,OAAO,MAAM,qBACX,OACA,KACA,KACA,aACmB,wBAAwB,OAAO,KAAK,KAAK,SAAS","names":[],"sources":["../../../src/utils/applyOxcProcessors/shared.ts"],"version":3,"sourcesContent":["import type { SourceLocation } from '@wyw-in-js/processor-utils';\nimport type { Program } from 'oxc-parser';\n\nimport { printOxcAstServiceImport, type AddedImport } from '../oxcAstService';\nimport { parseOxcProgram } from '../oxc/parse';\nimport {\n createOxcSourceLocation,\n type OxcLocationLookup,\n} from '../oxc/sourceLocations';\n\nexport const GENERATED_HELPER_NAME_RE = /^_exp\\d*$/;\nexport const WYW_META_EXTENDS_HELPER_RE =\n /(?:\\bextends|[\"']extends[\"'])\\s*:\\s*(_exp\\d*)\\s*\\(\\s*\\)/g;\nexport const JS_IDENTIFIER_RE = /[$A-Z_a-z][$\\w]*/g;\n\nexport const parseOxc = (code: string, filename: string): Program => {\n return parseOxcProgram(code, filename, 'module');\n};\n\nexport const insertAddedImports = (\n code: string,\n program: Program,\n addedImports: AddedImport[]\n): string => {\n if (addedImports.length === 0) {\n return code;\n }\n\n const uniqueImports = [\n ...new Map(\n addedImports.map((item) => [\n `${item.source}\\0${item.imported}\\0${item.local}`,\n item,\n ])\n ).values(),\n ];\n const importBlock = uniqueImports.map(printOxcAstServiceImport).join('\\n');\n const lastImport = [...program.body]\n .reverse()\n .find((statement) => statement.type === 'ImportDeclaration');\n const hashbangEnd = code.startsWith('#!')\n ? (() => {\n const newline = code.indexOf('\\n');\n return newline === -1 ? code.length : newline + 1;\n })()\n : 0;\n const insertionPoint = lastImport?.end ?? hashbangEnd;\n const prefix = code.slice(0, insertionPoint);\n const suffix = code.slice(insertionPoint);\n const leadingBreak = prefix.length > 0 && !prefix.endsWith('\\n') ? '\\n' : '';\n const trailingBreak =\n suffix.length > 0 && !suffix.startsWith('\\n') ? '\\n' : '';\n\n return `${prefix}${leadingBreak}${importBlock}${trailingBreak}${suffix}`;\n};\n\nexport const getSourceLocation = (\n start: number,\n end: number,\n loc: OxcLocationLookup,\n filename?: string | null\n): SourceLocation => createOxcSourceLocation(start, end, loc, filename);\n"],"file":"shared.js"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"","names":[],"sources":["../../../src/utils/applyOxcProcessors/types.ts"],"version":3,"sourcesContent":["import type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n CallExpression,\n Expression,\n Node,\n TaggedTemplateExpression,\n} from 'oxc-parser';\n\nimport type {\n OxcStaticValue,\n OxcStaticValueCandidate,\n} from '../collectOxcTemplateDependencies';\nimport type { OxcAstService } from '../oxcAstService';\nimport type { OxcValueReplacement } from '../oxc/replacements';\nimport type { OxcLocationLookup } from '../oxc/sourceLocations';\nimport type { ProcessorClass } from '../processorLookup';\n\nexport type DefinedProcessor = [\n ProcessorClass,\n { imported: string; source: string },\n];\n\nexport type Replacement = OxcValueReplacement;\n\nexport type ApplyOxcProcessorsResult = {\n code: string;\n // Selector-only processor class names (css`...`-style). Safe to use as\n // a class-name fallback in cross-file static-export resolution because\n // the runtime value of the binding IS this string.\n processorClassNamesByLocal: Map<string, string>;\n processors: BaseProcessor[];\n staticValueCandidates: OxcStaticValueCandidate[];\n staticValues: OxcStaticValue[];\n};\n\nexport type AnyNode = Node & Record<string, unknown>;\n\nexport type OxcIdentifier = Expression & {\n name: string;\n type: 'Identifier';\n};\n\nexport type ProcessorUsage =\n | {\n ancestors: Node[];\n callee: Expression;\n collapseQualifiedCallee: boolean;\n definedProcessor: DefinedProcessor;\n kind: 'call';\n replacementTarget: Expression;\n target: CallExpression;\n }\n | {\n ancestors: Node[];\n callee: Expression;\n collapseQualifiedCallee: boolean;\n definedProcessor: DefinedProcessor;\n kind: 'template';\n replacementTarget: Expression;\n target: TaggedTemplateExpression;\n };\n\nexport type ExpressionSpan = {\n end: number;\n start: number;\n};\n\nexport type CreatedProcessor = {\n astService: OxcAstService;\n processor: BaseProcessor;\n};\n\nexport type QualifiedExpression = Expression & {\n expressions?: Expression[];\n};\n\nexport type CallExpressionLike = Expression & {\n arguments: Node[];\n callee: Expression;\n type: 'CallExpression';\n};\n\nexport type SequenceExpressionLike = Expression & {\n expressions: Expression[];\n type: 'SequenceExpression';\n};\n\nexport type LocationLookup = OxcLocationLookup;\n\nexport type TopLevelStatementInfo = {\n bindings: Set<string>;\n node: Node;\n references: Set<string>;\n};\n\nexport type ScopedBindingKind = 'function' | 'import' | 'param' | 'variable';\n\nexport type ScopedBindingInfo = {\n declaration: Node;\n dependencies: Set<string>;\n externalReferences: number;\n id: string;\n incomingFromBindings: Set<string>;\n kind: ScopedBindingKind;\n name: string;\n};\n\nexport type ScopedCleanupScope = {\n bindings: Map<string, string>;\n parent: ScopedCleanupScope | null;\n};\n\nexport type SameFileProcessorObject = {\n properties: Map<string, BaseProcessor>;\n propertyNames: Set<string>;\n};\n"],"file":"types.js"}