@wyw-in-js/transform 1.1.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 (801) hide show
  1. package/esm/cache.js +433 -289
  2. package/esm/cache.js.map +1 -1
  3. package/esm/debug/fileReporter.js +171 -134
  4. package/esm/debug/fileReporter.js.map +1 -1
  5. package/esm/eval/broker.js +2275 -0
  6. package/esm/eval/broker.js.map +1 -0
  7. package/esm/eval/lru.js +36 -0
  8. package/esm/eval/lru.js.map +1 -0
  9. package/esm/eval/prepareModuleOnDemand.js +21 -0
  10. package/esm/eval/prepareModuleOnDemand.js.map +1 -0
  11. package/esm/eval/protocol.js +2 -0
  12. package/esm/eval/protocol.js.map +1 -0
  13. package/esm/eval/runner.js +1878 -0
  14. package/esm/eval/runner.js.map +1 -0
  15. package/esm/eval/serialize.js +333 -0
  16. package/esm/eval/serialize.js.map +1 -0
  17. package/esm/eval/writeQueue.js +81 -0
  18. package/esm/eval/writeQueue.js.map +1 -0
  19. package/esm/evaluators/index.js +11 -12
  20. package/esm/evaluators/index.js.map +1 -1
  21. package/esm/index.js +25 -29
  22. package/esm/index.js.map +1 -1
  23. package/esm/module.js +923 -520
  24. package/esm/module.js.map +1 -1
  25. package/esm/shaker.js +14 -80
  26. package/esm/shaker.js.map +1 -1
  27. package/esm/transform/BaseEntrypoint.js +162 -164
  28. package/esm/transform/BaseEntrypoint.js.map +1 -1
  29. package/esm/transform/Entrypoint.helpers.js +96 -253
  30. package/esm/transform/Entrypoint.helpers.js.map +1 -1
  31. package/esm/transform/Entrypoint.js +336 -270
  32. package/esm/transform/Entrypoint.js.map +1 -1
  33. package/esm/transform/Entrypoint.types.js +1 -1
  34. package/esm/transform/Entrypoint.types.js.map +1 -1
  35. package/esm/transform/EvaluatedEntrypoint.js +10 -4
  36. package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
  37. package/esm/transform/actions/AbortError.js +6 -6
  38. package/esm/transform/actions/AbortError.js.map +1 -1
  39. package/esm/transform/actions/BaseAction.js +140 -136
  40. package/esm/transform/actions/BaseAction.js.map +1 -1
  41. package/esm/transform/actions/UnprocessedEntrypointError.js +6 -6
  42. package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
  43. package/esm/transform/actions/actionRunner.js +63 -66
  44. package/esm/transform/actions/actionRunner.js.map +1 -1
  45. package/esm/transform/actions/types.js +1 -1
  46. package/esm/transform/actions/types.js.map +1 -1
  47. package/esm/transform/barrelManifest.types.js +2 -0
  48. package/esm/transform/barrelManifest.types.js.map +1 -0
  49. package/esm/transform/generators/baseProcessingHandlers.js +15 -17
  50. package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
  51. package/esm/transform/generators/collect.js +27 -55
  52. package/esm/transform/generators/collect.js.map +1 -1
  53. package/esm/transform/generators/createStylisPreprocessor.js +353 -321
  54. package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
  55. package/esm/transform/generators/evalFile.js +48 -47
  56. package/esm/transform/generators/evalFile.js.map +1 -1
  57. package/esm/transform/generators/extract.js +78 -90
  58. package/esm/transform/generators/extract.js.map +1 -1
  59. package/esm/transform/generators/getExports.js +57 -74
  60. package/esm/transform/generators/getExports.js.map +1 -1
  61. package/esm/transform/generators/index.js +11 -11
  62. package/esm/transform/generators/index.js.map +1 -1
  63. package/esm/transform/generators/processEntrypoint.js +93 -67
  64. package/esm/transform/generators/processEntrypoint.js.map +1 -1
  65. package/esm/transform/generators/processImports.js +102 -67
  66. package/esm/transform/generators/processImports.js.map +1 -1
  67. package/esm/transform/generators/resolveImports.js +212 -197
  68. package/esm/transform/generators/resolveImports.js.map +1 -1
  69. package/esm/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  70. package/esm/transform/generators/resolveStaticOxcValues/cache.js.map +1 -0
  71. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js +146 -0
  72. package/esm/transform/generators/resolveStaticOxcValues/candidateResolver.js.map +1 -0
  73. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js +33 -0
  74. package/esm/transform/generators/resolveStaticOxcValues/dependencies.js.map +1 -0
  75. package/esm/transform/generators/resolveStaticOxcValues/environment.js +29 -0
  76. package/esm/transform/generators/resolveStaticOxcValues/environment.js.map +1 -0
  77. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js +351 -0
  78. package/esm/transform/generators/resolveStaticOxcValues/exportResolver.js.map +1 -0
  79. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js +253 -0
  80. package/esm/transform/generators/resolveStaticOxcValues/exportTargets.js.map +1 -0
  81. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js +310 -0
  82. package/esm/transform/generators/resolveStaticOxcValues/objectAssign.js.map +1 -0
  83. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +74 -0
  84. package/esm/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js.map +1 -0
  85. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +229 -0
  86. package/esm/transform/generators/resolveStaticOxcValues/opaqueRuntime.js.map +1 -0
  87. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js +172 -0
  88. package/esm/transform/generators/resolveStaticOxcValues/processorStaticExport.js.map +1 -0
  89. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js +476 -0
  90. package/esm/transform/generators/resolveStaticOxcValues/processorStaticModel.js.map +1 -0
  91. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js +55 -0
  92. package/esm/transform/generators/resolveStaticOxcValues/processorTarget.js.map +1 -0
  93. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js +123 -0
  94. package/esm/transform/generators/resolveStaticOxcValues/programAnalysis.js.map +1 -0
  95. package/esm/transform/generators/resolveStaticOxcValues/prune.js +186 -0
  96. package/esm/transform/generators/resolveStaticOxcValues/prune.js.map +1 -0
  97. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +183 -0
  98. package/esm/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js.map +1 -0
  99. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js +298 -0
  100. package/esm/transform/generators/resolveStaticOxcValues/staticExpression.js.map +1 -0
  101. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +298 -0
  102. package/esm/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js.map +1 -0
  103. package/esm/transform/generators/resolveStaticOxcValues/types.js +3 -0
  104. package/esm/transform/generators/resolveStaticOxcValues/types.js.map +1 -0
  105. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +59 -0
  106. package/esm/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js.map +1 -0
  107. package/esm/transform/generators/resolveStaticOxcValues.js +2 -0
  108. package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -0
  109. package/esm/transform/generators/rewriteOxcBarrelImports.js +822 -0
  110. package/esm/transform/generators/rewriteOxcBarrelImports.js.map +1 -0
  111. package/esm/transform/generators/transform.js +251 -248
  112. package/esm/transform/generators/transform.js.map +1 -1
  113. package/esm/transform/generators/workflow.js +87 -90
  114. package/esm/transform/generators/workflow.js.map +1 -1
  115. package/esm/transform/helpers/loadWywOptions.js +183 -74
  116. package/esm/transform/helpers/loadWywOptions.js.map +1 -1
  117. package/esm/transform/helpers/withDefaultServices.js +13 -22
  118. package/esm/transform/helpers/withDefaultServices.js.map +1 -1
  119. package/esm/transform/isStaticallyEvaluatableModule.js +140 -152
  120. package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -1
  121. package/esm/transform/oxcBarrelManifest.js +349 -0
  122. package/esm/transform/oxcBarrelManifest.js.map +1 -0
  123. package/esm/transform/rootLog.js +3 -3
  124. package/esm/transform/rootLog.js.map +1 -1
  125. package/esm/transform/syntax.js +2 -0
  126. package/esm/transform/syntax.js.map +1 -0
  127. package/esm/transform/types.js +2 -2
  128. package/esm/transform/types.js.map +1 -1
  129. package/esm/transform.js +125 -147
  130. package/esm/transform.js.map +1 -1
  131. package/esm/types.js +4 -1
  132. package/esm/types.js.map +1 -1
  133. package/esm/utils/EventEmitter.js +79 -48
  134. package/esm/utils/EventEmitter.js.map +1 -1
  135. package/esm/utils/ShakerMetadata.js +2 -2
  136. package/esm/utils/ShakerMetadata.js.map +1 -1
  137. package/esm/utils/TransformDiagnostics.js +9 -9
  138. package/esm/utils/TransformDiagnostics.js.map +1 -1
  139. package/esm/utils/TransformMetadata.js +24 -26
  140. package/esm/utils/TransformMetadata.js.map +1 -1
  141. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js +160 -0
  142. package/esm/utils/applyOxcProcessors/applyOxcProcessors.js.map +1 -0
  143. package/esm/utils/applyOxcProcessors/cleanupBindings.js +157 -0
  144. package/esm/utils/applyOxcProcessors/cleanupBindings.js.map +1 -0
  145. package/esm/utils/applyOxcProcessors/cleanupRemovals.js +431 -0
  146. package/esm/utils/applyOxcProcessors/cleanupRemovals.js.map +1 -0
  147. package/esm/utils/applyOxcProcessors/displayName.js +93 -0
  148. package/esm/utils/applyOxcProcessors/displayName.js.map +1 -0
  149. package/esm/utils/applyOxcProcessors/expressionValues.js +152 -0
  150. package/esm/utils/applyOxcProcessors/expressionValues.js.map +1 -0
  151. package/esm/utils/applyOxcProcessors/processorFactory.js +62 -0
  152. package/esm/utils/applyOxcProcessors/processorFactory.js.map +1 -0
  153. package/esm/utils/applyOxcProcessors/processorUsages.js +143 -0
  154. package/esm/utils/applyOxcProcessors/processorUsages.js.map +1 -0
  155. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js +207 -0
  156. package/esm/utils/applyOxcProcessors/sameFileStaticValues.js.map +1 -0
  157. package/esm/utils/applyOxcProcessors/shared.js +29 -0
  158. package/esm/utils/applyOxcProcessors/shared.js.map +1 -0
  159. package/esm/utils/applyOxcProcessors/types.js +2 -0
  160. package/esm/utils/applyOxcProcessors/types.js.map +1 -0
  161. package/esm/utils/applyOxcProcessors.js +2 -0
  162. package/esm/utils/applyOxcProcessors.js.map +1 -0
  163. package/esm/utils/collectOxcExportsAndImports.js +934 -0
  164. package/esm/utils/collectOxcExportsAndImports.js.map +1 -0
  165. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js +157 -0
  166. package/esm/utils/collectOxcRuntime/normalizeRuntimeCode.js.map +1 -0
  167. package/esm/utils/collectOxcRuntime/sourceMap.js +36 -0
  168. package/esm/utils/collectOxcRuntime/sourceMap.js.map +1 -0
  169. package/esm/utils/collectOxcRuntime/types.js +2 -0
  170. package/esm/utils/collectOxcRuntime/types.js.map +1 -0
  171. package/esm/utils/collectOxcRuntime.js +32 -0
  172. package/esm/utils/collectOxcRuntime.js.map +1 -0
  173. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js +496 -0
  174. package/esm/utils/collectOxcTemplateDependencies/expressionExtraction.js.map +1 -0
  175. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js +113 -0
  176. package/esm/utils/collectOxcTemplateDependencies/expressionReplacements.js.map +1 -0
  177. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js +387 -0
  178. package/esm/utils/collectOxcTemplateDependencies/scopeAnalysis.js.map +1 -0
  179. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js +17 -0
  180. package/esm/utils/collectOxcTemplateDependencies/staticBindings.js.map +1 -0
  181. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js +540 -0
  182. package/esm/utils/collectOxcTemplateDependencies/staticEvaluator.js.map +1 -0
  183. package/esm/utils/collectOxcTemplateDependencies/types.js +2 -0
  184. package/esm/utils/collectOxcTemplateDependencies/types.js.map +1 -0
  185. package/esm/utils/collectOxcTemplateDependencies.js +4 -0
  186. package/esm/utils/collectOxcTemplateDependencies.js.map +1 -0
  187. package/esm/utils/dispose-polyfill.js +3 -4
  188. package/esm/utils/dispose-polyfill.js.map +1 -1
  189. package/esm/utils/getFileIdx.js +6 -6
  190. package/esm/utils/getFileIdx.js.map +1 -1
  191. package/esm/utils/getPluginKey.js +12 -12
  192. package/esm/utils/getPluginKey.js.map +1 -1
  193. package/esm/utils/getVisitorKeys.js +9 -3
  194. package/esm/utils/getVisitorKeys.js.map +1 -1
  195. package/esm/utils/hasCachedWywPrevalExport.js +23 -0
  196. package/esm/utils/hasCachedWywPrevalExport.js.map +1 -0
  197. package/esm/utils/hasWywPreval.js +5 -5
  198. package/esm/utils/hasWywPreval.js.map +1 -1
  199. package/esm/utils/importOverrides.js +75 -90
  200. package/esm/utils/importOverrides.js.map +1 -1
  201. package/esm/utils/isNode.js +2 -2
  202. package/esm/utils/isNode.js.map +1 -1
  203. package/esm/utils/isNotNull.js +2 -2
  204. package/esm/utils/isNotNull.js.map +1 -1
  205. package/esm/utils/isSerializable.js +11 -11
  206. package/esm/utils/isSerializable.js.map +1 -1
  207. package/esm/utils/nativeResolver.js +93 -0
  208. package/esm/utils/nativeResolver.js.map +1 -0
  209. package/esm/utils/oxc/ast.js +28 -0
  210. package/esm/utils/oxc/ast.js.map +1 -0
  211. package/esm/utils/oxc/parse.js +3 -0
  212. package/esm/utils/oxc/parse.js.map +1 -0
  213. package/esm/utils/oxc/replacements.js +14 -0
  214. package/esm/utils/oxc/replacements.js.map +1 -0
  215. package/esm/utils/oxc/sourceLocations.js +59 -0
  216. package/esm/utils/oxc/sourceLocations.js.map +1 -0
  217. package/esm/utils/oxcAstService.js +121 -0
  218. package/esm/utils/oxcAstService.js.map +1 -0
  219. package/esm/utils/oxcEmit.js +447 -0
  220. package/esm/utils/oxcEmit.js.map +1 -0
  221. package/esm/utils/oxcPreevalStage/evalStrategy.js +3 -0
  222. package/esm/utils/oxcPreevalStage/evalStrategy.js.map +1 -0
  223. package/esm/utils/oxcPreevalStage/prepareCode.js +21 -0
  224. package/esm/utils/oxcPreevalStage/prepareCode.js.map +1 -0
  225. package/esm/utils/oxcPreevalStage/prevalExport.js +23 -0
  226. package/esm/utils/oxcPreevalStage/prevalExport.js.map +1 -0
  227. package/esm/utils/oxcPreevalStage/processors.js +17 -0
  228. package/esm/utils/oxcPreevalStage/processors.js.map +1 -0
  229. package/esm/utils/oxcPreevalStage/staticOverlay.js +18 -0
  230. package/esm/utils/oxcPreevalStage/staticOverlay.js.map +1 -0
  231. package/esm/utils/oxcPreevalStage/types.js +2 -0
  232. package/esm/utils/oxcPreevalStage/types.js.map +1 -0
  233. package/esm/utils/oxcPreevalStage.js +41 -0
  234. package/esm/utils/oxcPreevalStage.js.map +1 -0
  235. package/esm/utils/oxcPreevalTransforms.js +1065 -0
  236. package/esm/utils/oxcPreevalTransforms.js.map +1 -0
  237. package/esm/utils/oxcShaker.js +662 -0
  238. package/esm/utils/oxcShaker.js.map +1 -0
  239. package/esm/utils/parseOxc.js +37 -0
  240. package/esm/utils/parseOxc.js.map +1 -0
  241. package/esm/utils/parseRequest.js +27 -27
  242. package/esm/utils/parseRequest.js.map +1 -1
  243. package/esm/utils/peek.js +1 -1
  244. package/esm/utils/peek.js.map +1 -1
  245. package/esm/utils/processorLookup.js +125 -0
  246. package/esm/utils/processorLookup.js.map +1 -0
  247. package/esm/utils/processorStaticSemantics.js +157 -0
  248. package/esm/utils/processorStaticSemantics.js.map +1 -0
  249. package/esm/utils/resolveWithConditions.js +99 -0
  250. package/esm/utils/resolveWithConditions.js.map +1 -0
  251. package/esm/vm/createVmContext.js +140 -141
  252. package/esm/vm/createVmContext.js.map +1 -1
  253. package/esm/vm/process.js +11 -13
  254. package/esm/vm/process.js.map +1 -1
  255. package/package.json +19 -26
  256. package/types/cache.d.ts +17 -8
  257. package/types/cache.js +245 -95
  258. package/types/debug/fileReporter.js +68 -23
  259. package/types/eval/broker.d.ts +92 -0
  260. package/types/eval/broker.js +2411 -0
  261. package/types/eval/lru.d.ts +10 -0
  262. package/types/eval/lru.js +36 -0
  263. package/types/eval/prepareModuleOnDemand.d.ts +7 -0
  264. package/types/eval/prepareModuleOnDemand.js +24 -0
  265. package/types/eval/protocol.d.ts +111 -0
  266. package/types/eval/protocol.js +1 -0
  267. package/types/eval/serialize.d.ts +78 -0
  268. package/types/eval/serialize.js +357 -0
  269. package/types/eval/writeQueue.d.ts +13 -0
  270. package/types/eval/writeQueue.js +80 -0
  271. package/types/evaluators/index.d.ts +2 -2
  272. package/types/evaluators/index.js +6 -9
  273. package/types/index.d.ts +3 -6
  274. package/types/index.js +24 -82
  275. package/types/module.d.ts +38 -7
  276. package/types/module.js +613 -192
  277. package/types/shaker.d.ts +2 -10
  278. package/types/shaker.js +10 -100
  279. package/types/transform/BaseEntrypoint.js +6 -11
  280. package/types/transform/Entrypoint.d.ts +15 -15
  281. package/types/transform/Entrypoint.helpers.d.ts +2 -5
  282. package/types/transform/Entrypoint.helpers.js +43 -203
  283. package/types/transform/Entrypoint.js +130 -53
  284. package/types/transform/Entrypoint.types.d.ts +31 -6
  285. package/types/transform/Entrypoint.types.js +1 -2
  286. package/types/transform/EvaluatedEntrypoint.d.ts +13 -2
  287. package/types/transform/EvaluatedEntrypoint.js +7 -6
  288. package/types/transform/actions/AbortError.js +2 -7
  289. package/types/transform/actions/BaseAction.js +4 -8
  290. package/types/transform/actions/UnprocessedEntrypointError.js +2 -7
  291. package/types/transform/actions/actionRunner.js +8 -12
  292. package/types/transform/actions/types.d.ts +2 -2
  293. package/types/transform/actions/types.js +1 -2
  294. package/types/transform/{barrelManifest.d.ts → barrelManifest.types.d.ts} +0 -2
  295. package/types/transform/barrelManifest.types.js +1 -0
  296. package/types/transform/generators/baseProcessingHandlers.d.ts +4 -5
  297. package/types/transform/generators/baseProcessingHandlers.js +10 -14
  298. package/types/transform/generators/collect.js +13 -39
  299. package/types/transform/generators/createStylisPreprocessor.js +19 -60
  300. package/types/transform/generators/evalFile.d.ts +2 -2
  301. package/types/transform/generators/evalFile.js +26 -28
  302. package/types/transform/generators/extract.js +5 -8
  303. package/types/transform/generators/getExports.js +23 -30
  304. package/types/transform/generators/index.d.ts +2 -2
  305. package/types/transform/generators/index.js +11 -14
  306. package/types/transform/generators/processEntrypoint.d.ts +2 -2
  307. package/types/transform/generators/processEntrypoint.js +60 -26
  308. package/types/transform/generators/processImports.d.ts +0 -3
  309. package/types/transform/generators/processImports.js +60 -20
  310. package/types/transform/generators/resolveImports.d.ts +3 -1
  311. package/types/transform/generators/resolveImports.js +66 -23
  312. package/types/transform/generators/resolveStaticOxcValues/cache.d.ts +25 -0
  313. package/types/transform/generators/resolveStaticOxcValues/cache.js +182 -0
  314. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.d.ts +5 -0
  315. package/types/transform/generators/resolveStaticOxcValues/candidateResolver.js +149 -0
  316. package/types/transform/generators/resolveStaticOxcValues/dependencies.d.ts +6 -0
  317. package/types/transform/generators/resolveStaticOxcValues/dependencies.js +37 -0
  318. package/types/transform/generators/resolveStaticOxcValues/environment.d.ts +12 -0
  319. package/types/transform/generators/resolveStaticOxcValues/environment.js +32 -0
  320. package/types/transform/generators/resolveStaticOxcValues/exportResolver.d.ts +4 -0
  321. package/types/transform/generators/resolveStaticOxcValues/exportResolver.js +358 -0
  322. package/types/transform/generators/resolveStaticOxcValues/exportTargets.d.ts +20 -0
  323. package/types/transform/generators/resolveStaticOxcValues/exportTargets.js +285 -0
  324. package/types/transform/generators/resolveStaticOxcValues/objectAssign.d.ts +41 -0
  325. package/types/transform/generators/resolveStaticOxcValues/objectAssign.js +352 -0
  326. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.d.ts +6 -0
  327. package/types/transform/generators/resolveStaticOxcValues/objectAssignStaticExport.js +88 -0
  328. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.d.ts +13 -0
  329. package/types/transform/generators/resolveStaticOxcValues/opaqueRuntime.js +263 -0
  330. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.d.ts +4 -0
  331. package/types/transform/generators/resolveStaticOxcValues/processorStaticExport.js +191 -0
  332. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.d.ts +40 -0
  333. package/types/transform/generators/resolveStaticOxcValues/processorStaticModel.js +516 -0
  334. package/types/transform/generators/resolveStaticOxcValues/processorTarget.d.ts +5 -0
  335. package/types/transform/generators/resolveStaticOxcValues/processorTarget.js +62 -0
  336. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.d.ts +11 -0
  337. package/types/transform/generators/resolveStaticOxcValues/programAnalysis.js +133 -0
  338. package/types/transform/generators/resolveStaticOxcValues/prune.d.ts +15 -0
  339. package/types/transform/generators/resolveStaticOxcValues/prune.js +220 -0
  340. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.d.ts +2 -0
  341. package/types/transform/generators/resolveStaticOxcValues/resolveStaticOxcPreevalValues.js +197 -0
  342. package/types/transform/generators/resolveStaticOxcValues/staticExpression.d.ts +25 -0
  343. package/types/transform/generators/resolveStaticOxcValues/staticExpression.js +391 -0
  344. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.d.ts +14 -0
  345. package/types/transform/generators/resolveStaticOxcValues/staticExpressionDependencies.js +304 -0
  346. package/types/transform/generators/resolveStaticOxcValues/types.d.ts +99 -0
  347. package/types/transform/generators/resolveStaticOxcValues/types.js +2 -0
  348. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.d.ts +7 -0
  349. package/types/transform/generators/resolveStaticOxcValues/zeroArgFunctionStaticExport.js +64 -0
  350. package/types/transform/generators/resolveStaticOxcValues.d.ts +1 -0
  351. package/types/transform/generators/resolveStaticOxcValues.js +1 -0
  352. package/types/transform/generators/{rewriteBarrelImports.d.ts → rewriteOxcBarrelImports.d.ts} +2 -3
  353. package/types/transform/generators/{rewriteBarrelImports.js → rewriteOxcBarrelImports.js} +282 -225
  354. package/types/transform/generators/transform.d.ts +3 -7
  355. package/types/transform/generators/transform.js +217 -199
  356. package/types/transform/generators/workflow.js +62 -45
  357. package/types/transform/helpers/loadWywOptions.js +115 -21
  358. package/types/transform/helpers/withDefaultServices.d.ts +1 -1
  359. package/types/transform/helpers/withDefaultServices.js +6 -44
  360. package/types/transform/isStaticallyEvaluatableModule.d.ts +1 -2
  361. package/types/transform/isStaticallyEvaluatableModule.js +125 -126
  362. package/types/transform/oxcBarrelManifest.d.ts +2 -0
  363. package/types/transform/{barrelManifest.js → oxcBarrelManifest.js} +156 -97
  364. package/types/transform/rootLog.js +2 -5
  365. package/types/transform/syntax.d.ts +38 -0
  366. package/types/transform/syntax.js +1 -0
  367. package/types/transform/types.d.ts +9 -6
  368. package/types/transform/types.js +1 -4
  369. package/types/transform.d.ts +2 -2
  370. package/types/transform.js +90 -101
  371. package/types/types.d.ts +0 -23
  372. package/types/types.js +1 -2
  373. package/types/utils/EventEmitter.d.ts +16 -1
  374. package/types/utils/EventEmitter.js +47 -18
  375. package/types/utils/ShakerMetadata.js +1 -5
  376. package/types/utils/TransformDiagnostics.js +3 -7
  377. package/types/utils/TransformMetadata.js +8 -16
  378. package/types/utils/applyOxcProcessors/applyOxcProcessors.d.ts +8 -0
  379. package/types/utils/applyOxcProcessors/applyOxcProcessors.js +167 -0
  380. package/types/utils/applyOxcProcessors/cleanupBindings.d.ts +12 -0
  381. package/types/utils/applyOxcProcessors/cleanupBindings.js +189 -0
  382. package/types/utils/applyOxcProcessors/cleanupRemovals.d.ts +16 -0
  383. package/types/utils/applyOxcProcessors/cleanupRemovals.js +482 -0
  384. package/types/utils/applyOxcProcessors/displayName.d.ts +9 -0
  385. package/types/utils/applyOxcProcessors/displayName.js +113 -0
  386. package/types/utils/applyOxcProcessors/expressionValues.d.ts +11 -0
  387. package/types/utils/applyOxcProcessors/expressionValues.js +170 -0
  388. package/types/utils/applyOxcProcessors/processorFactory.d.ts +7 -0
  389. package/types/utils/applyOxcProcessors/processorFactory.js +70 -0
  390. package/types/utils/applyOxcProcessors/processorUsages.d.ts +16 -0
  391. package/types/utils/applyOxcProcessors/processorUsages.js +163 -0
  392. package/types/utils/applyOxcProcessors/sameFileStaticValues.d.ts +23 -0
  393. package/types/utils/applyOxcProcessors/sameFileStaticValues.js +211 -0
  394. package/types/utils/applyOxcProcessors/shared.d.ts +10 -0
  395. package/types/utils/applyOxcProcessors/shared.js +37 -0
  396. package/types/utils/applyOxcProcessors/types.d.ts +88 -0
  397. package/types/utils/applyOxcProcessors/types.js +1 -0
  398. package/types/utils/applyOxcProcessors.d.ts +1 -0
  399. package/types/utils/applyOxcProcessors.js +1 -0
  400. package/types/utils/collectOxcExportsAndImports.d.ts +35 -0
  401. package/types/utils/collectOxcExportsAndImports.js +957 -0
  402. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.d.ts +1 -0
  403. package/types/utils/collectOxcRuntime/normalizeRuntimeCode.js +185 -0
  404. package/types/utils/collectOxcRuntime/sourceMap.d.ts +2 -0
  405. package/types/utils/collectOxcRuntime/sourceMap.js +37 -0
  406. package/types/utils/collectOxcRuntime/types.d.ts +16 -0
  407. package/types/utils/collectOxcRuntime/types.js +1 -0
  408. package/types/utils/collectOxcRuntime.d.ts +4 -0
  409. package/types/utils/collectOxcRuntime.js +31 -0
  410. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.d.ts +6 -0
  411. package/types/utils/collectOxcTemplateDependencies/expressionExtraction.js +550 -0
  412. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.d.ts +11 -0
  413. package/types/utils/collectOxcTemplateDependencies/expressionReplacements.js +131 -0
  414. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.d.ts +20 -0
  415. package/types/utils/collectOxcTemplateDependencies/scopeAnalysis.js +434 -0
  416. package/types/utils/collectOxcTemplateDependencies/staticBindings.d.ts +7 -0
  417. package/types/utils/collectOxcTemplateDependencies/staticBindings.js +13 -0
  418. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.d.ts +13 -0
  419. package/types/utils/collectOxcTemplateDependencies/staticEvaluator.js +626 -0
  420. package/types/utils/collectOxcTemplateDependencies/types.d.ts +116 -0
  421. package/types/utils/collectOxcTemplateDependencies/types.js +1 -0
  422. package/types/utils/collectOxcTemplateDependencies.d.ts +4 -0
  423. package/types/utils/collectOxcTemplateDependencies.js +3 -0
  424. package/types/utils/getFileIdx.js +1 -4
  425. package/types/utils/getPluginKey.d.ts +5 -2
  426. package/types/utils/getPluginKey.js +2 -6
  427. package/types/utils/getVisitorKeys.d.ts +4 -4
  428. package/types/utils/getVisitorKeys.js +9 -6
  429. package/types/utils/hasCachedWywPrevalExport.d.ts +14 -0
  430. package/types/utils/hasCachedWywPrevalExport.js +30 -0
  431. package/types/utils/hasWywPreval.js +1 -4
  432. package/types/utils/importOverrides.js +17 -27
  433. package/types/utils/isNode.d.ts +2 -2
  434. package/types/utils/isNode.js +2 -6
  435. package/types/utils/isNotNull.js +1 -4
  436. package/types/utils/isSerializable.js +3 -6
  437. package/types/utils/nativeResolver.d.ts +13 -0
  438. package/types/utils/nativeResolver.js +91 -0
  439. package/types/utils/oxc/ast.d.ts +4 -0
  440. package/types/utils/oxc/ast.js +37 -0
  441. package/types/utils/oxc/parse.d.ts +3 -0
  442. package/types/utils/oxc/parse.js +2 -0
  443. package/types/utils/oxc/replacements.d.ts +12 -0
  444. package/types/utils/oxc/replacements.js +18 -0
  445. package/types/utils/oxc/sourceLocations.d.ts +5 -0
  446. package/types/utils/oxc/sourceLocations.js +63 -0
  447. package/types/utils/oxcAstService.d.ts +11 -0
  448. package/types/utils/oxcAstService.js +79 -0
  449. package/types/utils/oxcEmit.d.ts +19 -0
  450. package/types/utils/oxcEmit.js +506 -0
  451. package/types/utils/oxcPreevalStage/evalStrategy.d.ts +3 -0
  452. package/types/utils/oxcPreevalStage/evalStrategy.js +2 -0
  453. package/types/utils/oxcPreevalStage/prepareCode.d.ts +3 -0
  454. package/types/utils/oxcPreevalStage/prepareCode.js +20 -0
  455. package/types/utils/oxcPreevalStage/prevalExport.d.ts +1 -0
  456. package/types/utils/oxcPreevalStage/prevalExport.js +22 -0
  457. package/types/utils/oxcPreevalStage/processors.d.ts +10 -0
  458. package/types/utils/oxcPreevalStage/processors.js +16 -0
  459. package/types/utils/oxcPreevalStage/staticOverlay.d.ts +3 -0
  460. package/types/utils/oxcPreevalStage/staticOverlay.js +23 -0
  461. package/types/utils/oxcPreevalStage/types.d.ts +22 -0
  462. package/types/utils/oxcPreevalStage/types.js +1 -0
  463. package/types/utils/oxcPreevalStage.d.ts +4 -0
  464. package/types/utils/oxcPreevalStage.js +40 -0
  465. package/types/utils/oxcPreevalTransforms.d.ts +13 -0
  466. package/types/utils/oxcPreevalTransforms.js +1192 -0
  467. package/types/utils/oxcShaker.d.ts +13 -0
  468. package/types/utils/oxcShaker.js +751 -0
  469. package/types/utils/parseOxc.d.ts +11 -0
  470. package/types/utils/parseOxc.js +38 -0
  471. package/types/utils/parseRequest.js +2 -7
  472. package/types/utils/peek.js +1 -5
  473. package/types/utils/processorLookup.d.ts +8 -0
  474. package/types/utils/processorLookup.js +135 -0
  475. package/types/utils/processorStaticSemantics.d.ts +13 -0
  476. package/types/utils/processorStaticSemantics.js +191 -0
  477. package/types/utils/resolveWithConditions.d.ts +12 -0
  478. package/types/utils/resolveWithConditions.js +103 -0
  479. package/types/vm/createVmContext.d.ts +2 -2
  480. package/types/vm/createVmContext.js +25 -62
  481. package/types/vm/process.js +20 -26
  482. package/esm/babel.js +0 -2
  483. package/esm/babel.js.map +0 -1
  484. package/esm/options/buildOptions.js +0 -168
  485. package/esm/options/buildOptions.js.map +0 -1
  486. package/esm/options/buildOptions.test.js +0 -138
  487. package/esm/options/buildOptions.test.js.map +0 -1
  488. package/esm/options/loadBabelOptions.js +0 -24
  489. package/esm/options/loadBabelOptions.js.map +0 -1
  490. package/esm/plugins/babel-transform.js +0 -53
  491. package/esm/plugins/babel-transform.js.map +0 -1
  492. package/esm/plugins/collector.js +0 -60
  493. package/esm/plugins/collector.js.map +0 -1
  494. package/esm/plugins/dynamic-import.js +0 -56
  495. package/esm/plugins/dynamic-import.js.map +0 -1
  496. package/esm/plugins/preeval.js +0 -73
  497. package/esm/plugins/preeval.js.map +0 -1
  498. package/esm/plugins/shaker.js +0 -680
  499. package/esm/plugins/shaker.js.map +0 -1
  500. package/esm/transform/barrelManifest.js +0 -291
  501. package/esm/transform/barrelManifest.js.map +0 -1
  502. package/esm/transform/generators/explodeReexports.js +0 -64
  503. package/esm/transform/generators/explodeReexports.js.map +0 -1
  504. package/esm/transform/generators/rewriteBarrelImports.js +0 -733
  505. package/esm/transform/generators/rewriteBarrelImports.js.map +0 -1
  506. package/esm/utils/addIdentifierToWywPreval.js +0 -68
  507. package/esm/utils/addIdentifierToWywPreval.js.map +0 -1
  508. package/esm/utils/collectExportsAndImports.js +0 -1157
  509. package/esm/utils/collectExportsAndImports.js.map +0 -1
  510. package/esm/utils/collectTemplateDependencies.js +0 -228
  511. package/esm/utils/collectTemplateDependencies.js.map +0 -1
  512. package/esm/utils/createId.js +0 -6
  513. package/esm/utils/createId.js.map +0 -1
  514. package/esm/utils/findIdentifiers.js +0 -62
  515. package/esm/utils/findIdentifiers.js.map +0 -1
  516. package/esm/utils/getConstantStringValue.js +0 -58
  517. package/esm/utils/getConstantStringValue.js.map +0 -1
  518. package/esm/utils/getMemberExpressionPropertyName.js +0 -11
  519. package/esm/utils/getMemberExpressionPropertyName.js.map +0 -1
  520. package/esm/utils/getScope.js +0 -6
  521. package/esm/utils/getScope.js.map +0 -1
  522. package/esm/utils/getSource.js +0 -15
  523. package/esm/utils/getSource.js.map +0 -1
  524. package/esm/utils/getTagProcessor.js +0 -404
  525. package/esm/utils/getTagProcessor.js.map +0 -1
  526. package/esm/utils/isExports.js +0 -22
  527. package/esm/utils/isExports.js.map +0 -1
  528. package/esm/utils/isGlobal.js +0 -6
  529. package/esm/utils/isGlobal.js.map +0 -1
  530. package/esm/utils/isNodePath.js +0 -4
  531. package/esm/utils/isNodePath.js.map +0 -1
  532. package/esm/utils/isRemoved.js +0 -46
  533. package/esm/utils/isRemoved.js.map +0 -1
  534. package/esm/utils/isRequire.js +0 -13
  535. package/esm/utils/isRequire.js.map +0 -1
  536. package/esm/utils/isTypedNode.js +0 -6
  537. package/esm/utils/isTypedNode.js.map +0 -1
  538. package/esm/utils/isUnnecessaryReactCall.js +0 -72
  539. package/esm/utils/isUnnecessaryReactCall.js.map +0 -1
  540. package/esm/utils/removeDangerousCode.js +0 -276
  541. package/esm/utils/removeDangerousCode.js.map +0 -1
  542. package/esm/utils/replaceImportMetaEnv.js +0 -44
  543. package/esm/utils/replaceImportMetaEnv.js.map +0 -1
  544. package/esm/utils/scopeHelpers.js +0 -527
  545. package/esm/utils/scopeHelpers.js.map +0 -1
  546. package/esm/utils/traversalCache.js +0 -23
  547. package/esm/utils/traversalCache.js.map +0 -1
  548. package/esm/utils/unwrapExpression.js +0 -18
  549. package/esm/utils/unwrapExpression.js.map +0 -1
  550. package/esm/utils/unwrapSequence.js +0 -14
  551. package/esm/utils/unwrapSequence.js.map +0 -1
  552. package/esm/utils/valueToLiteral.js +0 -59
  553. package/esm/utils/valueToLiteral.js.map +0 -1
  554. package/esm/utils/visitors/JSXElementsRemover.js +0 -51
  555. package/esm/utils/visitors/JSXElementsRemover.js.map +0 -1
  556. package/lib/babel.js +0 -2
  557. package/lib/babel.js.map +0 -1
  558. package/lib/cache.js +0 -308
  559. package/lib/cache.js.map +0 -1
  560. package/lib/debug/fileReporter.js +0 -153
  561. package/lib/debug/fileReporter.js.map +0 -1
  562. package/lib/evaluators/index.js +0 -20
  563. package/lib/evaluators/index.js.map +0 -1
  564. package/lib/index.js +0 -286
  565. package/lib/index.js.map +0 -1
  566. package/lib/module.js +0 -552
  567. package/lib/module.js.map +0 -1
  568. package/lib/options/buildOptions.js +0 -176
  569. package/lib/options/buildOptions.js.map +0 -1
  570. package/lib/options/buildOptions.test.js +0 -141
  571. package/lib/options/buildOptions.test.js.map +0 -1
  572. package/lib/options/loadBabelOptions.js +0 -31
  573. package/lib/options/loadBabelOptions.js.map +0 -1
  574. package/lib/plugins/babel-transform.js +0 -60
  575. package/lib/plugins/babel-transform.js.map +0 -1
  576. package/lib/plugins/collector.js +0 -70
  577. package/lib/plugins/collector.js.map +0 -1
  578. package/lib/plugins/dynamic-import.js +0 -61
  579. package/lib/plugins/dynamic-import.js.map +0 -1
  580. package/lib/plugins/preeval.js +0 -81
  581. package/lib/plugins/preeval.js.map +0 -1
  582. package/lib/plugins/shaker.js +0 -691
  583. package/lib/plugins/shaker.js.map +0 -1
  584. package/lib/shaker.js +0 -95
  585. package/lib/shaker.js.map +0 -1
  586. package/lib/transform/BaseEntrypoint.js +0 -179
  587. package/lib/transform/BaseEntrypoint.js.map +0 -1
  588. package/lib/transform/Entrypoint.helpers.js +0 -279
  589. package/lib/transform/Entrypoint.helpers.js.map +0 -1
  590. package/lib/transform/Entrypoint.js +0 -289
  591. package/lib/transform/Entrypoint.js.map +0 -1
  592. package/lib/transform/Entrypoint.types.js +0 -2
  593. package/lib/transform/Entrypoint.types.js.map +0 -1
  594. package/lib/transform/EvaluatedEntrypoint.js +0 -13
  595. package/lib/transform/EvaluatedEntrypoint.js.map +0 -1
  596. package/lib/transform/actions/AbortError.js +0 -16
  597. package/lib/transform/actions/AbortError.js.map +0 -1
  598. package/lib/transform/actions/BaseAction.js +0 -150
  599. package/lib/transform/actions/BaseAction.js.map +0 -1
  600. package/lib/transform/actions/UnprocessedEntrypointError.js +0 -16
  601. package/lib/transform/actions/UnprocessedEntrypointError.js.map +0 -1
  602. package/lib/transform/actions/actionRunner.js +0 -82
  603. package/lib/transform/actions/actionRunner.js.map +0 -1
  604. package/lib/transform/actions/types.js +0 -2
  605. package/lib/transform/actions/types.js.map +0 -1
  606. package/lib/transform/barrelManifest.js +0 -300
  607. package/lib/transform/barrelManifest.js.map +0 -1
  608. package/lib/transform/generators/baseProcessingHandlers.js +0 -27
  609. package/lib/transform/generators/baseProcessingHandlers.js.map +0 -1
  610. package/lib/transform/generators/collect.js +0 -66
  611. package/lib/transform/generators/collect.js.map +0 -1
  612. package/lib/transform/generators/createStylisPreprocessor.js +0 -372
  613. package/lib/transform/generators/createStylisPreprocessor.js.map +0 -1
  614. package/lib/transform/generators/evalFile.js +0 -57
  615. package/lib/transform/generators/evalFile.js.map +0 -1
  616. package/lib/transform/generators/explodeReexports.js +0 -71
  617. package/lib/transform/generators/explodeReexports.js.map +0 -1
  618. package/lib/transform/generators/extract.js +0 -102
  619. package/lib/transform/generators/extract.js.map +0 -1
  620. package/lib/transform/generators/getExports.js +0 -85
  621. package/lib/transform/generators/getExports.js.map +0 -1
  622. package/lib/transform/generators/index.js +0 -19
  623. package/lib/transform/generators/index.js.map +0 -1
  624. package/lib/transform/generators/processEntrypoint.js +0 -76
  625. package/lib/transform/generators/processEntrypoint.js.map +0 -1
  626. package/lib/transform/generators/processImports.js +0 -82
  627. package/lib/transform/generators/processImports.js.map +0 -1
  628. package/lib/transform/generators/resolveImports.js +0 -221
  629. package/lib/transform/generators/resolveImports.js.map +0 -1
  630. package/lib/transform/generators/rewriteBarrelImports.js +0 -743
  631. package/lib/transform/generators/rewriteBarrelImports.js.map +0 -1
  632. package/lib/transform/generators/transform.js +0 -272
  633. package/lib/transform/generators/transform.js.map +0 -1
  634. package/lib/transform/generators/workflow.js +0 -100
  635. package/lib/transform/generators/workflow.js.map +0 -1
  636. package/lib/transform/helpers/loadWywOptions.js +0 -88
  637. package/lib/transform/helpers/loadWywOptions.js.map +0 -1
  638. package/lib/transform/helpers/withDefaultServices.js +0 -31
  639. package/lib/transform/helpers/withDefaultServices.js.map +0 -1
  640. package/lib/transform/isStaticallyEvaluatableModule.js +0 -159
  641. package/lib/transform/isStaticallyEvaluatableModule.js.map +0 -1
  642. package/lib/transform/rootLog.js +0 -9
  643. package/lib/transform/rootLog.js.map +0 -1
  644. package/lib/transform/types.js +0 -8
  645. package/lib/transform/types.js.map +0 -1
  646. package/lib/transform.js +0 -160
  647. package/lib/transform.js.map +0 -1
  648. package/lib/types.js +0 -2
  649. package/lib/types.js.map +0 -1
  650. package/lib/utils/EventEmitter.js +0 -61
  651. package/lib/utils/EventEmitter.js.map +0 -1
  652. package/lib/utils/ShakerMetadata.js +0 -9
  653. package/lib/utils/ShakerMetadata.js.map +0 -1
  654. package/lib/utils/TransformDiagnostics.js +0 -20
  655. package/lib/utils/TransformDiagnostics.js.map +0 -1
  656. package/lib/utils/TransformMetadata.js +0 -45
  657. package/lib/utils/TransformMetadata.js.map +0 -1
  658. package/lib/utils/addIdentifierToWywPreval.js +0 -75
  659. package/lib/utils/addIdentifierToWywPreval.js.map +0 -1
  660. package/lib/utils/collectExportsAndImports.js +0 -1173
  661. package/lib/utils/collectExportsAndImports.js.map +0 -1
  662. package/lib/utils/collectTemplateDependencies.js +0 -242
  663. package/lib/utils/collectTemplateDependencies.js.map +0 -1
  664. package/lib/utils/createId.js +0 -13
  665. package/lib/utils/createId.js.map +0 -1
  666. package/lib/utils/dispose-polyfill.js +0 -9
  667. package/lib/utils/dispose-polyfill.js.map +0 -1
  668. package/lib/utils/findIdentifiers.js +0 -73
  669. package/lib/utils/findIdentifiers.js.map +0 -1
  670. package/lib/utils/getConstantStringValue.js +0 -66
  671. package/lib/utils/getConstantStringValue.js.map +0 -1
  672. package/lib/utils/getFileIdx.js +0 -16
  673. package/lib/utils/getFileIdx.js.map +0 -1
  674. package/lib/utils/getMemberExpressionPropertyName.js +0 -18
  675. package/lib/utils/getMemberExpressionPropertyName.js.map +0 -1
  676. package/lib/utils/getPluginKey.js +0 -21
  677. package/lib/utils/getPluginKey.js.map +0 -1
  678. package/lib/utils/getScope.js +0 -12
  679. package/lib/utils/getScope.js.map +0 -1
  680. package/lib/utils/getSource.js +0 -24
  681. package/lib/utils/getSource.js.map +0 -1
  682. package/lib/utils/getTagProcessor.js +0 -424
  683. package/lib/utils/getTagProcessor.js.map +0 -1
  684. package/lib/utils/getVisitorKeys.js +0 -11
  685. package/lib/utils/getVisitorKeys.js.map +0 -1
  686. package/lib/utils/hasWywPreval.js +0 -13
  687. package/lib/utils/hasWywPreval.js.map +0 -1
  688. package/lib/utils/importOverrides.js +0 -119
  689. package/lib/utils/importOverrides.js.map +0 -1
  690. package/lib/utils/isExports.js +0 -27
  691. package/lib/utils/isExports.js.map +0 -1
  692. package/lib/utils/isGlobal.js +0 -13
  693. package/lib/utils/isGlobal.js.map +0 -1
  694. package/lib/utils/isNode.js +0 -9
  695. package/lib/utils/isNode.js.map +0 -1
  696. package/lib/utils/isNodePath.js +0 -10
  697. package/lib/utils/isNodePath.js.map +0 -1
  698. package/lib/utils/isNotNull.js +0 -10
  699. package/lib/utils/isNotNull.js.map +0 -1
  700. package/lib/utils/isRemoved.js +0 -52
  701. package/lib/utils/isRemoved.js.map +0 -1
  702. package/lib/utils/isRequire.js +0 -18
  703. package/lib/utils/isRequire.js.map +0 -1
  704. package/lib/utils/isSerializable.js +0 -19
  705. package/lib/utils/isSerializable.js.map +0 -1
  706. package/lib/utils/isTypedNode.js +0 -13
  707. package/lib/utils/isTypedNode.js.map +0 -1
  708. package/lib/utils/isUnnecessaryReactCall.js +0 -81
  709. package/lib/utils/isUnnecessaryReactCall.js.map +0 -1
  710. package/lib/utils/parseRequest.js +0 -37
  711. package/lib/utils/parseRequest.js.map +0 -1
  712. package/lib/utils/peek.js +0 -9
  713. package/lib/utils/peek.js.map +0 -1
  714. package/lib/utils/removeDangerousCode.js +0 -284
  715. package/lib/utils/removeDangerousCode.js.map +0 -1
  716. package/lib/utils/replaceImportMetaEnv.js +0 -50
  717. package/lib/utils/replaceImportMetaEnv.js.map +0 -1
  718. package/lib/utils/scopeHelpers.js +0 -557
  719. package/lib/utils/scopeHelpers.js.map +0 -1
  720. package/lib/utils/traversalCache.js +0 -31
  721. package/lib/utils/traversalCache.js.map +0 -1
  722. package/lib/utils/unwrapExpression.js +0 -25
  723. package/lib/utils/unwrapExpression.js.map +0 -1
  724. package/lib/utils/unwrapSequence.js +0 -20
  725. package/lib/utils/unwrapSequence.js.map +0 -1
  726. package/lib/utils/valueToLiteral.js +0 -65
  727. package/lib/utils/valueToLiteral.js.map +0 -1
  728. package/lib/utils/visitors/JSXElementsRemover.js +0 -57
  729. package/lib/utils/visitors/JSXElementsRemover.js.map +0 -1
  730. package/lib/vm/createVmContext.js +0 -166
  731. package/lib/vm/createVmContext.js.map +0 -1
  732. package/lib/vm/process.js +0 -38
  733. package/lib/vm/process.js.map +0 -1
  734. package/types/babel.d.ts +0 -2
  735. package/types/babel.js +0 -2
  736. package/types/options/buildOptions.d.ts +0 -6
  737. package/types/options/buildOptions.js +0 -178
  738. package/types/options/loadBabelOptions.d.ts +0 -3
  739. package/types/options/loadBabelOptions.js +0 -26
  740. package/types/plugins/babel-transform.d.ts +0 -4
  741. package/types/plugins/babel-transform.js +0 -49
  742. package/types/plugins/collector.d.ts +0 -23
  743. package/types/plugins/collector.js +0 -62
  744. package/types/plugins/dynamic-import.d.ts +0 -6
  745. package/types/plugins/dynamic-import.js +0 -60
  746. package/types/plugins/preeval.d.ts +0 -16
  747. package/types/plugins/preeval.js +0 -69
  748. package/types/plugins/shaker.d.ts +0 -14
  749. package/types/plugins/shaker.js +0 -724
  750. package/types/transform/generators/explodeReexports.d.ts +0 -7
  751. package/types/transform/generators/explodeReexports.js +0 -65
  752. package/types/utils/addIdentifierToWywPreval.d.ts +0 -4
  753. package/types/utils/addIdentifierToWywPreval.js +0 -74
  754. package/types/utils/collectExportsAndImports.d.ts +0 -31
  755. package/types/utils/collectExportsAndImports.js +0 -1147
  756. package/types/utils/collectTemplateDependencies.d.ts +0 -17
  757. package/types/utils/collectTemplateDependencies.js +0 -220
  758. package/types/utils/createId.d.ts +0 -2
  759. package/types/utils/createId.js +0 -9
  760. package/types/utils/findIdentifiers.d.ts +0 -6
  761. package/types/utils/findIdentifiers.js +0 -67
  762. package/types/utils/getConstantStringValue.d.ts +0 -2
  763. package/types/utils/getConstantStringValue.js +0 -94
  764. package/types/utils/getMemberExpressionPropertyName.d.ts +0 -2
  765. package/types/utils/getMemberExpressionPropertyName.js +0 -46
  766. package/types/utils/getScope.d.ts +0 -2
  767. package/types/utils/getScope.js +0 -10
  768. package/types/utils/getSource.d.ts +0 -2
  769. package/types/utils/getSource.js +0 -22
  770. package/types/utils/getTagProcessor.d.ts +0 -13
  771. package/types/utils/getTagProcessor.js +0 -411
  772. package/types/utils/isExports.d.ts +0 -6
  773. package/types/utils/isExports.js +0 -19
  774. package/types/utils/isGlobal.d.ts +0 -2
  775. package/types/utils/isGlobal.js +0 -9
  776. package/types/utils/isNodePath.d.ts +0 -3
  777. package/types/utils/isNodePath.js +0 -6
  778. package/types/utils/isRemoved.d.ts +0 -5
  779. package/types/utils/isRemoved.js +0 -41
  780. package/types/utils/isRequire.d.ts +0 -6
  781. package/types/utils/isRequire.js +0 -14
  782. package/types/utils/isTypedNode.d.ts +0 -5
  783. package/types/utils/isTypedNode.js +0 -9
  784. package/types/utils/isUnnecessaryReactCall.d.ts +0 -3
  785. package/types/utils/isUnnecessaryReactCall.js +0 -75
  786. package/types/utils/removeDangerousCode.d.ts +0 -4
  787. package/types/utils/removeDangerousCode.js +0 -326
  788. package/types/utils/replaceImportMetaEnv.d.ts +0 -3
  789. package/types/utils/replaceImportMetaEnv.js +0 -39
  790. package/types/utils/scopeHelpers.d.ts +0 -12
  791. package/types/utils/scopeHelpers.js +0 -580
  792. package/types/utils/traversalCache.d.ts +0 -4
  793. package/types/utils/traversalCache.js +0 -27
  794. package/types/utils/unwrapExpression.d.ts +0 -2
  795. package/types/utils/unwrapExpression.js +0 -57
  796. package/types/utils/unwrapSequence.d.ts +0 -8
  797. package/types/utils/unwrapSequence.js +0 -16
  798. package/types/utils/valueToLiteral.d.ts +0 -3
  799. package/types/utils/valueToLiteral.js +0 -63
  800. package/types/utils/visitors/JSXElementsRemover.d.ts +0 -3
  801. package/types/utils/visitors/JSXElementsRemover.js +0 -51
