@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 @@
1
+ {"version":3,"file":"module.js","names":["fs","NativeModule","path","vm","invariant","Entrypoint","getStack","isSuperSet","isUnprocessedEntrypointError","createVmContext","DefaultModuleImplementation","builtins","assert","buffer","child_process","cluster","console","constants","crypto","dgram","dns","domain","events","http","https","module","net","os","punycode","process","querystring","readline","repl","stream","string_decoder","sys","timers","tls","tty","url","util","zlib","NOOP","getUncached","cached","test","cachedSet","Set","split","has","filter","t","resolve","id","resolved","resolveDependency","Module","callstack","isEvaluated","require","Object","assign","debug","dependency","isAbsolute","Error","source","dependencies","push","entrypoint","getEntrypoint","only","evaluated","evaluatedOnly","exports","m","createChild","evaluate","ensure","bind","entrypointRef","constructor","services","parentModule","moduleImpl","cache","WeakRef","idx","name","filename","log","extend","parentIsIgnored","ignored","extensions","options","pluginOptions","value","deref","assertTransformed","get","evaluatedCreated","supersededWith","add","createEvaluated","transformedCode","JSON","parse","context","teardown","features","__wyw_dynamic_import","__dirname","dirname","overrideContext","script","Script","runInContext","e","EvalError","message","join","extension","extname","includes","newEntrypoint","readFileSync","stack","uncachedExports","length","code","createRoot","getDependency","Promise","_extensions","added","forEach","ext","_resolveFilename","paths","_nodeModulePaths"],"sources":["../src/module.ts"],"sourcesContent":["/**\n * This is a custom implementation for the module system for evaluating code,\n * used for resolving values for dependencies interpolated in `css` or `styled`.\n *\n * This serves 2 purposes:\n * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`\n * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds\n *\n * We also use it to transpile the code with Babel by default.\n * We also store source maps for it to provide correct error stacktraces.\n *\n */\n\nimport fs from 'fs';\nimport NativeModule from 'module';\nimport path from 'path';\nimport vm from 'vm';\n\nimport { invariant } from 'ts-invariant';\n\nimport type { Debugger } from '@wyw-in-js/shared';\n\nimport './utils/dispose-polyfill';\nimport type { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport { getStack, isSuperSet } from './transform/Entrypoint.helpers';\nimport type { IEntrypointDependency } from './transform/Entrypoint.types';\nimport type { IEvaluatedEntrypoint } from './transform/EvaluatedEntrypoint';\nimport { isUnprocessedEntrypointError } from './transform/actions/UnprocessedEntrypointError';\nimport type { Services } from './transform/types';\nimport { createVmContext } from './vm/createVmContext';\n\ntype HiddenModuleMembers = {\n _extensions: Record<string, () => void>;\n _resolveFilename: (\n id: string,\n options: { filename: string; id: string; paths: string[] }\n ) => string;\n _nodeModulePaths(filename: string): string[];\n};\n\nexport const DefaultModuleImplementation = NativeModule as typeof NativeModule &\n HiddenModuleMembers;\n\n// Supported node builtins based on the modules polyfilled by webpack\n// `true` means module is polyfilled, `false` means module is empty\nconst builtins = {\n assert: true,\n buffer: true,\n child_process: false,\n cluster: false,\n console: true,\n constants: true,\n crypto: true,\n dgram: false,\n dns: false,\n domain: true,\n events: true,\n fs: false,\n http: true,\n https: true,\n module: false,\n net: false,\n os: true,\n path: true,\n punycode: true,\n process: true,\n querystring: true,\n readline: false,\n repl: false,\n stream: true,\n string_decoder: true,\n sys: true,\n timers: true,\n tls: false,\n tty: true,\n url: true,\n util: true,\n vm: true,\n zlib: true,\n};\n\nconst NOOP = () => {};\n\nfunction getUncached(cached: string | string[], test: string[]): string[] {\n const cachedSet = new Set(\n typeof cached === 'string' ? cached.split(',') : cached\n );\n\n if (cachedSet.has('*')) {\n return [];\n }\n\n return test.filter((t) => !cachedSet.has(t));\n}\n\nfunction resolve(\n this: { resolveDependency: (id: string) => IEntrypointDependency },\n id: string\n): string {\n const { resolved } = this.resolveDependency(id);\n invariant(resolved, `Unable to resolve \"${id}\"`);\n return resolved;\n}\n\nexport class Module {\n public readonly callstack: string[] = [];\n\n public readonly debug: Debugger;\n\n public readonly dependencies: string[];\n\n public readonly extensions: string[];\n\n public readonly filename: string;\n\n public id: string;\n\n public readonly idx: string;\n\n public readonly ignored: boolean;\n\n public isEvaluated: boolean = false;\n\n public readonly parentIsIgnored: boolean;\n\n public require: {\n (id: string): unknown;\n ensure: () => void;\n resolve: (id: string) => string;\n } = Object.assign(\n (id: string) => {\n if (id in builtins) {\n // The module is in the allowed list of builtin node modules\n // Ideally we should prevent importing them, but webpack polyfills some\n // So we check for the list of polyfills to determine which ones to support\n if (builtins[id as keyof typeof builtins]) {\n this.debug('require', `builtin '${id}'`);\n return require(id);\n }\n\n return null;\n }\n\n // Resolve module id (and filename) relatively to parent module\n const dependency = this.resolveDependency(id);\n if (dependency.resolved === id && !path.isAbsolute(id)) {\n // The module is a builtin node modules, but not in the allowed list\n throw new Error(\n `Unable to import \"${id}\". Importing Node builtins is not supported in the sandbox.`\n );\n }\n\n invariant(\n dependency.resolved,\n `Dependency ${dependency.source} cannot be resolved`\n );\n\n this.dependencies.push(id);\n\n this.debug('require', `${id} -> ${dependency.resolved}`);\n\n const entrypoint = this.getEntrypoint(\n dependency.resolved,\n dependency.only,\n this.debug\n );\n\n if (entrypoint === null) {\n return dependency.resolved;\n }\n\n if (\n entrypoint.evaluated ||\n isSuperSet(entrypoint.evaluatedOnly, dependency.only)\n ) {\n return entrypoint.exports;\n }\n\n const m = this.createChild(entrypoint);\n m.evaluate();\n\n return entrypoint.exports;\n },\n {\n ensure: NOOP,\n resolve: resolve.bind(this),\n }\n );\n\n public resolve = resolve.bind(this);\n\n private cache: TransformCacheCollection;\n\n #entrypointRef: WeakRef<Entrypoint>;\n\n constructor(\n private services: Services,\n entrypoint: Entrypoint,\n parentModule?: Module,\n private moduleImpl: HiddenModuleMembers = DefaultModuleImplementation\n ) {\n this.cache = services.cache;\n this.#entrypointRef = new WeakRef(entrypoint);\n this.idx = entrypoint.idx;\n this.id = entrypoint.name;\n this.filename = entrypoint.name;\n this.dependencies = [];\n this.debug = entrypoint.log.extend('module');\n this.parentIsIgnored = parentModule?.ignored ?? false;\n this.ignored = entrypoint.ignored ?? this.parentIsIgnored;\n\n if (parentModule) {\n this.callstack = [entrypoint.name, ...parentModule.callstack];\n } else {\n this.callstack = [entrypoint.name];\n }\n\n this.extensions = services.options.pluginOptions.extensions;\n\n this.debug('init', entrypoint.name);\n }\n\n public get exports() {\n return this.entrypoint.exports;\n }\n\n public set exports(value) {\n this.entrypoint.exports = value;\n\n this.debug('the whole exports was overridden with %O', value);\n }\n\n protected get entrypoint(): Entrypoint {\n const entrypoint = this.#entrypointRef.deref();\n invariant(entrypoint, `Module ${this.idx} is disposed`);\n return entrypoint;\n }\n\n evaluate(): void {\n const { entrypoint } = this;\n entrypoint.assertTransformed();\n\n const cached = this.cache.get('entrypoints', entrypoint.name)!;\n let evaluatedCreated = false;\n if (!entrypoint.supersededWith) {\n this.cache.add(\n 'entrypoints',\n entrypoint.name,\n entrypoint.createEvaluated()\n );\n evaluatedCreated = true;\n }\n\n const { transformedCode: source } = entrypoint;\n const { pluginOptions } = this.services.options;\n\n if (!source) {\n this.debug(`evaluate`, 'there is nothing to evaluate');\n return;\n }\n\n if (this.isEvaluated) {\n this.debug('evaluate', `is already evaluated`);\n return;\n }\n\n this.debug('evaluate');\n this.debug.extend('source')('%s', source);\n\n this.isEvaluated = true;\n\n const { filename } = this;\n\n if (/\\.json$/.test(filename)) {\n // For JSON files, parse it to a JS object similar to Node\n this.exports = JSON.parse(source);\n return;\n }\n\n const { context, teardown } = createVmContext(\n filename,\n pluginOptions.features,\n {\n module: this,\n exports: entrypoint.exports,\n require: this.require,\n __wyw_dynamic_import: async (id: string) => this.require(id),\n __dirname: path.dirname(filename),\n },\n pluginOptions.overrideContext\n );\n\n try {\n const script = new vm.Script(\n `(function (exports) { ${source}\\n})(exports);`,\n {\n filename,\n }\n );\n\n script.runInContext(context);\n } catch (e) {\n this.isEvaluated = false;\n if (evaluatedCreated) {\n this.cache.add('entrypoints', entrypoint.name, cached);\n }\n\n if (isUnprocessedEntrypointError(e)) {\n // It will be handled by evalFile scenario\n throw e;\n }\n\n if (e instanceof EvalError) {\n this.debug('%O', e);\n\n throw e;\n }\n\n this.debug('%O\\n%O', e, this.callstack);\n throw new EvalError(\n `${(e as Error).message} in${this.callstack.join('\\n| ')}\\n`\n );\n } finally {\n teardown();\n }\n }\n\n getEntrypoint(\n filename: string,\n only: string[],\n log: Debugger\n ): Entrypoint | IEvaluatedEntrypoint | null {\n const extension = path.extname(filename);\n if (extension !== '.json' && !this.extensions.includes(extension)) {\n return null;\n }\n\n const entrypoint = this.cache.get('entrypoints', filename);\n if (entrypoint && isSuperSet(entrypoint.evaluatedOnly ?? [], only)) {\n log('✅ file has been already evaluated');\n return entrypoint;\n }\n\n if (entrypoint?.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return entrypoint;\n }\n\n if (this.ignored) {\n log(\n '✅ one of the parent files has been ignored during prepare stage. Original code will be used'\n );\n\n const newEntrypoint = this.entrypoint.createChild(\n filename,\n ['*'],\n fs.readFileSync(filename, 'utf-8')\n );\n\n if (newEntrypoint === 'loop') {\n const stack = getStack(this.entrypoint);\n throw new Error(\n `Circular dependency detected: ${stack.join(' -> ')} -> ${filename}`\n );\n }\n\n return newEntrypoint;\n }\n\n // Requested file can be already prepared for evaluation on the stage 1\n if (only && entrypoint) {\n const uncachedExports = getUncached(entrypoint.only ?? [], only);\n if (uncachedExports.length === 0) {\n log('✅ ready for evaluation');\n return entrypoint;\n }\n\n log(\n '❌ file has been processed during prepare stage but %o is not evaluated yet (evaluated: %o)',\n uncachedExports,\n entrypoint.only\n );\n } else {\n log('❌ file has not been processed during prepare stage');\n }\n\n // If code wasn't extracted from cache, it indicates that we were unable\n // to process some of the imports on stage1. Let's try to reprocess.\n const code = fs.readFileSync(filename, 'utf-8');\n const newEntrypoint = Entrypoint.createRoot(\n this.services,\n filename,\n only,\n code\n );\n\n if (newEntrypoint.evaluated) {\n log('✅ file has been already evaluated');\n return newEntrypoint;\n }\n\n if (newEntrypoint.ignored) {\n log(\n '✅ file has been ignored during prepare stage. Original code will be used'\n );\n return newEntrypoint;\n }\n\n return newEntrypoint;\n }\n\n resolveDependency = (id: string): IEntrypointDependency => {\n const cached = this.entrypoint.getDependency(id);\n invariant(!(cached instanceof Promise), 'Dependency is not resolved yet');\n\n if (cached) {\n return cached;\n }\n\n if (!this.ignored) {\n this.debug(\n '❌ import has not been resolved during prepare stage. Fallback to Node.js resolver'\n );\n }\n\n const extensions = this.moduleImpl._extensions;\n const added: string[] = [];\n\n try {\n // Check for supported extensions\n this.extensions.forEach((ext) => {\n if (ext in extensions) {\n return;\n }\n\n // When an extension is not supported, add it\n // And keep track of it to clean it up after resolving\n // Use noop for the transform function since we handle it\n extensions[ext] = NOOP;\n added.push(ext);\n });\n\n const { filename } = this;\n\n const resolved = this.moduleImpl._resolveFilename(id, {\n id: filename,\n filename,\n paths: this.moduleImpl._nodeModulePaths(path.dirname(filename)),\n });\n\n return {\n source: id,\n only: ['*'],\n resolved,\n };\n } finally {\n // Cleanup the extensions we added to restore previous behaviour\n added.forEach((ext) => delete extensions[ext]);\n }\n };\n\n protected createChild(entrypoint: Entrypoint): Module {\n return new Module(this.services, entrypoint, this, this.moduleImpl);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,IAAI;AACnB,OAAOC,YAAY,MAAM,QAAQ;AACjC,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AAEnB,SAASC,SAAS,QAAQ,cAAc;AAIxC,OAAO,0BAA0B;AAEjC,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,QAAQ,EAAEC,UAAU,QAAQ,gCAAgC;AAGrE,SAASC,4BAA4B,QAAQ,gDAAgD;AAE7F,SAASC,eAAe,QAAQ,sBAAsB;AAWtD,OAAO,MAAMC,2BAA2B,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AG,CAAC;QACXjB;MACF,CAAC;IACH,CAAC,SAAS;MACR;MACAiF,KAAK,CAACC,OAAO,CAAEC,GAAG,IAAK,OAAO3C,UAAU,CAAC2C,GAAG,CAAC,CAAC;IAChD;EACF,CAAC;EAES7D,WAAWA,CAACP,UAAsB,EAAU;IACpD,OAAO,IAAIb,MAAM,CAAC,IAAI,CAAC0B,QAAQ,EAAEb,UAAU,EAAE,IAAI,EAAE,IAAI,CAACe,UAAU,CAAC;EACrE;AACF"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=babel-merge.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-merge.d.js","names":[],"sources":["../../src/options/babel-merge.d.ts"],"sourcesContent":["declare module 'babel-merge' {\n import type { TransformOptions } from '@babel/core';\n\n interface Options {\n clone?: boolean;\n customMerge?: (\n key: string,\n options?: Options\n ) => ((x: unknown, y: unknown) => unknown) | undefined;\n arrayMerge?(\n target: unknown[],\n source: unknown[],\n options?: Options\n ): unknown[];\n isMergeableObject?(value: object): boolean;\n }\n\n interface BabelMerge {\n (\n source?: TransformOptions,\n overrides?: TransformOptions,\n deepmergeOpts?: Options\n ): TransformOptions;\n all(\n values: (TransformOptions | undefined)[],\n deepmergeOpts?: Options\n ): TransformOptions;\n }\n\n const babelMerge: BabelMerge;\n\n export = babelMerge;\n}\n"],"mappings":""}
@@ -0,0 +1,28 @@
1
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
2
+ /// <reference path="./babel-merge.d.ts" />
3
+
4
+ import babelMerge from 'babel-merge';
5
+ import { isNotNull } from '../utils/isNotNull';
6
+ const cache = new WeakMap();
7
+ const merge = (a, b) => {
8
+ if (!cache.has(a)) {
9
+ cache.set(a, new WeakMap());
10
+ }
11
+ const cacheForA = cache.get(a);
12
+ if (cacheForA.has(b)) {
13
+ return cacheForA.get(b);
14
+ }
15
+ const result = babelMerge(a, b);
16
+ cacheForA.set(b, result);
17
+ return result;
18
+ };
19
+
20
+ /**
21
+ * Merges babel configs together. If a pair of configs were merged before,
22
+ * it will return the cached result.
23
+ */
24
+ export function buildOptions(...configs) {
25
+ // Merge all configs together
26
+ return configs.map(i => i ?? null).filter(isNotNull).reduce(merge);
27
+ }
28
+ //# sourceMappingURL=buildOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildOptions.js","names":["babelMerge","isNotNull","cache","WeakMap","merge","a","b","has","set","cacheForA","get","result","buildOptions","configs","map","i","filter","reduce"],"sources":["../../src/options/buildOptions.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/triple-slash-reference\n/// <reference path=\"./babel-merge.d.ts\" />\n\nimport type { TransformOptions } from '@babel/core';\nimport babelMerge from 'babel-merge';\n\nimport { isNotNull } from '../utils/isNotNull';\n\nconst cache = new WeakMap<\n TransformOptions,\n WeakMap<TransformOptions, TransformOptions>\n>();\n\nconst merge = (a: TransformOptions, b: TransformOptions) => {\n if (!cache.has(a)) {\n cache.set(a, new WeakMap());\n }\n\n const cacheForA = cache.get(a)!;\n if (cacheForA.has(b)) {\n return cacheForA.get(b)!;\n }\n\n const result = babelMerge(a, b);\n cacheForA.set(b, result);\n return result;\n};\n\n/**\n * Merges babel configs together. If a pair of configs were merged before,\n * it will return the cached result.\n */\nexport function buildOptions(\n ...configs: (TransformOptions | null | undefined)[]\n): TransformOptions {\n // Merge all configs together\n return configs\n .map((i) => i ?? null)\n .filter(isNotNull)\n .reduce(merge);\n}\n"],"mappings":"AAAA;AACA;;AAGA,OAAOA,UAAU,MAAM,aAAa;AAEpC,SAASC,SAAS,QAAQ,oBAAoB;AAE9C,MAAMC,KAAK,GAAG,IAAIC,OAAO,CAGvB,CAAC;AAEH,MAAMC,KAAK,GAAGA,CAACC,CAAmB,EAAEC,CAAmB,KAAK;EAC1D,IAAI,CAACJ,KAAK,CAACK,GAAG,CAACF,CAAC,CAAC,EAAE;IACjBH,KAAK,CAACM,GAAG,CAACH,CAAC,EAAE,IAAIF,OAAO,CAAC,CAAC,CAAC;EAC7B;EAEA,MAAMM,SAAS,GAAGP,KAAK,CAACQ,GAAG,CAACL,CAAC,CAAE;EAC/B,IAAII,SAAS,CAACF,GAAG,CAACD,CAAC,CAAC,EAAE;IACpB,OAAOG,SAAS,CAACC,GAAG,CAACJ,CAAC,CAAC;EACzB;EAEA,MAAMK,MAAM,GAAGX,UAAU,CAACK,CAAC,EAAEC,CAAC,CAAC;EAC/BG,SAAS,CAACD,GAAG,CAACF,CAAC,EAAEK,MAAM,CAAC;EACxB,OAAOA,MAAM;AACf,CAAC;;AAED;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAC1B,GAAGC,OAAgD,EACjC;EAClB;EACA,OAAOA,OAAO,CACXC,GAAG,CAAEC,CAAC,IAAKA,CAAC,IAAI,IAAI,CAAC,CACrBC,MAAM,CAACf,SAAS,CAAC,CACjBgB,MAAM,CAACb,KAAK,CAAC;AAClB"}
@@ -0,0 +1,24 @@
1
+ const cache = new WeakMap();
2
+ const empty = {};
3
+ export function loadBabelOptions(babel, filename, overrides = empty) {
4
+ const fileCache = cache.get(overrides) ?? new Map();
5
+ if (fileCache.has(filename)) {
6
+ return fileCache.get(filename);
7
+ }
8
+ const babelOptions = babel.loadOptions({
9
+ ...overrides,
10
+ filename,
11
+ caller: {
12
+ name: 'linaria',
13
+ // Indicates for @babel/preset-env to support all ESM syntax and avoid transforms before it's needed
14
+ supportsStaticESM: true,
15
+ supportsDynamicImport: true,
16
+ supportsTopLevelAwait: true,
17
+ supportsExportNamespaceFrom: true
18
+ }
19
+ }) ?? {};
20
+ fileCache.set(filename, babelOptions);
21
+ cache.set(overrides, fileCache);
22
+ return babelOptions;
23
+ }
24
+ //# sourceMappingURL=loadBabelOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadBabelOptions.js","names":["cache","WeakMap","empty","loadBabelOptions","babel","filename","overrides","fileCache","get","Map","has","babelOptions","loadOptions","caller","name","supportsStaticESM","supportsDynamicImport","supportsTopLevelAwait","supportsExportNamespaceFrom","set"],"sources":["../../src/options/loadBabelOptions.ts"],"sourcesContent":["import type { TransformOptions } from '@babel/core';\n\nimport type { Core } from '../babel';\n\nconst cache = new WeakMap<\n Partial<TransformOptions>,\n Map<string, TransformOptions>\n>();\n\nconst empty = {};\n\nexport function loadBabelOptions(\n babel: Core,\n filename: string,\n overrides: TransformOptions = empty\n) {\n const fileCache = cache.get(overrides) ?? new Map<string, TransformOptions>();\n if (fileCache.has(filename)) {\n return fileCache.get(filename)!;\n }\n\n const babelOptions: TransformOptions =\n babel.loadOptions({\n ...overrides,\n filename,\n caller: {\n name: 'linaria',\n\n // Indicates for @babel/preset-env to support all ESM syntax and avoid transforms before it's needed\n supportsStaticESM: true,\n supportsDynamicImport: true,\n supportsTopLevelAwait: true,\n supportsExportNamespaceFrom: true,\n },\n }) ?? {};\n\n fileCache.set(filename, babelOptions);\n cache.set(overrides, fileCache);\n\n return babelOptions;\n}\n"],"mappings":"AAIA,MAAMA,KAAK,GAAG,IAAIC,OAAO,CAGvB,CAAC;AAEH,MAAMC,KAAK,GAAG,CAAC,CAAC;AAEhB,OAAO,SAASC,gBAAgBA,CAC9BC,KAAW,EACXC,QAAgB,EAChBC,SAA2B,GAAGJ,KAAK,EACnC;EACA,MAAMK,SAAS,GAAGP,KAAK,CAACQ,GAAG,CAACF,SAAS,CAAC,IAAI,IAAIG,GAAG,CAA2B,CAAC;EAC7E,IAAIF,SAAS,CAACG,GAAG,CAACL,QAAQ,CAAC,EAAE;IAC3B,OAAOE,SAAS,CAACC,GAAG,CAACH,QAAQ,CAAC;EAChC;EAEA,MAAMM,YAA8B,GAClCP,KAAK,CAACQ,WAAW,CAAC;IAChB,GAAGN,SAAS;IACZD,QAAQ;IACRQ,MAAM,EAAE;MACNC,IAAI,EAAE,SAAS;MAEf;MACAC,iBAAiB,EAAE,IAAI;MACvBC,qBAAqB,EAAE,IAAI;MAC3BC,qBAAqB,EAAE,IAAI;MAC3BC,2BAA2B,EAAE;IAC/B;EACF,CAAC,CAAC,IAAI,CAAC,CAAC;EAEVX,SAAS,CAACY,GAAG,CAACd,QAAQ,EAAEM,YAAY,CAAC;EACrCX,KAAK,CAACmB,GAAG,CAACb,SAAS,EAAEC,SAAS,CAAC;EAE/B,OAAOI,YAAY;AACrB"}
@@ -0,0 +1,53 @@
1
+ import { logger, syncResolve } from '@wyw-in-js/shared';
2
+ import { TransformCacheCollection } from '../cache';
3
+ import { transformSync } from '../transform';
4
+ import { loadLinariaOptions } from '../transform/helpers/loadLinariaOptions';
5
+ import { collector } from './collector';
6
+ export default function babelTransform(babel, options) {
7
+ const cache = new TransformCacheCollection();
8
+ const debug = logger.extend('babel-transform');
9
+ return {
10
+ name: '@wyw-in-js/transform/babel-transform',
11
+ pre(file) {
12
+ // eslint-disable-next-line require-yield
13
+ function* collect() {
14
+ const {
15
+ valueCache
16
+ } = this.data;
17
+ const {
18
+ loadedAndParsed
19
+ } = this.entrypoint;
20
+ const {
21
+ pluginOptions
22
+ } = this.services.options;
23
+ if (loadedAndParsed.evaluator === 'ignored') {
24
+ throw new Error('entrypoint was ignored');
25
+ }
26
+ collector(file, pluginOptions, valueCache);
27
+ return {
28
+ ast: loadedAndParsed.ast,
29
+ code: loadedAndParsed.code
30
+ };
31
+ }
32
+ debug('start %s', file.opts.filename);
33
+ const pluginOptions = loadLinariaOptions(options);
34
+ transformSync({
35
+ babel,
36
+ cache,
37
+ options: {
38
+ filename: file.opts.filename,
39
+ root: file.opts.root ?? undefined,
40
+ inputSourceMap: file.opts.inputSourceMap ?? undefined,
41
+ pluginOptions
42
+ }
43
+ }, file.code, syncResolve, {
44
+ collect
45
+ });
46
+ },
47
+ visitor: {},
48
+ post(file) {
49
+ debug('end %s', file.opts.filename);
50
+ }
51
+ };
52
+ }
53
+ //# sourceMappingURL=babel-transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-transform.js","names":["logger","syncResolve","TransformCacheCollection","transformSync","loadLinariaOptions","collector","babelTransform","babel","options","cache","debug","extend","name","pre","file","collect","valueCache","data","loadedAndParsed","entrypoint","pluginOptions","services","evaluator","Error","ast","code","opts","filename","root","undefined","inputSourceMap","visitor","post"],"sources":["../../src/plugins/babel-transform.ts"],"sourcesContent":["import type { BabelFile, PluginObj } from '@babel/core';\n\nimport { logger, syncResolve } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport { TransformCacheCollection } from '../cache';\nimport { transformSync } from '../transform';\nimport { loadLinariaOptions } from '../transform/helpers/loadLinariaOptions';\nimport type { ICollectAction, SyncScenarioForAction } from '../transform/types';\nimport type { IPluginState, PluginOptions } from '../types';\n\nimport { collector } from './collector';\n\nexport default function babelTransform(\n babel: Core,\n options: Partial<PluginOptions>\n): PluginObj<IPluginState> {\n const cache = new TransformCacheCollection();\n const debug = logger.extend('babel-transform');\n\n return {\n name: '@wyw-in-js/transform/babel-transform',\n pre(file: BabelFile) {\n // eslint-disable-next-line require-yield\n function* collect(\n this: ICollectAction\n ): SyncScenarioForAction<ICollectAction> {\n const { valueCache } = this.data;\n const { loadedAndParsed } = this.entrypoint;\n const { pluginOptions } = this.services.options;\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n collector(file, pluginOptions, valueCache);\n\n return {\n ast: loadedAndParsed.ast,\n code: loadedAndParsed.code,\n };\n }\n\n debug('start %s', file.opts.filename);\n\n const pluginOptions = loadLinariaOptions(options);\n\n transformSync(\n {\n babel,\n cache,\n options: {\n filename: file.opts.filename!,\n root: file.opts.root ?? undefined,\n inputSourceMap: file.opts.inputSourceMap ?? undefined,\n pluginOptions,\n },\n },\n file.code,\n syncResolve,\n {\n collect,\n }\n );\n },\n visitor: {},\n post(file: BabelFile) {\n debug('end %s', file.opts.filename);\n },\n };\n}\n"],"mappings":"AAEA,SAASA,MAAM,EAAEC,WAAW,QAAQ,mBAAmB;AAGvD,SAASC,wBAAwB,QAAQ,UAAU;AACnD,SAASC,aAAa,QAAQ,cAAc;AAC5C,SAASC,kBAAkB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,CAAC;IACH,CAAC;IACDgB,OAAO,EAAE,CAAC,CAAC;IACXC,IAAIA,CAAClB,IAAe,EAAE;MACpBJ,KAAK,CAAC,QAAQ,EAAEI,IAAI,CAACY,IAAI,CAACC,QAAQ,CAAC;IACrC;EACF,CAAC;AACH"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Collector traverses the AST and collects information about imports and
3
+ * all usages of WYW-processors.
4
+ */
5
+
6
+ import { logger } from '@wyw-in-js/shared';
7
+ import { processTemplateExpression } from '../utils/processTemplateExpression';
8
+ import { removeWithRelated } from '../utils/scopeHelpers';
9
+ import { invalidateTraversalCache } from '../utils/traversalCache';
10
+ export const filename = __filename;
11
+ export function collector(file, options, values) {
12
+ const processors = [];
13
+ const identifiers = [];
14
+ file.path.traverse({
15
+ Identifier: p => {
16
+ identifiers.push(p);
17
+ }
18
+ });
19
+
20
+ // TODO: process transformed literals
21
+ identifiers.forEach(p => {
22
+ processTemplateExpression(p, file.opts, options, processor => {
23
+ processor.build(values);
24
+ processor.doRuntimeReplacement();
25
+ processors.push(processor);
26
+ });
27
+ });
28
+ if (processors.length === 0) {
29
+ // We didn't find any processors.
30
+ return processors;
31
+ }
32
+
33
+ // We can remove __linariaPreval export and all related code
34
+ const prevalExport = file.path.scope.getData('__linariaPreval')?.findParent(p => p.isExpressionStatement());
35
+ if (prevalExport) {
36
+ removeWithRelated([prevalExport]);
37
+ }
38
+ return processors;
39
+ }
40
+ export default function collectorPlugin(babel, options) {
41
+ const values = options.values ?? new Map();
42
+ const debug = logger.extend('collector');
43
+ return {
44
+ name: '@wyw-in-js/transform/collector',
45
+ pre(file) {
46
+ debug('start %s', file.opts.filename);
47
+ const processors = collector(file, options, values);
48
+ if (processors.length === 0) {
49
+ // We didn't find any Linaria template literals.
50
+ return;
51
+ }
52
+ this.file.metadata.linaria = {
53
+ processors,
54
+ replacements: [],
55
+ rules: {},
56
+ dependencies: []
57
+ };
58
+ debug('end %s', file.opts.filename);
59
+ },
60
+ visitor: {},
61
+ post(file) {
62
+ invalidateTraversalCache(file.path);
63
+ }
64
+ };
65
+ }
66
+ //# sourceMappingURL=collector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.js","names":["logger","processTemplateExpression","removeWithRelated","invalidateTraversalCache","filename","__filename","collector","file","options","values","processors","identifiers","path","traverse","Identifier","p","push","forEach","opts","processor","build","doRuntimeReplacement","length","prevalExport","scope","getData","findParent","isExpressionStatement","collectorPlugin","babel","Map","debug","extend","name","pre","metadata","linaria","replacements","rules","dependencies","visitor","post"],"sources":["../../src/plugins/collector.ts"],"sourcesContent":["/**\n * Collector traverses the AST and collects information about imports and\n * all usages of WYW-processors.\n */\n\nimport type { BabelFile, PluginObj } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { Identifier } from '@babel/types';\n\nimport type { ValueCache } from '@wyw-in-js/processor-utils';\nimport { logger } from '@wyw-in-js/shared';\nimport type { StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport type { IPluginState } from '../types';\nimport type { WYWTransformMetadata } from '../utils/TransformMetadata';\nimport { processTemplateExpression } from '../utils/processTemplateExpression';\nimport { removeWithRelated } from '../utils/scopeHelpers';\nimport { invalidateTraversalCache } from '../utils/traversalCache';\n\nexport const filename = __filename;\n\nexport function collector(\n file: BabelFile,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n values: ValueCache\n) {\n const processors: WYWTransformMetadata['processors'] = [];\n\n const identifiers: NodePath<Identifier>[] = [];\n file.path.traverse({\n Identifier: (p) => {\n identifiers.push(p);\n },\n });\n\n // TODO: process transformed literals\n identifiers.forEach((p) => {\n processTemplateExpression(p, file.opts, options, (processor) => {\n processor.build(values);\n processor.doRuntimeReplacement();\n processors.push(processor);\n });\n });\n\n if (processors.length === 0) {\n // We didn't find any processors.\n return processors;\n }\n\n // We can remove __linariaPreval export and all related code\n const prevalExport = (\n file.path.scope.getData('__linariaPreval') as NodePath | undefined\n )?.findParent((p) => p.isExpressionStatement());\n if (prevalExport) {\n removeWithRelated([prevalExport]);\n }\n\n return processors;\n}\n\nexport default function collectorPlugin(\n babel: Core,\n options: StrictOptions & { values?: ValueCache }\n): PluginObj<IPluginState> {\n const values = options.values ?? new Map<string, unknown>();\n const debug = logger.extend('collector');\n return {\n name: '@wyw-in-js/transform/collector',\n pre(file: BabelFile) {\n debug('start %s', file.opts.filename);\n\n const processors = collector(file, options, values);\n\n if (processors.length === 0) {\n // We didn't find any Linaria template literals.\n return;\n }\n\n this.file.metadata.linaria = {\n processors,\n replacements: [],\n rules: {},\n dependencies: [],\n };\n\n debug('end %s', file.opts.filename);\n },\n visitor: {},\n post(file: BabelFile) {\n invalidateTraversalCache(file.path);\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAOA,SAASA,MAAM,QAAQ,mBAAmB;AAM1C,SAASC,yBAAyB,QAAQ,oCAAoC;AAC9E,SAASC,iBAAiB,QAAQ,uBAAuB;AACzD,SAASC,wBAAwB,QAAQ,yBAAyB;AAElE,OAAO,MAAMC,QAAQ,GAAGC,UAAU;AAElC,OAAO,SAASC,SAASA,CACvBC,IAAe,EACfC,OAGC,EACDC,MAAkB,EAClB;EACA,MAAMC,UAA8C,GAAG,EAAE;EAEzD,MAAMC,WAAmC,GAAG,EAAE;EAC9CJ,IAAI,CAACK,IAAI,CAACC,QAAQ,CAAC;IACjBC,UAAU,EAAGC,CAAC,IAAK;MACjBJ,WAAW,CAACK,IAAI,CAACD,CAAC,CAAC;IACrB;EACF,CAAC,CAAC;;EAEF;EACAJ,WAAW,CAACM,OAAO,CAAEF,CAAC,IAAK;IACzBd,yBAAyB,CAACc,CAAC,EAAER,IAAI,CAACW,IAAI,EAAEV,OAAO,EAAGW,SAAS,IAAK;MAC9DA,SAAS,CAACC,KAAK,CAACX,MAAM,CAAC;MACvBU,SAAS,CAACE,oBAAoB,CAAC,CAAC;MAChCX,UAAU,CAACM,IAAI,CAACG,SAAS,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AACK,IAAI,CAAC;IACrC;EACF,CAAC;AACH"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The plugin that replaces `import()` with `__wyw_dynamic_import` as Node VM does not support dynamic imports yet.
3
+ */
4
+ export default function dynamicImport(babel) {
5
+ const {
6
+ types: t
7
+ } = babel;
8
+ return {
9
+ name: '@wyw-in-js/transform/dynamic-import',
10
+ visitor: {
11
+ CallExpression(path) {
12
+ if (path.get('callee').isImport()) {
13
+ const moduleName = path.get('arguments.0');
14
+ if (moduleName.isStringLiteral()) {
15
+ path.replaceWith(t.callExpression(t.identifier('__wyw_dynamic_import'), [t.stringLiteral(moduleName.node.value)]));
16
+ return;
17
+ }
18
+ if (moduleName.isTemplateLiteral()) {
19
+ path.replaceWith(t.callExpression(t.identifier('__wyw_dynamic_import'), [t.cloneNode(moduleName.node, true, true)]));
20
+ return;
21
+ }
22
+ throw new Error('Dynamic import argument must be a string or a template literal');
23
+ }
24
+ }
25
+ }
26
+ };
27
+ }
28
+ //# sourceMappingURL=dynamic-import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamic-import.js","names":["dynamicImport","babel","types","t","name","visitor","CallExpression","path","get","isImport","moduleName","isStringLiteral","replaceWith","callExpression","identifier","stringLiteral","node","value","isTemplateLiteral","cloneNode","Error"],"sources":["../../src/plugins/dynamic-import.ts"],"sourcesContent":["import type { NodePath, PluginObj } from '@babel/core';\n\nimport type { Core } from '../babel';\n\n/**\n * The plugin that replaces `import()` with `__wyw_dynamic_import` as Node VM does not support dynamic imports yet.\n */\nexport default function dynamicImport(babel: Core): PluginObj {\n const { types: t } = babel;\n\n return {\n name: '@wyw-in-js/transform/dynamic-import',\n visitor: {\n CallExpression(path) {\n if (path.get('callee').isImport()) {\n const moduleName = path.get('arguments.0') as NodePath;\n\n if (moduleName.isStringLiteral()) {\n path.replaceWith(\n t.callExpression(t.identifier('__wyw_dynamic_import'), [\n t.stringLiteral(moduleName.node.value),\n ])\n );\n return;\n }\n\n if (moduleName.isTemplateLiteral()) {\n path.replaceWith(\n t.callExpression(t.identifier('__wyw_dynamic_import'), [\n t.cloneNode(moduleName.node, true, true),\n ])\n );\n return;\n }\n\n throw new Error(\n 'Dynamic import argument must be a string or a template literal'\n );\n }\n },\n },\n };\n}\n"],"mappings":"AAIA;AACA;AACA;AACA,eAAe,SAASA,aAAaA,CAACC,KAAW,EAAa;EAC5D,MAAM;IAAEC,KAAK,EAAEC;EAAE,CAAC,GAAGF,KAAK;EAE1B,OAAO;IACLG,IAAI,EAAE,qCAAqC;IAC3CC,OAAO,EAAE;MACPC,cAAcA,CAACC,IAAI,EAAE;QACnB,IAAIA,IAAI,CAACC,GAAG,CAAC,QAAQ,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE;UACjC,MAAMC,UAAU,GAAGH,IAAI,CAACC,GAAG,CAAC,aAAa,CAAa;UAEtD,IAAIE,UAAU,CAACC,eAAe,CAAC,CAAC,EAAE;YAChCJ,IAAI,CAACK,WAAW,CACdT,CAAC,CAACU,cAAc,CAACV,CAAC,CAACW,UAAU,CAAC,sBAAsB,CAAC,EAAE,CACrDX,CAAC,CAACY,aAAa,CAACL,UAAU,CAACM,IAAI,CAACC,KAAK,CAAC,CACvC,CACH,CAAC;YACD;UACF;UAEA,IAAIP,UAAU,CAACQ,iBAAiB,CAAC,CAAC,EAAE;YAClCX,IAAI,CAACK,WAAW,CACdT,CAAC,CAACU,cAAc,CAACV,CAAC,CAACW,UAAU,CAAC,sBAAsB,CAAC,EAAE,CACrDX,CAAC,CAACgB,SAAS,CAACT,UAAU,CAACM,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CACzC,CACH,CAAC;YACD;UACF;UAEA,MAAM,IAAII,KAAK,CACb,gEACF,CAAC;QACH;MACF;IACF;EACF,CAAC;AACH"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * This file is a babel preset used to transform files inside evaluators.
3
+ * It works the same as main `babel/extract` preset, but do not evaluate lazy dependencies.
4
+ */
5
+
6
+ import { isFeatureEnabled, logger } from '@wyw-in-js/shared';
7
+ import { EventEmitter } from '../utils/EventEmitter';
8
+ import { addIdentifierToLinariaPreval } from '../utils/addIdentifierToLinariaPreval';
9
+ import { getFileIdx } from '../utils/getFileIdx';
10
+ import { processTemplateExpression } from '../utils/processTemplateExpression';
11
+ import { removeDangerousCode } from '../utils/removeDangerousCode';
12
+ import { invalidateTraversalCache } from '../utils/traversalCache';
13
+ export function preeval(babel, {
14
+ eventEmitter = EventEmitter.dummy,
15
+ ...options
16
+ }) {
17
+ const {
18
+ types: t
19
+ } = babel;
20
+ return {
21
+ name: '@wyw-in-js/transform/preeval',
22
+ pre(file) {
23
+ const filename = file.opts.filename;
24
+ const log = logger.extend('preeval').extend(getFileIdx(filename));
25
+ log('start', 'Looking for template literals…');
26
+ const rootScope = file.scope;
27
+ this.processors = [];
28
+ eventEmitter.perf('transform:preeval:processTemplate', () => {
29
+ file.path.traverse({
30
+ Identifier: p => {
31
+ processTemplateExpression(p, file.opts, options, processor => {
32
+ processor.dependencies.forEach(dependency => {
33
+ if (dependency.ex.type === 'Identifier') {
34
+ addIdentifierToLinariaPreval(rootScope, dependency.ex.name);
35
+ }
36
+ });
37
+ processor.doEvaltimeReplacement();
38
+ this.processors.push(processor);
39
+ });
40
+ }
41
+ });
42
+ });
43
+ if (isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)) {
44
+ log('start', 'Strip all JSX and browser related stuff');
45
+ eventEmitter.perf('transform:preeval:removeDangerousCode', () => removeDangerousCode(file.path));
46
+ }
47
+ },
48
+ visitor: {},
49
+ post(file) {
50
+ const log = logger.extend('preeval').extend(getFileIdx(file.opts.filename));
51
+ invalidateTraversalCache(file.path);
52
+ if (this.processors.length === 0) {
53
+ log('end', "We didn't find any Linaria template literals");
54
+
55
+ // We didn't find any Linaria template literals.
56
+ return;
57
+ }
58
+ this.file.metadata.linaria = {
59
+ processors: this.processors,
60
+ replacements: [],
61
+ rules: {},
62
+ dependencies: []
63
+ };
64
+ const linariaPreval = file.path.getData('__linariaPreval');
65
+ if (!linariaPreval) {
66
+ // Event if there is no dependencies, we still need to add __linariaPreval
67
+ const linariaExport = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('exports'), t.identifier('__linariaPreval')), t.objectExpression([])));
68
+ file.path.pushContainer('body', linariaExport);
69
+ }
70
+ log('end', '__linariaPreval has been added');
71
+ }
72
+ };
73
+ }
74
+ export default preeval;
75
+ //# sourceMappingURL=preeval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preeval.js","names":["isFeatureEnabled","logger","EventEmitter","addIdentifierToLinariaPreval","getFileIdx","processTemplateExpression","removeDangerousCode","invalidateTraversalCache","preeval","babel","eventEmitter","dummy","options","types","t","name","pre","file","filename","opts","log","extend","rootScope","scope","processors","perf","path","traverse","Identifier","p","processor","dependencies","forEach","dependency","ex","type","doEvaltimeReplacement","push","features","visitor","post","length","metadata","linaria","replacements","rules","linariaPreval","getData","linariaExport","expressionStatement","assignmentExpression","memberExpression","identifier","objectExpression","pushContainer"],"sources":["../../src/plugins/preeval.ts"],"sourcesContent":["/**\n * This file is a babel preset used to transform files inside evaluators.\n * It works the same as main `babel/extract` preset, but do not evaluate lazy dependencies.\n */\nimport type { BabelFile, PluginObj } from '@babel/core';\n\nimport type { StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled, logger } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport type { IPluginState } from '../types';\nimport { EventEmitter } from '../utils/EventEmitter';\nimport { addIdentifierToLinariaPreval } from '../utils/addIdentifierToLinariaPreval';\nimport { getFileIdx } from '../utils/getFileIdx';\nimport { processTemplateExpression } from '../utils/processTemplateExpression';\nimport { removeDangerousCode } from '../utils/removeDangerousCode';\nimport { invalidateTraversalCache } from '../utils/traversalCache';\n\nexport type PreevalOptions = Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'features'\n> & { eventEmitter: EventEmitter };\n\nexport function preeval(\n babel: Core,\n { eventEmitter = EventEmitter.dummy, ...options }: PreevalOptions\n): PluginObj<IPluginState & { onFinish: () => void }> {\n const { types: t } = babel;\n return {\n name: '@wyw-in-js/transform/preeval',\n pre(file: BabelFile) {\n const filename = file.opts.filename!;\n const log = logger.extend('preeval').extend(getFileIdx(filename));\n\n log('start', 'Looking for template literals…');\n\n const rootScope = file.scope;\n this.processors = [];\n\n eventEmitter.perf('transform:preeval:processTemplate', () => {\n file.path.traverse({\n Identifier: (p) => {\n processTemplateExpression(p, file.opts, options, (processor) => {\n processor.dependencies.forEach((dependency) => {\n if (dependency.ex.type === 'Identifier') {\n addIdentifierToLinariaPreval(rootScope, dependency.ex.name);\n }\n });\n\n processor.doEvaltimeReplacement();\n this.processors.push(processor);\n });\n },\n });\n });\n\n if (\n isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)\n ) {\n log('start', 'Strip all JSX and browser related stuff');\n eventEmitter.perf('transform:preeval:removeDangerousCode', () =>\n removeDangerousCode(file.path)\n );\n }\n },\n visitor: {},\n post(file: BabelFile) {\n const log = logger\n .extend('preeval')\n .extend(getFileIdx(file.opts.filename!));\n\n invalidateTraversalCache(file.path);\n\n if (this.processors.length === 0) {\n log('end', \"We didn't find any Linaria template literals\");\n\n // We didn't find any Linaria template literals.\n return;\n }\n\n this.file.metadata.linaria = {\n processors: this.processors,\n replacements: [],\n rules: {},\n dependencies: [],\n };\n\n const linariaPreval = file.path.getData('__linariaPreval');\n if (!linariaPreval) {\n // Event if there is no dependencies, we still need to add __linariaPreval\n const linariaExport = t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(\n t.identifier('exports'),\n t.identifier('__linariaPreval')\n ),\n t.objectExpression([])\n )\n );\n\n file.path.pushContainer('body', linariaExport);\n }\n\n log('end', '__linariaPreval has been added');\n },\n };\n}\n\nexport default preeval;\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAIA,SAASA,gBAAgB,EAAEC,MAAM,QAAQ,mBAAmB;AAI5D,SAASC,YAAY,QA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