@wyw-in-js/transform 0.1.0

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 (480) hide show
  1. package/LICENSE +21 -0
  2. package/esm/babel.js +2 -0
  3. package/esm/babel.js.map +1 -0
  4. package/esm/cache.js +80 -0
  5. package/esm/cache.js.map +1 -0
  6. package/esm/debug/fileReporter.js +144 -0
  7. package/esm/debug/fileReporter.js.map +1 -0
  8. package/esm/evaluators/index.js +14 -0
  9. package/esm/evaluators/index.js.map +1 -0
  10. package/esm/index.js +24 -0
  11. package/esm/index.js.map +1 -0
  12. package/esm/module.js +316 -0
  13. package/esm/module.js.map +1 -0
  14. package/esm/options/babel-merge.d.js +2 -0
  15. package/esm/options/babel-merge.d.js.map +1 -0
  16. package/esm/options/buildOptions.js +28 -0
  17. package/esm/options/buildOptions.js.map +1 -0
  18. package/esm/options/loadBabelOptions.js +24 -0
  19. package/esm/options/loadBabelOptions.js.map +1 -0
  20. package/esm/plugins/babel-transform.js +53 -0
  21. package/esm/plugins/babel-transform.js.map +1 -0
  22. package/esm/plugins/collector.js +66 -0
  23. package/esm/plugins/collector.js.map +1 -0
  24. package/esm/plugins/dynamic-import.js +28 -0
  25. package/esm/plugins/dynamic-import.js.map +1 -0
  26. package/esm/plugins/preeval.js +75 -0
  27. package/esm/plugins/preeval.js.map +1 -0
  28. package/esm/plugins/shaker.js +296 -0
  29. package/esm/plugins/shaker.js.map +1 -0
  30. package/esm/shaker.js +50 -0
  31. package/esm/shaker.js.map +1 -0
  32. package/esm/transform/BaseEntrypoint.js +164 -0
  33. package/esm/transform/BaseEntrypoint.js.map +1 -0
  34. package/esm/transform/Entrypoint.helpers.js +168 -0
  35. package/esm/transform/Entrypoint.helpers.js.map +1 -0
  36. package/esm/transform/Entrypoint.js +212 -0
  37. package/esm/transform/Entrypoint.js.map +1 -0
  38. package/esm/transform/Entrypoint.types.js +2 -0
  39. package/esm/transform/Entrypoint.types.js.map +1 -0
  40. package/esm/transform/EvaluatedEntrypoint.js +6 -0
  41. package/esm/transform/EvaluatedEntrypoint.js.map +1 -0
  42. package/esm/transform/actions/AbortError.js +8 -0
  43. package/esm/transform/actions/AbortError.js.map +1 -0
  44. package/esm/transform/actions/BaseAction.js +134 -0
  45. package/esm/transform/actions/BaseAction.js.map +1 -0
  46. package/esm/transform/actions/UnprocessedEntrypointError.js +8 -0
  47. package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -0
  48. package/esm/transform/actions/actionRunner.js +73 -0
  49. package/esm/transform/actions/actionRunner.js.map +1 -0
  50. package/esm/transform/actions/types.js +2 -0
  51. package/esm/transform/actions/types.js.map +1 -0
  52. package/esm/transform/generators/baseProcessingHandlers.js +22 -0
  53. package/esm/transform/generators/baseProcessingHandlers.js.map +1 -0
  54. package/esm/transform/generators/collect.js +58 -0
  55. package/esm/transform/generators/collect.js.map +1 -0
  56. package/esm/transform/generators/evalFile.js +50 -0
  57. package/esm/transform/generators/evalFile.js.map +1 -0
  58. package/esm/transform/generators/explodeReexports.js +63 -0
  59. package/esm/transform/generators/explodeReexports.js.map +1 -0
  60. package/esm/transform/generators/extract.js +120 -0
  61. package/esm/transform/generators/extract.js.map +1 -0
  62. package/esm/transform/generators/getExports.js +73 -0
  63. package/esm/transform/generators/getExports.js.map +1 -0
  64. package/esm/transform/generators/index.js +13 -0
  65. package/esm/transform/generators/index.js.map +1 -0
  66. package/esm/transform/generators/processEntrypoint.js +43 -0
  67. package/esm/transform/generators/processEntrypoint.js.map +1 -0
  68. package/esm/transform/generators/processImports.js +23 -0
  69. package/esm/transform/generators/processImports.js.map +1 -0
  70. package/esm/transform/generators/resolveImports.js +148 -0
  71. package/esm/transform/generators/resolveImports.js.map +1 -0
  72. package/esm/transform/generators/transform.js +117 -0
  73. package/esm/transform/generators/transform.js.map +1 -0
  74. package/esm/transform/generators/workflow.js +82 -0
  75. package/esm/transform/generators/workflow.js.map +1 -0
  76. package/esm/transform/helpers/loadLinariaOptions.js +66 -0
  77. package/esm/transform/helpers/loadLinariaOptions.js.map +1 -0
  78. package/esm/transform/helpers/withDefaultServices.js +21 -0
  79. package/esm/transform/helpers/withDefaultServices.js.map +1 -0
  80. package/esm/transform/rootLog.js +3 -0
  81. package/esm/transform/rootLog.js.map +1 -0
  82. package/esm/transform/types.js +2 -0
  83. package/esm/transform/types.js.map +1 -0
  84. package/esm/transform.js +121 -0
  85. package/esm/transform.js.map +1 -0
  86. package/esm/types.js +2 -0
  87. package/esm/types.js.map +1 -0
  88. package/esm/utils/EventEmitter.js +52 -0
  89. package/esm/utils/EventEmitter.js.map +1 -0
  90. package/esm/utils/ShakerMetadata.js +2 -0
  91. package/esm/utils/ShakerMetadata.js.map +1 -0
  92. package/esm/utils/TransformMetadata.js +11 -0
  93. package/esm/utils/TransformMetadata.js.map +1 -0
  94. package/esm/utils/addIdentifierToLinariaPreval.js +68 -0
  95. package/esm/utils/addIdentifierToLinariaPreval.js.map +1 -0
  96. package/esm/utils/collectExportsAndImports.js +974 -0
  97. package/esm/utils/collectExportsAndImports.js.map +1 -0
  98. package/esm/utils/collectTemplateDependencies.js +219 -0
  99. package/esm/utils/collectTemplateDependencies.js.map +1 -0
  100. package/esm/utils/createId.js +6 -0
  101. package/esm/utils/createId.js.map +1 -0
  102. package/esm/utils/dispose-polyfill.js +6 -0
  103. package/esm/utils/dispose-polyfill.js.map +1 -0
  104. package/esm/utils/findIdentifiers.js +62 -0
  105. package/esm/utils/findIdentifiers.js.map +1 -0
  106. package/esm/utils/findPackageJSON.js +22 -0
  107. package/esm/utils/findPackageJSON.js.map +1 -0
  108. package/esm/utils/getFileIdx.js +10 -0
  109. package/esm/utils/getFileIdx.js.map +1 -0
  110. package/esm/utils/getPluginKey.js +13 -0
  111. package/esm/utils/getPluginKey.js.map +1 -0
  112. package/esm/utils/getScope.js +6 -0
  113. package/esm/utils/getScope.js.map +1 -0
  114. package/esm/utils/getSource.js +15 -0
  115. package/esm/utils/getSource.js.map +1 -0
  116. package/esm/utils/getTagProcessor.js +304 -0
  117. package/esm/utils/getTagProcessor.js.map +1 -0
  118. package/esm/utils/getVisitorKeys.js +5 -0
  119. package/esm/utils/getVisitorKeys.js.map +1 -0
  120. package/esm/utils/hasLinariaPreval.js +7 -0
  121. package/esm/utils/hasLinariaPreval.js.map +1 -0
  122. package/esm/utils/isExports.js +22 -0
  123. package/esm/utils/isExports.js.map +1 -0
  124. package/esm/utils/isGlobal.js +6 -0
  125. package/esm/utils/isGlobal.js.map +1 -0
  126. package/esm/utils/isNode.js +2 -0
  127. package/esm/utils/isNode.js.map +1 -0
  128. package/esm/utils/isNodePath.js +4 -0
  129. package/esm/utils/isNodePath.js.map +1 -0
  130. package/esm/utils/isNotNull.js +4 -0
  131. package/esm/utils/isNotNull.js.map +1 -0
  132. package/esm/utils/isRemoved.js +46 -0
  133. package/esm/utils/isRemoved.js.map +1 -0
  134. package/esm/utils/isRequire.js +13 -0
  135. package/esm/utils/isRequire.js.map +1 -0
  136. package/esm/utils/isSerializable.js +13 -0
  137. package/esm/utils/isSerializable.js.map +1 -0
  138. package/esm/utils/isTypedNode.js +6 -0
  139. package/esm/utils/isTypedNode.js.map +1 -0
  140. package/esm/utils/isUnnecessaryReactCall.js +72 -0
  141. package/esm/utils/isUnnecessaryReactCall.js.map +1 -0
  142. package/esm/utils/peek.js +2 -0
  143. package/esm/utils/peek.js.map +1 -0
  144. package/esm/utils/processTemplateExpression.js +11 -0
  145. package/esm/utils/processTemplateExpression.js.map +1 -0
  146. package/esm/utils/removeDangerousCode.js +127 -0
  147. package/esm/utils/removeDangerousCode.js.map +1 -0
  148. package/esm/utils/scopeHelpers.js +514 -0
  149. package/esm/utils/scopeHelpers.js.map +1 -0
  150. package/esm/utils/traversalCache.js +28 -0
  151. package/esm/utils/traversalCache.js.map +1 -0
  152. package/esm/utils/unwrapSequence.js +14 -0
  153. package/esm/utils/unwrapSequence.js.map +1 -0
  154. package/esm/utils/valueToLiteral.js +59 -0
  155. package/esm/utils/valueToLiteral.js.map +1 -0
  156. package/esm/utils/visitors/JSXElementsRemover.js +51 -0
  157. package/esm/utils/visitors/JSXElementsRemover.js.map +1 -0
  158. package/esm/vm/createVmContext.js +72 -0
  159. package/esm/vm/createVmContext.js.map +1 -0
  160. package/esm/vm/process.js +29 -0
  161. package/esm/vm/process.js.map +1 -0
  162. package/lib/babel.js +2 -0
  163. package/lib/babel.js.map +1 -0
  164. package/lib/cache.js +87 -0
  165. package/lib/cache.js.map +1 -0
  166. package/lib/debug/fileReporter.js +153 -0
  167. package/lib/debug/fileReporter.js.map +1 -0
  168. package/lib/evaluators/index.js +20 -0
  169. package/lib/evaluators/index.js.map +1 -0
  170. package/lib/index.js +225 -0
  171. package/lib/index.js.map +1 -0
  172. package/lib/module.js +327 -0
  173. package/lib/module.js.map +1 -0
  174. package/lib/options/babel-merge.d.js +2 -0
  175. package/lib/options/babel-merge.d.js.map +1 -0
  176. package/lib/options/buildOptions.js +35 -0
  177. package/lib/options/buildOptions.js.map +1 -0
  178. package/lib/options/loadBabelOptions.js +31 -0
  179. package/lib/options/loadBabelOptions.js.map +1 -0
  180. package/lib/plugins/babel-transform.js +60 -0
  181. package/lib/plugins/babel-transform.js.map +1 -0
  182. package/lib/plugins/collector.js +76 -0
  183. package/lib/plugins/collector.js.map +1 -0
  184. package/lib/plugins/dynamic-import.js +34 -0
  185. package/lib/plugins/dynamic-import.js.map +1 -0
  186. package/lib/plugins/preeval.js +82 -0
  187. package/lib/plugins/preeval.js.map +1 -0
  188. package/lib/plugins/shaker.js +303 -0
  189. package/lib/plugins/shaker.js.map +1 -0
  190. package/lib/shaker.js +58 -0
  191. package/lib/shaker.js.map +1 -0
  192. package/lib/transform/BaseEntrypoint.js +175 -0
  193. package/lib/transform/BaseEntrypoint.js.map +1 -0
  194. package/lib/transform/Entrypoint.helpers.js +182 -0
  195. package/lib/transform/Entrypoint.helpers.js.map +1 -0
  196. package/lib/transform/Entrypoint.js +226 -0
  197. package/lib/transform/Entrypoint.js.map +1 -0
  198. package/lib/transform/Entrypoint.types.js +2 -0
  199. package/lib/transform/Entrypoint.types.js.map +1 -0
  200. package/lib/transform/EvaluatedEntrypoint.js +13 -0
  201. package/lib/transform/EvaluatedEntrypoint.js.map +1 -0
  202. package/lib/transform/actions/AbortError.js +16 -0
  203. package/lib/transform/actions/AbortError.js.map +1 -0
  204. package/lib/transform/actions/BaseAction.js +144 -0
  205. package/lib/transform/actions/BaseAction.js.map +1 -0
  206. package/lib/transform/actions/UnprocessedEntrypointError.js +16 -0
  207. package/lib/transform/actions/UnprocessedEntrypointError.js.map +1 -0
  208. package/lib/transform/actions/actionRunner.js +82 -0
  209. package/lib/transform/actions/actionRunner.js.map +1 -0
  210. package/lib/transform/actions/types.js +2 -0
  211. package/lib/transform/actions/types.js.map +1 -0
  212. package/lib/transform/generators/baseProcessingHandlers.js +27 -0
  213. package/lib/transform/generators/baseProcessingHandlers.js.map +1 -0
  214. package/lib/transform/generators/collect.js +66 -0
  215. package/lib/transform/generators/collect.js.map +1 -0
  216. package/lib/transform/generators/evalFile.js +57 -0
  217. package/lib/transform/generators/evalFile.js.map +1 -0
  218. package/lib/transform/generators/explodeReexports.js +70 -0
  219. package/lib/transform/generators/explodeReexports.js.map +1 -0
  220. package/lib/transform/generators/extract.js +128 -0
  221. package/lib/transform/generators/extract.js.map +1 -0
  222. package/lib/transform/generators/getExports.js +80 -0
  223. package/lib/transform/generators/getExports.js.map +1 -0
  224. package/lib/transform/generators/index.js +19 -0
  225. package/lib/transform/generators/index.js.map +1 -0
  226. package/lib/transform/generators/processEntrypoint.js +49 -0
  227. package/lib/transform/generators/processEntrypoint.js.map +1 -0
  228. package/lib/transform/generators/processImports.js +29 -0
  229. package/lib/transform/generators/processImports.js.map +1 -0
  230. package/lib/transform/generators/resolveImports.js +158 -0
  231. package/lib/transform/generators/resolveImports.js.map +1 -0
  232. package/lib/transform/generators/transform.js +130 -0
  233. package/lib/transform/generators/transform.js.map +1 -0
  234. package/lib/transform/generators/workflow.js +90 -0
  235. package/lib/transform/generators/workflow.js.map +1 -0
  236. package/lib/transform/helpers/loadLinariaOptions.js +73 -0
  237. package/lib/transform/helpers/loadLinariaOptions.js.map +1 -0
  238. package/lib/transform/helpers/withDefaultServices.js +30 -0
  239. package/lib/transform/helpers/withDefaultServices.js.map +1 -0
  240. package/lib/transform/rootLog.js +9 -0
  241. package/lib/transform/rootLog.js.map +1 -0
  242. package/lib/transform/types.js +8 -0
  243. package/lib/transform/types.js.map +1 -0
  244. package/lib/transform.js +128 -0
  245. package/lib/transform.js.map +1 -0
  246. package/lib/types.js +2 -0
  247. package/lib/types.js.map +1 -0
  248. package/lib/utils/EventEmitter.js +61 -0
  249. package/lib/utils/EventEmitter.js.map +1 -0
  250. package/lib/utils/ShakerMetadata.js +9 -0
  251. package/lib/utils/ShakerMetadata.js.map +1 -0
  252. package/lib/utils/TransformMetadata.js +19 -0
  253. package/lib/utils/TransformMetadata.js.map +1 -0
  254. package/lib/utils/addIdentifierToLinariaPreval.js +75 -0
  255. package/lib/utils/addIdentifierToLinariaPreval.js.map +1 -0
  256. package/lib/utils/collectExportsAndImports.js +990 -0
  257. package/lib/utils/collectExportsAndImports.js.map +1 -0
  258. package/lib/utils/collectTemplateDependencies.js +233 -0
  259. package/lib/utils/collectTemplateDependencies.js.map +1 -0
  260. package/lib/utils/createId.js +13 -0
  261. package/lib/utils/createId.js.map +1 -0
  262. package/lib/utils/dispose-polyfill.js +9 -0
  263. package/lib/utils/dispose-polyfill.js.map +1 -0
  264. package/lib/utils/findIdentifiers.js +73 -0
  265. package/lib/utils/findIdentifiers.js.map +1 -0
  266. package/lib/utils/findPackageJSON.js +29 -0
  267. package/lib/utils/findPackageJSON.js.map +1 -0
  268. package/lib/utils/getFileIdx.js +16 -0
  269. package/lib/utils/getFileIdx.js.map +1 -0
  270. package/lib/utils/getPluginKey.js +21 -0
  271. package/lib/utils/getPluginKey.js.map +1 -0
  272. package/lib/utils/getScope.js +12 -0
  273. package/lib/utils/getScope.js.map +1 -0
  274. package/lib/utils/getSource.js +24 -0
  275. package/lib/utils/getSource.js.map +1 -0
  276. package/lib/utils/getTagProcessor.js +318 -0
  277. package/lib/utils/getTagProcessor.js.map +1 -0
  278. package/lib/utils/getVisitorKeys.js +11 -0
  279. package/lib/utils/getVisitorKeys.js.map +1 -0
  280. package/lib/utils/hasLinariaPreval.js +13 -0
  281. package/lib/utils/hasLinariaPreval.js.map +1 -0
  282. package/lib/utils/isExports.js +27 -0
  283. package/lib/utils/isExports.js.map +1 -0
  284. package/lib/utils/isGlobal.js +13 -0
  285. package/lib/utils/isGlobal.js.map +1 -0
  286. package/lib/utils/isNode.js +9 -0
  287. package/lib/utils/isNode.js.map +1 -0
  288. package/lib/utils/isNodePath.js +10 -0
  289. package/lib/utils/isNodePath.js.map +1 -0
  290. package/lib/utils/isNotNull.js +10 -0
  291. package/lib/utils/isNotNull.js.map +1 -0
  292. package/lib/utils/isRemoved.js +52 -0
  293. package/lib/utils/isRemoved.js.map +1 -0
  294. package/lib/utils/isRequire.js +18 -0
  295. package/lib/utils/isRequire.js.map +1 -0
  296. package/lib/utils/isSerializable.js +19 -0
  297. package/lib/utils/isSerializable.js.map +1 -0
  298. package/lib/utils/isTypedNode.js +13 -0
  299. package/lib/utils/isTypedNode.js.map +1 -0
  300. package/lib/utils/isUnnecessaryReactCall.js +81 -0
  301. package/lib/utils/isUnnecessaryReactCall.js.map +1 -0
  302. package/lib/utils/peek.js +9 -0
  303. package/lib/utils/peek.js.map +1 -0
  304. package/lib/utils/processTemplateExpression.js +18 -0
  305. package/lib/utils/processTemplateExpression.js.map +1 -0
  306. package/lib/utils/removeDangerousCode.js +134 -0
  307. package/lib/utils/removeDangerousCode.js.map +1 -0
  308. package/lib/utils/scopeHelpers.js +544 -0
  309. package/lib/utils/scopeHelpers.js.map +1 -0
  310. package/lib/utils/traversalCache.js +38 -0
  311. package/lib/utils/traversalCache.js.map +1 -0
  312. package/lib/utils/unwrapSequence.js +20 -0
  313. package/lib/utils/unwrapSequence.js.map +1 -0
  314. package/lib/utils/valueToLiteral.js +65 -0
  315. package/lib/utils/valueToLiteral.js.map +1 -0
  316. package/lib/utils/visitors/JSXElementsRemover.js +57 -0
  317. package/lib/utils/visitors/JSXElementsRemover.js.map +1 -0
  318. package/lib/vm/createVmContext.js +80 -0
  319. package/lib/vm/createVmContext.js.map +1 -0
  320. package/lib/vm/process.js +38 -0
  321. package/lib/vm/process.js.map +1 -0
  322. package/package.json +63 -0
  323. package/types/babel.d.ts +2 -0
  324. package/types/babel.js +2 -0
  325. package/types/cache.d.ts +24 -0
  326. package/types/cache.js +85 -0
  327. package/types/debug/fileReporter.d.ts +27 -0
  328. package/types/debug/fileReporter.js +151 -0
  329. package/types/evaluators/index.d.ts +10 -0
  330. package/types/evaluators/index.js +15 -0
  331. package/types/index.d.ts +30 -0
  332. package/types/index.js +69 -0
  333. package/types/module.d.ts +62 -0
  334. package/types/module.js +318 -0
  335. package/types/options/buildOptions.d.ts +7 -0
  336. package/types/options/buildOptions.js +35 -0
  337. package/types/options/loadBabelOptions.d.ts +3 -0
  338. package/types/options/loadBabelOptions.js +27 -0
  339. package/types/plugins/babel-transform.d.ts +4 -0
  340. package/types/plugins/babel-transform.js +49 -0
  341. package/types/plugins/collector.d.ts +16 -0
  342. package/types/plugins/collector.js +67 -0
  343. package/types/plugins/dynamic-import.d.ts +6 -0
  344. package/types/plugins/dynamic-import.js +32 -0
  345. package/types/plugins/preeval.d.ts +16 -0
  346. package/types/plugins/preeval.js +69 -0
  347. package/types/plugins/shaker.d.ts +11 -0
  348. package/types/plugins/shaker.js +299 -0
  349. package/types/shaker.d.ts +3 -0
  350. package/types/shaker.js +64 -0
  351. package/types/transform/BaseEntrypoint.d.ts +23 -0
  352. package/types/transform/BaseEntrypoint.js +182 -0
  353. package/types/transform/Entrypoint.d.ts +50 -0
  354. package/types/transform/Entrypoint.helpers.d.ts +14 -0
  355. package/types/transform/Entrypoint.helpers.js +169 -0
  356. package/types/transform/Entrypoint.js +223 -0
  357. package/types/transform/Entrypoint.types.d.ts +23 -0
  358. package/types/transform/Entrypoint.types.js +2 -0
  359. package/types/transform/EvaluatedEntrypoint.d.ts +16 -0
  360. package/types/transform/EvaluatedEntrypoint.js +9 -0
  361. package/types/transform/actions/AbortError.d.ts +4 -0
  362. package/types/transform/actions/AbortError.js +12 -0
  363. package/types/transform/actions/BaseAction.d.ts +40 -0
  364. package/types/transform/actions/BaseAction.js +149 -0
  365. package/types/transform/actions/UnprocessedEntrypointError.d.ts +6 -0
  366. package/types/transform/actions/UnprocessedEntrypointError.js +13 -0
  367. package/types/transform/actions/actionRunner.d.ts +4 -0
  368. package/types/transform/actions/actionRunner.js +86 -0
  369. package/types/transform/actions/types.d.ts +15 -0
  370. package/types/transform/actions/types.js +2 -0
  371. package/types/transform/generators/baseProcessingHandlers.d.ts +17 -0
  372. package/types/transform/generators/baseProcessingHandlers.js +23 -0
  373. package/types/transform/generators/collect.d.ts +6 -0
  374. package/types/transform/generators/collect.js +57 -0
  375. package/types/transform/generators/evalFile.d.ts +6 -0
  376. package/types/transform/generators/evalFile.js +56 -0
  377. package/types/transform/generators/explodeReexports.d.ts +7 -0
  378. package/types/transform/generators/explodeReexports.js +67 -0
  379. package/types/transform/generators/extract.d.ts +8 -0
  380. package/types/transform/generators/extract.js +116 -0
  381. package/types/transform/generators/getExports.d.ts +8 -0
  382. package/types/transform/generators/getExports.js +65 -0
  383. package/types/transform/generators/index.d.ts +15 -0
  384. package/types/transform/generators/index.js +15 -0
  385. package/types/transform/generators/processEntrypoint.d.ts +9 -0
  386. package/types/transform/generators/processEntrypoint.js +88 -0
  387. package/types/transform/generators/processImports.d.ts +5 -0
  388. package/types/transform/generators/processImports.js +21 -0
  389. package/types/transform/generators/resolveImports.d.ts +9 -0
  390. package/types/transform/generators/resolveImports.js +124 -0
  391. package/types/transform/generators/transform.d.ts +17 -0
  392. package/types/transform/generators/transform.js +115 -0
  393. package/types/transform/generators/workflow.d.ts +7 -0
  394. package/types/transform/generators/workflow.js +77 -0
  395. package/types/transform/helpers/loadLinariaOptions.d.ts +6 -0
  396. package/types/transform/helpers/loadLinariaOptions.js +86 -0
  397. package/types/transform/helpers/withDefaultServices.d.ts +5 -0
  398. package/types/transform/helpers/withDefaultServices.js +40 -0
  399. package/types/transform/rootLog.d.ts +3 -0
  400. package/types/transform/rootLog.js +5 -0
  401. package/types/transform/types.d.ts +137 -0
  402. package/types/transform/types.js +4 -0
  403. package/types/transform.d.ts +20 -0
  404. package/types/transform.js +121 -0
  405. package/types/types.d.ts +72 -0
  406. package/types/types.js +5 -0
  407. package/types/utils/EventEmitter.d.ts +58 -0
  408. package/types/utils/EventEmitter.js +61 -0
  409. package/types/utils/ShakerMetadata.d.ts +7 -0
  410. package/types/utils/ShakerMetadata.js +5 -0
  411. package/types/utils/TransformMetadata.d.ts +13 -0
  412. package/types/utils/TransformMetadata.js +17 -0
  413. package/types/utils/addIdentifierToLinariaPreval.d.ts +4 -0
  414. package/types/utils/addIdentifierToLinariaPreval.js +75 -0
  415. package/types/utils/collectExportsAndImports.d.ts +31 -0
  416. package/types/utils/collectExportsAndImports.js +962 -0
  417. package/types/utils/collectTemplateDependencies.d.ts +17 -0
  418. package/types/utils/collectTemplateDependencies.js +212 -0
  419. package/types/utils/createId.d.ts +2 -0
  420. package/types/utils/createId.js +9 -0
  421. package/types/utils/dispose-polyfill.d.ts +0 -0
  422. package/types/utils/dispose-polyfill.js +5 -0
  423. package/types/utils/findIdentifiers.d.ts +6 -0
  424. package/types/utils/findIdentifiers.js +68 -0
  425. package/types/utils/findPackageJSON.d.ts +1 -0
  426. package/types/utils/findPackageJSON.js +29 -0
  427. package/types/utils/getFileIdx.d.ts +1 -0
  428. package/types/utils/getFileIdx.js +13 -0
  429. package/types/utils/getPluginKey.d.ts +2 -0
  430. package/types/utils/getPluginKey.js +16 -0
  431. package/types/utils/getScope.d.ts +2 -0
  432. package/types/utils/getScope.js +11 -0
  433. package/types/utils/getSource.d.ts +2 -0
  434. package/types/utils/getSource.js +22 -0
  435. package/types/utils/getTagProcessor.d.ts +6 -0
  436. package/types/utils/getTagProcessor.js +315 -0
  437. package/types/utils/getVisitorKeys.d.ts +5 -0
  438. package/types/utils/getVisitorKeys.js +8 -0
  439. package/types/utils/hasLinariaPreval.d.ts +4 -0
  440. package/types/utils/hasLinariaPreval.js +9 -0
  441. package/types/utils/isExports.d.ts +6 -0
  442. package/types/utils/isExports.js +20 -0
  443. package/types/utils/isGlobal.d.ts +2 -0
  444. package/types/utils/isGlobal.js +9 -0
  445. package/types/utils/isNode.d.ts +2 -0
  446. package/types/utils/isNode.js +7 -0
  447. package/types/utils/isNodePath.d.ts +3 -0
  448. package/types/utils/isNodePath.js +7 -0
  449. package/types/utils/isNotNull.d.ts +1 -0
  450. package/types/utils/isNotNull.js +7 -0
  451. package/types/utils/isRemoved.d.ts +5 -0
  452. package/types/utils/isRemoved.js +42 -0
  453. package/types/utils/isRequire.d.ts +6 -0
  454. package/types/utils/isRequire.js +15 -0
  455. package/types/utils/isSerializable.d.ts +2 -0
  456. package/types/utils/isSerializable.js +18 -0
  457. package/types/utils/isTypedNode.d.ts +5 -0
  458. package/types/utils/isTypedNode.js +9 -0
  459. package/types/utils/isUnnecessaryReactCall.d.ts +3 -0
  460. package/types/utils/isUnnecessaryReactCall.js +76 -0
  461. package/types/utils/peek.d.ts +1 -0
  462. package/types/utils/peek.js +5 -0
  463. package/types/utils/processTemplateExpression.d.ts +5 -0
  464. package/types/utils/processTemplateExpression.js +17 -0
  465. package/types/utils/removeDangerousCode.d.ts +3 -0
  466. package/types/utils/removeDangerousCode.js +144 -0
  467. package/types/utils/scopeHelpers.d.ts +12 -0
  468. package/types/utils/scopeHelpers.js +568 -0
  469. package/types/utils/traversalCache.d.ts +5 -0
  470. package/types/utils/traversalCache.js +36 -0
  471. package/types/utils/unwrapSequence.d.ts +8 -0
  472. package/types/utils/unwrapSequence.js +17 -0
  473. package/types/utils/valueToLiteral.d.ts +3 -0
  474. package/types/utils/valueToLiteral.js +64 -0
  475. package/types/utils/visitors/JSXElementsRemover.d.ts +3 -0
  476. package/types/utils/visitors/JSXElementsRemover.js +52 -0
  477. package/types/vm/createVmContext.d.ts +7 -0
  478. package/types/vm/createVmContext.js +92 -0
  479. package/types/vm/process.d.ts +25 -0
  480. package/types/vm/process.js +32 -0