@@ -0,0 +1,1192 @@
1
+ /* eslint-disable no-restricted-syntax,no-continue */
2
+ import { collectOxcExportsAndImports } from './collectOxcExportsAndImports';
3
+ import { EventEmitter } from './EventEmitter';
4
+ import { parseOxcProgramCached } from './parseOxc';
5
+ const ssrCheckFields = new Set([
6
+ 'document',
7
+ 'location',
8
+ 'navigator',
9
+ 'sessionStorage',
10
+ 'localStorage',
11
+ 'window',
12
+ ]);
13
+ const forbiddenGlobals = new Set([
14
+ ...ssrCheckFields,
15
+ '$RefreshReg$',
16
+ '$RefreshSig$',
17
+ 'XMLHttpRequest',
18
+ 'clearImmediate',
19
+ 'clearInterval',
20
+ 'clearTimeout',
21
+ 'fetch',
22
+ 'navigator',
23
+ 'setImmediate',
24
+ 'setInterval',
25
+ 'setTimeout',
26
+ ]);
27
+ const alwaysForbiddenIdentifiers = new Set(['$RefreshReg$', '$RefreshSig$']);
28
+ const promiseCallbackMethods = new Set(['then', 'catch', 'finally']);
29
+ const jsxRuntimeSources = new Set([
30
+ 'react/jsx-runtime',
31
+ 'react/jsx-dev-runtime',
32
+ ]);
33
+ const defaultPlaceholder = '...';
34
+ const defaultReactComponentTypes = [
35
+ 'ExoticComponent',
36
+ 'FC',
37
+ 'ForwardRefExoticComponent',
38
+ 'FunctionComponent',
39
+ 'LazyExoticComponent',
40
+ 'MemoExoticComponent',
41
+ 'NamedExoticComponent',
42
+ ];
43
+ const defaultReactHocs = ['forwardRef', 'memo'];
44
+ const generatedProcessorHelperNameRe = /^_exp\d*$/;
45
+ const requireCallRe = /\brequire\s*\(/;
46
+ const windowTokenRe = /\bwindow\b/;
47
+ const removableOwnerTypes = new Set([
48
+ 'DoWhileStatement',
49
+ 'ExpressionStatement',
50
+ 'ForInStatement',
51
+ 'ForOfStatement',
52
+ 'ForStatement',
53
+ 'FunctionDeclaration',
54
+ 'IfStatement',
55
+ 'PropertyDefinition',
56
+ 'ReturnStatement',
57
+ 'VariableDeclaration',
58
+ 'WhileStatement',
59
+ ]);
60
+ const importMetaEnvRe = /\bimport\s*\.\s*meta\s*\.\s*env\b/;
61
+ const createScope = (parent, key) => ({
62
+ bindings: new Map(),
63
+ key,
64
+ names: new Set(),
65
+ parent,
66
+ });
67
+ const createsScope = (node) => node.type === 'Program' ||
68
+ node.type === 'BlockStatement' ||
69
+ node.type === 'FunctionDeclaration' ||
70
+ node.type === 'FunctionExpression' ||
71
+ node.type === 'ArrowFunctionExpression';
72
+ const hasBinding = (scope, name) => {
73
+ let current = scope;
74
+ while (current) {
75
+ if (current.names.has(name)) {
76
+ return true;
77
+ }
78
+ current = current.parent;
79
+ }
80
+ return false;
81
+ };
82
+ const getBindingKey = (scope, name) => {
83
+ let current = scope;
84
+ while (current) {
85
+ if (current.names.has(name)) {
86
+ return `${current.key}\0${name}`;
87
+ }
88
+ current = current.parent;
89
+ }
90
+ return null;
91
+ };
92
+ const getStaticBinding = (scope, name) => {
93
+ let current = scope;
94
+ while (current) {
95
+ if (current.bindings.has(name)) {
96
+ return current.bindings.get(name);
97
+ }
98
+ current = current.parent;
99
+ }
100
+ return undefined;
101
+ };
102
+ const isFileLikeRequireSpecifier = (value) => value.startsWith('.') || value.startsWith('/') || value.startsWith('file:');
103
+ const isNode = (value) => !!value &&
104
+ typeof value === 'object' &&
105
+ 'type' in value &&
106
+ typeof value.type === 'string';
107
+ const getChildren = (node) => {
108
+ const result = [];
109
+ const record = node;
110
+ Object.keys(record).forEach((key) => {
111
+ if (key === 'type' || key === 'start' || key === 'end' || key === 'range') {
112
+ return;
113
+ }
114
+ const value = record[key];
115
+ if (isNode(value)) {
116
+ result.push(value);
117
+ return;
118
+ }
119
+ if (Array.isArray(value)) {
120
+ value.forEach((item) => {
121
+ if (isNode(item)) {
122
+ result.push(item);
123
+ }
124
+ });
125
+ }
126
+ });
127
+ return result;
128
+ };
129
+ const parseOxc = (code, filename) => {
130
+ return parseOxcProgramCached(filename, code, 'unambiguous');
131
+ };
132
+ const unwrapExpression = (node) => {
133
+ if (node.type === 'TSAsExpression' ||
134
+ node.type === 'TSSatisfiesExpression' ||
135
+ node.type === 'TSNonNullExpression' ||
136
+ node.type === 'TSTypeAssertion' ||
137
+ node.type === 'ParenthesizedExpression') {
138
+ return unwrapExpression(node.expression);
139
+ }
140
+ return node;
141
+ };
142
+ const getMemberPropertyName = (node) => {
143
+ if (node.type !== 'MemberExpression') {
144
+ return null;
145
+ }
146
+ if (node.computed) {
147
+ return node.property.type === 'Literal' &&
148
+ typeof node.property.value === 'string'
149
+ ? node.property.value
150
+ : null;
151
+ }
152
+ return node.property.type === 'Identifier' ? node.property.name : null;
153
+ };
154
+ const isStringLikeExpression = (node) => {
155
+ const expression = unwrapExpression(node);
156
+ if (expression.type === 'Literal' && typeof expression.value === 'string') {
157
+ return true;
158
+ }
159
+ if (expression.type === 'TemplateLiteral') {
160
+ return true;
161
+ }
162
+ if (expression.type === 'BinaryExpression' && expression.operator === '+') {
163
+ return (isStringLikeExpression(expression.left) ||
164
+ isStringLikeExpression(expression.right));
165
+ }
166
+ if (expression.type === 'CallExpression' &&
167
+ expression.callee.type === 'MemberExpression' &&
168
+ getMemberPropertyName(expression.callee) === 'concat') {
169
+ return isStringLikeExpression(expression.callee.object);
170
+ }
171
+ return false;
172
+ };
173
+ const templateLiteralToConcat = (code, node) => {
174
+ if (node.type !== 'TemplateLiteral' || node.expressions.length === 0) {
175
+ return code.slice(node.start, node.end);
176
+ }
177
+ const parts = [];
178
+ node.quasis.forEach((quasi, index) => {
179
+ const cooked = quasi.value.cooked ?? quasi.value.raw;
180
+ if (cooked !== '') {
181
+ parts.push(JSON.stringify(cooked));
182
+ }
183
+ const expression = node.expressions[index];
184
+ if (expression) {
185
+ parts.push(code.slice(expression.start, expression.end));
186
+ }
187
+ });
188
+ return parts.length > 0 ? parts.join(' + ') : '""';
189
+ };
190
+ const dynamicImportArgumentCode = (code, node) => {
191
+ if (node.type === 'TemplateLiteral') {
192
+ return templateLiteralToConcat(code, node);
193
+ }
194
+ return code.slice(node.start, node.end);
195
+ };
196
+ const evaluateStaticValue = (node, scope, seen = new Set()) => {
197
+ const expression = unwrapExpression(node);
198
+ if (expression.type === 'Literal') {
199
+ return expression.value;
200
+ }
201
+ if (expression.type === 'TemplateLiteral') {
202
+ let result = '';
203
+ for (let idx = 0; idx < expression.quasis.length; idx += 1) {
204
+ result += expression.quasis[idx]?.value.cooked ?? '';
205
+ const nextExpression = expression.expressions[idx];
206
+ if (!nextExpression) {
207
+ continue;
208
+ }
209
+ const value = evaluateStaticValue(nextExpression, scope, seen);
210
+ if (value === undefined ||
211
+ (typeof value !== 'string' && typeof value !== 'number')) {
212
+ return undefined;
213
+ }
214
+ result += String(value);
215
+ }
216
+ return result;
217
+ }
218
+ if (expression.type === 'Identifier') {
219
+ if (seen.has(expression.name)) {
220
+ return undefined;
221
+ }
222
+ const binding = getStaticBinding(scope, expression.name);
223
+ if (!binding) {
224
+ return undefined;
225
+ }
226
+ return evaluateStaticValue(binding, scope, new Set([...seen, expression.name]));
227
+ }
228
+ if (expression.type === 'BinaryExpression' && expression.operator === '+') {
229
+ const left = evaluateStaticValue(expression.left, scope, seen);
230
+ const right = evaluateStaticValue(expression.right, scope, seen);
231
+ if (left === undefined || right === undefined) {
232
+ return undefined;
233
+ }
234
+ if (typeof left === 'number' && typeof right === 'number') {
235
+ return left + right;
236
+ }
237
+ if ((typeof left === 'string' || typeof left === 'number') &&
238
+ (typeof right === 'string' || typeof right === 'number')) {
239
+ return `${left}${right}`;
240
+ }
241
+ }
242
+ if (expression.type === 'CallExpression' &&
243
+ expression.callee.type === 'MemberExpression') {
244
+ const objectValue = evaluateStaticValue(expression.callee.object, scope, seen);
245
+ const propertyName = getMemberPropertyName(expression.callee);
246
+ if (!propertyName) {
247
+ return undefined;
248
+ }
249
+ if (typeof objectValue === 'string') {
250
+ if (propertyName === 'toLowerCase' && expression.arguments.length === 0) {
251
+ return objectValue.toLowerCase();
252
+ }
253
+ if (propertyName === 'toUpperCase' && expression.arguments.length === 0) {
254
+ return objectValue.toUpperCase();
255
+ }
256
+ if (propertyName === 'trim' && expression.arguments.length === 0) {
257
+ return objectValue.trim();
258
+ }
259
+ if (propertyName === 'concat') {
260
+ const args = expression.arguments.map((argument) => argument.type === 'SpreadElement'
261
+ ? undefined
262
+ : evaluateStaticValue(argument, scope, seen));
263
+ if (args.some((value) => value === undefined) ||
264
+ args.some((value) => typeof value !== 'string' && typeof value !== 'number')) {
265
+ return undefined;
266
+ }
267
+ return objectValue.concat(...args.map((value) => String(value)));
268
+ }
269
+ }
270
+ }
271
+ return undefined;
272
+ };
273
+ const isLiteralRequireArg = (node) => {
274
+ const expression = unwrapExpression(node);
275
+ if (expression.type === 'Literal' && typeof expression.value === 'string') {
276
+ return true;
277
+ }
278
+ if (expression.type === 'TemplateLiteral' &&
279
+ expression.expressions.length === 0) {
280
+ return true;
281
+ }
282
+ return false;
283
+ };
284
+ const applyReplacements = (code, replacements) => {
285
+ let result = code;
286
+ replacements
287
+ .sort((a, b) => b.start - a.start)
288
+ .forEach((replacement) => {
289
+ result =
290
+ result.slice(0, replacement.start) +
291
+ replacement.value +
292
+ result.slice(replacement.end);
293
+ });
294
+ return result;
295
+ };
296
+ const isIdentifierNamed = (value, name) => isNode(value) && value.type === 'Identifier' && value.name === name;
297
+ const isImportMeta = (node) => {
298
+ if (!isNode(node) || node.type !== 'MetaProperty') {
299
+ return false;
300
+ }
301
+ const metaProperty = node;
302
+ return (isIdentifierNamed(metaProperty.meta, 'import') &&
303
+ isIdentifierNamed(metaProperty.property, 'meta'));
304
+ };
305
+ const isImportMetaEnv = (node) => {
306
+ if (node.type !== 'MemberExpression') {
307
+ return false;
308
+ }
309
+ if (node.computed || !isIdentifierNamed(node.property, 'env')) {
310
+ return false;
311
+ }
312
+ return isImportMeta(node.object);
313
+ };
314
+ const collectBindingNames = (node) => {
315
+ if (node.type === 'Identifier') {
316
+ return [node.name];
317
+ }
318
+ if (node.type === 'RestElement') {
319
+ return collectBindingNames(node.argument);
320
+ }
321
+ if (node.type === 'AssignmentPattern') {
322
+ return collectBindingNames(node.left);
323
+ }
324
+ if (node.type === 'ObjectPattern') {
325
+ return node.properties.flatMap((property) => property.type === 'RestElement'
326
+ ? collectBindingNames(property.argument)
327
+ : collectBindingNames(property.value));
328
+ }
329
+ if (node.type === 'ArrayPattern') {
330
+ return node.elements.flatMap((element) => element ? collectBindingNames(element) : []);
331
+ }
332
+ if (node.type === 'TSParameterProperty') {
333
+ return collectBindingNames(node.parameter);
334
+ }
335
+ return [];
336
+ };
337
+ const predeclareScopeNames = (node, scope) => {
338
+ if (node.type === 'FunctionDeclaration' ||
339
+ node.type === 'FunctionExpression' ||
340
+ node.type === 'ArrowFunctionExpression') {
341
+ if (node.type !== 'ArrowFunctionExpression' && node.id) {
342
+ scope.names.add(node.id.name);
343
+ }
344
+ node.params.forEach((param) => {
345
+ collectBindingNames(param).forEach((name) => {
346
+ scope.names.add(name);
347
+ });
348
+ });
349
+ }
350
+ const visitScopeDescendants = (child) => {
351
+ if (child.type === 'VariableDeclarator') {
352
+ collectBindingNames(child.id).forEach((name) => {
353
+ scope.names.add(name);
354
+ });
355
+ }
356
+ else if (child.type === 'FunctionDeclaration' && child.id) {
357
+ scope.names.add(child.id.name);
358
+ }
359
+ else if (child.type === 'ClassDeclaration' && child.id) {
360
+ scope.names.add(child.id.name);
361
+ }
362
+ else if (child.type === 'ImportDefaultSpecifier' ||
363
+ child.type === 'ImportNamespaceSpecifier' ||
364
+ child.type === 'ImportSpecifier') {
365
+ scope.names.add(child.local.name);
366
+ }
367
+ if (createsScope(child)) {
368
+ return;
369
+ }
370
+ getChildren(child).forEach(visitScopeDescendants);
371
+ };
372
+ getChildren(node).forEach(visitScopeDescendants);
373
+ };
374
+ const declareBindings = (node, scope) => {
375
+ if (node.type === 'VariableDeclarator') {
376
+ const names = collectBindingNames(node.id);
377
+ names.forEach((name) => {
378
+ scope.names.add(name);
379
+ scope.bindings.set(name, null);
380
+ });
381
+ if (node.id.type === 'Identifier' && node.init) {
382
+ scope.bindings.set(node.id.name, node.init);
383
+ }
384
+ return;
385
+ }
386
+ if (node.type === 'FunctionDeclaration' && node.id) {
387
+ scope.names.add(node.id.name);
388
+ scope.bindings.set(node.id.name, null);
389
+ }
390
+ if (node.type === 'ClassDeclaration' && node.id) {
391
+ scope.names.add(node.id.name);
392
+ scope.bindings.set(node.id.name, null);
393
+ return;
394
+ }
395
+ if (node.type === 'ImportDefaultSpecifier' ||
396
+ node.type === 'ImportNamespaceSpecifier' ||
397
+ node.type === 'ImportSpecifier') {
398
+ scope.names.add(node.local.name);
399
+ scope.bindings.set(node.local.name, null);
400
+ return;
401
+ }
402
+ if (node.type === 'FunctionDeclaration' ||
403
+ node.type === 'FunctionExpression' ||
404
+ node.type === 'ArrowFunctionExpression') {
405
+ node.params.forEach((param) => {
406
+ collectBindingNames(param).forEach((name) => {
407
+ scope.names.add(name);
408
+ scope.bindings.set(name, null);
409
+ });
410
+ });
411
+ }
412
+ };
413
+ const visit = (node, scope, enter, parent = null, ancestors = []) => {
414
+ let currentScope = scope;
415
+ if (createsScope(node)) {
416
+ currentScope = createScope(scope, `${node.type}:${node.start}:${node.end}`);
417
+ predeclareScopeNames(node, currentScope);
418
+ }
419
+ declareBindings(node, currentScope);
420
+ enter(node, currentScope, parent, ancestors);
421
+ getChildren(node).forEach((child) => visit(child, currentScope, enter, node, [...ancestors, node]));
422
+ };
423
+ export const replaceImportMetaEnvWithOxc = (code, filename) => {
424
+ if (!importMetaEnvRe.test(code)) {
425
+ return code;
426
+ }
427
+ const replacements = [];
428
+ visit(parseOxc(code, filename), createScope(null, 'root'), (node) => {
429
+ if (!isImportMetaEnv(node)) {
430
+ return;
431
+ }
432
+ replacements.push({
433
+ end: node.end,
434
+ start: node.start,
435
+ value: '__wyw_import_meta_env',
436
+ });
437
+ });
438
+ return applyReplacements(code, replacements);
439
+ };
440
+ function collectDynamicImportAndRequireFallbackReplacements(code, filename, options) {
441
+ const eventEmitter = options.eventEmitter ?? EventEmitter.dummy;
442
+ const dynamicImportCandidates = [];
443
+ const requireFallbackCandidates = [];
444
+ eventEmitter.perf('transform:preeval:dynamicImportRequireFallback:scan', () => {
445
+ visit(parseOxc(code, filename), createScope(null, 'root'), (node, scope) => {
446
+ if (options.rewriteDynamicImports &&
447
+ node.type === 'ImportExpression') {
448
+ dynamicImportCandidates.push(node);
449
+ }
450
+ if (!options.addRequireFallback || node.type !== 'CallExpression') {
451
+ return;
452
+ }
453
+ const call = node;
454
+ if (call.callee.type !== 'Identifier' ||
455
+ call.callee.name !== 'require' ||
456
+ hasBinding(scope, 'require') ||
457
+ call.arguments.length !== 1) {
458
+ return;
459
+ }
460
+ const [firstArg] = call.arguments;
461
+ if (!firstArg ||
462
+ firstArg.type === 'SpreadElement' ||
463
+ isLiteralRequireArg(firstArg)) {
464
+ return;
465
+ }
466
+ requireFallbackCandidates.push({
467
+ call,
468
+ scope,
469
+ });
470
+ });
471
+ });
472
+ const replacements = [];
473
+ eventEmitter.perf('transform:preeval:dynamicImport', () => {
474
+ dynamicImportCandidates.forEach((importExpression) => {
475
+ const argument = importExpression.source;
476
+ const nextArgument = isStringLikeExpression(argument)
477
+ ? unwrapExpression(argument)
478
+ : argument;
479
+ replacements.push({
480
+ end: importExpression.end,
481
+ start: importExpression.start,
482
+ value: `__wyw_dynamic_import(${dynamicImportArgumentCode(code, nextArgument)})`,
483
+ });
484
+ });
485
+ });
486
+ eventEmitter.perf('transform:preeval:requireFallback', () => {
487
+ requireFallbackCandidates.forEach(({ call, scope }) => {
488
+ const [firstArg] = call.arguments;
489
+ if (!firstArg || firstArg.type === 'SpreadElement') {
490
+ return;
491
+ }
492
+ const staticValue = evaluateStaticValue(firstArg, scope);
493
+ if (typeof staticValue === 'string' &&
494
+ isFileLikeRequireSpecifier(staticValue)) {
495
+ replacements.push({
496
+ end: firstArg.end,
497
+ start: firstArg.start,
498
+ value: JSON.stringify(staticValue),
499
+ });
500
+ return;
501
+ }
502
+ replacements.push({
503
+ end: firstArg.end,
504
+ start: firstArg.end,
505
+ value: ', true',
506
+ });
507
+ });
508
+ });
509
+ return replacements;
510
+ }
511
+ export const rewriteDynamicImportsWithOxc = (code, filename) => {
512
+ const replacements = collectDynamicImportAndRequireFallbackReplacements(code, filename, {
513
+ addRequireFallback: false,
514
+ rewriteDynamicImports: true,
515
+ });
516
+ return applyReplacements(code, replacements);
517
+ };
518
+ export const addRequireFallbackWithOxc = (code, filename) => {
519
+ const replacements = collectDynamicImportAndRequireFallbackReplacements(code, filename, {
520
+ addRequireFallback: true,
521
+ rewriteDynamicImports: false,
522
+ });
523
+ return applyReplacements(code, replacements);
524
+ };
525
+ export const rewriteDynamicImportsAndAddRequireFallbackWithOxc = (code, filename, options) => {
526
+ const replacements = collectDynamicImportAndRequireFallbackReplacements(code, filename, options);
527
+ return applyReplacements(code, replacements);
528
+ };
529
+ const isBindingPosition = (node, parent) => {
530
+ if (!parent) {
531
+ return false;
532
+ }
533
+ if (parent.type === 'VariableDeclarator' && parent.id === node) {
534
+ return true;
535
+ }
536
+ if ((parent.type === 'FunctionDeclaration' ||
537
+ parent.type === 'FunctionExpression' ||
538
+ parent.type === 'ClassDeclaration' ||
539
+ parent.type === 'ClassExpression') &&
540
+ parent.id === node) {
541
+ return true;
542
+ }
543
+ if (parent.type === 'ImportSpecifier' &&
544
+ (parent.local === node || parent.imported === node)) {
545
+ return true;
546
+ }
547
+ if ((parent.type === 'ImportDefaultSpecifier' ||
548
+ parent.type === 'ImportNamespaceSpecifier') &&
549
+ parent.local === node) {
550
+ return true;
551
+ }
552
+ if (parent.type === 'ExportSpecifier' &&
553
+ (parent.local === node || parent.exported === node)) {
554
+ return true;
555
+ }
556
+ return false;
557
+ };
558
+ const isPropertyOnlyIdentifier = (node, parent) => {
559
+ if (!parent) {
560
+ return false;
561
+ }
562
+ if (parent.type === 'MemberExpression' &&
563
+ !parent.computed &&
564
+ parent.property === node) {
565
+ return true;
566
+ }
567
+ if ((parent.type === 'Property' ||
568
+ parent.type === 'MethodDefinition' ||
569
+ parent.type === 'PropertyDefinition') &&
570
+ !parent.computed &&
571
+ parent.key === node) {
572
+ return true;
573
+ }
574
+ return false;
575
+ };
576
+ const isTypeContext = (ancestors) => ancestors.some((ancestor) => ancestor.type.startsWith('TS') || ancestor.type.startsWith('JSDoc'));
577
+ const isInsideTypeof = (ancestors) => ancestors.some((ancestor) => ancestor.type === 'UnaryExpression' && ancestor.operator === 'typeof');
578
+ const isInsideImportDeclaration = (ancestors) => ancestors.some((ancestor) => ancestor.type === 'ImportDeclaration');
579
+ function findLastAncestor(ancestors, predicate) {
580
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
581
+ const ancestor = ancestors[idx];
582
+ if (predicate(ancestor)) {
583
+ return ancestor;
584
+ }
585
+ }
586
+ return null;
587
+ }
588
+ const findRemovableOwner = (node, ancestors) => {
589
+ let owner = node;
590
+ let ownerAncestorIndex = -1;
591
+ if (!removableOwnerTypes.has(node.type)) {
592
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
593
+ const ancestor = ancestors[idx];
594
+ if (removableOwnerTypes.has(ancestor.type)) {
595
+ owner = ancestor;
596
+ ownerAncestorIndex = idx;
597
+ break;
598
+ }
599
+ }
600
+ }
601
+ const parent = ownerAncestorIndex > 0 ? ancestors[ownerAncestorIndex - 1] : null;
602
+ if (parent?.type === 'ExportNamedDeclaration' &&
603
+ 'declaration' in parent &&
604
+ parent.declaration === owner) {
605
+ return parent;
606
+ }
607
+ return owner;
608
+ };
609
+ const collectReExportedLocalNames = (program) => {
610
+ const names = new Set();
611
+ for (const stmt of program.body) {
612
+ if (stmt.type !== 'ExportNamedDeclaration' ||
613
+ stmt.declaration ||
614
+ stmt.source) {
615
+ continue;
616
+ }
617
+ for (const spec of stmt.specifiers) {
618
+ if (spec.type === 'ExportSpecifier' && spec.local.type === 'Identifier') {
619
+ names.add(spec.local.name);
620
+ }
621
+ }
622
+ }
623
+ return names;
624
+ };
625
+ // When an offending identifier sits inside the value of a top-level export,
626
+ // removing the surrounding declaration would strip the export binding too.
627
+ // ESM linker then fails on consumers' `import { name } from '...'` because the
628
+ // named export no longer exists. To keep the binding alive, replace just the
629
+ // value (declarator init or default-export expression) with `undefined`.
630
+ const findExportedBindingProtection = (node, ancestors, reExportedLocalNames) => {
631
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
632
+ const ancestor = ancestors[idx];
633
+ if (ancestor.type === 'ExportDefaultDeclaration') {
634
+ const decl = ancestor.declaration;
635
+ if (decl && decl !== node && 'start' in decl && 'end' in decl) {
636
+ return { start: decl.start, end: decl.end, value: 'undefined' };
637
+ }
638
+ return null;
639
+ }
640
+ if (ancestor.type !== 'VariableDeclarator') {
641
+ continue;
642
+ }
643
+ if (ancestor.id.type !== 'Identifier' ||
644
+ !ancestor.init ||
645
+ ancestor.init === node) {
646
+ return null;
647
+ }
648
+ const varDecl = ancestors[idx - 1];
649
+ const wrapper = ancestors[idx - 2] ?? null;
650
+ if (varDecl?.type !== 'VariableDeclaration') {
651
+ return null;
652
+ }
653
+ const isDirectExport = wrapper?.type === 'ExportNamedDeclaration' &&
654
+ wrapper.declaration === varDecl;
655
+ const isTopLevelDeclaration = wrapper === null || wrapper?.type === 'Program';
656
+ const isReExported = isTopLevelDeclaration && reExportedLocalNames.has(ancestor.id.name);
657
+ if (!isDirectExport && !isReExported) {
658
+ return null;
659
+ }
660
+ return {
661
+ start: ancestor.init.start,
662
+ end: ancestor.init.end,
663
+ value: 'undefined',
664
+ };
665
+ }
666
+ return null;
667
+ };
668
+ const findPromiseCallbackOwner = (ancestors) => {
669
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
670
+ const ancestor = ancestors[idx];
671
+ if (ancestor.type === 'NewExpression' &&
672
+ ancestor.callee.type === 'Identifier' &&
673
+ ancestor.callee.name === 'Promise') {
674
+ return ancestor;
675
+ }
676
+ if (ancestor.type === 'CallExpression' &&
677
+ ancestor.callee.type === 'MemberExpression' &&
678
+ promiseCallbackMethods.has(getMemberPropertyName(ancestor.callee) ?? '')) {
679
+ return ancestor;
680
+ }
681
+ }
682
+ return null;
683
+ };
684
+ const containsForbiddenIdentifier = (node) => {
685
+ if (node.type === 'Identifier' && alwaysForbiddenIdentifiers.has(node.name)) {
686
+ return true;
687
+ }
688
+ return getChildren(node).some(containsForbiddenIdentifier);
689
+ };
690
+ const collectWindowScopedNames = (program) => {
691
+ const windowScopedNames = new Set();
692
+ visit(program, createScope(null, 'root'), (node, scope) => {
693
+ if (node.type !== 'MemberExpression' ||
694
+ node.object.type !== 'Identifier' ||
695
+ node.object.name !== 'window' ||
696
+ hasBinding(scope, 'window')) {
697
+ return;
698
+ }
699
+ const propertyName = getMemberPropertyName(node);
700
+ if (propertyName) {
701
+ windowScopedNames.add(propertyName);
702
+ }
703
+ });
704
+ return windowScopedNames;
705
+ };
706
+ const containsForbiddenReference = (node, scope, windowScopedNames, derivedForbiddenBindings = new Set()) => {
707
+ let found = false;
708
+ visit(node, scope, (child, childScope, parent, ancestors) => {
709
+ if (found ||
710
+ child.type !== 'Identifier' ||
711
+ isTypeContext(ancestors) ||
712
+ isInsideTypeof(ancestors) ||
713
+ isPropertyOnlyIdentifier(child, parent) ||
714
+ isBindingPosition(child, parent)) {
715
+ return;
716
+ }
717
+ const bindingKey = getBindingKey(childScope, child.name);
718
+ if (alwaysForbiddenIdentifiers.has(child.name) ||
719
+ (forbiddenGlobals.has(child.name) &&
720
+ !hasBinding(childScope, child.name)) ||
721
+ (windowScopedNames.has(child.name) &&
722
+ !hasBinding(childScope, child.name)) ||
723
+ (bindingKey !== null && derivedForbiddenBindings.has(bindingKey))) {
724
+ found = true;
725
+ }
726
+ });
727
+ return found;
728
+ };
729
+ const nameFromModuleExport = (node) => {
730
+ if (node.type === 'Identifier') {
731
+ return node.name;
732
+ }
733
+ if (node.type === 'Literal' && typeof node.value === 'string') {
734
+ return node.value;
735
+ }
736
+ return null;
737
+ };
738
+ const collectImportBindings = (code, filename, program) => {
739
+ const bindings = new Map();
740
+ const addBinding = (binding) => {
741
+ bindings.set(`${binding.local}\0${binding.source}\0${binding.imported}`, binding);
742
+ };
743
+ program.body.forEach((statement) => {
744
+ if (statement.type !== 'ImportDeclaration') {
745
+ return;
746
+ }
747
+ const source = statement.source.value;
748
+ statement.specifiers.forEach((specifier) => {
749
+ if (specifier.type === 'ImportDefaultSpecifier') {
750
+ addBinding({
751
+ imported: 'default',
752
+ local: specifier.local.name,
753
+ source,
754
+ });
755
+ return;
756
+ }
757
+ if (specifier.type === 'ImportNamespaceSpecifier') {
758
+ addBinding({
759
+ imported: '*',
760
+ local: specifier.local.name,
761
+ source,
762
+ });
763
+ return;
764
+ }
765
+ const imported = nameFromModuleExport(specifier.imported);
766
+ if (!imported) {
767
+ return;
768
+ }
769
+ addBinding({
770
+ imported,
771
+ local: specifier.local.name,
772
+ source,
773
+ });
774
+ });
775
+ });
776
+ if (!requireCallRe.test(code)) {
777
+ return [...bindings.values()];
778
+ }
779
+ collectOxcExportsAndImports(code, filename).imports.forEach((item) => {
780
+ if (item.imported === 'side-effect') {
781
+ return;
782
+ }
783
+ addBinding({
784
+ imported: item.imported,
785
+ local: item.local.code,
786
+ source: item.source,
787
+ });
788
+ if (item.local.name && item.local.name !== item.local.code) {
789
+ addBinding({
790
+ imported: item.imported,
791
+ local: item.local.name,
792
+ source: item.source,
793
+ });
794
+ }
795
+ });
796
+ return [...bindings.values()];
797
+ };
798
+ const getImportBinding = (imports, local) => imports.find((item) => item.local === local);
799
+ function unwrapSequenceCallee(node) {
800
+ if (node.type === 'SequenceExpression' &&
801
+ node.expressions.length === 2 &&
802
+ node.expressions[0]?.type === 'Literal' &&
803
+ node.expressions[0].value === 0) {
804
+ return node.expressions[1];
805
+ }
806
+ return node;
807
+ }
808
+ const getExpressionImportKey = (node) => {
809
+ const expression = unwrapSequenceCallee(node);
810
+ if (expression.type === 'Identifier') {
811
+ return expression.name;
812
+ }
813
+ if (expression.type !== 'MemberExpression') {
814
+ return null;
815
+ }
816
+ if (expression.object.type !== 'Identifier') {
817
+ return null;
818
+ }
819
+ const propertyName = getMemberPropertyName(expression);
820
+ return propertyName ? `${expression.object.name}.${propertyName}` : null;
821
+ };
822
+ const isHookOrCreateElement = (name) => name === 'createElement' || /use[A-Z]/.test(name);
823
+ const getInnermostCallee = (call) => {
824
+ let callee = unwrapSequenceCallee(call.callee);
825
+ while (callee.type === 'CallExpression') {
826
+ callee = unwrapSequenceCallee(callee.callee);
827
+ }
828
+ return callee;
829
+ };
830
+ const getImportForExpression = (node, imports) => {
831
+ const expression = unwrapSequenceCallee(node);
832
+ const directMatchKey = getExpressionImportKey(expression);
833
+ if (directMatchKey) {
834
+ const directMatch = getImportBinding(imports, directMatchKey);
835
+ if (directMatch) {
836
+ return [directMatch.source, directMatch.imported];
837
+ }
838
+ }
839
+ if (expression.type === 'Identifier') {
840
+ const matched = getImportBinding(imports, expression.name);
841
+ return matched ? [matched.source, matched.imported] : undefined;
842
+ }
843
+ if (expression.type !== 'MemberExpression') {
844
+ return undefined;
845
+ }
846
+ if (expression.object.type !== 'Identifier') {
847
+ return undefined;
848
+ }
849
+ const propertyName = getMemberPropertyName(expression);
850
+ if (!propertyName) {
851
+ return undefined;
852
+ }
853
+ const objectImport = getImportBinding(imports, expression.object.name);
854
+ if (!objectImport) {
855
+ return undefined;
856
+ }
857
+ if (objectImport.imported === 'default' ||
858
+ objectImport.imported === '*' ||
859
+ objectImport.source === 'react') {
860
+ return [objectImport.source, propertyName];
861
+ }
862
+ return undefined;
863
+ };
864
+ const isReactRuntimeCall = (call, imports) => {
865
+ const callee = unwrapSequenceCallee(call.callee);
866
+ const matched = getImportForExpression(callee, imports);
867
+ if (!matched) {
868
+ return false;
869
+ }
870
+ const [source, imported] = matched;
871
+ if (jsxRuntimeSources.has(source)) {
872
+ return true;
873
+ }
874
+ return source === 'react' && isHookOrCreateElement(imported);
875
+ };
876
+ const isHocCall = (call, hocs, imports) => {
877
+ const matched = getImportForExpression(getInnermostCallee(call), imports);
878
+ return !!matched && hocs[matched[0]]?.includes(matched[1]);
879
+ };
880
+ const isInsideHocCall = (ancestors, hocs, imports) => ancestors.some((ancestor) => ancestor.type === 'CallExpression' && isHocCall(ancestor, hocs, imports));
881
+ const getComponentTypes = (options) => {
882
+ const componentTypes = {
883
+ ...(options?.componentTypes ?? { react: [defaultPlaceholder] }),
884
+ };
885
+ const reactTypes = componentTypes.react;
886
+ if (Array.isArray(reactTypes) && reactTypes.includes(defaultPlaceholder)) {
887
+ const idx = reactTypes.indexOf(defaultPlaceholder);
888
+ componentTypes.react = [...reactTypes];
889
+ componentTypes.react.splice(idx, 1, ...defaultReactComponentTypes);
890
+ }
891
+ return componentTypes;
892
+ };
893
+ const getHocs = (options) => {
894
+ const hocs = {
895
+ ...(options?.hocs ?? {}),
896
+ };
897
+ const reactHocs = new Set([...defaultReactHocs, ...(hocs.react ?? [])]);
898
+ hocs.react = [...reactHocs];
899
+ return hocs;
900
+ };
901
+ const getTypeImport = (node, imports) => {
902
+ if (node.type === 'Identifier') {
903
+ const matched = getImportBinding(imports, node.name);
904
+ return matched ? [matched.source, matched.imported] : undefined;
905
+ }
906
+ if (node.type !== 'TSQualifiedName') {
907
+ return undefined;
908
+ }
909
+ if (node.left.type !== 'Identifier') {
910
+ return undefined;
911
+ }
912
+ const matched = getImportBinding(imports, node.left.name);
913
+ return matched ? [matched.source, node.right.name] : undefined;
914
+ };
915
+ const isComponentTypeMatch = (id, componentTypes, imports) => {
916
+ if (id.type !== 'Identifier') {
917
+ return false;
918
+ }
919
+ const annotation = id.typeAnnotation;
920
+ if (!annotation ||
921
+ annotation.type !== 'TSTypeAnnotation' ||
922
+ annotation.typeAnnotation.type !== 'TSTypeReference') {
923
+ return false;
924
+ }
925
+ const matched = getTypeImport(annotation.typeAnnotation.typeName, imports);
926
+ return !!matched && componentTypes[matched[0]]?.includes(matched[1]);
927
+ };
928
+ const getClassName = (node) => node.type === 'ClassDeclaration' && node.id ? node.id.name : null;
929
+ const isFunctionLikeNode = (node) => node.type === 'FunctionDeclaration' ||
930
+ node.type === 'FunctionExpression' ||
931
+ node.type === 'ArrowFunctionExpression';
932
+ const isImmediatelyInvokedFunction = (fnNode, ancestors, fnIndex) => {
933
+ // Walk past any ParenthesizedExpression / SequenceExpression wrappers that
934
+ // sit between the function and its enclosing CallExpression. oxc-parser
935
+ // preserves ParenthesizedExpression nodes, so `(() => {...})()` shows up
936
+ // as CallExpression -> ParenthesizedExpression -> ArrowFunctionExpression.
937
+ let child = fnNode;
938
+ for (let idx = fnIndex - 1; idx >= 0; idx -= 1) {
939
+ const ancestor = ancestors[idx];
940
+ if (ancestor.type === 'ParenthesizedExpression' &&
941
+ 'expression' in ancestor &&
942
+ ancestor.expression === child) {
943
+ child = ancestor;
944
+ continue;
945
+ }
946
+ if (ancestor.type === 'SequenceExpression' &&
947
+ Array.isArray(ancestor.expressions) &&
948
+ ancestor.expressions[ancestor.expressions.length - 1] === child) {
949
+ child = ancestor;
950
+ continue;
951
+ }
952
+ return ancestor.type === 'CallExpression' && ancestor.callee === child;
953
+ }
954
+ return false;
955
+ };
956
+ // A reference is "deferred" when it lives inside a function body that is
957
+ // not immediately invoked. Module preeval reads exports without calling
958
+ // them, so deferred references never run and must not be sanitized — that
959
+ // would silently drop the binding (or remove the entire export) and break
960
+ // importers that expect the function to be callable.
961
+ const isInDeferredFunctionScope = (ancestors) => {
962
+ for (let idx = ancestors.length - 1; idx >= 0; idx -= 1) {
963
+ const ancestor = ancestors[idx];
964
+ if (!isFunctionLikeNode(ancestor)) {
965
+ continue;
966
+ }
967
+ if (!isImmediatelyInvokedFunction(ancestor, ancestors, idx)) {
968
+ return true;
969
+ }
970
+ }
971
+ return false;
972
+ };
973
+ const findFunctionReplacement = (ancestors) => {
974
+ const renderMethod = findLastAncestor(ancestors, (ancestor) => ancestor.type === 'MethodDefinition' &&
975
+ ancestor.key.type === 'Identifier' &&
976
+ ancestor.key.name === 'render');
977
+ if (renderMethod) {
978
+ const classDecl = findLastAncestor(ancestors, (ancestor) => ancestor.type === 'ClassDeclaration');
979
+ const className = classDecl ? getClassName(classDecl) : null;
980
+ if (classDecl && className) {
981
+ return {
982
+ start: classDecl.start,
983
+ end: classDecl.end,
984
+ value: `function ${className}() { return null; }`,
985
+ };
986
+ }
987
+ }
988
+ const functionNode = findLastAncestor(ancestors, isFunctionLikeNode);
989
+ if (!functionNode) {
990
+ return null;
991
+ }
992
+ if (functionNode.type === 'ArrowFunctionExpression') {
993
+ return {
994
+ start: functionNode.start,
995
+ end: functionNode.end,
996
+ value: `${functionNode.async ? 'async ' : ''}() => { return null; }`,
997
+ };
998
+ }
999
+ if (functionNode.type === 'FunctionDeclaration') {
1000
+ return {
1001
+ start: functionNode.start,
1002
+ end: functionNode.end,
1003
+ value: `${functionNode.async ? 'async ' : ''}function ${functionNode.id?.name ?? ''}() { return null; }`,
1004
+ };
1005
+ }
1006
+ return {
1007
+ start: functionNode.body.start,
1008
+ end: functionNode.body.end,
1009
+ value: '{ return null; }',
1010
+ };
1011
+ };
1012
+ const normalizeReplacements = (replacements) => {
1013
+ const sorted = [...replacements].sort((a, b) => a.start === b.start ? b.end - a.end : a.start - b.start);
1014
+ const result = [];
1015
+ sorted.forEach((replacement) => {
1016
+ const last = result[result.length - 1];
1017
+ if (last &&
1018
+ replacement.start >= last.start &&
1019
+ replacement.end <= last.end) {
1020
+ return;
1021
+ }
1022
+ result.push(replacement);
1023
+ });
1024
+ return result;
1025
+ };
1026
+ export const removeDangerousCodeWithOxc = (code, filename, options) => {
1027
+ const replacements = [];
1028
+ const derivedForbiddenBindings = new Set();
1029
+ const program = parseOxc(code, filename);
1030
+ const imports = collectImportBindings(code, filename, program);
1031
+ const componentTypes = getComponentTypes(options);
1032
+ const hocs = getHocs(options);
1033
+ const hasHocs = Object.keys(hocs).length > 0;
1034
+ const windowScopedNames = windowTokenRe.test(code)
1035
+ ? collectWindowScopedNames(program)
1036
+ : new Set();
1037
+ const reExportedLocalNames = collectReExportedLocalNames(program);
1038
+ const derivedBindingDiscovery = { found: true };
1039
+ while (derivedBindingDiscovery.found) {
1040
+ derivedBindingDiscovery.found = false;
1041
+ visit(program, createScope(null, 'root'), (node, scope) => {
1042
+ if (node.type !== 'VariableDeclarator' ||
1043
+ node.id.type !== 'Identifier' ||
1044
+ !node.init) {
1045
+ return;
1046
+ }
1047
+ const bindingKey = getBindingKey(scope, node.id.name);
1048
+ if (!bindingKey || derivedForbiddenBindings.has(bindingKey)) {
1049
+ return;
1050
+ }
1051
+ if (containsForbiddenIdentifier(node.init) ||
1052
+ containsForbiddenReference(node.init, scope, windowScopedNames, derivedForbiddenBindings)) {
1053
+ derivedForbiddenBindings.add(bindingKey);
1054
+ derivedBindingDiscovery.found = true;
1055
+ }
1056
+ });
1057
+ }
1058
+ visit(program, createScope(null, 'root'), (node, scope, parent, ancestors) => {
1059
+ if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
1060
+ replacements.push(findFunctionReplacement(ancestors) ?? {
1061
+ start: node.start,
1062
+ end: node.end,
1063
+ value: 'null',
1064
+ });
1065
+ return;
1066
+ }
1067
+ if (node.type === 'CallExpression') {
1068
+ if (isReactRuntimeCall(node, imports)) {
1069
+ const replacement = findFunctionReplacement(ancestors);
1070
+ if (replacement) {
1071
+ replacements.push(replacement);
1072
+ }
1073
+ return;
1074
+ }
1075
+ if (hasHocs && isHocCall(node, hocs, imports)) {
1076
+ replacements.push({
1077
+ start: node.start,
1078
+ end: node.end,
1079
+ value: '() => null',
1080
+ });
1081
+ return;
1082
+ }
1083
+ }
1084
+ if (node.type === 'VariableDeclarator' &&
1085
+ node.id.type === 'Identifier' &&
1086
+ node.init &&
1087
+ isComponentTypeMatch(node.id, componentTypes, imports)) {
1088
+ replacements.push({
1089
+ start: node.init.start,
1090
+ end: node.init.end,
1091
+ value: '() => null',
1092
+ });
1093
+ return;
1094
+ }
1095
+ if (node.type === 'UnaryExpression' &&
1096
+ node.operator === 'typeof' &&
1097
+ node.argument.type === 'Identifier' &&
1098
+ ssrCheckFields.has(node.argument.name) &&
1099
+ !hasBinding(scope, node.argument.name)) {
1100
+ replacements.push({
1101
+ start: node.start,
1102
+ end: node.end,
1103
+ value: '"undefined"',
1104
+ });
1105
+ return;
1106
+ }
1107
+ if (node.type === 'MetaProperty') {
1108
+ const owner = findRemovableOwner(node, ancestors);
1109
+ replacements.push({ start: owner.start, end: owner.end, value: '' });
1110
+ return;
1111
+ }
1112
+ if (node.type !== 'Identifier' ||
1113
+ isTypeContext(ancestors) ||
1114
+ isInsideTypeof(ancestors) ||
1115
+ isInsideImportDeclaration(ancestors)) {
1116
+ return;
1117
+ }
1118
+ if (isPropertyOnlyIdentifier(node, parent)) {
1119
+ return;
1120
+ }
1121
+ const isAlwaysForbidden = alwaysForbiddenIdentifiers.has(node.name);
1122
+ const bindingKey = getBindingKey(scope, node.name);
1123
+ const isDerivedForbidden = bindingKey !== null && derivedForbiddenBindings.has(bindingKey);
1124
+ const isWindowScoped = windowScopedNames.has(node.name) && !hasBinding(scope, node.name);
1125
+ const isForbiddenGlobal = forbiddenGlobals.has(node.name) && !hasBinding(scope, node.name);
1126
+ if (!isAlwaysForbidden &&
1127
+ !isDerivedForbidden &&
1128
+ !isWindowScoped &&
1129
+ !isForbiddenGlobal) {
1130
+ return;
1131
+ }
1132
+ if (!isAlwaysForbidden && isInDeferredFunctionScope(ancestors)) {
1133
+ return;
1134
+ }
1135
+ if (hasHocs && isInsideHocCall(ancestors, hocs, imports)) {
1136
+ return;
1137
+ }
1138
+ if (isBindingPosition(node, parent) && !isAlwaysForbidden) {
1139
+ return;
1140
+ }
1141
+ if (parent?.type === 'ExportDefaultDeclaration' &&
1142
+ parent.declaration === node) {
1143
+ return;
1144
+ }
1145
+ if (generatedProcessorHelperNameRe.test(node.name) &&
1146
+ hasBinding(scope, node.name)) {
1147
+ return;
1148
+ }
1149
+ const generatedHelperDeclarator = findLastAncestor(ancestors, (ancestor) => ancestor.type === 'VariableDeclarator' &&
1150
+ ancestor.id.type === 'Identifier' &&
1151
+ generatedProcessorHelperNameRe.test(ancestor.id.name));
1152
+ if (generatedHelperDeclarator) {
1153
+ return;
1154
+ }
1155
+ if (parent?.type === 'Property' &&
1156
+ parent.value === node &&
1157
+ hasBinding(scope, node.name)) {
1158
+ return;
1159
+ }
1160
+ if (parent?.type === 'Property' && parent.value === node) {
1161
+ replacements.push({
1162
+ start: node.start,
1163
+ end: node.end,
1164
+ value: parent.shorthand ? `${node.name}: undefined` : 'undefined',
1165
+ });
1166
+ return;
1167
+ }
1168
+ const grandparent = ancestors[ancestors.length - 2] ?? null;
1169
+ if (parent?.type === 'MemberExpression' &&
1170
+ parent.object === node &&
1171
+ grandparent?.type === 'SpreadElement' &&
1172
+ grandparent.argument === parent) {
1173
+ replacements.push({
1174
+ start: grandparent.start,
1175
+ end: grandparent.end,
1176
+ value: '...{}',
1177
+ });
1178
+ return;
1179
+ }
1180
+ const exportProtection = findExportedBindingProtection(node, ancestors, reExportedLocalNames);
1181
+ if (exportProtection) {
1182
+ replacements.push(exportProtection);
1183
+ return;
1184
+ }
1185
+ const promiseOwner = findPromiseCallbackOwner(ancestors);
1186
+ const owner = promiseOwner
1187
+ ? findRemovableOwner(promiseOwner, ancestors)
1188
+ : findRemovableOwner(node, ancestors);
1189
+ replacements.push({ start: owner.start, end: owner.end, value: '' });
1190
+ });
1191
+ return applyReplacements(code, normalizeReplacements(replacements));
1192
+ };