@embroider/compat 4.1.25 → 4.1.26

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 (305) hide show
  1. package/package.json +5 -5
  2. package/dist/src/add-to-tree.d.ts +0 -9
  3. package/dist/src/add-to-tree.d.ts.map +0 -1
  4. package/dist/src/add-to-tree.js +0 -22
  5. package/dist/src/add-to-tree.js.map +0 -1
  6. package/dist/src/addon-dependency-rules/ember-basic-dropdown.d.ts +0 -4
  7. package/dist/src/addon-dependency-rules/ember-basic-dropdown.d.ts.map +0 -1
  8. package/dist/src/addon-dependency-rules/ember-basic-dropdown.js +0 -28
  9. package/dist/src/addon-dependency-rules/ember-basic-dropdown.js.map +0 -1
  10. package/dist/src/addon-dependency-rules/ember-modal-dialog.d.ts +0 -4
  11. package/dist/src/addon-dependency-rules/ember-modal-dialog.d.ts.map +0 -1
  12. package/dist/src/addon-dependency-rules/ember-modal-dialog.js +0 -27
  13. package/dist/src/addon-dependency-rules/ember-modal-dialog.js.map +0 -1
  14. package/dist/src/addon-dependency-rules/ember-power-select-typeahead.d.ts +0 -4
  15. package/dist/src/addon-dependency-rules/ember-power-select-typeahead.d.ts.map +0 -1
  16. package/dist/src/addon-dependency-rules/ember-power-select-typeahead.js +0 -23
  17. package/dist/src/addon-dependency-rules/ember-power-select-typeahead.js.map +0 -1
  18. package/dist/src/addon-dependency-rules/ember-power-select-with-create.d.ts +0 -4
  19. package/dist/src/addon-dependency-rules/ember-power-select-with-create.d.ts.map +0 -1
  20. package/dist/src/addon-dependency-rules/ember-power-select-with-create.js +0 -18
  21. package/dist/src/addon-dependency-rules/ember-power-select-with-create.js.map +0 -1
  22. package/dist/src/addon-dependency-rules/ember-power-select.d.ts +0 -4
  23. package/dist/src/addon-dependency-rules/ember-power-select.d.ts.map +0 -1
  24. package/dist/src/addon-dependency-rules/ember-power-select.js +0 -57
  25. package/dist/src/addon-dependency-rules/ember-power-select.js.map +0 -1
  26. package/dist/src/audit/babel-visitor.d.ts +0 -41
  27. package/dist/src/audit/babel-visitor.d.ts.map +0 -1
  28. package/dist/src/audit/babel-visitor.js +0 -230
  29. package/dist/src/audit/babel-visitor.js.map +0 -1
  30. package/dist/src/audit/build.d.ts +0 -8
  31. package/dist/src/audit/build.d.ts.map +0 -1
  32. package/dist/src/audit/build.js +0 -71
  33. package/dist/src/audit/build.js.map +0 -1
  34. package/dist/src/audit/options.d.ts +0 -9
  35. package/dist/src/audit/options.d.ts.map +0 -1
  36. package/dist/src/audit/options.js +0 -3
  37. package/dist/src/audit/options.js.map +0 -1
  38. package/dist/src/audit.d.ts +0 -60
  39. package/dist/src/audit.d.ts.map +0 -1
  40. package/dist/src/audit.js +0 -296
  41. package/dist/src/audit.js.map +0 -1
  42. package/dist/src/babel.d.ts +0 -18
  43. package/dist/src/babel.d.ts.map +0 -1
  44. package/dist/src/babel.js +0 -138
  45. package/dist/src/babel.js.map +0 -1
  46. package/dist/src/build-compat-addon.d.ts +0 -5
  47. package/dist/src/build-compat-addon.d.ts.map +0 -1
  48. package/dist/src/build-compat-addon.js +0 -43
  49. package/dist/src/build-compat-addon.js.map +0 -1
  50. package/dist/src/compat-adapters/@ember/test-waiters.d.ts +0 -6
  51. package/dist/src/compat-adapters/@ember/test-waiters.d.ts.map +0 -1
  52. package/dist/src/compat-adapters/@ember/test-waiters.js +0 -26
  53. package/dist/src/compat-adapters/@ember/test-waiters.js.map +0 -1
  54. package/dist/src/compat-adapters/@ember-data/adapter.d.ts +0 -2
  55. package/dist/src/compat-adapters/@ember-data/adapter.d.ts.map +0 -1
  56. package/dist/src/compat-adapters/@ember-data/adapter.js +0 -6
  57. package/dist/src/compat-adapters/@ember-data/adapter.js.map +0 -1
  58. package/dist/src/compat-adapters/@ember-data/model.d.ts +0 -2
  59. package/dist/src/compat-adapters/@ember-data/model.d.ts.map +0 -1
  60. package/dist/src/compat-adapters/@ember-data/model.js +0 -6
  61. package/dist/src/compat-adapters/@ember-data/model.js.map +0 -1
  62. package/dist/src/compat-adapters/@ember-data/record-data.d.ts +0 -2
  63. package/dist/src/compat-adapters/@ember-data/record-data.d.ts.map +0 -1
  64. package/dist/src/compat-adapters/@ember-data/record-data.js +0 -6
  65. package/dist/src/compat-adapters/@ember-data/record-data.js.map +0 -1
  66. package/dist/src/compat-adapters/@ember-data/serializer.d.ts +0 -2
  67. package/dist/src/compat-adapters/@ember-data/serializer.d.ts.map +0 -1
  68. package/dist/src/compat-adapters/@ember-data/serializer.js +0 -6
  69. package/dist/src/compat-adapters/@ember-data/serializer.js.map +0 -1
  70. package/dist/src/compat-adapters/@ember-data/store.d.ts +0 -2
  71. package/dist/src/compat-adapters/@ember-data/store.d.ts.map +0 -1
  72. package/dist/src/compat-adapters/@ember-data/store.js +0 -6
  73. package/dist/src/compat-adapters/@ember-data/store.js.map +0 -1
  74. package/dist/src/compat-adapters/@glimmer/tracking.d.ts +0 -10
  75. package/dist/src/compat-adapters/@glimmer/tracking.d.ts.map +0 -1
  76. package/dist/src/compat-adapters/@glimmer/tracking.js +0 -36
  77. package/dist/src/compat-adapters/@glimmer/tracking.js.map +0 -1
  78. package/dist/src/compat-adapters/@html-next/vertical-collection.d.ts +0 -5
  79. package/dist/src/compat-adapters/@html-next/vertical-collection.d.ts.map +0 -1
  80. package/dist/src/compat-adapters/@html-next/vertical-collection.js +0 -14
  81. package/dist/src/compat-adapters/@html-next/vertical-collection.js.map +0 -1
  82. package/dist/src/compat-adapters/active-model-adapter.d.ts +0 -5
  83. package/dist/src/compat-adapters/active-model-adapter.d.ts.map +0 -1
  84. package/dist/src/compat-adapters/active-model-adapter.js +0 -16
  85. package/dist/src/compat-adapters/active-model-adapter.js.map +0 -1
  86. package/dist/src/compat-adapters/ember-asset-loader.d.ts +0 -6
  87. package/dist/src/compat-adapters/ember-asset-loader.d.ts.map +0 -1
  88. package/dist/src/compat-adapters/ember-asset-loader.js +0 -36
  89. package/dist/src/compat-adapters/ember-asset-loader.js.map +0 -1
  90. package/dist/src/compat-adapters/ember-cli-addon-docs.d.ts +0 -5
  91. package/dist/src/compat-adapters/ember-cli-addon-docs.d.ts.map +0 -1
  92. package/dist/src/compat-adapters/ember-cli-addon-docs.js +0 -14
  93. package/dist/src/compat-adapters/ember-cli-addon-docs.js.map +0 -1
  94. package/dist/src/compat-adapters/ember-cli-babel.d.ts +0 -5
  95. package/dist/src/compat-adapters/ember-cli-babel.d.ts.map +0 -1
  96. package/dist/src/compat-adapters/ember-cli-babel.js +0 -25
  97. package/dist/src/compat-adapters/ember-cli-babel.js.map +0 -1
  98. package/dist/src/compat-adapters/ember-cli-clipboard.d.ts +0 -5
  99. package/dist/src/compat-adapters/ember-cli-clipboard.d.ts.map +0 -1
  100. package/dist/src/compat-adapters/ember-cli-clipboard.js +0 -31
  101. package/dist/src/compat-adapters/ember-cli-clipboard.js.map +0 -1
  102. package/dist/src/compat-adapters/ember-cli-deprecation-workflow.d.ts +0 -6
  103. package/dist/src/compat-adapters/ember-cli-deprecation-workflow.d.ts.map +0 -1
  104. package/dist/src/compat-adapters/ember-cli-deprecation-workflow.js +0 -46
  105. package/dist/src/compat-adapters/ember-cli-deprecation-workflow.js.map +0 -1
  106. package/dist/src/compat-adapters/ember-cli-fastboot-testing.d.ts +0 -5
  107. package/dist/src/compat-adapters/ember-cli-fastboot-testing.d.ts.map +0 -1
  108. package/dist/src/compat-adapters/ember-cli-fastboot-testing.js +0 -21
  109. package/dist/src/compat-adapters/ember-cli-fastboot-testing.js.map +0 -1
  110. package/dist/src/compat-adapters/ember-cli-fastboot.d.ts +0 -12
  111. package/dist/src/compat-adapters/ember-cli-fastboot.d.ts.map +0 -1
  112. package/dist/src/compat-adapters/ember-cli-fastboot.js +0 -157
  113. package/dist/src/compat-adapters/ember-cli-fastboot.js.map +0 -1
  114. package/dist/src/compat-adapters/ember-cli-mirage.d.ts +0 -7
  115. package/dist/src/compat-adapters/ember-cli-mirage.d.ts.map +0 -1
  116. package/dist/src/compat-adapters/ember-cli-mirage.js +0 -29
  117. package/dist/src/compat-adapters/ember-cli-mirage.js.map +0 -1
  118. package/dist/src/compat-adapters/ember-composable-helpers.d.ts +0 -6
  119. package/dist/src/compat-adapters/ember-composable-helpers.d.ts.map +0 -1
  120. package/dist/src/compat-adapters/ember-composable-helpers.js +0 -40
  121. package/dist/src/compat-adapters/ember-composable-helpers.js.map +0 -1
  122. package/dist/src/compat-adapters/ember-data.d.ts +0 -10
  123. package/dist/src/compat-adapters/ember-data.d.ts.map +0 -1
  124. package/dist/src/compat-adapters/ember-data.js +0 -74
  125. package/dist/src/compat-adapters/ember-data.js.map +0 -1
  126. package/dist/src/compat-adapters/ember-decorators.d.ts +0 -5
  127. package/dist/src/compat-adapters/ember-decorators.d.ts.map +0 -1
  128. package/dist/src/compat-adapters/ember-decorators.js +0 -16
  129. package/dist/src/compat-adapters/ember-decorators.js.map +0 -1
  130. package/dist/src/compat-adapters/ember-engines.d.ts +0 -15
  131. package/dist/src/compat-adapters/ember-engines.d.ts.map +0 -1
  132. package/dist/src/compat-adapters/ember-engines.js +0 -34
  133. package/dist/src/compat-adapters/ember-engines.js.map +0 -1
  134. package/dist/src/compat-adapters/ember-exam.d.ts +0 -16
  135. package/dist/src/compat-adapters/ember-exam.d.ts.map +0 -1
  136. package/dist/src/compat-adapters/ember-exam.js +0 -30
  137. package/dist/src/compat-adapters/ember-exam.js.map +0 -1
  138. package/dist/src/compat-adapters/ember-fetch.d.ts +0 -7
  139. package/dist/src/compat-adapters/ember-fetch.d.ts.map +0 -1
  140. package/dist/src/compat-adapters/ember-fetch.js +0 -56
  141. package/dist/src/compat-adapters/ember-fetch.js.map +0 -1
  142. package/dist/src/compat-adapters/ember-get-config.d.ts +0 -17
  143. package/dist/src/compat-adapters/ember-get-config.d.ts.map +0 -1
  144. package/dist/src/compat-adapters/ember-get-config.js +0 -41
  145. package/dist/src/compat-adapters/ember-get-config.js.map +0 -1
  146. package/dist/src/compat-adapters/ember-inflector.d.ts +0 -7
  147. package/dist/src/compat-adapters/ember-inflector.d.ts.map +0 -1
  148. package/dist/src/compat-adapters/ember-inflector.js +0 -39
  149. package/dist/src/compat-adapters/ember-inflector.js.map +0 -1
  150. package/dist/src/compat-adapters/ember-percy.d.ts +0 -5
  151. package/dist/src/compat-adapters/ember-percy.d.ts.map +0 -1
  152. package/dist/src/compat-adapters/ember-percy.js +0 -18
  153. package/dist/src/compat-adapters/ember-percy.js.map +0 -1
  154. package/dist/src/compat-adapters/ember-resolver.d.ts +0 -5
  155. package/dist/src/compat-adapters/ember-resolver.d.ts.map +0 -1
  156. package/dist/src/compat-adapters/ember-resolver.js +0 -21
  157. package/dist/src/compat-adapters/ember-resolver.js.map +0 -1
  158. package/dist/src/compat-adapters/ember-scroll-modifiers.d.ts +0 -5
  159. package/dist/src/compat-adapters/ember-scroll-modifiers.d.ts.map +0 -1
  160. package/dist/src/compat-adapters/ember-scroll-modifiers.js +0 -23
  161. package/dist/src/compat-adapters/ember-scroll-modifiers.js.map +0 -1
  162. package/dist/src/compat-adapters/ember-source.d.ts +0 -12
  163. package/dist/src/compat-adapters/ember-source.d.ts.map +0 -1
  164. package/dist/src/compat-adapters/ember-source.js +0 -465
  165. package/dist/src/compat-adapters/ember-source.js.map +0 -1
  166. package/dist/src/compat-adapters/ember-svg-jar.d.ts +0 -5
  167. package/dist/src/compat-adapters/ember-svg-jar.d.ts.map +0 -1
  168. package/dist/src/compat-adapters/ember-svg-jar.js +0 -29
  169. package/dist/src/compat-adapters/ember-svg-jar.js.map +0 -1
  170. package/dist/src/compat-adapters/ember-test-selectors.d.ts +0 -6
  171. package/dist/src/compat-adapters/ember-test-selectors.d.ts.map +0 -1
  172. package/dist/src/compat-adapters/ember-test-selectors.js +0 -19
  173. package/dist/src/compat-adapters/ember-test-selectors.js.map +0 -1
  174. package/dist/src/compat-addons.d.ts +0 -17
  175. package/dist/src/compat-addons.d.ts.map +0 -1
  176. package/dist/src/compat-addons.js +0 -48
  177. package/dist/src/compat-addons.js.map +0 -1
  178. package/dist/src/compat-app-builder.d.ts +0 -28
  179. package/dist/src/compat-app-builder.d.ts.map +0 -1
  180. package/dist/src/compat-app-builder.js +0 -221
  181. package/dist/src/compat-app-builder.js.map +0 -1
  182. package/dist/src/compat-app.d.ts +0 -62
  183. package/dist/src/compat-app.d.ts.map +0 -1
  184. package/dist/src/compat-app.js +0 -618
  185. package/dist/src/compat-app.js.map +0 -1
  186. package/dist/src/compat-utils.d.ts +0 -10
  187. package/dist/src/compat-utils.d.ts.map +0 -1
  188. package/dist/src/compat-utils.js +0 -65
  189. package/dist/src/compat-utils.js.map +0 -1
  190. package/dist/src/content-for-config.d.ts +0 -12
  191. package/dist/src/content-for-config.d.ts.map +0 -1
  192. package/dist/src/content-for-config.js +0 -66
  193. package/dist/src/content-for-config.js.map +0 -1
  194. package/dist/src/dasherize-component-name.d.ts +0 -3
  195. package/dist/src/dasherize-component-name.d.ts.map +0 -1
  196. package/dist/src/dasherize-component-name.js +0 -28
  197. package/dist/src/dasherize-component-name.js.map +0 -1
  198. package/dist/src/default-pipeline.d.ts +0 -10
  199. package/dist/src/default-pipeline.d.ts.map +0 -1
  200. package/dist/src/default-pipeline.js +0 -43
  201. package/dist/src/default-pipeline.js.map +0 -1
  202. package/dist/src/dependency-rules.d.ts +0 -62
  203. package/dist/src/dependency-rules.d.ts.map +0 -1
  204. package/dist/src/dependency-rules.js +0 -89
  205. package/dist/src/dependency-rules.js.map +0 -1
  206. package/dist/src/detect-babel-plugins.d.ts +0 -7
  207. package/dist/src/detect-babel-plugins.d.ts.map +0 -1
  208. package/dist/src/detect-babel-plugins.js +0 -96
  209. package/dist/src/detect-babel-plugins.js.map +0 -1
  210. package/dist/src/detect-compact-reexports.d.ts +0 -3
  211. package/dist/src/detect-compact-reexports.d.ts.map +0 -1
  212. package/dist/src/detect-compact-reexports.js +0 -17
  213. package/dist/src/detect-compact-reexports.js.map +0 -1
  214. package/dist/src/dummy-package.d.ts +0 -9
  215. package/dist/src/dummy-package.d.ts.map +0 -1
  216. package/dist/src/dummy-package.js +0 -44
  217. package/dist/src/dummy-package.js.map +0 -1
  218. package/dist/src/empty-package-tree.d.ts +0 -9
  219. package/dist/src/empty-package-tree.d.ts.map +0 -1
  220. package/dist/src/empty-package-tree.js +0 -36
  221. package/dist/src/empty-package-tree.js.map +0 -1
  222. package/dist/src/get-real-addon.d.ts +0 -7
  223. package/dist/src/get-real-addon.d.ts.map +0 -1
  224. package/dist/src/get-real-addon.js +0 -33
  225. package/dist/src/get-real-addon.js.map +0 -1
  226. package/dist/src/hbs-to-js-broccoli-plugin.d.ts +0 -9
  227. package/dist/src/hbs-to-js-broccoli-plugin.d.ts.map +0 -1
  228. package/dist/src/hbs-to-js-broccoli-plugin.js +0 -39
  229. package/dist/src/hbs-to-js-broccoli-plugin.js.map +0 -1
  230. package/dist/src/htmlbars-unwrapper.d.ts +0 -6
  231. package/dist/src/htmlbars-unwrapper.d.ts.map +0 -1
  232. package/dist/src/htmlbars-unwrapper.js +0 -8
  233. package/dist/src/htmlbars-unwrapper.js.map +0 -1
  234. package/dist/src/http-audit.d.ts +0 -14
  235. package/dist/src/http-audit.d.ts.map +0 -1
  236. package/dist/src/http-audit.js +0 -60
  237. package/dist/src/http-audit.js.map +0 -1
  238. package/dist/src/index.d.ts +0 -8
  239. package/dist/src/index.d.ts.map +0 -1
  240. package/dist/src/index.js +0 -18
  241. package/dist/src/index.js.map +0 -1
  242. package/dist/src/merges.d.ts +0 -3
  243. package/dist/src/merges.d.ts.map +0 -1
  244. package/dist/src/merges.js +0 -32
  245. package/dist/src/merges.js.map +0 -1
  246. package/dist/src/module-visitor.d.ts +0 -53
  247. package/dist/src/module-visitor.d.ts.map +0 -1
  248. package/dist/src/module-visitor.js +0 -285
  249. package/dist/src/module-visitor.js.map +0 -1
  250. package/dist/src/modules-compat.d.ts +0 -3
  251. package/dist/src/modules-compat.d.ts.map +0 -1
  252. package/dist/src/modules-compat.js +0 -18
  253. package/dist/src/modules-compat.js.map +0 -1
  254. package/dist/src/observe-tree.d.ts +0 -8
  255. package/dist/src/observe-tree.d.ts.map +0 -1
  256. package/dist/src/observe-tree.js +0 -17
  257. package/dist/src/observe-tree.js.map +0 -1
  258. package/dist/src/options.d.ts +0 -17
  259. package/dist/src/options.d.ts.map +0 -1
  260. package/dist/src/options.js +0 -57
  261. package/dist/src/options.js.map +0 -1
  262. package/dist/src/prepare-htmlbars-ast-plugins.d.ts +0 -3
  263. package/dist/src/prepare-htmlbars-ast-plugins.d.ts.map +0 -1
  264. package/dist/src/prepare-htmlbars-ast-plugins.js +0 -39
  265. package/dist/src/prepare-htmlbars-ast-plugins.js.map +0 -1
  266. package/dist/src/resolver-transform.d.ts +0 -29
  267. package/dist/src/resolver-transform.d.ts.map +0 -1
  268. package/dist/src/resolver-transform.js +0 -1094
  269. package/dist/src/resolver-transform.js.map +0 -1
  270. package/dist/src/rewrite-addon-tree.d.ts +0 -9
  271. package/dist/src/rewrite-addon-tree.d.ts.map +0 -1
  272. package/dist/src/rewrite-addon-tree.js +0 -46
  273. package/dist/src/rewrite-addon-tree.js.map +0 -1
  274. package/dist/src/rewrite-package-json.d.ts +0 -8
  275. package/dist/src/rewrite-package-json.d.ts.map +0 -1
  276. package/dist/src/rewrite-package-json.js +0 -23
  277. package/dist/src/rewrite-package-json.js.map +0 -1
  278. package/dist/src/smoosh-package-json.d.ts +0 -9
  279. package/dist/src/smoosh-package-json.d.ts.map +0 -1
  280. package/dist/src/smoosh-package-json.js +0 -30
  281. package/dist/src/smoosh-package-json.js.map +0 -1
  282. package/dist/src/snitch.d.ts +0 -14
  283. package/dist/src/snitch.d.ts.map +0 -1
  284. package/dist/src/snitch.js +0 -42
  285. package/dist/src/snitch.js.map +0 -1
  286. package/dist/src/standalone-addon-build.d.ts +0 -3
  287. package/dist/src/standalone-addon-build.d.ts.map +0 -1
  288. package/dist/src/standalone-addon-build.js +0 -106
  289. package/dist/src/standalone-addon-build.js.map +0 -1
  290. package/dist/src/synthesize-template-only-components.d.ts +0 -17
  291. package/dist/src/synthesize-template-only-components.d.ts.map +0 -1
  292. package/dist/src/synthesize-template-only-components.js +0 -109
  293. package/dist/src/synthesize-template-only-components.js.map +0 -1
  294. package/dist/src/v1-addon.d.ts +0 -71
  295. package/dist/src/v1-addon.d.ts.map +0 -1
  296. package/dist/src/v1-addon.js +0 -1025
  297. package/dist/src/v1-addon.js.map +0 -1
  298. package/dist/src/v1-config.d.ts +0 -17
  299. package/dist/src/v1-config.d.ts.map +0 -1
  300. package/dist/src/v1-config.js +0 -26
  301. package/dist/src/v1-config.js.map +0 -1
  302. package/dist/src/v1-instance-cache.d.ts +0 -14
  303. package/dist/src/v1-instance-cache.d.ts.map +0 -1
  304. package/dist/src/v1-instance-cache.js +0 -66
  305. package/dist/src/v1-instance-cache.js.map +0 -1
