@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,211 @@
1
+ /* eslint-disable no-restricted-syntax */
2
+ import { isOxcNode } from '../oxc/ast';
3
+ import { processorExpressionToStaticValue, resolveProcessorStaticRuntimeValue, unknownProcessorStaticValue, } from '../processorStaticSemantics';
4
+ import { GENERATED_HELPER_NAME_RE, JS_IDENTIFIER_RE, WYW_META_EXTENDS_HELPER_RE, } from './shared';
5
+ export const oxcLiteralValue = (expression) => {
6
+ const expressionWithValue = expression;
7
+ const expressionType = expression.type;
8
+ if (expressionType === 'StringLiteral' ||
9
+ expressionType === 'NumericLiteral' ||
10
+ expressionType === 'BooleanLiteral' ||
11
+ expressionType === 'Literal') {
12
+ return expressionWithValue.value;
13
+ }
14
+ if (expressionType === 'NullLiteral') {
15
+ return null;
16
+ }
17
+ return unknownProcessorStaticValue;
18
+ };
19
+ export const oxcPropertyKeyName = (key) => {
20
+ if (key.type === 'Identifier') {
21
+ return key.name;
22
+ }
23
+ const value = oxcLiteralValue(key);
24
+ return typeof value === 'string' ? value : null;
25
+ };
26
+ export const collectStaticObjectPropertyNames = (objectExpression) => {
27
+ if (objectExpression.type !== 'ObjectExpression') {
28
+ return null;
29
+ }
30
+ const { properties } = objectExpression;
31
+ if (!properties) {
32
+ return null;
33
+ }
34
+ const names = new Set();
35
+ for (const property of properties) {
36
+ const propertyType = property.type;
37
+ if (propertyType !== 'ObjectProperty' && propertyType !== 'Property') {
38
+ return null;
39
+ }
40
+ if (!property.key || !property.value) {
41
+ return null;
42
+ }
43
+ const name = oxcPropertyKeyName(property.key);
44
+ if (!name || names.has(name)) {
45
+ return null;
46
+ }
47
+ names.add(name);
48
+ }
49
+ return names;
50
+ };
51
+ export const getSameFileProcessorObjectProperty = (ancestors) => {
52
+ let propertyIndex = -1;
53
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
54
+ if (ancestors[idx].type === 'Property') {
55
+ propertyIndex = idx;
56
+ break;
57
+ }
58
+ }
59
+ if (propertyIndex <= 0) {
60
+ return null;
61
+ }
62
+ const property = ancestors[propertyIndex];
63
+ const objectExpression = ancestors[propertyIndex - 1];
64
+ if (!property.key || objectExpression.type !== 'ObjectExpression') {
65
+ return null;
66
+ }
67
+ const propertyName = oxcPropertyKeyName(property.key);
68
+ const propertyNames = collectStaticObjectPropertyNames(objectExpression);
69
+ if (!propertyName || !propertyNames) {
70
+ return null;
71
+ }
72
+ for (let idx = propertyIndex - 2; idx >= 0; idx -= 1) {
73
+ const ancestor = ancestors[idx];
74
+ if (ancestor.type === 'VariableDeclarator') {
75
+ const { id, init } = ancestor;
76
+ if (isOxcNode(id) &&
77
+ id.type === 'Identifier' &&
78
+ init === objectExpression) {
79
+ return {
80
+ localName: id.name,
81
+ propertyName,
82
+ propertyNames,
83
+ };
84
+ }
85
+ }
86
+ }
87
+ return null;
88
+ };
89
+ export const createSameFileProcessorStaticValueResolver = (processorsByLocal, expressionValues) => {
90
+ const expressionSourceByName = new Map();
91
+ expressionValues.forEach((value) => {
92
+ if (value.ex.type === 'Identifier') {
93
+ expressionSourceByName.set(value.ex.name, value.source);
94
+ }
95
+ });
96
+ const memo = new Map();
97
+ const resolving = new Set();
98
+ function resolveLocal(local) {
99
+ if (memo.has(local)) {
100
+ return memo.get(local);
101
+ }
102
+ const processor = processorsByLocal.get(local);
103
+ if (!processor || resolving.has(local)) {
104
+ return unknownProcessorStaticValue;
105
+ }
106
+ resolving.add(local);
107
+ const contractValue = resolveProcessorStaticRuntimeValue(processor);
108
+ const value = contractValue !== unknownProcessorStaticValue
109
+ ? contractValue
110
+ : processorExpressionToStaticValue(processor.value, (helperName) => {
111
+ const source = expressionSourceByName.get(helperName);
112
+ return source ? resolveLocal(source) : unknownProcessorStaticValue;
113
+ });
114
+ resolving.delete(local);
115
+ memo.set(local, value);
116
+ return value;
117
+ }
118
+ function resolveProcessor(processor) {
119
+ const contractValue = resolveProcessorStaticRuntimeValue(processor);
120
+ if (contractValue !== unknownProcessorStaticValue) {
121
+ return contractValue;
122
+ }
123
+ return processorExpressionToStaticValue(processor.value, (helperName) => {
124
+ const source = expressionSourceByName.get(helperName);
125
+ return source ? resolveLocal(source) : unknownProcessorStaticValue;
126
+ });
127
+ }
128
+ return { resolveLocal, resolveProcessor };
129
+ };
130
+ export const collectSameFileProcessorStaticValuesByLocal = (processorsByLocal, expressionValues) => {
131
+ const { resolveLocal } = createSameFileProcessorStaticValueResolver(processorsByLocal, expressionValues);
132
+ const result = new Map();
133
+ processorsByLocal.forEach((_processor, local) => {
134
+ const value = resolveLocal(local);
135
+ if (value !== unknownProcessorStaticValue) {
136
+ result.set(local, value);
137
+ }
138
+ });
139
+ return result;
140
+ };
141
+ export const collectSameFileProcessorObjectStaticValuesByLocal = (processorObjectsByLocal, processorsByLocal, expressionValues) => {
142
+ const { resolveProcessor } = createSameFileProcessorStaticValueResolver(processorsByLocal, expressionValues);
143
+ const result = new Map();
144
+ for (const [local, object] of processorObjectsByLocal) {
145
+ if (object.properties.size === object.propertyNames.size) {
146
+ const value = {};
147
+ let complete = true;
148
+ for (const propertyName of object.propertyNames) {
149
+ const processor = object.properties.get(propertyName);
150
+ if (!processor) {
151
+ complete = false;
152
+ break;
153
+ }
154
+ const propertyValue = resolveProcessor(processor);
155
+ if (propertyValue === unknownProcessorStaticValue) {
156
+ complete = false;
157
+ break;
158
+ }
159
+ value[propertyName] = propertyValue;
160
+ }
161
+ if (complete) {
162
+ result.set(local, value);
163
+ }
164
+ }
165
+ }
166
+ return result;
167
+ };
168
+ export const collectWYWMetaExtendsHelperNames = (code) => {
169
+ const names = new Set();
170
+ let match = WYW_META_EXTENDS_HELPER_RE.exec(code);
171
+ while (match) {
172
+ const name = match[1];
173
+ if (name && GENERATED_HELPER_NAME_RE.test(name)) {
174
+ names.add(name);
175
+ }
176
+ match = WYW_META_EXTENDS_HELPER_RE.exec(code);
177
+ }
178
+ return names;
179
+ };
180
+ export const collectCandidateInlineConstants = (candidate, processorStaticValuesByLocal) => {
181
+ const inlineConstants = {};
182
+ let hasInlineConstant = false;
183
+ let match = JS_IDENTIFIER_RE.exec(candidate.source);
184
+ while (match) {
185
+ const name = match[0];
186
+ if (processorStaticValuesByLocal.has(name)) {
187
+ inlineConstants[name] = processorStaticValuesByLocal.get(name);
188
+ hasInlineConstant = true;
189
+ }
190
+ match = JS_IDENTIFIER_RE.exec(candidate.source);
191
+ }
192
+ return hasInlineConstant ? inlineConstants : null;
193
+ };
194
+ export const addCandidateInlineConstants = (candidates, processorStaticValuesByLocal) => {
195
+ if (processorStaticValuesByLocal.size === 0) {
196
+ return candidates;
197
+ }
198
+ return candidates.map((candidate) => {
199
+ const inlineConstants = collectCandidateInlineConstants(candidate, processorStaticValuesByLocal);
200
+ if (!inlineConstants) {
201
+ return candidate;
202
+ }
203
+ return {
204
+ ...candidate,
205
+ inlineConstants: {
206
+ ...candidate.inlineConstants,
207
+ ...inlineConstants,
208
+ },
209
+ };
210
+ });
211
+ };
@@ -0,0 +1,10 @@
1
+ import type { SourceLocation } from '@wyw-in-js/processor-utils';
2
+ import type { Program } from 'oxc-parser';
3
+ import { type AddedImport } from '../oxcAstService';
4
+ import { type OxcLocationLookup } from '../oxc/sourceLocations';
5
+ export declare const GENERATED_HELPER_NAME_RE: RegExp;
6
+ export declare const WYW_META_EXTENDS_HELPER_RE: RegExp;
7
+ export declare const JS_IDENTIFIER_RE: RegExp;
8
+ export declare const parseOxc: (code: string, filename: string) => Program;
9
+ export declare const insertAddedImports: (code: string, program: Program, addedImports: AddedImport[]) => string;
10
+ export declare const getSourceLocation: (start: number, end: number, loc: OxcLocationLookup, filename?: string | null) => SourceLocation;
@@ -0,0 +1,37 @@
1
+ import { printOxcAstServiceImport } from '../oxcAstService';
2
+ import { parseOxcProgram } from '../oxc/parse';
3
+ import { createOxcSourceLocation, } from '../oxc/sourceLocations';
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 = [
15
+ ...new Map(addedImports.map((item) => [
16
+ `${item.source}\0${item.imported}\0${item.local}`,
17
+ item,
18
+ ])).values(),
19
+ ];
20
+ const importBlock = uniqueImports.map(printOxcAstServiceImport).join('\n');
21
+ const lastImport = [...program.body]
22
+ .reverse()
23
+ .find((statement) => statement.type === 'ImportDeclaration');
24
+ const hashbangEnd = code.startsWith('#!')
25
+ ? (() => {
26
+ const newline = code.indexOf('\n');
27
+ return newline === -1 ? code.length : newline + 1;
28
+ })()
29
+ : 0;
30
+ const insertionPoint = lastImport?.end ?? hashbangEnd;
31
+ const prefix = code.slice(0, insertionPoint);
32
+ const suffix = code.slice(insertionPoint);
33
+ const leadingBreak = prefix.length > 0 && !prefix.endsWith('\n') ? '\n' : '';
34
+ const trailingBreak = suffix.length > 0 && !suffix.startsWith('\n') ? '\n' : '';
35
+ return `${prefix}${leadingBreak}${importBlock}${trailingBreak}${suffix}`;
36
+ };
37
+ export const getSourceLocation = (start, end, loc, filename) => createOxcSourceLocation(start, end, loc, filename);
@@ -0,0 +1,88 @@
1
+ import type { BaseProcessor } from '@wyw-in-js/processor-utils';
2
+ import type { CallExpression, Expression, Node, TaggedTemplateExpression } from 'oxc-parser';
3
+ import type { OxcStaticValue, OxcStaticValueCandidate } from '../collectOxcTemplateDependencies';
4
+ import type { OxcAstService } from '../oxcAstService';
5
+ import type { OxcValueReplacement } from '../oxc/replacements';
6
+ import type { OxcLocationLookup } from '../oxc/sourceLocations';
7
+ import type { ProcessorClass } from '../processorLookup';
8
+ export type DefinedProcessor = [
9
+ ProcessorClass,
10
+ {
11
+ imported: string;
12
+ source: string;
13
+ }
14
+ ];
15
+ export type Replacement = OxcValueReplacement;
16
+ export type ApplyOxcProcessorsResult = {
17
+ code: string;
18
+ processorClassNamesByLocal: Map<string, string>;
19
+ processors: BaseProcessor[];
20
+ staticValueCandidates: OxcStaticValueCandidate[];
21
+ staticValues: OxcStaticValue[];
22
+ };
23
+ export type AnyNode = Node & Record<string, unknown>;
24
+ export type OxcIdentifier = Expression & {
25
+ name: string;
26
+ type: 'Identifier';
27
+ };
28
+ export type ProcessorUsage = {
29
+ ancestors: Node[];
30
+ callee: Expression;
31
+ collapseQualifiedCallee: boolean;
32
+ definedProcessor: DefinedProcessor;
33
+ kind: 'call';
34
+ replacementTarget: Expression;
35
+ target: CallExpression;
36
+ } | {
37
+ ancestors: Node[];
38
+ callee: Expression;
39
+ collapseQualifiedCallee: boolean;
40
+ definedProcessor: DefinedProcessor;
41
+ kind: 'template';
42
+ replacementTarget: Expression;
43
+ target: TaggedTemplateExpression;
44
+ };
45
+ export type ExpressionSpan = {
46
+ end: number;
47
+ start: number;
48
+ };
49
+ export type CreatedProcessor = {
50
+ astService: OxcAstService;
51
+ processor: BaseProcessor;
52
+ };
53
+ export type QualifiedExpression = Expression & {
54
+ expressions?: Expression[];
55
+ };
56
+ export type CallExpressionLike = Expression & {
57
+ arguments: Node[];
58
+ callee: Expression;
59
+ type: 'CallExpression';
60
+ };
61
+ export type SequenceExpressionLike = Expression & {
62
+ expressions: Expression[];
63
+ type: 'SequenceExpression';
64
+ };
65
+ export type LocationLookup = OxcLocationLookup;
66
+ export type TopLevelStatementInfo = {
67
+ bindings: Set<string>;
68
+ node: Node;
69
+ references: Set<string>;
70
+ };
71
+ export type ScopedBindingKind = 'function' | 'import' | 'param' | 'variable';
72
+ export type ScopedBindingInfo = {
73
+ declaration: Node;
74
+ dependencies: Set<string>;
75
+ externalReferences: number;
76
+ id: string;
77
+ incomingFromBindings: Set<string>;
78
+ kind: ScopedBindingKind;
79
+ name: string;
80
+ };
81
+ export type ScopedCleanupScope = {
82
+ bindings: Map<string, string>;
83
+ parent: ScopedCleanupScope | null;
84
+ };
85
+ export type SameFileProcessorObject = {
86
+ properties: Map<string, BaseProcessor>;
87
+ propertyNames: Set<string>;
88
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,16 +1 @@
1
- import { BaseProcessor } from '@wyw-in-js/processor-utils';
2
- import type { IFileContext } from '@wyw-in-js/processor-utils';
3
- import type { StrictOptions } from '@wyw-in-js/shared';
4
- import { EventEmitter } from './EventEmitter';
5
- import { type OxcStaticValue, type OxcStaticValueCandidate } from './collectOxcTemplateDependencies';
6
- type ApplyOxcProcessorsResult = {
7
- code: string;
8
- processors: BaseProcessor[];
9
- staticValueCandidates: OxcStaticValueCandidate[];
10
- staticValues: OxcStaticValue[];
11
- };
12
- export declare const applyOxcProcessors: (code: string, fileContext: IFileContext, options: Pick<StrictOptions, "classNameSlug" | "displayName" | "extensions" | "evaluate" | "tagResolver"> & {
13
- eventEmitter?: EventEmitter;
14
- preserveSideEffectImportLocals?: Set<string>;
15
- }, callback: (processor: BaseProcessor) => void, cleanupUnused?: boolean) => ApplyOxcProcessorsResult;
16
- export {};
1
+ export { applyOxcProcessors } from './applyOxcProcessors/applyOxcProcessors';