@@ -0,0 +1,514 @@
1
+ /* eslint-disable no-restricted-syntax */
2
+ /* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
3
+
4
+ import { NODE_FIELDS } from '@babel/types';
5
+ import { findIdentifiers, nonType } from './findIdentifiers';
6
+ import { getScope } from './getScope';
7
+ import { isNotNull } from './isNotNull';
8
+ import { isRemoved } from './isRemoved';
9
+ function validateField(node, key, val, field) {
10
+ if (!(field != null && field.validate)) return true;
11
+ if (field.optional && val == null) return true;
12
+ try {
13
+ field.validate(node, key, val);
14
+ return true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ }
19
+ function getBinding(path) {
20
+ const binding = getScope(path).getBinding(path.node.name);
21
+ if (!binding) {
22
+ return undefined;
23
+ }
24
+ return binding;
25
+ }
26
+ export function reference(path, referencePath = path, force = false) {
27
+ if (!force && !path.isReferencedIdentifier()) return;
28
+ const binding = getBinding(path);
29
+ if (!binding) return;
30
+ if (binding.referencePaths.includes(referencePath)) {
31
+ return;
32
+ }
33
+ binding.referenced = true;
34
+ binding.referencePaths.push(referencePath ?? path);
35
+ binding.references = binding.referencePaths.length;
36
+ }
37
+ function isReferenced(binding) {
38
+ const {
39
+ kind,
40
+ referenced,
41
+ referencePaths,
42
+ path
43
+ } = binding;
44
+ if (path.isFunctionExpression() && path.key === 'init' && path.parentPath.isVariableDeclarator()) {
45
+ // It is a function expression in a variable declarator
46
+ const id = path.parentPath.get('id');
47
+ if (id.isIdentifier()) {
48
+ const idBinding = getBinding(id);
49
+ return idBinding ? isReferenced(idBinding) : true;
50
+ }
51
+ return true;
52
+ }
53
+ if (!referenced) {
54
+ return false;
55
+ }
56
+
57
+ // If it's a param binding, we can't just remove it
58
+ // because it brakes the function signature. Keep it alive for now.
59
+ if (kind === 'param') {
60
+ return true;
61
+ }
62
+
63
+ // If all remaining references are in TS/Flow types, binding is unreferenced
64
+ return referencePaths.length > 0 || referencePaths.every(i => i.find(ancestor => ancestor.isTSType() || ancestor.isFlowType()));
65
+ }
66
+ function isReferencedConstantViolation(path, binding) {
67
+ if (path.find(p => p === binding.path)) {
68
+ // function a(flag) { return (a = function(flag) { flag ? 1 : 2 }) }
69
+ // ^ Looks crazy, yeh? Welcome to the wonderful world of transpilers!
70
+ // `a = …` here isn't a reference.
71
+ return false;
72
+ }
73
+ if (!path.isReferenced()) {
74
+ return false;
75
+ }
76
+ if (path.isAssignmentExpression() && path.parentPath.isExpressionStatement()) {
77
+ // A root assignment without a parent expression statement is not a reference
78
+ return false;
79
+ }
80
+ return true;
81
+ }
82
+ export function dereference(path) {
83
+ const binding = getBinding(path);
84
+ if (!binding) return null;
85
+ const isReference = binding.referencePaths.includes(path);
86
+ let referencesInConstantViolations = binding.constantViolations.filter(i => isReferencedConstantViolation(i, binding));
87
+ const isConstantViolation = referencesInConstantViolations.includes(path);
88
+ if (!isReference && !isConstantViolation) {
89
+ return null;
90
+ }
91
+ if (isReference) {
92
+ binding.referencePaths = binding.referencePaths.filter(i => i !== path);
93
+ binding.references -= 1;
94
+ } else {
95
+ referencesInConstantViolations = referencesInConstantViolations.filter(i => i !== path);
96
+ }
97
+ const nonTypeReferences = binding.referencePaths.filter(nonType);
98
+ binding.referenced = nonTypeReferences.length + referencesInConstantViolations.length > 0;
99
+ return binding;
100
+ }
101
+ function dereferenceAll(path) {
102
+ return findIdentifiers([path]).map(identifierPath => dereference(identifierPath)).filter(isNotNull);
103
+ }
104
+ export function referenceAll(path) {
105
+ findIdentifiers([path]).forEach(identifierPath => reference(identifierPath));
106
+ }
107
+ const deletingNodes = new WeakSet();
108
+ const isEmptyList = list => list.length === 0 || list.every(i => deletingNodes.has(i));
109
+ const getPathFromAction = action => {
110
+ if (!Array.isArray(action)) {
111
+ return action;
112
+ }
113
+ if (action[0] === 'replace' || action[0] === 'remove') {
114
+ return action[1];
115
+ }
116
+ throw new Error(`Unknown action type: ${action[0]}`);
117
+ };
118
+ function isPrototypeAssignment(path) {
119
+ if (!path.isAssignmentExpression()) {
120
+ return false;
121
+ }
122
+ const {
123
+ left
124
+ } = path.node;
125
+ if (!left) {
126
+ return false;
127
+ }
128
+ if (left.type !== 'MemberExpression') {
129
+ return false;
130
+ }
131
+ const {
132
+ object,
133
+ property
134
+ } = left;
135
+ if (!object || !property) {
136
+ return false;
137
+ }
138
+ return object.type === 'MemberExpression' && object.property.type === 'Identifier' && object.property.name === 'prototype';
139
+ }
140
+ function canFunctionBeDelete(fnPath) {
141
+ if (isPrototypeAssignment(fnPath.parentPath)) {
142
+ // It is a prototype assignment, we can't delete it since we can't find all usages
143
+ return false;
144
+ }
145
+ const fnScope = fnPath.scope;
146
+ const parentScope = fnScope.parent;
147
+ if (parentScope.parent) {
148
+ // It isn't a top-level function, so we can't delete it
149
+ return true;
150
+ }
151
+ if (fnPath.listKey === 'arguments') {
152
+ // It is passed as an argument to another function, we can't delete it
153
+ return true;
154
+ }
155
+ return false;
156
+ }
157
+ export function findActionForNode(path) {
158
+ if (isRemoved(path)) return null;
159
+ deletingNodes.add(path);
160
+ const parent = path.parentPath;
161
+ if (!parent) return ['remove', path];
162
+ if (parent.isProgram()) {
163
+ // Do not delete Program node
164
+ return ['remove', path];
165
+ }
166
+ if (parent.isClassDeclaration() || parent.isClassExpression()) {
167
+ if (path.key === 'body') {
168
+ return ['replace', path, {
169
+ type: 'ClassBody',
170
+ body: []
171
+ }];
172
+ }
173
+ }
174
+ if (parent.isFunction()) {
175
+ if (path.listKey === 'params') {
176
+ // Do not remove params of functions
177
+ return null;
178
+ }
179
+ if (path.isBlockStatement() && isEmptyList(path.get('body')) || path === parent.get('body')) {
180
+ if (!canFunctionBeDelete(parent)) {
181
+ return ['replace', parent, {
182
+ ...parent.node,
183
+ async: false,
184
+ body: {
185
+ type: 'BlockStatement',
186
+ body: [],
187
+ directives: []
188
+ },
189
+ generator: false,
190
+ params: []
191
+ }];
192
+ }
193
+ }
194
+ }
195
+ if (parent.isConditionalExpression()) {
196
+ if (path.key === 'test') {
197
+ return ['replace', parent, parent.node.alternate];
198
+ }
199
+ if (path.key === 'consequent') {
200
+ return ['replace', path, {
201
+ type: 'Identifier',
202
+ name: 'undefined'
203
+ }];
204
+ }
205
+ if (path.key === 'alternate') {
206
+ return ['replace', path, {
207
+ type: 'Identifier',
208
+ name: 'undefined'
209
+ }];
210
+ }
211
+ }
212
+ if (parent.isLogicalExpression({
213
+ operator: '&&'
214
+ })) {
215
+ return ['replace', parent, {
216
+ type: 'BooleanLiteral',
217
+ value: false
218
+ }];
219
+ }
220
+ if (parent.isLogicalExpression({
221
+ operator: '||'
222
+ })) {
223
+ return ['replace', parent, path.key === 'left' ? parent.node.right : parent.node.left];
224
+ }
225
+ if (parent.isObjectProperty()) {
226
+ // let's check if it is a special case with Object.defineProperty
227
+ const key = parent.get('key');
228
+ if (key.isIdentifier({
229
+ name: 'get'
230
+ })) {
231
+ const maybeDefineProperty = parent.parentPath.parentPath;
232
+ if (maybeDefineProperty?.isCallExpression() && maybeDefineProperty.get('callee').matchesPattern('Object.defineProperty')) {
233
+ return findActionForNode(maybeDefineProperty);
234
+ }
235
+ }
236
+ return findActionForNode(parent);
237
+ }
238
+ if (parent.isTemplateLiteral()) {
239
+ return ['replace', path, {
240
+ type: 'StringLiteral',
241
+ value: ''
242
+ }];
243
+ }
244
+ if (parent.isAssignmentExpression()) {
245
+ return findActionForNode(parent);
246
+ }
247
+ if (parent.isCallExpression()) {
248
+ return findActionForNode(parent);
249
+ }
250
+ if (parent.isForInStatement({
251
+ left: path.node
252
+ })) {
253
+ return findActionForNode(parent);
254
+ }
255
+ if (parent.isFunctionExpression({
256
+ body: path.node
257
+ }) || parent.isFunctionDeclaration() || parent.isObjectMethod() || parent.isClassMethod()) {
258
+ return findActionForNode(parent);
259
+ }
260
+ if (parent.isBlockStatement()) {
261
+ const body = parent.get('body');
262
+ if (isEmptyList(body)) {
263
+ return findActionForNode(parent);
264
+ }
265
+ if (path.listKey === 'body' && typeof path.key === 'number') {
266
+ if (path.key > 0) {
267
+ // We can check whether the previous one can be removed
268
+ const prevStatement = body[path.key - 1];
269
+ if (prevStatement.isIfStatement() && prevStatement.get('consequent').isReturnStatement()) {
270
+ // It's `if (…) return …`, we can remove it.
271
+ return findActionForNode(prevStatement);
272
+ }
273
+ } else if (body.slice(1).every(statement => deletingNodes.has(statement))) {
274
+ // If it is the first statement and all other statements
275
+ // are marked for deletion, we can remove the whole block.
276
+ return findActionForNode(parent);
277
+ }
278
+ }
279
+ }
280
+ if (parent.isVariableDeclarator()) {
281
+ return findActionForNode(parent);
282
+ }
283
+ if (parent.isExportNamedDeclaration() && (path.key === 'specifiers' && isEmptyList(parent.get('specifiers')) || path.key === 'declaration' && parent.node.declaration === path.node)) {
284
+ return findActionForNode(parent);
285
+ }
286
+ for (const key of ['body', 'declarations', 'specifiers']) {
287
+ if (path.listKey === key && typeof path.key === 'number') {
288
+ const list = parent.get(key);
289
+ if (isEmptyList(list)) {
290
+ return findActionForNode(parent);
291
+ }
292
+ }
293
+ }
294
+ if (parent.isTryStatement()) {
295
+ return findActionForNode(parent);
296
+ }
297
+ if (!path.listKey && path.key) {
298
+ const field = NODE_FIELDS[parent.type][path.key];
299
+ if (!validateField(parent.node, path.key, null, field)) {
300
+ // The parent node isn't valid without this field, so we should remove it also.
301
+ return findActionForNode(parent);
302
+ }
303
+ }
304
+ for (const key of ['argument', 'block', 'body', 'callee', 'discriminant', 'expression', 'id', 'left', 'object', 'property', 'right', 'test']) {
305
+ if (path.key === key && parent.get(key) === path) {
306
+ return findActionForNode(parent);
307
+ }
308
+ }
309
+ return ['remove', path];
310
+ }
311
+
312
+ // @babel/preset-typescript transpiles enums, but doesn't reference used identifiers.
313
+ function referenceEnums(program) {
314
+ /*
315
+ * We are looking for transpiled enums.
316
+ * (function (Colors) {
317
+ * Colors["BLUE"] = "#27509A";
318
+ * })(Colors || (Colors = {}));
319
+ */
320
+ program.traverse({
321
+ ExpressionStatement(expressionStatement) {
322
+ const expression = expressionStatement.get('expression');
323
+ if (!expression.isCallExpression()) return;
324
+ const callee = expression.get('callee');
325
+ const args = expression.get('arguments');
326
+ if (!callee.isFunctionExpression() || args.length !== 1) return;
327
+ const [arg] = args;
328
+ if (arg.isLogicalExpression({
329
+ operator: '||'
330
+ })) {
331
+ referenceAll(arg);
332
+ }
333
+ }
334
+ });
335
+ }
336
+ const fixed = new WeakSet();
337
+ function removeUnreferenced(items) {
338
+ const referenced = new Set();
339
+ items.forEach(item => {
340
+ if (!item.node || isRemoved(item)) return;
341
+ const binding = getScope(item).getBinding(item.node.name);
342
+ if (!binding) return;
343
+ const hasReferences = binding.referencePaths.filter(i => !isRemoved(i)).length > 0;
344
+ if (hasReferences) {
345
+ referenced.add(item);
346
+ return;
347
+ }
348
+ const forDeleting = [binding.path, ...binding.constantViolations].map(findActionForNode).filter(isNotNull).map(getPathFromAction);
349
+ if (forDeleting.length === 0) return;
350
+ findIdentifiers(forDeleting).forEach(identifier => {
351
+ referenced.add(identifier);
352
+ });
353
+ removeWithRelated(forDeleting);
354
+ });
355
+ const result = [...referenced];
356
+ result.sort((a, b) => a.node?.name.localeCompare(b.node?.name));
357
+ return result;
358
+ }
359
+ function getNodeForValue(value) {
360
+ if (typeof value === 'string') {
361
+ return {
362
+ type: 'StringLiteral',
363
+ value
364
+ };
365
+ }
366
+ if (typeof value === 'number') {
367
+ return {
368
+ type: 'NumericLiteral',
369
+ value
370
+ };
371
+ }
372
+ if (typeof value === 'boolean') {
373
+ return {
374
+ type: 'BooleanLiteral',
375
+ value
376
+ };
377
+ }
378
+ if (value === null) {
379
+ return {
380
+ type: 'NullLiteral'
381
+ };
382
+ }
383
+ if (value === undefined) {
384
+ return {
385
+ type: 'Identifier',
386
+ name: 'undefined'
387
+ };
388
+ }
389
+ return undefined;
390
+ }
391
+ function staticEvaluate(path) {
392
+ if (!path) return;
393
+ const evaluated = path.evaluate();
394
+ if (evaluated.confident) {
395
+ const node = getNodeForValue(evaluated.value);
396
+ if (node) {
397
+ applyAction(['replace', path, node]);
398
+ return;
399
+ }
400
+ }
401
+ if (path.isIfStatement()) {
402
+ const test = path.get('test');
403
+ if (!test.isBooleanLiteral()) {
404
+ return;
405
+ }
406
+ const {
407
+ consequent,
408
+ alternate
409
+ } = path.node;
410
+ if (test.node.value) {
411
+ applyAction(['replace', path, consequent]);
412
+ } else if (alternate) {
413
+ applyAction(['replace', path, alternate]);
414
+ } else {
415
+ applyAction(['remove', path]);
416
+ }
417
+ }
418
+ }
419
+ function applyAction(action) {
420
+ mutate(action[1], p => {
421
+ if (isRemoved(p)) return;
422
+ const parent = p.parentPath;
423
+ if (action[0] === 'remove') {
424
+ p.remove();
425
+ }
426
+ if (action[0] === 'replace') {
427
+ p.replaceWith(action[2]);
428
+ }
429
+ staticEvaluate(parent);
430
+ });
431
+ }
432
+ function removeWithRelated(paths) {
433
+ if (paths.length === 0) return;
434
+ const rootPath = getScope(paths[0]).getProgramParent().path;
435
+ if (!fixed.has(rootPath)) {
436
+ // Some libraries don't care about bindings, references, and other staff
437
+ // So we have to fix the scope before we can detect unused code
438
+ referenceEnums(rootPath);
439
+ fixed.add(rootPath);
440
+ }
441
+ const actions = paths.map(findActionForNode).filter(isNotNull);
442
+ const affectedPaths = actions.map(getPathFromAction);
443
+ let referencedIdentifiers = findIdentifiers(affectedPaths, 'reference');
444
+ referencedIdentifiers.sort((a, b) => a.node?.name.localeCompare(b.node?.name));
445
+ const referencesOfBinding = findIdentifiers(affectedPaths, 'declaration').map(i => (i.node && getScope(i).getBinding(i.node.name)) ?? null).filter(isNotNull).reduce((acc, i) => [...acc, ...i.referencePaths.filter(nonType)], []).filter(ref =>
446
+ // Do not remove `export default function`
447
+ !ref.isExportDefaultDeclaration() || !ref.get('declaration').isFunctionDeclaration());
448
+ actions.forEach(applyAction);
449
+ removeWithRelated(referencesOfBinding);
450
+ let clean = false;
451
+ while (!clean && referencedIdentifiers.length > 0) {
452
+ const referenced = removeUnreferenced(referencedIdentifiers);
453
+ clean = referenced.map(i => i.node?.name).join('|') === referencedIdentifiers.map(i => i.node?.name).join('|');
454
+ referencedIdentifiers = referenced;
455
+ }
456
+ }
457
+ function mutate(path, fn) {
458
+ const dereferenced = dereferenceAll(path);
459
+ const mutated = fn(path);
460
+ referenceAll(path);
461
+ mutated?.forEach(p => referenceAll(p));
462
+ const dead = dereferenced.filter(p => !isReferenced(p));
463
+ const forDeleting = [];
464
+ dead.forEach(binding => {
465
+ const assignments = [binding.path, ...binding.constantViolations];
466
+ assignments.forEach(assignment => {
467
+ const {
468
+ scope
469
+ } = assignment;
470
+ const declared = Object.values(assignment.getOuterBindingIdentifiers(false));
471
+ if (declared.length === 1 && 'name' in declared[0] && declared[0].name === binding.identifier.name) {
472
+ const init = assignment.get('init');
473
+ if (!Array.isArray(init) && init?.isAssignmentExpression()) {
474
+ // `const a = b = 1` → `b = 1`
475
+ assignment.parentPath?.replaceWith({
476
+ type: 'ExpressionStatement',
477
+ expression: init.node
478
+ });
479
+ const left = init.get('left');
480
+ if (left.isIdentifier()) {
481
+ // If it was forcefully referenced in the shaker
482
+ dereference(left);
483
+ }
484
+ return;
485
+ }
486
+ // Only one identifier is declared, so we can remove the whole declaration
487
+ forDeleting.push(assignment);
488
+ return;
489
+ }
490
+ if (declared.every(identifier => identifier.type === 'Identifier' && !scope.getBinding(identifier.name)?.referenced)) {
491
+ // No other identifier is referenced, so we can remove the whole declaration
492
+ forDeleting.push(assignment);
493
+ return;
494
+ }
495
+
496
+ // We can't remove the binding, but we can remove the part of it
497
+ assignment.traverse({
498
+ Identifier(identifier) {
499
+ if (identifier.node.name === binding.identifier.name) {
500
+ const parent = identifier.parentPath;
501
+ if (parent.isArrayPattern() && identifier.listKey === 'elements' && typeof identifier.key === 'number') {
502
+ parent.node.elements[identifier.key] = null;
503
+ } else if (parent.isObjectProperty()) {
504
+ forDeleting.push(parent);
505
+ }
506
+ }
507
+ }
508
+ });
509
+ });
510
+ });
511
+ removeWithRelated(forDeleting);
512
+ }
513
+ export { applyAction, mutate, removeWithRelated };
514
+ //# sourceMappingURL=scopeHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopeHelpers.js","names":["NODE_FIELDS","findIdentifiers","nonType","getScope","isNotNull","isRemoved","validateField","node","key","val","field","validate","optional","getBinding","path","binding","name","undefined","reference","referencePath","force","isReferencedIdentifier","referencePaths","includes","referenced","push","references","length","isReferenced","kind","isFunctionExpression","parentPath","isVariableDeclarator","id","get","isIdentifier","idBinding","every","i","find","ancestor","isTSType","isFlowType","isReferencedConstantViolation","p","isAssignmentExpression","isExpressionStatement","dereference","isReference","referencesInConstantViolations","constantViolations","filter","isConstantViolation","nonTypeReferences","dereferenceAll","map","identifierPath","referenceAll","forEach","deletingNodes","WeakSet","isEmptyList","list","has","getPathFromAction","action","Array","isArray","Error","isPrototypeAssignment","left","type","object","property","canFunctionBeDelete","fnPath","fnScope","scope","parentScope","parent","listKey","findActionForNode","add","isProgram","isClassDeclaration","isClassExpression","body","isFunction","isBlockStatement","async","directives","generator","params","isConditionalExpression","alternate","isLogicalExpression","operator","value","right","isObjectProperty","maybeDefineProperty","isCallExpression","matchesPattern","isTemplateLiteral","isForInStatement","isFunctionDeclaration","isObjectMethod","isClassMethod","prevStatement","isIfStatement","isReturnStatement","slice","statement","isExportNamedDeclaration","declaration","isTryStatement","referenceEnums","program","traverse","ExpressionStatement","expressionStatement","expression","callee","args","arg","fixed","removeUnreferenced","items","Set","item","hasReferences","forDeleting","identifier","removeWithRelated","result","sort","a","b","localeCompare","getNodeForValue","staticEvaluate","evaluated","evaluate","confident","applyAction","test","isBooleanLiteral","consequent","mutate","remove","replaceWith","paths","rootPath","getProgramParent","actions","affectedPaths","referencedIdentifiers","referencesOfBinding","reduce","acc","ref","isExportDefaultDeclaration","clean","join","fn","dereferenced","mutated","dead","assignments","assignment","declared","Object","values","getOuterBindingIdentifiers","init","Identifier","isArrayPattern","elements"],"sources":["../../src/utils/scopeHelpers.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n/* eslint @typescript-eslint/no-use-before-define: [\"error\", { \"functions\": false }] */\n\nimport type { Binding, NodePath } from '@babel/traverse';\nimport type {\n FieldOptions,\n Function as FunctionNode,\n Identifier,\n JSXIdentifier,\n Node,\n Program,\n} from '@babel/types';\nimport { NODE_FIELDS } from '@babel/types';\n\nimport { findIdentifiers, nonType } from './findIdentifiers';\nimport { getScope } from './getScope';\nimport { isNotNull } from './isNotNull';\nimport { isRemoved } from './isRemoved';\n\nfunction validateField(\n node: Node,\n key: string,\n val: unknown,\n field: FieldOptions\n) {\n if (!(field != null && field.validate)) return true;\n if (field.optional && val == null) return true;\n try {\n field.validate(node, key, val);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction getBinding(path: NodePath<Identifier | JSXIdentifier>) {\n const binding = getScope(path).getBinding(path.node.name);\n if (!binding) {\n return undefined;\n }\n\n return binding;\n}\n\nexport function reference(\n path: NodePath<Identifier | JSXIdentifier>,\n referencePath: NodePath = path,\n force = false\n): void {\n if (!force && !path.isReferencedIdentifier()) return;\n\n const binding = getBinding(path);\n if (!binding) return;\n\n if (binding.referencePaths.includes(referencePath)) {\n return;\n }\n\n binding.referenced = true;\n binding.referencePaths.push(referencePath ?? path);\n binding.references = binding.referencePaths.length;\n}\n\nfunction isReferenced(binding: Binding): boolean {\n const { kind, referenced, referencePaths, path } = binding;\n\n if (\n path.isFunctionExpression() &&\n path.key === 'init' &&\n path.parentPath.isVariableDeclarator()\n ) {\n // It is a function expression in a variable declarator\n const id = path.parentPath.get('id');\n if (id.isIdentifier()) {\n const idBinding = getBinding(id);\n return idBinding ? isReferenced(idBinding) : true;\n }\n\n return true;\n }\n\n if (!referenced) {\n return false;\n }\n\n // If it's a param binding, we can't just remove it\n // because it brakes the function signature. Keep it alive for now.\n if ((kind as string) === 'param') {\n return true;\n }\n\n // If all remaining references are in TS/Flow types, binding is unreferenced\n return (\n referencePaths.length > 0 ||\n referencePaths.every((i) =>\n i.find((ancestor) => ancestor.isTSType() || ancestor.isFlowType())\n )\n );\n}\n\nfunction isReferencedConstantViolation(path: NodePath, binding: Binding) {\n if (path.find((p) => p === binding.path)) {\n // function a(flag) { return (a = function(flag) { flag ? 1 : 2 }) }\n // ^ Looks crazy, yeh? Welcome to the wonderful world of transpilers!\n // `a = …` here isn't a reference.\n return false;\n }\n\n if (!path.isReferenced()) {\n return false;\n }\n\n if (\n path.isAssignmentExpression() &&\n path.parentPath.isExpressionStatement()\n ) {\n // A root assignment without a parent expression statement is not a reference\n return false;\n }\n\n return true;\n}\n\nexport function dereference(\n path: NodePath<Identifier | JSXIdentifier>\n): Binding | null {\n const binding = getBinding(path);\n if (!binding) return null;\n\n const isReference = binding.referencePaths.includes(path);\n let referencesInConstantViolations = binding.constantViolations.filter((i) =>\n isReferencedConstantViolation(i, binding)\n );\n\n const isConstantViolation = referencesInConstantViolations.includes(path);\n\n if (!isReference && !isConstantViolation) {\n return null;\n }\n\n if (isReference) {\n binding.referencePaths = binding.referencePaths.filter((i) => i !== path);\n binding.references -= 1;\n } else {\n referencesInConstantViolations = referencesInConstantViolations.filter(\n (i) => i !== path\n );\n }\n\n const nonTypeReferences = binding.referencePaths.filter(nonType);\n binding.referenced =\n nonTypeReferences.length + referencesInConstantViolations.length > 0;\n\n return binding;\n}\n\nfunction dereferenceAll(path: NodePath): Binding[] {\n return findIdentifiers([path])\n .map((identifierPath) => dereference(identifierPath))\n .filter(isNotNull);\n}\n\nexport function referenceAll(path: NodePath): void {\n findIdentifiers([path]).forEach((identifierPath) =>\n reference(identifierPath)\n );\n}\n\nconst deletingNodes = new WeakSet<NodePath>();\n\nconst isEmptyList = (list: NodePath[]) =>\n list.length === 0 || list.every((i) => deletingNodes.has(i));\n\ntype ReplaceAction = [action: 'replace', what: NodePath, by: Node];\ntype RemoveAction = [action: 'remove', what: NodePath];\n\nconst getPathFromAction = (action: RemoveAction | ReplaceAction) => {\n if (!Array.isArray(action)) {\n return action;\n }\n\n if (action[0] === 'replace' || action[0] === 'remove') {\n return action[1];\n }\n\n throw new Error(`Unknown action type: ${action[0]}`);\n};\n\nfunction isPrototypeAssignment(path: NodePath) {\n if (!path.isAssignmentExpression()) {\n return false;\n }\n\n const { left } = path.node;\n if (!left) {\n return false;\n }\n\n if (left.type !== 'MemberExpression') {\n return false;\n }\n\n const { object, property } = left;\n if (!object || !property) {\n return false;\n }\n\n return (\n object.type === 'MemberExpression' &&\n object.property.type === 'Identifier' &&\n object.property.name === 'prototype'\n );\n}\n\nfunction canFunctionBeDelete(fnPath: NodePath<FunctionNode>) {\n if (isPrototypeAssignment(fnPath.parentPath)) {\n // It is a prototype assignment, we can't delete it since we can't find all usages\n return false;\n }\n\n const fnScope = fnPath.scope;\n const parentScope = fnScope.parent;\n if (parentScope.parent) {\n // It isn't a top-level function, so we can't delete it\n return true;\n }\n\n if (fnPath.listKey === 'arguments') {\n // It is passed as an argument to another function, we can't delete it\n return true;\n }\n\n return false;\n}\n\nexport function findActionForNode(\n path: NodePath\n): RemoveAction | ReplaceAction | null {\n if (isRemoved(path)) return null;\n\n deletingNodes.add(path);\n\n const parent = path.parentPath;\n\n if (!parent) return ['remove', path];\n\n if (parent.isProgram()) {\n // Do not delete Program node\n return ['remove', path];\n }\n\n if (parent.isClassDeclaration() || parent.isClassExpression()) {\n if (path.key === 'body') {\n return ['replace', path, { type: 'ClassBody', body: [] }];\n }\n }\n\n if (parent.isFunction()) {\n if (path.listKey === 'params') {\n // Do not remove params of functions\n return null;\n }\n\n if (\n (path.isBlockStatement() && isEmptyList(path.get('body'))) ||\n path === parent.get('body')\n ) {\n if (!canFunctionBeDelete(parent)) {\n return [\n 'replace',\n parent,\n {\n ...parent.node,\n async: false,\n body: {\n type: 'BlockStatement',\n body: [],\n directives: [],\n },\n generator: false,\n params: [],\n },\n ];\n }\n }\n }\n\n if (parent.isConditionalExpression()) {\n if (path.key === 'test') {\n return ['replace', parent, parent.node.alternate];\n }\n\n if (path.key === 'consequent') {\n return ['replace', path, { type: 'Identifier', name: 'undefined' }];\n }\n\n if (path.key === 'alternate') {\n return ['replace', path, { type: 'Identifier', name: 'undefined' }];\n }\n }\n\n if (parent.isLogicalExpression({ operator: '&&' })) {\n return [\n 'replace',\n parent,\n {\n type: 'BooleanLiteral',\n value: false,\n },\n ];\n }\n\n if (parent.isLogicalExpression({ operator: '||' })) {\n return [\n 'replace',\n parent,\n path.key === 'left' ? parent.node.right : parent.node.left,\n ];\n }\n\n if (parent.isObjectProperty()) {\n // let's check if it is a special case with Object.defineProperty\n const key = parent.get('key');\n if (key.isIdentifier({ name: 'get' })) {\n const maybeDefineProperty = parent.parentPath.parentPath;\n if (\n maybeDefineProperty?.isCallExpression() &&\n maybeDefineProperty\n .get('callee')\n .matchesPattern('Object.defineProperty')\n ) {\n return findActionForNode(maybeDefineProperty);\n }\n }\n\n return findActionForNode(parent);\n }\n\n if (parent.isTemplateLiteral()) {\n return [\n 'replace',\n path,\n {\n type: 'StringLiteral',\n value: '',\n },\n ];\n }\n\n if (parent.isAssignmentExpression()) {\n return findActionForNode(parent);\n }\n\n if (parent.isCallExpression()) {\n return findActionForNode(parent);\n }\n\n if (parent.isForInStatement({ left: path.node })) {\n return findActionForNode(parent);\n }\n\n if (\n parent.isFunctionExpression({ body: path.node }) ||\n parent.isFunctionDeclaration() ||\n parent.isObjectMethod() ||\n parent.isClassMethod()\n ) {\n return findActionForNode(parent);\n }\n\n if (parent.isBlockStatement()) {\n const body = parent.get('body');\n if (isEmptyList(body)) {\n return findActionForNode(parent);\n }\n\n if (path.listKey === 'body' && typeof path.key === 'number') {\n if (path.key > 0) {\n // We can check whether the previous one can be removed\n const prevStatement = body[path.key - 1];\n if (\n prevStatement.isIfStatement() &&\n prevStatement.get('consequent').isReturnStatement()\n ) {\n // It's `if (…) return …`, we can remove it.\n return findActionForNode(prevStatement);\n }\n } else if (\n body.slice(1).every((statement) => deletingNodes.has(statement))\n ) {\n // If it is the first statement and all other statements\n // are marked for deletion, we can remove the whole block.\n return findActionForNode(parent);\n }\n }\n }\n\n if (parent.isVariableDeclarator()) {\n return findActionForNode(parent);\n }\n\n if (\n parent.isExportNamedDeclaration() &&\n ((path.key === 'specifiers' && isEmptyList(parent.get('specifiers'))) ||\n (path.key === 'declaration' && parent.node.declaration === path.node))\n ) {\n return findActionForNode(parent);\n }\n\n for (const key of ['body', 'declarations', 'specifiers']) {\n if (path.listKey === key && typeof path.key === 'number') {\n const list = parent.get(key) as NodePath[];\n if (isEmptyList(list)) {\n return findActionForNode(parent);\n }\n }\n }\n\n if (parent.isTryStatement()) {\n return findActionForNode(parent);\n }\n\n if (!path.listKey && path.key) {\n const field = NODE_FIELDS[parent.type][path.key];\n if (!validateField(parent.node, path.key as string, null, field)) {\n // The parent node isn't valid without this field, so we should remove it also.\n return findActionForNode(parent);\n }\n }\n\n for (const key of [\n 'argument',\n 'block',\n 'body',\n 'callee',\n 'discriminant',\n 'expression',\n 'id',\n 'left',\n 'object',\n 'property',\n 'right',\n 'test',\n ]) {\n if (path.key === key && parent.get(key) === path) {\n return findActionForNode(parent);\n }\n }\n\n return ['remove', path];\n}\n\n// @babel/preset-typescript transpiles enums, but doesn't reference used identifiers.\nfunction referenceEnums(program: NodePath<Program>) {\n /*\n * We are looking for transpiled enums.\n * (function (Colors) {\n * Colors[\"BLUE\"] = \"#27509A\";\n * })(Colors || (Colors = {}));\n */\n program.traverse({\n ExpressionStatement(expressionStatement) {\n const expression = expressionStatement.get('expression');\n if (!expression.isCallExpression()) return;\n\n const callee = expression.get('callee');\n const args = expression.get('arguments');\n if (!callee.isFunctionExpression() || args.length !== 1) return;\n const [arg] = args;\n if (arg.isLogicalExpression({ operator: '||' })) {\n referenceAll(arg);\n }\n },\n });\n}\n\nconst fixed = new WeakSet<NodePath<Program>>();\n\nfunction removeUnreferenced(items: NodePath<Identifier | JSXIdentifier>[]) {\n const referenced = new Set<NodePath<Identifier | JSXIdentifier>>();\n items.forEach((item) => {\n if (!item.node || isRemoved(item)) return;\n const binding = getScope(item).getBinding(item.node.name);\n if (!binding) return;\n const hasReferences =\n binding.referencePaths.filter((i) => !isRemoved(i)).length > 0;\n if (hasReferences) {\n referenced.add(item);\n return;\n }\n\n const forDeleting = [binding.path, ...binding.constantViolations]\n .map(findActionForNode)\n .filter(isNotNull)\n .map(getPathFromAction);\n\n if (forDeleting.length === 0) return;\n\n findIdentifiers(forDeleting).forEach((identifier) => {\n referenced.add(identifier);\n });\n\n removeWithRelated(forDeleting);\n });\n\n const result = [...referenced];\n result.sort((a, b) => a.node?.name.localeCompare(b.node?.name));\n\n return result;\n}\n\nfunction getNodeForValue(value: unknown): Node | undefined {\n if (typeof value === 'string') {\n return {\n type: 'StringLiteral',\n value,\n };\n }\n\n if (typeof value === 'number') {\n return {\n type: 'NumericLiteral',\n value,\n };\n }\n\n if (typeof value === 'boolean') {\n return {\n type: 'BooleanLiteral',\n value,\n };\n }\n\n if (value === null) {\n return {\n type: 'NullLiteral',\n };\n }\n\n if (value === undefined) {\n return {\n type: 'Identifier',\n name: 'undefined',\n };\n }\n\n return undefined;\n}\n\nfunction staticEvaluate(path: NodePath | null | undefined): void {\n if (!path) return;\n const evaluated = path.evaluate();\n if (evaluated.confident) {\n const node = getNodeForValue(evaluated.value);\n if (node) {\n applyAction(['replace', path, node]);\n return;\n }\n }\n\n if (path.isIfStatement()) {\n const test = path.get('test');\n if (!test.isBooleanLiteral()) {\n return;\n }\n\n const { consequent, alternate } = path.node;\n if (test.node.value) {\n applyAction(['replace', path, consequent]);\n } else if (alternate) {\n applyAction(['replace', path, alternate]);\n } else {\n applyAction(['remove', path]);\n }\n }\n}\n\nfunction applyAction(action: ReplaceAction | RemoveAction) {\n mutate(action[1], (p) => {\n if (isRemoved(p)) return;\n\n const parent = p.parentPath;\n\n if (action[0] === 'remove') {\n p.remove();\n }\n\n if (action[0] === 'replace') {\n p.replaceWith(action[2]);\n }\n\n staticEvaluate(parent);\n });\n}\n\nfunction removeWithRelated(paths: NodePath[]) {\n if (paths.length === 0) return;\n\n const rootPath = getScope(paths[0]).getProgramParent()\n .path as NodePath<Program>;\n\n if (!fixed.has(rootPath)) {\n // Some libraries don't care about bindings, references, and other staff\n // So we have to fix the scope before we can detect unused code\n referenceEnums(rootPath);\n fixed.add(rootPath);\n }\n\n const actions: (ReplaceAction | RemoveAction)[] = paths\n .map(findActionForNode)\n .filter(isNotNull);\n\n const affectedPaths = actions.map(getPathFromAction);\n\n let referencedIdentifiers = findIdentifiers(affectedPaths, 'reference');\n referencedIdentifiers.sort(\n (a, b) => a.node?.name.localeCompare(b.node?.name)\n );\n\n const referencesOfBinding = findIdentifiers(affectedPaths, 'declaration')\n .map((i) => (i.node && getScope(i).getBinding(i.node.name)) ?? null)\n .filter(isNotNull)\n .reduce(\n (acc, i) => [...acc, ...i.referencePaths.filter(nonType)],\n [] as NodePath[]\n )\n .filter(\n (ref) =>\n // Do not remove `export default function`\n !ref.isExportDefaultDeclaration() ||\n !ref.get('declaration').isFunctionDeclaration()\n );\n\n actions.forEach(applyAction);\n\n removeWithRelated(referencesOfBinding);\n\n let clean = false;\n while (!clean && referencedIdentifiers.length > 0) {\n const referenced = removeUnreferenced(referencedIdentifiers);\n clean =\n referenced.map((i) => i.node?.name).join('|') ===\n referencedIdentifiers.map((i) => i.node?.name).join('|');\n referencedIdentifiers = referenced;\n }\n}\n\nfunction mutate<T extends NodePath>(path: T, fn: (p: T) => NodePath[] | void) {\n const dereferenced = dereferenceAll(path);\n\n const mutated = fn(path);\n\n referenceAll(path);\n mutated?.forEach((p) => referenceAll(p));\n\n const dead = dereferenced.filter((p) => !isReferenced(p));\n\n const forDeleting: NodePath[] = [];\n dead.forEach((binding) => {\n const assignments = [binding.path, ...binding.constantViolations];\n assignments.forEach((assignment) => {\n const { scope } = assignment;\n const declared = Object.values(\n assignment.getOuterBindingIdentifiers(false)\n );\n if (\n declared.length === 1 &&\n 'name' in declared[0] &&\n declared[0].name === binding.identifier.name\n ) {\n const init = assignment.get('init');\n if (!Array.isArray(init) && init?.isAssignmentExpression()) {\n // `const a = b = 1` → `b = 1`\n assignment.parentPath?.replaceWith({\n type: 'ExpressionStatement',\n expression: init.node,\n });\n\n const left = init.get('left');\n if (left.isIdentifier()) {\n // If it was forcefully referenced in the shaker\n dereference(left);\n }\n\n return;\n }\n // Only one identifier is declared, so we can remove the whole declaration\n forDeleting.push(assignment);\n return;\n }\n\n if (\n declared.every(\n (identifier) =>\n identifier.type === 'Identifier' &&\n !scope.getBinding(identifier.name)?.referenced\n )\n ) {\n // No other identifier is referenced, so we can remove the whole declaration\n forDeleting.push(assignment);\n return;\n }\n\n // We can't remove the binding, but we can remove the part of it\n assignment.traverse({\n Identifier(identifier) {\n if (identifier.node.name === binding.identifier.name) {\n const parent = identifier.parentPath;\n if (\n parent.isArrayPattern() &&\n identifier.listKey === 'elements' &&\n typeof identifier.key === 'number'\n ) {\n parent.node.elements[identifier.key] = null;\n } else if (parent.isObjectProperty()) {\n forDeleting.push(parent);\n }\n }\n },\n });\n });\n });\n\n removeWithRelated(forDeleting);\n}\n\nexport { applyAction, mutate, removeWithRelated };\n"],"mappings":"AAAA;AACA;;AAWA,SAASA,WAAW,QAAQ,cAAc;AAE1C,SAASC,eAAe,EAAEC,OAAO,QAAQ,mBAAmB;AAC5D,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,aAAa;AAEvC,SAASC,aAAaA,CACpBC,IAAU,EACVC,GAAW,EACXC,GAAY,EACZC,KAAmB,EACnB;EACA,IAAI,EAAEA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACC,QAAQ,CAAC,EAAE,OAAO,IAAI;EACnD,IAAID,KAAK,CAACE,QAAQ,IAAIH,GAAG,IAAI,IAAI,EAAE,OAAO,IAAI;EAC9C,IAAI;IACFC,KAAK,CAACC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I,CAAC;UACnB;UAEA;QACF;QACA;QACA6D,WAAW,CAAC1G,IAAI,CAACgJ,UAAU,CAAC;QAC5B;MACF;MAEA,IACEC,QAAQ,CAACrI,KAAK,CACX+F,UAAU,IACTA,UAAU,CAAC7D,IAAI,KAAK,YAAY,IAChC,CAACM,KAAK,CAAChE,UAAU,CAACuH,UAAU,CAACpH,IAAI,CAAC,EAAEQ,UACxC,CAAC,EACD;QACA;QACA2G,WAAW,CAAC1G,IAAI,CAACgJ,UAAU,CAAC;QAC5B;MACF;;MAEA;MACAA,UAAU,CAACnD,QAAQ,CAAC;QAClByD,UAAUA,CAAC3C,UAAU,EAAE;UACrB,IAAIA,UAAU,CAAC7H,IAAI,CAACS,IAAI,KAAKD,OAAO,CAACqH,UAAU,CAACpH,IAAI,EAAE;YACpD,MAAM+D,MAAM,GAAGqD,UAAU,CAACrG,UAAU;YACpC,IACEgD,MAAM,CAACiG,cAAc,CAAC,CAAC,IACvB5C,UAAU,CAACpD,OAAO,KAAK,UAAU,IACjC,OAAOoD,UAAU,CAAC5H,GAAG,KAAK,QAAQ,EAClC;cACAuE,MAAM,CAACxE,IAAI,CAAC0K,QAAQ,CAAC7C,UAAU,CAAC5H,GAAG,CAAC,GAAG,IAAI;YAC7C,CAAC,MAAM,IAAIuE,MAAM,CAACoB,gBAAgB,CAAC,CAAC,EAAE;cACpCgC,WAAW,CAAC1G,IAAI,CAACsD,MAAM,CAAC;YAC1B;UACF;QACF;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFsD,iBAAiB,CAACF,WAAW,CAAC;AAChC;AAEA,SAASa,WAAW,EAAEI,MAAM,EAAEf,iBAAiB"}
@@ -0,0 +1,28 @@
1
+ import traverse from '@babel/traverse';
2
+ const caches = new WeakMap();
3
+ export const getTraversalCache = (path, name) => {
4
+ const programPath = path.find(p => p.isProgram());
5
+ if (!programPath) {
6
+ throw new Error(`Could not find program for ${path.node.type}`);
7
+ }
8
+ if (!caches.has(programPath)) {
9
+ caches.set(programPath, new Map());
10
+ }
11
+ const cache = caches.get(programPath);
12
+ if (!cache.has(name)) {
13
+ cache.set(name, new WeakMap());
14
+ }
15
+ return cache.get(name);
16
+ };
17
+ const traverseCache = traverse.cache;
18
+ export const clearBabelTraversalCache = () => {
19
+ traverseCache.clear();
20
+ };
21
+ export const invalidateTraversalCache = path => {
22
+ const programPath = path.find(p => p.isProgram());
23
+ if (!programPath) {
24
+ throw new Error(`Could not find program for ${path.node.type}`);
25
+ }
26
+ caches.delete(programPath);
27
+ };
28
+ //# sourceMappingURL=traversalCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traversalCache.js","names":["traverse","caches","WeakMap","getTraversalCache","path","name","programPath","find","p","isProgram","Error","node","type","has","set","Map","cache","get","traverseCache","clearBabelTraversalCache","clear","invalidateTraversalCache","delete"],"sources":["../../src/utils/traversalCache.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport traverse from '@babel/traverse';\nimport type { Node } from '@babel/types';\n\nconst caches = new WeakMap<\n NodePath,\n Map<string, WeakMap<NodePath | Node, unknown>>\n>();\n\nexport const getTraversalCache = <\n TValue,\n TKey extends NodePath | Node = NodePath,\n>(\n path: NodePath,\n name: string\n) => {\n const programPath = path.find((p) => p.isProgram());\n if (!programPath) {\n throw new Error(`Could not find program for ${path.node.type}`);\n }\n\n if (!caches.has(programPath)) {\n caches.set(programPath, new Map());\n }\n\n const cache = caches.get(programPath)!;\n if (!cache.has(name)) {\n cache.set(name, new WeakMap());\n }\n\n return cache.get(name) as WeakMap<TKey, TValue>;\n};\n\nconst traverseCache = (traverse as unknown as { cache: unknown }).cache;\nexport const clearBabelTraversalCache = () => {\n (traverseCache as { clear: () => void }).clear();\n};\n\nexport const invalidateTraversalCache = (path: NodePath) => {\n const programPath = path.find((p) => p.isProgram());\n if (!programPath) {\n throw new Error(`Could not find program for ${path.node.type}`);\n }\n\n caches.delete(programPath);\n};\n"],"mappings":"AACA,OAAOA,QAAQ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AAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * If expression is a sequence like `(a, b, c)`, returns `c`
3
+ * otherwise returns an original expression
4
+ * @param path
5
+ */
6
+ export function unwrapSequence(path) {
7
+ if (path.isSequenceExpression()) {
8
+ const [...expressions] = path.get('expressions');
9
+ const lastExpression = expressions.pop();
10
+ return lastExpression ? unwrapSequence(lastExpression) : undefined;
11
+ }
12
+ return path;
13
+ }
14
+ //# sourceMappingURL=unwrapSequence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrapSequence.js","names":["unwrapSequence","path","isSequenceExpression","expressions","get","lastExpression","pop","undefined"],"sources":["../../src/utils/unwrapSequence.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { Expression, V8IntrinsicIdentifier } from '@babel/types';\n\n/**\n * If expression is a sequence like `(a, b, c)`, returns `c`\n * otherwise returns an original expression\n * @param path\n */\nexport function unwrapSequence(\n path: NodePath<Expression | V8IntrinsicIdentifier>\n): NodePath<Expression | V8IntrinsicIdentifier> | undefined {\n if (path.isSequenceExpression()) {\n const [...expressions] = path.get('expressions');\n const lastExpression = expressions.pop();\n return lastExpression ? unwrapSequence(lastExpression) : undefined;\n }\n\n return path;\n}\n"],"mappings":"AAGA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,cAAcA,CAC5BC,IAAkD,EACQ;EAC1D,IAAIA,IAAI,CAACC,oBAAoB,CAAC,CAAC,EAAE;IAC/B,MAAM,CAAC,GAAGC,WAAW,CAAC,GAAGF,IAAI,CAACG,GAAG,CAAC,aAAa,CAAC;IAChD,MAAMC,cAAc,GAAGF,WAAW,CAACG,GAAG,CAAC,CAAC;IACxC,OAAOD,cAAc,GAAGL,cAAc,CAACK,cAAc,CAAC,GAAGE,SAAS;EACpE;EAEA,OAAON,IAAI;AACb"}