@@ -1,1094 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = makeResolverTransform;
13
- const dependency_rules_1 = require("./dependency-rules");
14
- const typescript_memoize_1 = require("typescript-memoize");
15
- const assert_never_1 = __importDefault(require("assert-never"));
16
- const path_1 = require("path");
17
- const dasherize_component_name_1 = require("./dasherize-component-name");
18
- const core_1 = require("@embroider/core");
19
- const lodash_1 = require("lodash");
20
- const semver_1 = require("semver");
21
- function builtInKeywords(emberVersion) {
22
- const builtInKeywords = {
23
- '-get-dynamic-var': {},
24
- '-in-element': {},
25
- '-with-dynamic-vars': {},
26
- action: {},
27
- array: {
28
- importableHelper: ['array', '@ember/helper'],
29
- },
30
- component: {},
31
- concat: {
32
- importableHelper: ['concat', '@ember/helper'],
33
- },
34
- debugger: {},
35
- 'each-in': {},
36
- each: {},
37
- fn: {
38
- importableHelper: ['fn', '@ember/helper'],
39
- },
40
- get: {
41
- importableHelper: ['get', '@ember/helper'],
42
- },
43
- 'has-block-params': {},
44
- 'has-block': {},
45
- hasBlock: {},
46
- hasBlockParams: {},
47
- hash: {
48
- importableHelper: ['hash', '@ember/helper'],
49
- },
50
- helper: {},
51
- if: {},
52
- 'in-element': {},
53
- input: {
54
- importableComponent: ['Input', '@ember/component'],
55
- },
56
- let: {},
57
- 'link-to': {
58
- importableComponent: ['LinkTo', '@ember/routing'],
59
- },
60
- loc: {},
61
- log: {},
62
- modifier: {},
63
- mount: {},
64
- mut: {},
65
- on: {
66
- importableModifier: ['on', '@ember/modifier'],
67
- },
68
- outlet: {},
69
- partial: {},
70
- 'query-params': {},
71
- readonly: {},
72
- textarea: {
73
- importableComponent: ['Textarea', '@ember/component'],
74
- },
75
- unbound: {},
76
- 'unique-id': {},
77
- unless: {},
78
- with: {},
79
- yield: {},
80
- };
81
- if ((0, semver_1.satisfies)(emberVersion, '>=5.2')) {
82
- builtInKeywords['unique-id'] = {
83
- importableHelper: ['uniqueId', '@ember/helper'],
84
- };
85
- }
86
- // Template macro helpers from @embroider/macros.
87
- //
88
- // In app builds these helpers are normally handled by @embroider/macros'
89
- // template transforms. The template-tag codemod needs to recognize them
90
- // explicitly while generating scoped .gjs/.gts output, otherwise the
91
- // resolver can produce unresolvable @embroider/virtual/helpers/* imports.
92
- //
93
- // Treat these as legacy template macro keywords, not as importable JS
94
- // helpers. Some related JS macros are importable from @embroider/macros,
95
- // but template macro usage should not cause the codemod to generate those
96
- // imports.
97
- const embroiderTemplateMacroHelpers = {
98
- macroGetOwnConfig: {},
99
- macroGetConfig: {},
100
- macroCondition: {},
101
- macroDependencySatisfies: {},
102
- macroAppEmberSatisfies: {},
103
- macroMaybeAttrs: {},
104
- macroFailBuild: {},
105
- };
106
- Object.assign(builtInKeywords, embroiderTemplateMacroHelpers);
107
- return builtInKeywords;
108
- }
109
- function supportsThisFallback(emberVersion) {
110
- return (0, semver_1.satisfies)(emberVersion, '<= 4.0.0-alpha.0', { includePrerelease: true });
111
- }
112
- class TemplateResolver {
113
- constructor(env, config, builtInsForEmberVersion, supportsThisFallback, externalNameHint, externalResolve) {
114
- this.env = env;
115
- this.config = config;
116
- this.builtInsForEmberVersion = builtInsForEmberVersion;
117
- this.supportsThisFallback = supportsThisFallback;
118
- this.externalNameHint = externalNameHint;
119
- this.externalResolve = externalResolve;
120
- this.name = 'embroider-build-time-resolver';
121
- this.scopeStack = new ScopeStack();
122
- this.visitor = {
123
- Template: {
124
- enter: (node, path) => {
125
- this.ownRules = this.findRules(this.env.filename);
126
- this.implementInvokesRule(node, path);
127
- if (this.env.locals) {
128
- this.scopeStack.pushMustacheBlock(this.env.locals, { top: true });
129
- }
130
- },
131
- exit: () => {
132
- if (this.env.locals) {
133
- this.scopeStack.pop();
134
- }
135
- },
136
- },
137
- Block: {
138
- enter: node => {
139
- this.scopeStack.pushMustacheBlock(node.blockParams);
140
- },
141
- exit: () => {
142
- this.scopeStack.pop();
143
- },
144
- },
145
- BlockStatement: (node, path) => {
146
- if (node.path.type !== 'PathExpression') {
147
- return;
148
- }
149
- let rootName = headOf(node.path);
150
- if (this.scopeStack.inScope(rootName, path)) {
151
- return;
152
- }
153
- if (isThisHead(node.path)) {
154
- return;
155
- }
156
- if (parts(node.path).length > 1) {
157
- // paths with a dot in them (which therefore split into more than
158
- // one "part") are classically understood by ember to be contextual
159
- // components, which means there's nothing to resolve at this
160
- // location.
161
- return;
162
- }
163
- if (node.path.original === 'component' && node.params.length > 0) {
164
- let resolution = this.handleComponentHelper(node.params[0]);
165
- this.emit(path, resolution, (node, newIdentifier) => {
166
- node.params[0] = newIdentifier;
167
- });
168
- return;
169
- }
170
- let resolution = this.targetComponent(node.path.original, node.path.original);
171
- this.emit(path, resolution, (node, newId) => {
172
- node.path = newId;
173
- });
174
- if ((resolution === null || resolution === void 0 ? void 0 : resolution.type) === 'component') {
175
- this.scopeStack.enteringComponentBlock(resolution, ({ argumentsAreComponents }) => {
176
- this.handleDynamicComponentArguments(rootName, argumentsAreComponents, extendPath(extendPath(path, 'hash'), 'pairs'));
177
- });
178
- }
179
- },
180
- SubExpression: (node, path) => {
181
- if (node.path.type !== 'PathExpression') {
182
- return;
183
- }
184
- if (isThisHead(node.path)) {
185
- return;
186
- }
187
- if (this.scopeStack.inScope(headOf(node.path), path)) {
188
- return;
189
- }
190
- if (node.path.original === 'component' && node.params.length > 0) {
191
- let resolution = this.handleComponentHelper(node.params[0]);
192
- this.emit(path, resolution, (node, newId) => {
193
- node.params[0] = newId;
194
- });
195
- return;
196
- }
197
- if (node.path.original === 'helper' && node.params.length > 0) {
198
- let resolution = this.handleDynamicHelper(node.params[0]);
199
- this.emit(path, resolution, (node, newId) => {
200
- node.params[0] = newId;
201
- });
202
- return;
203
- }
204
- if (node.path.original === 'modifier' && node.params.length > 0) {
205
- let resolution = this.handleDynamicModifier(node.params[0]);
206
- this.emit(path, resolution, (node, newId) => {
207
- node.params[0] = newId;
208
- });
209
- return;
210
- }
211
- if (node.path.tail.length === 0 && node.path.head.type === 'VarHead') {
212
- let resolution = this.targetHelper(node.path.original);
213
- this.emit(path, resolution, (node, newId) => {
214
- node.path = newId;
215
- });
216
- }
217
- },
218
- MustacheStatement: {
219
- enter: (node, path) => {
220
- var _a;
221
- if (node.path.type !== 'PathExpression') {
222
- return;
223
- }
224
- let rootName = headOf(node.path);
225
- if (this.scopeStack.inScope(rootName, path)) {
226
- let resolution = this.scopeStack.resolutionInScope(rootName, path);
227
- if ((resolution === null || resolution === void 0 ? void 0 : resolution.type) === 'component') {
228
- this.handleDynamicComponentArguments(node.path.original, resolution.argumentsAreComponents, extendPath(extendPath(path, 'hash'), 'pairs'));
229
- }
230
- return;
231
- }
232
- if (isThisHead(node.path)) {
233
- return;
234
- }
235
- if (parts(node.path).length > 1) {
236
- // paths with a dot in them (which therefore split into more than
237
- // one "part") are classically understood by ember to be contextual
238
- // components, which means there's nothing to resolve at this
239
- // location.
240
- return;
241
- }
242
- if (node.path.original.startsWith('@')) {
243
- // similarly, global resolution of helpers and components never
244
- // happens with argument paths (it could still be an invocation, but
245
- // it would be a lexically-scoped invocation, not one we need to
246
- // adjust)
247
- return;
248
- }
249
- if (node.path.original === 'component' && node.params.length > 0) {
250
- let resolution = this.handleComponentHelper(node.params[0]);
251
- this.emit(path, resolution, (node, newId) => {
252
- node.params[0] = newId;
253
- });
254
- return;
255
- }
256
- if (node.path.original === 'helper' && node.params.length > 0) {
257
- let resolution = this.handleDynamicHelper(node.params[0]);
258
- this.emit(path, resolution, (node, newIdentifier) => {
259
- node.params[0] = newIdentifier;
260
- });
261
- return;
262
- }
263
- if (((_a = path.parent) === null || _a === void 0 ? void 0 : _a.node.type) === 'AttrNode') {
264
- // this mustache is the value of an attribute. Components aren't
265
- // allowed here, so we're not ambiguous, so resolve a helper.
266
- let resolution = this.targetHelper(node.path.original);
267
- this.emit(path, resolution, (node, newIdentifier) => {
268
- node.path = newIdentifier;
269
- });
270
- return;
271
- }
272
- let hasArgs = node.params.length > 0 || node.hash.pairs.length > 0;
273
- let resolution = this.targetHelperOrComponent(node.path.original, node.path.loc, hasArgs);
274
- this.emit(path, resolution, (node, newIdentifier) => {
275
- node.path = newIdentifier;
276
- });
277
- if ((resolution === null || resolution === void 0 ? void 0 : resolution.type) === 'component') {
278
- this.handleDynamicComponentArguments(node.path.original, resolution.argumentsAreComponents, extendPath(extendPath(path, 'hash'), 'pairs'));
279
- }
280
- },
281
- },
282
- ElementModifierStatement: (node, path) => {
283
- if (node.path.type !== 'PathExpression') {
284
- return;
285
- }
286
- if (this.scopeStack.inScope(headOf(node.path), path)) {
287
- return;
288
- }
289
- if (isThisHead(node.path)) {
290
- return;
291
- }
292
- if (isAtHead(node.path)) {
293
- return;
294
- }
295
- if (parts(node.path).length > 1) {
296
- // paths with a dot in them (which therefore split into more than
297
- // one "part") are classically understood by ember to be contextual
298
- // components. With the introduction of `Template strict mode` in Ember 3.25
299
- // it is also possible to pass modifiers this way which means there's nothing
300
- // to resolve at this location.
301
- return;
302
- }
303
- let resolution = this.targetElementModifier(node.path.original);
304
- this.emit(path, resolution, (node, newId) => {
305
- node.path = newId;
306
- });
307
- },
308
- ElementNode: {
309
- enter: (node, path) => {
310
- let rootName = node.tag.split('.')[0];
311
- if (this.scopeStack.inScope(rootName, path)) {
312
- let existingResolution = this.scopeStack.resolutionInScope(rootName, path);
313
- if ((existingResolution === null || existingResolution === void 0 ? void 0 : existingResolution.type) === 'component') {
314
- this.scopeStack.enteringComponentBlock(existingResolution, ({ argumentsAreComponents }) => {
315
- this.handleDynamicComponentArguments(node.tag, argumentsAreComponents, extendPath(path, 'attributes'));
316
- });
317
- }
318
- }
319
- else {
320
- let resolution = null;
321
- // if it starts with lower case, it can't be a component we need to
322
- // globally resolve
323
- if (node.tag[0] !== node.tag[0].toLowerCase()) {
324
- resolution = this.targetComponent((0, dasherize_component_name_1.dasherize)(node.tag), node.tag);
325
- }
326
- this.emit(path, resolution, (node, newId) => {
327
- node.tag = newId.original;
328
- });
329
- if ((resolution === null || resolution === void 0 ? void 0 : resolution.type) === 'component') {
330
- this.scopeStack.enteringComponentBlock(resolution, ({ argumentsAreComponents }) => {
331
- this.handleDynamicComponentArguments(node.tag, argumentsAreComponents, extendPath(path, 'attributes'));
332
- });
333
- }
334
- }
335
- this.scopeStack.pushElementBlock(node.blockParams, node);
336
- },
337
- exit: () => {
338
- this.scopeStack.pop();
339
- },
340
- },
341
- };
342
- this.moduleResolver = new core_1.Resolver(config);
343
- if (globalThis.embroider_audit) {
344
- this.auditHandler = globalThis.embroider_audit;
345
- }
346
- }
347
- emit(parentPath, resolution, setter) {
348
- switch (resolution === null || resolution === void 0 ? void 0 : resolution.type) {
349
- case 'error':
350
- this.reportError(resolution);
351
- return;
352
- case 'component':
353
- case 'modifier':
354
- case 'helper': {
355
- let specifier = resolution.specifier;
356
- if (this.externalResolve) {
357
- specifier = this.externalResolve(specifier);
358
- }
359
- let name = this.env.meta.jsutils.bindImport(specifier, resolution.importedName, parentPath, {
360
- nameHint: resolution.nameHint,
361
- });
362
- setter(parentPath.node, this.env.syntax.builders.path(name));
363
- this.scopeStack.emittedResolution(name, resolution);
364
- return;
365
- }
366
- case undefined:
367
- return;
368
- default:
369
- (0, assert_never_1.default)(resolution);
370
- }
371
- }
372
- reportError(dep) {
373
- if (!this.auditHandler && !this.config.options.allowUnsafeDynamicComponents) {
374
- let e = new Error(`${dep.message}: ${dep.detail} in ${this.humanReadableFile(this.env.filename)}`);
375
- e.isTemplateResolverError = true;
376
- e.loc = dep.loc;
377
- e.moduleName = this.env.filename;
378
- throw e;
379
- }
380
- if (this.auditHandler) {
381
- this.auditHandler({
382
- message: dep.message,
383
- filename: this.env.filename,
384
- detail: dep.detail,
385
- loc: dep.loc,
386
- source: this.env.contents,
387
- });
388
- }
389
- }
390
- humanReadableFile(file) {
391
- let { appRoot } = this.config;
392
- if (!appRoot.endsWith(path_1.sep)) {
393
- appRoot += path_1.sep;
394
- }
395
- if (file.startsWith(appRoot)) {
396
- return file.slice(appRoot.length);
397
- }
398
- return file;
399
- }
400
- handleComponentHelper(param, impliedBecause) {
401
- let locator;
402
- switch (param.type) {
403
- case 'StringLiteral':
404
- locator = { type: 'literal', path: param.value };
405
- break;
406
- case 'PathExpression':
407
- locator = { type: 'path', path: param.original };
408
- break;
409
- case 'MustacheStatement':
410
- if (param.hash.pairs.length === 0 && param.params.length === 0) {
411
- return this.handleComponentHelper(param.path, impliedBecause);
412
- }
413
- else if (param.path.type === 'PathExpression' && param.path.original === 'component') {
414
- // safe because we will handle this inner `{{component ...}}` mustache on its own
415
- return null;
416
- }
417
- else {
418
- locator = { type: 'other' };
419
- }
420
- break;
421
- case 'TextNode':
422
- locator = { type: 'literal', path: param.chars };
423
- break;
424
- case 'SubExpression':
425
- if (param.path.type === 'PathExpression' && param.path.original === 'component') {
426
- // safe because we will handle this inner `(component ...)` subexpression on its own
427
- return null;
428
- }
429
- if (param.path.type === 'PathExpression' && param.path.original === 'ensure-safe-component') {
430
- // safe because we trust ensure-safe-component
431
- return null;
432
- }
433
- locator = { type: 'other' };
434
- break;
435
- default:
436
- locator = { type: 'other' };
437
- }
438
- if (locator.type === 'path' && this.scopeStack.safeComponentInScope(locator.path)) {
439
- return null;
440
- }
441
- return this.targetComponentHelper(locator, param.loc, impliedBecause);
442
- }
443
- handleDynamicComponentArguments(componentName, argumentsAreComponents, attributes) {
444
- for (let name of argumentsAreComponents) {
445
- let attr = attributes.find(attr => {
446
- if (attr.node.type === 'AttrNode') {
447
- return attr.node.name === '@' + name;
448
- }
449
- else {
450
- return attr.node.key === name;
451
- }
452
- });
453
- if (attr) {
454
- let resolution = this.handleComponentHelper(attr.node.value, {
455
- componentName,
456
- argumentName: name,
457
- });
458
- this.emit(attr, resolution, (node, newId) => {
459
- if (node.type === 'AttrNode') {
460
- node.value = this.env.syntax.builders.mustache(newId);
461
- }
462
- else {
463
- node.value = newId;
464
- }
465
- });
466
- }
467
- }
468
- }
469
- get staticInvokablesEnabled() {
470
- var _a;
471
- if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.options)) {
472
- return true;
473
- }
474
- return this.config.options.staticInvokables || Boolean(this.auditHandler);
475
- }
476
- isIgnoredComponent(dasherizedName) {
477
- var _a;
478
- return (_a = this.rules.components.get(dasherizedName)) === null || _a === void 0 ? void 0 : _a.safeToIgnore;
479
- }
480
- get rules() {
481
- var _a, _b;
482
- // rules that are keyed by the filename they're talking about
483
- let files = new Map();
484
- // rules that are keyed by our dasherized interpretation of the component's name
485
- let components = new Map();
486
- // we're not responsible for filtering out rules for inactive packages here,
487
- // that is done before getting to us. So we should assume these are all in
488
- // force.
489
- for (let rule of (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.activePackageRules) !== null && _b !== void 0 ? _b : []) {
490
- if (rule.components) {
491
- for (let [snippet, rules] of Object.entries(rule.components)) {
492
- let processedRules = (0, dependency_rules_1.preprocessComponentRule)(rules);
493
- let dasherizedName = this.standardDasherize(snippet, rule);
494
- components.set(dasherizedName, processedRules);
495
- if (rules.layout) {
496
- for (let root of rule.roots) {
497
- if (rules.layout.addonPath) {
498
- files.set((0, path_1.join)(root, rules.layout.addonPath), processedRules);
499
- }
500
- if (rules.layout.appPath) {
501
- files.set((0, path_1.join)(root, rules.layout.appPath), processedRules);
502
- }
503
- }
504
- }
505
- }
506
- }
507
- if (rule.appTemplates) {
508
- for (let [path, templateRules] of Object.entries(rule.appTemplates)) {
509
- let processedRules = (0, dependency_rules_1.preprocessComponentRule)(templateRules);
510
- for (let root of rule.roots) {
511
- files.set((0, path_1.join)((0, dependency_rules_1.appTreeRulesDir)(root, this.moduleResolver), path), processedRules);
512
- }
513
- }
514
- }
515
- if (rule.addonTemplates) {
516
- for (let [path, templateRules] of Object.entries(rule.addonTemplates)) {
517
- let processedRules = (0, dependency_rules_1.preprocessComponentRule)(templateRules);
518
- for (let root of rule.roots) {
519
- files.set((0, path_1.join)(root, path), processedRules);
520
- }
521
- }
522
- }
523
- }
524
- return { files, components };
525
- }
526
- findRules(absPath) {
527
- // when babel is invoked by vite our filenames can have query params still
528
- // hanging off them. That would break rule matching.
529
- absPath = (0, core_1.cleanUrl)(absPath);
530
- let fileRules = this.rules.files.get(absPath);
531
- let componentRules;
532
- let componentName = this.moduleResolver.reverseComponentLookup(absPath);
533
- if (componentName) {
534
- componentRules = this.rules.components.get(componentName);
535
- }
536
- if (fileRules && componentRules) {
537
- return (0, lodash_1.mergeWith)(fileRules, componentRules, appendArrays);
538
- }
539
- return fileRules !== null && fileRules !== void 0 ? fileRules : componentRules;
540
- }
541
- standardDasherize(snippet, rule) {
542
- let name = (0, dasherize_component_name_1.snippetToDasherizedName)(snippet);
543
- if (name == null) {
544
- throw new Error(`unable to parse component snippet "${snippet}" from rule ${JSON.stringify(rule, null, 2)}`);
545
- }
546
- return name;
547
- }
548
- targetComponent(name, nameHint) {
549
- if (!this.staticInvokablesEnabled) {
550
- return null;
551
- }
552
- const builtIn = this.builtInsForEmberVersion[name];
553
- if (builtIn === null || builtIn === void 0 ? void 0 : builtIn.importableComponent) {
554
- let [importedName, specifier] = builtIn.importableComponent;
555
- return {
556
- type: 'component',
557
- specifier,
558
- importedName,
559
- yieldsComponents: [],
560
- yieldsArguments: [],
561
- argumentsAreComponents: [],
562
- nameHint: importedName,
563
- };
564
- }
565
- if (builtIn) {
566
- return null;
567
- }
568
- if (this.isIgnoredComponent(name)) {
569
- return null;
570
- }
571
- let componentRules = this.rules.components.get(name);
572
- return {
573
- type: 'component',
574
- specifier: `@embroider/virtual/components/${name}`,
575
- importedName: 'default',
576
- yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [],
577
- yieldsArguments: componentRules ? componentRules.yieldsArguments : [],
578
- argumentsAreComponents: componentRules ? componentRules.argumentsAreComponents : [],
579
- nameHint: this.nameHint(nameHint, 'component'),
580
- };
581
- }
582
- targetComponentHelper(component, loc, impliedBecause) {
583
- var _a;
584
- if (!this.staticInvokablesEnabled) {
585
- return null;
586
- }
587
- let message;
588
- if (impliedBecause) {
589
- message = `argument "${impliedBecause.argumentName}" to component "${impliedBecause.componentName}" is treated as a component, but the value you're passing is dynamic`;
590
- }
591
- else {
592
- message = `Unsafe dynamic component`;
593
- }
594
- if (component.type === 'other') {
595
- return {
596
- type: 'error',
597
- message,
598
- detail: `cannot statically analyze this expression`,
599
- loc,
600
- };
601
- }
602
- if (component.type === 'path') {
603
- if ((_a = this.ownRules) === null || _a === void 0 ? void 0 : _a.safeInteriorPaths.includes(component.path)) {
604
- return null;
605
- }
606
- return {
607
- type: 'error',
608
- message,
609
- detail: component.path,
610
- loc,
611
- };
612
- }
613
- return this.targetComponent(component.path, component.path);
614
- }
615
- targetHelper(path) {
616
- if (!this.staticInvokablesEnabled) {
617
- return null;
618
- }
619
- // people are not allowed to override the built-in helpers with their own
620
- // globally-named helpers. It throws an error. So it's fine for us to
621
- // prioritize the builtIns here without bothering to resolve a user helper
622
- // of the same name.
623
- const builtIn = this.builtInsForEmberVersion[path];
624
- if (builtIn === null || builtIn === void 0 ? void 0 : builtIn.importableHelper) {
625
- let [importedName, specifier] = builtIn.importableHelper;
626
- return {
627
- type: 'helper',
628
- specifier,
629
- importedName,
630
- nameHint: importedName,
631
- };
632
- }
633
- if (builtIn) {
634
- return null;
635
- }
636
- return {
637
- type: 'helper',
638
- specifier: `@embroider/virtual/helpers/${path}`,
639
- importedName: 'default',
640
- nameHint: this.nameHint(path, 'helper'),
641
- };
642
- }
643
- targetHelperOrComponent(path, loc, hasArgs) {
644
- /*
645
-
646
- In earlier embroider versions we would do a bunch of module resolution right
647
- here inside the ast transform to try to resolve the ambiguity of this case
648
- and if we didn't find anything, leave the template unchanged. But that leads
649
- to both a lot of extra build-time expense (since we are attempting
650
- resolution for lots of things that may in fact be just some data and not a
651
- component invocation at all, and also since we are pre-resolving modules
652
- that will get resolved a second time by the final stage packager).
653
-
654
- Now, we're going to be less forgiving, because it streamlines the build for
655
- everyone who's not still using these *extremely* old patterns.
656
-
657
- The problematic case is:
658
-
659
- 1. In a non-strict template (because this whole resolver-transform.ts is a
660
- no-op on strict handlebars).
661
-
662
- 2. Have a mustache statement like: `{{something}}`, where `something` is:
663
-
664
- a. Not a variable in scope (for example, there's no preceeding line
665
- like `<Parent as |something|>`)
666
- b. Does not start with `@` because that must be an argument from outside this template.
667
- c. Does not contain a dot, like `some.thing` (because that case is classically
668
- never a global component resolution that we would need to handle)
669
- d. Does not start with `this` (this rule is mostly redundant with the previous rule,
670
- but even a standalone `this` is never a component invocation).
671
- e. Does not have any arguments. If there are argument like `{{something a=b}}`,
672
- there is still ambiguity between helper vs component, but there is no longer
673
- the possibility that this was just rendering some data.
674
- f. Does not take a block, like `{{#something}}{{/something}}` (because that is
675
- always a component, no ambiguity.)
676
-
677
- We can't tell if this problematic case is really:
678
-
679
- 1. A helper invocation with no arguments that is being directly rendered.
680
- Out-of-the-box, ember already generates [a lint
681
- error](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-curly-component-invocation.md)
682
- for this, although it tells you to whitelist your helper when IMO it
683
- should tell you to use an unambiguous syntax like `{{ (something) }}`
684
- instead.
685
-
686
- 2. A component invocation, which you could have written `<Something />`
687
- instead. Angle-bracket invocation has been available and easy-to-adopt
688
- for a very long time.
689
-
690
- 3. Property-this-fallback for `{{this.something}}`. Property-this-fallback
691
- is eliminated at Ember 4.0, so people have been heavily pushed to get
692
- it out of their addons.
693
- */
694
- // first, bail out on all the stuff we can obviously ignore
695
- if (!this.staticInvokablesEnabled || this.isIgnoredComponent(path)) {
696
- return null;
697
- }
698
- let builtIn = this.builtInsForEmberVersion[path];
699
- if (builtIn === null || builtIn === void 0 ? void 0 : builtIn.importableComponent) {
700
- let [importedName, specifier] = builtIn.importableComponent;
701
- return {
702
- type: 'component',
703
- specifier,
704
- importedName,
705
- yieldsComponents: [],
706
- yieldsArguments: [],
707
- argumentsAreComponents: [],
708
- nameHint: importedName,
709
- };
710
- }
711
- if (builtIn === null || builtIn === void 0 ? void 0 : builtIn.importableHelper) {
712
- let [importedName, specifier] = builtIn.importableHelper;
713
- return {
714
- type: 'helper',
715
- specifier,
716
- importedName,
717
- nameHint: importedName,
718
- };
719
- }
720
- if (builtIn) {
721
- return null;
722
- }
723
- let ownComponentRules = this.findRules(this.env.filename);
724
- if (ownComponentRules === null || ownComponentRules === void 0 ? void 0 : ownComponentRules.disambiguate[path]) {
725
- switch (ownComponentRules.disambiguate[path]) {
726
- case 'component':
727
- return this.targetComponent(path, path);
728
- case 'helper':
729
- return this.targetHelper(path);
730
- case 'data':
731
- return null;
732
- }
733
- }
734
- if (!hasArgs && !path.includes('/') && !path.includes('@') && this.supportsThisFallback) {
735
- // this is the case that could also be property-this-fallback. We're going
736
- // to force people to disambiguate, because letting a potential component
737
- // or helper invocation lurk inside every bit of data you render is not
738
- // ok.
739
- this.reportError({
740
- type: 'error',
741
- message: 'unsupported ambiguous syntax',
742
- detail: `"{{${path}}}" is ambiguous and could mean "{{this.${path}}}" or component "<${capitalize((0, lodash_1.camelCase)(path))} />" or helper "{{ (${path}) }}". Change it to one of those unambigous forms, or use a "disambiguate" packageRule to work around the problem if its in third-party code you cannot easily fix.`,
743
- loc,
744
- });
745
- return null;
746
- }
747
- let componentRules = this.rules.components.get(path);
748
- return {
749
- type: 'component',
750
- specifier: `@embroider/virtual/ambiguous/${path}`,
751
- importedName: 'default',
752
- yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [],
753
- yieldsArguments: componentRules ? componentRules.yieldsArguments : [],
754
- argumentsAreComponents: componentRules ? componentRules.argumentsAreComponents : [],
755
- nameHint: this.nameHint(path, 'ambiguous-component-or-helper'),
756
- };
757
- }
758
- targetElementModifier(path) {
759
- if (!this.staticInvokablesEnabled) {
760
- return null;
761
- }
762
- const builtIn = this.builtInsForEmberVersion[path];
763
- if (builtIn === null || builtIn === void 0 ? void 0 : builtIn.importableModifier) {
764
- let [importedName, specifier] = builtIn.importableModifier;
765
- return {
766
- type: 'modifier',
767
- specifier,
768
- importedName,
769
- nameHint: importedName,
770
- };
771
- }
772
- if (builtIn) {
773
- return null;
774
- }
775
- return {
776
- type: 'modifier',
777
- specifier: `@embroider/virtual/modifiers/${path}`,
778
- importedName: 'default',
779
- nameHint: this.nameHint(path, 'modifier'),
780
- };
781
- }
782
- targetDynamicModifier(modifier, loc) {
783
- if (!this.staticInvokablesEnabled) {
784
- return null;
785
- }
786
- if (modifier.type === 'literal') {
787
- return this.targetElementModifier(modifier.path);
788
- }
789
- else {
790
- return {
791
- type: 'error',
792
- message: 'Unsafe dynamic modifier',
793
- detail: `cannot statically analyze this expression`,
794
- loc,
795
- };
796
- }
797
- }
798
- targetDynamicHelper(helper) {
799
- if (!this.staticInvokablesEnabled) {
800
- return null;
801
- }
802
- if (helper.type === 'literal') {
803
- return this.targetHelper(helper.path);
804
- }
805
- // we don't have to manage any errors in this case because ember itself
806
- // considers it an error to pass anything but a string literal to the
807
- // `helper` helper.
808
- return null;
809
- }
810
- nameHint(path, kind) {
811
- var _a;
812
- let hint = (_a = this.externalNameHint) === null || _a === void 0 ? void 0 : _a.call(this, path, kind);
813
- if (hint != null) {
814
- return hint;
815
- }
816
- let parts = path.split('@');
817
- hint = parts[parts.length - 1];
818
- // if our name is going to be entirely lower case letter, we add an
819
- // underscore to avoid any possible HTML element collision.
820
- if (/^[a-z]+$/.test(hint)) {
821
- hint += '_';
822
- }
823
- return hint;
824
- }
825
- handleDynamicModifier(param) {
826
- if (param.type === 'StringLiteral') {
827
- return this.targetDynamicModifier({ type: 'literal', path: param.value }, param.loc);
828
- }
829
- // we don't have to manage any errors in this case because ember itself
830
- // considers it an error to pass anything but a string literal to the
831
- // modifier helper.
832
- return null;
833
- }
834
- handleDynamicHelper(param) {
835
- // We only need to handle StringLiterals since Ember already throws an error if unsupported values
836
- // are passed to the helper keyword.
837
- // If a helper reference is passed in we don't need to do anything since it's either the result of a previous
838
- // helper keyword invocation, or a helper reference that was imported somewhere.
839
- if (param.type === 'StringLiteral') {
840
- return this.targetDynamicHelper({ type: 'literal', path: param.value });
841
- }
842
- return null;
843
- }
844
- implementInvokesRule(node, path) {
845
- var _a;
846
- if (!((_a = this.ownRules) === null || _a === void 0 ? void 0 : _a.invokes)) {
847
- return;
848
- }
849
- let registrations = [];
850
- for (let snippets of Object.values(this.ownRules.invokes)) {
851
- for (let snippet of snippets) {
852
- let dasherizedName = (0, dasherize_component_name_1.snippetToDasherizedName)(snippet);
853
- if (!dasherizedName) {
854
- throw new Error(`Package rule contains unparseable component snippet: ${snippet}`);
855
- }
856
- let resolution = this.targetComponentHelper({ type: 'literal', path: dasherizedName }, node.loc);
857
- this.emit(path, resolution, (_target, id) => {
858
- registrations.push(this.env.syntax.builders.pair(dasherizedName, id));
859
- });
860
- }
861
- }
862
- if (registrations.length > 0) {
863
- node.body.unshift(this.env.syntax.builders.mustache(this.env.meta.jsutils.bindExpression(registrationHelper, path, { nameHint: 'registerComponents' }), [], this.env.syntax.builders.hash(registrations)));
864
- }
865
- }
866
- }
867
- __decorate([
868
- (0, typescript_memoize_1.Memoize)()
869
- ], TemplateResolver.prototype, "rules", null);
870
- // This is the AST transform that resolves components, helpers and modifiers at build time
871
- function makeResolverTransform({ appRoot, emberVersion, externalNameHint, externalResolve }) {
872
- let loader = new core_1.ResolverLoader(appRoot);
873
- let config = loader.resolver.options;
874
- const resolverTransform = env => {
875
- if (env.strictMode) {
876
- return {
877
- name: 'embroider-build-time-resolver-strict-noop',
878
- visitor: {},
879
- };
880
- }
881
- return new TemplateResolver(env, config, builtInKeywords(emberVersion), supportsThisFallback(emberVersion), externalNameHint, externalResolve);
882
- };
883
- resolverTransform.parallelBabel = {
884
- requireFile: __filename,
885
- buildUsing: 'makeResolverTransform',
886
- params: { appRoot: appRoot },
887
- };
888
- return resolverTransform;
889
- }
890
- class ScopeStack {
891
- constructor() {
892
- this.stack = [];
893
- }
894
- // mustache blocks like:
895
- //
896
- // {{#stuff as |some block vars|}}
897
- //
898
- // are relatively simple for us because there's a dedicated `Block` AST node
899
- // that exactly covers the range in which the variables are in scope.
900
- pushMustacheBlock(blockParams, params) {
901
- let entry = { type: 'mustache', blockParams };
902
- if (params === null || params === void 0 ? void 0 : params.top) {
903
- entry.emittedResolutions = new Map();
904
- }
905
- this.stack.unshift(entry);
906
- }
907
- // element blocks like:
908
- //
909
- // <Stuff as |some block vars|>
910
- //
911
- // are *not* so simple for us because there's no single AST node that exactly
912
- // covers the range in which the variables are in scope. For example, the
913
- // *attributes* of the element do not see the variables, but the children of
914
- // the element do.
915
- pushElementBlock(blockParams, childrenOf) {
916
- this.stack.unshift({ type: 'element', blockParams, childrenOf });
917
- }
918
- // and when we leave the block they go out of scope. If this block was tagged
919
- // by a safe component marker, we also clear that.
920
- pop() {
921
- this.stack.shift();
922
- let next = this.stack[0];
923
- if (next && next.type === 'componentBlockMarker') {
924
- next.exit(next);
925
- this.stack.shift();
926
- }
927
- }
928
- // right before we enter a block, we might determine that some of the values
929
- // that will be yielded as marked (by a rule) as safe to be used with the
930
- // {{component}} helper.
931
- enteringComponentBlock(resolution, exit) {
932
- this.stack.unshift({
933
- type: 'componentBlockMarker',
934
- resolution,
935
- argumentsAreComponents: resolution.argumentsAreComponents.slice(),
936
- exit,
937
- });
938
- }
939
- inScope(name, fromPath) {
940
- for (let scope of this.stack) {
941
- if (scope.type === 'mustache' && scope.blockParams.includes(name)) {
942
- return true;
943
- }
944
- if (scope.type === 'element' &&
945
- scope.blockParams.includes(name) &&
946
- withinElementBlock(fromPath, scope.childrenOf)) {
947
- return true;
948
- }
949
- }
950
- return false;
951
- }
952
- // some names in scope are things that this transform itself has already
953
- // emitted. This identifies them.
954
- resolutionInScope(name, fromPath) {
955
- for (let scope of this.stack) {
956
- if (scope.type === 'mustache' && scope.blockParams.includes(name)) {
957
- if (scope.emittedResolutions) {
958
- return scope.emittedResolutions.get(name);
959
- }
960
- }
961
- if (scope.type === 'element' &&
962
- scope.blockParams.includes(name) &&
963
- withinElementBlock(fromPath, scope.childrenOf)) {
964
- return;
965
- }
966
- }
967
- return;
968
- }
969
- emittedResolution(name, resolution) {
970
- let top = this.stack[0];
971
- if ((top === null || top === void 0 ? void 0 : top.type) === 'mustache' && top.emittedResolutions) {
972
- top.emittedResolutions.set(name, resolution);
973
- }
974
- }
975
- safeComponentInScope(name) {
976
- let parts = name.split('.');
977
- if (parts.length > 2) {
978
- // we let component rules specify that they yield components or objects
979
- // containing components. But not deeper than that. So the max path length
980
- // that can refer to a marked-safe component is two segments.
981
- return false;
982
- }
983
- for (let i = 0; i < this.stack.length - 1; i++) {
984
- let here = this.stack[i];
985
- let next = this.stack[i + 1];
986
- if ((here.type === 'mustache' || here.type === 'element') && next.type === 'componentBlockMarker') {
987
- let positionalIndex = here.blockParams.indexOf(parts[0]);
988
- if (positionalIndex === -1) {
989
- continue;
990
- }
991
- if (parts.length === 1) {
992
- if (next.resolution.yieldsComponents[positionalIndex] === true) {
993
- return true;
994
- }
995
- let sourceArg = next.resolution.yieldsArguments[positionalIndex];
996
- if (typeof sourceArg === 'string') {
997
- next.argumentsAreComponents.push(sourceArg);
998
- return true;
999
- }
1000
- }
1001
- else {
1002
- let entry = next.resolution.yieldsComponents[positionalIndex];
1003
- if (entry && typeof entry === 'object') {
1004
- return entry[parts[1]] === true;
1005
- }
1006
- let argsEntry = next.resolution.yieldsArguments[positionalIndex];
1007
- if (argsEntry && typeof argsEntry === 'object') {
1008
- let sourceArg = argsEntry[parts[1]];
1009
- if (typeof sourceArg === 'string') {
1010
- next.argumentsAreComponents.push(sourceArg);
1011
- return true;
1012
- }
1013
- }
1014
- }
1015
- // we found the source of the name, but there were no rules to cover it.
1016
- // Don't keep searching higher, those are different names.
1017
- return false;
1018
- }
1019
- }
1020
- return false;
1021
- }
1022
- }
1023
- function extendPath(path, key) {
1024
- const _WalkerPath = path.constructor;
1025
- let child = path.node[key];
1026
- if (Array.isArray(child)) {
1027
- return child.map(c => new _WalkerPath(c, path, key));
1028
- }
1029
- else {
1030
- return new _WalkerPath(child, path, key);
1031
- }
1032
- }
1033
- function capitalize(word) {
1034
- return word[0].toUpperCase() + word.slice(1);
1035
- }
1036
- // ElementNodes have both children and attributes and both of those are
1037
- // "children" in the abstract syntax tree sense, but here we want to distinguish
1038
- // between them.
1039
- function withinElementBlock(childPath, ancestorNode) {
1040
- let cursor = childPath;
1041
- while (cursor && cursor.node !== ancestorNode) {
1042
- if (ancestorNode.children.includes(cursor.node)) {
1043
- return true;
1044
- }
1045
- cursor = cursor.parent;
1046
- }
1047
- return false;
1048
- }
1049
- function appendArrays(objValue, srcValue) {
1050
- if (Array.isArray(objValue)) {
1051
- return objValue.concat(srcValue);
1052
- }
1053
- }
1054
- function headOf(path) {
1055
- if (!path)
1056
- return;
1057
- return 'head' in path ? path.head.name : path.parts[0];
1058
- }
1059
- function isThisHead(path) {
1060
- if (!path)
1061
- return;
1062
- if ('head' in path) {
1063
- return path.head.type === 'ThisHead';
1064
- }
1065
- return path.this === true;
1066
- }
1067
- function isAtHead(path) {
1068
- if (!path)
1069
- return;
1070
- if ('head' in path) {
1071
- return path.head.type === 'AtHead';
1072
- }
1073
- return path.data === true;
1074
- }
1075
- function parts(path) {
1076
- if (!path)
1077
- return;
1078
- return 'original' in path ? path.original.split('.') : path.parts;
1079
- }
1080
- function registrationHelper(context) {
1081
- let Helper = context.import('@ember/component/helper', 'default', 'Helper');
1082
- let getOwner = context.import('@ember/owner', 'getOwner');
1083
- return `
1084
- (class extends ${Helper} {
1085
- compute(_positional, registrations) {
1086
- let owner = ${getOwner}(this);
1087
- for (let [name, definition] of Object.entries(registrations)) {
1088
- owner.register(\`component:\${name}\`, definition);
1089
- }
1090
- }
1091
- })
1092
- `;
1093
- }
1094
- //# sourceMappingURL=resolver-transform.js.map