@angular/build 18.0.0-next.3

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 (253) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/builders.json +14 -0
  4. package/package.json +87 -0
  5. package/src/builders/application/build-action.d.ts +33 -0
  6. package/src/builders/application/build-action.js +183 -0
  7. package/src/builders/application/execute-build.d.ts +11 -0
  8. package/src/builders/application/execute-build.js +125 -0
  9. package/src/builders/application/execute-post-bundle.d.ts +25 -0
  10. package/src/builders/application/execute-post-bundle.js +93 -0
  11. package/src/builders/application/i18n.d.ts +29 -0
  12. package/src/builders/application/i18n.js +128 -0
  13. package/src/builders/application/index.d.ts +57 -0
  14. package/src/builders/application/index.js +121 -0
  15. package/src/builders/application/options.d.ts +149 -0
  16. package/src/builders/application/options.js +369 -0
  17. package/src/builders/application/schema.d.ts +512 -0
  18. package/src/builders/application/schema.js +58 -0
  19. package/src/builders/application/schema.json +635 -0
  20. package/src/builders/application/setup-bundling.d.ts +19 -0
  21. package/src/builders/application/setup-bundling.js +71 -0
  22. package/src/builders/dev-server/builder.d.ts +32 -0
  23. package/src/builders/dev-server/builder.js +70 -0
  24. package/src/builders/dev-server/index.d.ts +14 -0
  25. package/src/builders/dev-server/index.js +15 -0
  26. package/src/builders/dev-server/internal.d.ts +19 -0
  27. package/src/builders/dev-server/internal.js +29 -0
  28. package/src/builders/dev-server/options.d.ts +47 -0
  29. package/src/builders/dev-server/options.js +65 -0
  30. package/src/builders/dev-server/output.d.ts +16 -0
  31. package/src/builders/dev-server/output.js +9 -0
  32. package/src/builders/dev-server/schema.d.ts +118 -0
  33. package/src/builders/dev-server/schema.js +4 -0
  34. package/src/builders/dev-server/schema.json +131 -0
  35. package/src/builders/dev-server/vite-server.d.ts +31 -0
  36. package/src/builders/dev-server/vite-server.js +504 -0
  37. package/src/index.d.ts +11 -0
  38. package/src/index.js +16 -0
  39. package/src/private.d.ts +35 -0
  40. package/src/private.js +70 -0
  41. package/src/tools/babel/plugins/adjust-static-class-members.d.ts +26 -0
  42. package/src/tools/babel/plugins/adjust-static-class-members.js +351 -0
  43. package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +22 -0
  44. package/src/tools/babel/plugins/adjust-typescript-enums.js +113 -0
  45. package/src/tools/babel/plugins/elide-angular-metadata.d.ts +22 -0
  46. package/src/tools/babel/plugins/elide-angular-metadata.js +110 -0
  47. package/src/tools/babel/plugins/index.d.ts +11 -0
  48. package/src/tools/babel/plugins/index.js +21 -0
  49. package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +15 -0
  50. package/src/tools/babel/plugins/pure-toplevel-functions.js +90 -0
  51. package/src/tools/babel/typings.d.ts +21 -0
  52. package/src/tools/esbuild/angular/angular-host.d.ts +26 -0
  53. package/src/tools/esbuild/angular/angular-host.js +134 -0
  54. package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +42 -0
  55. package/src/tools/esbuild/angular/compilation/angular-compilation.js +94 -0
  56. package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +21 -0
  57. package/src/tools/esbuild/angular/compilation/aot-compilation.js +224 -0
  58. package/src/tools/esbuild/angular/compilation/factory.d.ts +16 -0
  59. package/src/tools/esbuild/angular/compilation/factory.js +56 -0
  60. package/src/tools/esbuild/angular/compilation/index.d.ts +10 -0
  61. package/src/tools/esbuild/angular/compilation/index.js +17 -0
  62. package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.d.ts +10 -0
  63. package/src/tools/esbuild/angular/compilation/jit-bootstrap-transformer.js +182 -0
  64. package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +21 -0
  65. package/src/tools/esbuild/angular/compilation/jit-compilation.js +106 -0
  66. package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +20 -0
  67. package/src/tools/esbuild/angular/compilation/noop-compilation.js +26 -0
  68. package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +42 -0
  69. package/src/tools/esbuild/angular/compilation/parallel-compilation.js +123 -0
  70. package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +33 -0
  71. package/src/tools/esbuild/angular/compilation/parallel-worker.js +90 -0
  72. package/src/tools/esbuild/angular/compilation-state.d.ts +15 -0
  73. package/src/tools/esbuild/angular/compilation-state.js +44 -0
  74. package/src/tools/esbuild/angular/compiler-plugin.d.ts +27 -0
  75. package/src/tools/esbuild/angular/compiler-plugin.js +441 -0
  76. package/src/tools/esbuild/angular/component-stylesheets.d.ts +44 -0
  77. package/src/tools/esbuild/angular/component-stylesheets.js +150 -0
  78. package/src/tools/esbuild/angular/diagnostics.d.ts +15 -0
  79. package/src/tools/esbuild/angular/diagnostics.js +69 -0
  80. package/src/tools/esbuild/angular/file-reference-tracker.d.ts +17 -0
  81. package/src/tools/esbuild/angular/file-reference-tracker.js +57 -0
  82. package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +23 -0
  83. package/src/tools/esbuild/angular/jit-plugin-callbacks.js +117 -0
  84. package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +17 -0
  85. package/src/tools/esbuild/angular/jit-resource-transformer.js +186 -0
  86. package/src/tools/esbuild/angular/source-file-cache.d.ts +18 -0
  87. package/src/tools/esbuild/angular/source-file-cache.js +65 -0
  88. package/src/tools/esbuild/angular/uri.d.ts +54 -0
  89. package/src/tools/esbuild/angular/uri.js +74 -0
  90. package/src/tools/esbuild/angular/web-worker-transformer.d.ts +17 -0
  91. package/src/tools/esbuild/angular/web-worker-transformer.js +94 -0
  92. package/src/tools/esbuild/application-code-bundle.d.ts +20 -0
  93. package/src/tools/esbuild/application-code-bundle.js +368 -0
  94. package/src/tools/esbuild/budget-stats.d.ts +19 -0
  95. package/src/tools/esbuild/budget-stats.js +59 -0
  96. package/src/tools/esbuild/bundler-context.d.ts +75 -0
  97. package/src/tools/esbuild/bundler-context.js +366 -0
  98. package/src/tools/esbuild/bundler-execution-result.d.ts +71 -0
  99. package/src/tools/esbuild/bundler-execution-result.js +131 -0
  100. package/src/tools/esbuild/cache.d.ts +88 -0
  101. package/src/tools/esbuild/cache.js +92 -0
  102. package/src/tools/esbuild/commonjs-checker.d.ts +28 -0
  103. package/src/tools/esbuild/commonjs-checker.js +151 -0
  104. package/src/tools/esbuild/compiler-plugin-options.d.ts +16 -0
  105. package/src/tools/esbuild/compiler-plugin-options.js +49 -0
  106. package/src/tools/esbuild/external-packages-plugin.d.ts +18 -0
  107. package/src/tools/esbuild/external-packages-plugin.js +70 -0
  108. package/src/tools/esbuild/global-scripts.d.ts +16 -0
  109. package/src/tools/esbuild/global-scripts.js +142 -0
  110. package/src/tools/esbuild/global-styles.d.ts +10 -0
  111. package/src/tools/esbuild/global-styles.js +74 -0
  112. package/src/tools/esbuild/i18n-inliner-worker.d.ts +42 -0
  113. package/src/tools/esbuild/i18n-inliner-worker.js +136 -0
  114. package/src/tools/esbuild/i18n-inliner.d.ts +44 -0
  115. package/src/tools/esbuild/i18n-inliner.js +150 -0
  116. package/src/tools/esbuild/i18n-locale-plugin.d.ts +22 -0
  117. package/src/tools/esbuild/i18n-locale-plugin.js +120 -0
  118. package/src/tools/esbuild/index-html-generator.d.ts +15 -0
  119. package/src/tools/esbuild/index-html-generator.js +81 -0
  120. package/src/tools/esbuild/javascript-transformer-worker.d.ts +19 -0
  121. package/src/tools/esbuild/javascript-transformer-worker.js +154 -0
  122. package/src/tools/esbuild/javascript-transformer.d.ts +54 -0
  123. package/src/tools/esbuild/javascript-transformer.js +147 -0
  124. package/src/tools/esbuild/license-extractor.d.ts +25 -0
  125. package/src/tools/esbuild/license-extractor.js +158 -0
  126. package/src/tools/esbuild/load-result-cache.d.ts +21 -0
  127. package/src/tools/esbuild/load-result-cache.js +75 -0
  128. package/src/tools/esbuild/profiling.d.ts +11 -0
  129. package/src/tools/esbuild/profiling.js +78 -0
  130. package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +18 -0
  131. package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +44 -0
  132. package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +17 -0
  133. package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +73 -0
  134. package/src/tools/esbuild/stylesheets/bundle-options.d.ts +35 -0
  135. package/src/tools/esbuild/stylesheets/bundle-options.js +64 -0
  136. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +25 -0
  137. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +57 -0
  138. package/src/tools/esbuild/stylesheets/css-language.d.ts +9 -0
  139. package/src/tools/esbuild/stylesheets/css-language.js +15 -0
  140. package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +18 -0
  141. package/src/tools/esbuild/stylesheets/css-resource-plugin.js +114 -0
  142. package/src/tools/esbuild/stylesheets/less-language.d.ts +9 -0
  143. package/src/tools/esbuild/stylesheets/less-language.js +155 -0
  144. package/src/tools/esbuild/stylesheets/sass-language.d.ts +10 -0
  145. package/src/tools/esbuild/stylesheets/sass-language.js +185 -0
  146. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +58 -0
  147. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +282 -0
  148. package/src/tools/esbuild/utils.d.ts +49 -0
  149. package/src/tools/esbuild/utils.js +392 -0
  150. package/src/tools/esbuild/virtual-module-plugin.d.ts +33 -0
  151. package/src/tools/esbuild/virtual-module-plugin.js +43 -0
  152. package/src/tools/esbuild/watcher.d.ts +25 -0
  153. package/src/tools/esbuild/watcher.js +118 -0
  154. package/src/tools/sass/lexer.d.ts +18 -0
  155. package/src/tools/sass/lexer.js +161 -0
  156. package/src/tools/sass/rebasing-importer.d.ts +101 -0
  157. package/src/tools/sass/rebasing-importer.js +334 -0
  158. package/src/tools/sass/sass-service.d.ts +72 -0
  159. package/src/tools/sass/sass-service.js +213 -0
  160. package/src/tools/sass/worker.d.ts +8 -0
  161. package/src/tools/sass/worker.js +192 -0
  162. package/src/tools/vite/angular-memory-plugin.d.ts +24 -0
  163. package/src/tools/vite/angular-memory-plugin.js +268 -0
  164. package/src/tools/vite/i18n-locale-plugin.d.ts +18 -0
  165. package/src/tools/vite/i18n-locale-plugin.js +55 -0
  166. package/src/utils/bundle-calculator.d.ts +44 -0
  167. package/src/utils/bundle-calculator.js +303 -0
  168. package/src/utils/check-port.d.ts +8 -0
  169. package/src/utils/check-port.js +58 -0
  170. package/src/utils/color.d.ts +10 -0
  171. package/src/utils/color.js +63 -0
  172. package/src/utils/delete-output-dir.d.ts +11 -0
  173. package/src/utils/delete-output-dir.js +46 -0
  174. package/src/utils/environment-options.d.ts +16 -0
  175. package/src/utils/environment-options.js +79 -0
  176. package/src/utils/error.d.ts +10 -0
  177. package/src/utils/error.js +21 -0
  178. package/src/utils/format-bytes.d.ts +8 -0
  179. package/src/utils/format-bytes.js +22 -0
  180. package/src/utils/i18n-options.d.ts +33 -0
  181. package/src/utils/i18n-options.js +161 -0
  182. package/src/utils/index-file/add-event-dispatch-contract.d.ts +8 -0
  183. package/src/utils/index-file/add-event-dispatch-contract.js +28 -0
  184. package/src/utils/index-file/augment-index-html.d.ts +40 -0
  185. package/src/utils/index-file/augment-index-html.js +239 -0
  186. package/src/utils/index-file/html-rewriting-stream.d.ts +11 -0
  187. package/src/utils/index-file/html-rewriting-stream.js +28 -0
  188. package/src/utils/index-file/index-html-generator.d.ts +57 -0
  189. package/src/utils/index-file/index-html-generator.js +135 -0
  190. package/src/utils/index-file/inline-critical-css.d.ts +24 -0
  191. package/src/utils/index-file/inline-critical-css.js +179 -0
  192. package/src/utils/index-file/inline-fonts.d.ts +23 -0
  193. package/src/utils/index-file/inline-fonts.js +267 -0
  194. package/src/utils/index-file/nonce.d.ts +12 -0
  195. package/src/utils/index-file/nonce.js +55 -0
  196. package/src/utils/index-file/style-nonce.d.ts +12 -0
  197. package/src/utils/index-file/style-nonce.js +55 -0
  198. package/src/utils/index.d.ts +11 -0
  199. package/src/utils/index.js +27 -0
  200. package/src/utils/load-esm.d.ts +20 -0
  201. package/src/utils/load-esm.js +31 -0
  202. package/src/utils/load-proxy-config.d.ts +8 -0
  203. package/src/utils/load-proxy-config.js +189 -0
  204. package/src/utils/load-translations.d.ts +16 -0
  205. package/src/utils/load-translations.js +84 -0
  206. package/src/utils/normalize-asset-patterns.d.ts +14 -0
  207. package/src/utils/normalize-asset-patterns.js +96 -0
  208. package/src/utils/normalize-cache.d.ts +16 -0
  209. package/src/utils/normalize-cache.js +44 -0
  210. package/src/utils/normalize-optimization.d.ts +13 -0
  211. package/src/utils/normalize-optimization.js +42 -0
  212. package/src/utils/normalize-source-maps.d.ts +9 -0
  213. package/src/utils/normalize-source-maps.js +23 -0
  214. package/src/utils/postcss-configuration.d.ts +17 -0
  215. package/src/utils/postcss-configuration.js +86 -0
  216. package/src/utils/purge-cache.d.ts +10 -0
  217. package/src/utils/purge-cache.js +40 -0
  218. package/src/utils/resolve-assets.d.ts +18 -0
  219. package/src/utils/resolve-assets.js +35 -0
  220. package/src/utils/routes-extractor/extractor.d.ts +15 -0
  221. package/src/utils/routes-extractor/extractor.js +97 -0
  222. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +18 -0
  223. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +129 -0
  224. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +8 -0
  225. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +13 -0
  226. package/src/utils/server-rendering/fetch-patch.d.ts +8 -0
  227. package/src/utils/server-rendering/fetch-patch.js +66 -0
  228. package/src/utils/server-rendering/load-esm-from-memory.d.ts +10 -0
  229. package/src/utils/server-rendering/load-esm-from-memory.js +26 -0
  230. package/src/utils/server-rendering/main-bundle-exports.d.ts +27 -0
  231. package/src/utils/server-rendering/main-bundle-exports.js +9 -0
  232. package/src/utils/server-rendering/prerender.d.ts +23 -0
  233. package/src/utils/server-rendering/prerender.js +192 -0
  234. package/src/utils/server-rendering/render-page.d.ts +26 -0
  235. package/src/utils/server-rendering/render-page.js +110 -0
  236. package/src/utils/server-rendering/render-worker.d.ts +22 -0
  237. package/src/utils/server-rendering/render-worker.js +30 -0
  238. package/src/utils/server-rendering/routes-extractor-worker.d.ts +21 -0
  239. package/src/utils/server-rendering/routes-extractor-worker.js +53 -0
  240. package/src/utils/service-worker.d.ts +25 -0
  241. package/src/utils/service-worker.js +211 -0
  242. package/src/utils/spinner.d.ts +20 -0
  243. package/src/utils/spinner.js +55 -0
  244. package/src/utils/stats-table.d.ts +20 -0
  245. package/src/utils/stats-table.js +205 -0
  246. package/src/utils/supported-browsers.d.ts +10 -0
  247. package/src/utils/supported-browsers.js +42 -0
  248. package/src/utils/tty.d.ts +8 -0
  249. package/src/utils/tty.js +23 -0
  250. package/src/utils/url.d.ts +8 -0
  251. package/src/utils/url.js +18 -0
  252. package/src/utils/version.d.ts +8 -0
  253. package/src/utils/version.js +59 -0
package/src/private.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.assertCompatibleAngularVersion = exports.getSupportedBrowsers = exports.generateBuildStatsTable = exports.augmentAppWithServiceWorker = exports.purgeStaleBuildCache = exports.createTranslationLoader = exports.loadProxyConfiguration = exports.InlineCriticalCssProcessor = exports.IndexHtmlGenerator = exports.loadTranslations = exports.createI18nOptions = exports.deleteOutputDir = exports.checkPort = exports.SassWorkerImplementation = exports.transformSupportedBrowsersToTargets = exports.emitFilesToDisk = exports.serveWithVite = exports.buildApplicationInternal = void 0;
25
+ /**
26
+ * @fileoverview
27
+ * Private exports intended only for use with the @angular-devkit/build-angular package.
28
+ * All exports are not supported for external use, do not provide SemVer guarantees, and
29
+ * their existence may change in any future version.
30
+ */
31
+ // Builders
32
+ var application_1 = require("./builders/application");
33
+ Object.defineProperty(exports, "buildApplicationInternal", { enumerable: true, get: function () { return application_1.buildApplicationInternal; } });
34
+ var vite_server_1 = require("./builders/dev-server/vite-server");
35
+ Object.defineProperty(exports, "serveWithVite", { enumerable: true, get: function () { return vite_server_1.serveWithVite; } });
36
+ // Tools
37
+ __exportStar(require("./tools/babel/plugins"), exports);
38
+ var utils_1 = require("./tools/esbuild/utils");
39
+ Object.defineProperty(exports, "emitFilesToDisk", { enumerable: true, get: function () { return utils_1.emitFilesToDisk; } });
40
+ var utils_2 = require("./tools/esbuild/utils");
41
+ Object.defineProperty(exports, "transformSupportedBrowsersToTargets", { enumerable: true, get: function () { return utils_2.transformSupportedBrowsersToTargets; } });
42
+ var sass_service_1 = require("./tools/sass/sass-service");
43
+ Object.defineProperty(exports, "SassWorkerImplementation", { enumerable: true, get: function () { return sass_service_1.SassWorkerImplementation; } });
44
+ // Utilities
45
+ __exportStar(require("./utils/bundle-calculator"), exports);
46
+ var check_port_1 = require("./utils/check-port");
47
+ Object.defineProperty(exports, "checkPort", { enumerable: true, get: function () { return check_port_1.checkPort; } });
48
+ var delete_output_dir_1 = require("./utils/delete-output-dir");
49
+ Object.defineProperty(exports, "deleteOutputDir", { enumerable: true, get: function () { return delete_output_dir_1.deleteOutputDir; } });
50
+ var i18n_options_1 = require("./utils/i18n-options");
51
+ Object.defineProperty(exports, "createI18nOptions", { enumerable: true, get: function () { return i18n_options_1.createI18nOptions; } });
52
+ Object.defineProperty(exports, "loadTranslations", { enumerable: true, get: function () { return i18n_options_1.loadTranslations; } });
53
+ var index_html_generator_1 = require("./utils/index-file/index-html-generator");
54
+ Object.defineProperty(exports, "IndexHtmlGenerator", { enumerable: true, get: function () { return index_html_generator_1.IndexHtmlGenerator; } });
55
+ var inline_critical_css_1 = require("./utils/index-file/inline-critical-css");
56
+ Object.defineProperty(exports, "InlineCriticalCssProcessor", { enumerable: true, get: function () { return inline_critical_css_1.InlineCriticalCssProcessor; } });
57
+ var load_proxy_config_1 = require("./utils/load-proxy-config");
58
+ Object.defineProperty(exports, "loadProxyConfiguration", { enumerable: true, get: function () { return load_proxy_config_1.loadProxyConfiguration; } });
59
+ var load_translations_1 = require("./utils/load-translations");
60
+ Object.defineProperty(exports, "createTranslationLoader", { enumerable: true, get: function () { return load_translations_1.createTranslationLoader; } });
61
+ var purge_cache_1 = require("./utils/purge-cache");
62
+ Object.defineProperty(exports, "purgeStaleBuildCache", { enumerable: true, get: function () { return purge_cache_1.purgeStaleBuildCache; } });
63
+ var service_worker_1 = require("./utils/service-worker");
64
+ Object.defineProperty(exports, "augmentAppWithServiceWorker", { enumerable: true, get: function () { return service_worker_1.augmentAppWithServiceWorker; } });
65
+ var stats_table_1 = require("./utils/stats-table");
66
+ Object.defineProperty(exports, "generateBuildStatsTable", { enumerable: true, get: function () { return stats_table_1.generateBuildStatsTable; } });
67
+ var supported_browsers_1 = require("./utils/supported-browsers");
68
+ Object.defineProperty(exports, "getSupportedBrowsers", { enumerable: true, get: function () { return supported_browsers_1.getSupportedBrowsers; } });
69
+ var version_1 = require("./utils/version");
70
+ Object.defineProperty(exports, "assertCompatibleAngularVersion", { enumerable: true, get: function () { return version_1.assertCompatibleAngularVersion; } });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /// <reference types="@angular/compiler-cli/private/babel" />
9
+ import { PluginObj } from '@babel/core';
10
+ /**
11
+ * Provides one or more keywords that if found within the content of a source file indicate
12
+ * that this plugin should be used with a source file.
13
+ *
14
+ * @returns An a string iterable containing one or more keywords.
15
+ */
16
+ export declare function getKeywords(): Iterable<string>;
17
+ /**
18
+ * A babel plugin factory function for adjusting classes; primarily with Angular metadata.
19
+ * The adjustments include wrapping classes with known safe or no side effects with pure
20
+ * annotations to support dead code removal of unused classes. Angular compiler generated
21
+ * metadata static fields not required in AOT mode are also elided to better support bundler-
22
+ * level treeshaking.
23
+ *
24
+ * @returns A babel plugin object instance.
25
+ */
26
+ export default function (): PluginObj;
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.getKeywords = void 0;
14
+ const core_1 = require("@babel/core");
15
+ const helper_annotate_as_pure_1 = __importDefault(require("@babel/helper-annotate-as-pure"));
16
+ const helper_split_export_declaration_1 = __importDefault(require("@babel/helper-split-export-declaration"));
17
+ /**
18
+ * The name of the Typescript decorator helper function created by the TypeScript compiler.
19
+ */
20
+ const TSLIB_DECORATE_HELPER_NAME = '__decorate';
21
+ /**
22
+ * The set of Angular static fields that should always be wrapped.
23
+ * These fields may appear to have side effects but are safe to remove if the associated class
24
+ * is otherwise unused within the output.
25
+ */
26
+ const angularStaticsToWrap = new Set([
27
+ 'ɵcmp',
28
+ 'ɵdir',
29
+ 'ɵfac',
30
+ 'ɵinj',
31
+ 'ɵmod',
32
+ 'ɵpipe',
33
+ 'ɵprov',
34
+ 'INJECTOR_KEY',
35
+ ]);
36
+ /**
37
+ * An object map of static fields and related value checks for discovery of Angular generated
38
+ * JIT related static fields.
39
+ */
40
+ const angularStaticsToElide = {
41
+ 'ctorParameters'(path) {
42
+ return path.isFunctionExpression() || path.isArrowFunctionExpression();
43
+ },
44
+ 'decorators'(path) {
45
+ return path.isArrayExpression();
46
+ },
47
+ 'propDecorators'(path) {
48
+ return path.isObjectExpression();
49
+ },
50
+ };
51
+ /**
52
+ * Provides one or more keywords that if found within the content of a source file indicate
53
+ * that this plugin should be used with a source file.
54
+ *
55
+ * @returns An a string iterable containing one or more keywords.
56
+ */
57
+ function getKeywords() {
58
+ return ['class'];
59
+ }
60
+ exports.getKeywords = getKeywords;
61
+ /**
62
+ * Determines whether a property and its initializer value can be safely wrapped in a pure
63
+ * annotated IIFE. Values that may cause side effects are not considered safe to wrap.
64
+ * Wrapping such values may cause runtime errors and/or incorrect runtime behavior.
65
+ *
66
+ * @param propertyName The name of the property to analyze.
67
+ * @param assignmentValue The initializer value that will be assigned to the property.
68
+ * @returns If the property can be safely wrapped, then true; otherwise, false.
69
+ */
70
+ function canWrapProperty(propertyName, assignmentValue) {
71
+ if (angularStaticsToWrap.has(propertyName)) {
72
+ return true;
73
+ }
74
+ const { leadingComments } = assignmentValue.node;
75
+ if (leadingComments?.some(
76
+ // `@pureOrBreakMyCode` is used by closure and is present in Angular code
77
+ ({ value }) => value.includes('@__PURE__') ||
78
+ value.includes('#__PURE__') ||
79
+ value.includes('@pureOrBreakMyCode'))) {
80
+ return true;
81
+ }
82
+ return assignmentValue.isPure();
83
+ }
84
+ /**
85
+ * Analyze the sibling nodes of a class to determine if any downlevel elements should be
86
+ * wrapped in a pure annotated IIFE. Also determines if any elements have potential side
87
+ * effects.
88
+ *
89
+ * @param origin The starting NodePath location for analyzing siblings.
90
+ * @param classIdentifier The identifier node that represents the name of the class.
91
+ * @param allowWrappingDecorators Whether to allow decorators to be wrapped.
92
+ * @returns An object containing the results of the analysis.
93
+ */
94
+ function analyzeClassSiblings(origin, classIdentifier, allowWrappingDecorators) {
95
+ const wrapStatementPaths = [];
96
+ let hasPotentialSideEffects = false;
97
+ for (let i = 1;; ++i) {
98
+ const nextStatement = origin.getSibling(+(origin.key ?? 0) + i);
99
+ if (!nextStatement.isExpressionStatement()) {
100
+ break;
101
+ }
102
+ // Valid sibling statements for class declarations are only assignment expressions
103
+ // and TypeScript decorator helper call expressions
104
+ const nextExpression = nextStatement.get('expression');
105
+ if (nextExpression.isCallExpression()) {
106
+ if (!core_1.types.isIdentifier(nextExpression.node.callee) ||
107
+ nextExpression.node.callee.name !== TSLIB_DECORATE_HELPER_NAME) {
108
+ break;
109
+ }
110
+ if (allowWrappingDecorators) {
111
+ wrapStatementPaths.push(nextStatement);
112
+ }
113
+ else {
114
+ // Statement cannot be safely wrapped which makes wrapping the class unneeded.
115
+ // The statement will prevent even a wrapped class from being optimized away.
116
+ hasPotentialSideEffects = true;
117
+ }
118
+ continue;
119
+ }
120
+ else if (!nextExpression.isAssignmentExpression()) {
121
+ break;
122
+ }
123
+ // Valid assignment expressions should be member access expressions using the class
124
+ // name as the object and an identifier as the property for static fields or only
125
+ // the class name for decorators.
126
+ const left = nextExpression.get('left');
127
+ if (left.isIdentifier()) {
128
+ if (!left.scope.bindingIdentifierEquals(left.node.name, classIdentifier) ||
129
+ !core_1.types.isCallExpression(nextExpression.node.right) ||
130
+ !core_1.types.isIdentifier(nextExpression.node.right.callee) ||
131
+ nextExpression.node.right.callee.name !== TSLIB_DECORATE_HELPER_NAME) {
132
+ break;
133
+ }
134
+ if (allowWrappingDecorators) {
135
+ wrapStatementPaths.push(nextStatement);
136
+ }
137
+ else {
138
+ // Statement cannot be safely wrapped which makes wrapping the class unneeded.
139
+ // The statement will prevent even a wrapped class from being optimized away.
140
+ hasPotentialSideEffects = true;
141
+ }
142
+ continue;
143
+ }
144
+ else if (!left.isMemberExpression() ||
145
+ !core_1.types.isIdentifier(left.node.object) ||
146
+ !left.scope.bindingIdentifierEquals(left.node.object.name, classIdentifier) ||
147
+ !core_1.types.isIdentifier(left.node.property)) {
148
+ break;
149
+ }
150
+ const propertyName = left.node.property.name;
151
+ const assignmentValue = nextExpression.get('right');
152
+ if (angularStaticsToElide[propertyName]?.(assignmentValue)) {
153
+ nextStatement.remove();
154
+ --i;
155
+ }
156
+ else if (canWrapProperty(propertyName, assignmentValue)) {
157
+ wrapStatementPaths.push(nextStatement);
158
+ }
159
+ else {
160
+ // Statement cannot be safely wrapped which makes wrapping the class unneeded.
161
+ // The statement will prevent even a wrapped class from being optimized away.
162
+ hasPotentialSideEffects = true;
163
+ }
164
+ }
165
+ return { hasPotentialSideEffects, wrapStatementPaths };
166
+ }
167
+ /**
168
+ * The set of classes already visited and analyzed during the plugin's execution.
169
+ * This is used to prevent adjusted classes from being repeatedly analyzed which can lead
170
+ * to an infinite loop.
171
+ */
172
+ const visitedClasses = new WeakSet();
173
+ /**
174
+ * A map of classes that have already been analyzed during the default export splitting step.
175
+ * This is used to avoid analyzing a class declaration twice if it is a direct default export.
176
+ */
177
+ const exportDefaultAnalysis = new WeakMap();
178
+ /**
179
+ * A babel plugin factory function for adjusting classes; primarily with Angular metadata.
180
+ * The adjustments include wrapping classes with known safe or no side effects with pure
181
+ * annotations to support dead code removal of unused classes. Angular compiler generated
182
+ * metadata static fields not required in AOT mode are also elided to better support bundler-
183
+ * level treeshaking.
184
+ *
185
+ * @returns A babel plugin object instance.
186
+ */
187
+ // eslint-disable-next-line max-lines-per-function
188
+ function default_1() {
189
+ return {
190
+ visitor: {
191
+ // When a class is converted to a variable declaration, the default export must be moved
192
+ // to a subsequent statement to prevent a JavaScript syntax error.
193
+ ExportDefaultDeclaration(path, state) {
194
+ const declaration = path.get('declaration');
195
+ if (!declaration.isClassDeclaration() || !declaration.node.id) {
196
+ return;
197
+ }
198
+ const { wrapDecorators } = state.opts;
199
+ const analysis = analyzeClassSiblings(path, declaration.node.id, wrapDecorators);
200
+ exportDefaultAnalysis.set(declaration.node, analysis);
201
+ // Splitting the export declaration is not needed if the class will not be wrapped
202
+ if (analysis.hasPotentialSideEffects) {
203
+ return;
204
+ }
205
+ (0, helper_split_export_declaration_1.default)(path);
206
+ },
207
+ ClassDeclaration(path, state) {
208
+ const { node: classNode, parentPath } = path;
209
+ const { wrapDecorators } = state.opts;
210
+ // Skip if already visited or has no name
211
+ if (visitedClasses.has(classNode) || !classNode.id) {
212
+ return;
213
+ }
214
+ // Analyze sibling statements for elements of the class that were downleveled
215
+ const origin = parentPath.isExportNamedDeclaration() ? parentPath : path;
216
+ const { wrapStatementPaths, hasPotentialSideEffects } = exportDefaultAnalysis.get(classNode) ??
217
+ analyzeClassSiblings(origin, classNode.id, wrapDecorators);
218
+ visitedClasses.add(classNode);
219
+ if (hasPotentialSideEffects) {
220
+ return;
221
+ }
222
+ // If no statements to wrap, check for static class properties.
223
+ // Static class properties may be downleveled at later stages in the build pipeline
224
+ // which results in additional function calls outside the class body. These calls
225
+ // then cause the class to be referenced and not eligible for removal. Since it is
226
+ // not known at this stage whether the class needs to be downleveled, the transform
227
+ // wraps classes preemptively to allow for potential removal within the optimization
228
+ // stages.
229
+ if (wrapStatementPaths.length === 0) {
230
+ let shouldWrap = false;
231
+ for (const element of path.get('body').get('body')) {
232
+ if (element.isClassProperty()) {
233
+ // Only need to analyze static properties
234
+ if (!element.node.static) {
235
+ continue;
236
+ }
237
+ // Check for potential side effects.
238
+ // These checks are conservative and could potentially be expanded in the future.
239
+ const elementKey = element.get('key');
240
+ const elementValue = element.get('value');
241
+ if (elementKey.isIdentifier() &&
242
+ (!elementValue.isExpression() ||
243
+ canWrapProperty(elementKey.node.name, elementValue))) {
244
+ shouldWrap = true;
245
+ }
246
+ else {
247
+ // Not safe to wrap
248
+ shouldWrap = false;
249
+ break;
250
+ }
251
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
252
+ }
253
+ else if (element.isStaticBlock()) {
254
+ // Only need to analyze static blocks
255
+ const body = element.get('body');
256
+ if (Array.isArray(body) && body.length > 1) {
257
+ // Not safe to wrap
258
+ shouldWrap = false;
259
+ break;
260
+ }
261
+ const expression = body.find((n) => n.isExpressionStatement());
262
+ const assignmentExpression = expression?.get('expression');
263
+ if (assignmentExpression?.isAssignmentExpression()) {
264
+ const left = assignmentExpression.get('left');
265
+ if (!left.isMemberExpression()) {
266
+ continue;
267
+ }
268
+ if (!left.get('object').isThisExpression()) {
269
+ // Not safe to wrap
270
+ shouldWrap = false;
271
+ break;
272
+ }
273
+ const element = left.get('property');
274
+ const right = assignmentExpression.get('right');
275
+ if (element.isIdentifier() &&
276
+ (!right.isExpression() || canWrapProperty(element.node.name, right))) {
277
+ shouldWrap = true;
278
+ }
279
+ else {
280
+ // Not safe to wrap
281
+ shouldWrap = false;
282
+ break;
283
+ }
284
+ }
285
+ }
286
+ }
287
+ if (!shouldWrap) {
288
+ return;
289
+ }
290
+ }
291
+ const wrapStatementNodes = [];
292
+ for (const statementPath of wrapStatementPaths) {
293
+ wrapStatementNodes.push(statementPath.node);
294
+ statementPath.remove();
295
+ }
296
+ // Wrap class and safe static assignments in a pure annotated IIFE
297
+ const container = core_1.types.arrowFunctionExpression([], core_1.types.blockStatement([
298
+ classNode,
299
+ ...wrapStatementNodes,
300
+ core_1.types.returnStatement(core_1.types.cloneNode(classNode.id)),
301
+ ]));
302
+ const replacementInitializer = core_1.types.callExpression(core_1.types.parenthesizedExpression(container), []);
303
+ (0, helper_annotate_as_pure_1.default)(replacementInitializer);
304
+ // Replace class with IIFE wrapped class
305
+ const declaration = core_1.types.variableDeclaration('let', [
306
+ core_1.types.variableDeclarator(core_1.types.cloneNode(classNode.id), replacementInitializer),
307
+ ]);
308
+ path.replaceWith(declaration);
309
+ },
310
+ ClassExpression(path, state) {
311
+ const { node: classNode, parentPath } = path;
312
+ const { wrapDecorators } = state.opts;
313
+ // Class expressions are used by TypeScript to represent downlevel class/constructor decorators.
314
+ // If not wrapping decorators, they do not need to be processed.
315
+ if (!wrapDecorators || visitedClasses.has(classNode)) {
316
+ return;
317
+ }
318
+ if (!parentPath.isVariableDeclarator() || !core_1.types.isIdentifier(parentPath.node.id)) {
319
+ return;
320
+ }
321
+ const origin = parentPath.parentPath;
322
+ if (!origin.isVariableDeclaration() || origin.node.declarations.length !== 1) {
323
+ return;
324
+ }
325
+ const { wrapStatementPaths, hasPotentialSideEffects } = analyzeClassSiblings(origin, parentPath.node.id, wrapDecorators);
326
+ visitedClasses.add(classNode);
327
+ if (hasPotentialSideEffects || wrapStatementPaths.length === 0) {
328
+ return;
329
+ }
330
+ const wrapStatementNodes = [];
331
+ for (const statementPath of wrapStatementPaths) {
332
+ wrapStatementNodes.push(statementPath.node);
333
+ statementPath.remove();
334
+ }
335
+ // Wrap class and safe static assignments in a pure annotated IIFE
336
+ const container = core_1.types.arrowFunctionExpression([], core_1.types.blockStatement([
337
+ core_1.types.variableDeclaration('let', [
338
+ core_1.types.variableDeclarator(core_1.types.cloneNode(parentPath.node.id), classNode),
339
+ ]),
340
+ ...wrapStatementNodes,
341
+ core_1.types.returnStatement(core_1.types.cloneNode(parentPath.node.id)),
342
+ ]));
343
+ const replacementInitializer = core_1.types.callExpression(core_1.types.parenthesizedExpression(container), []);
344
+ (0, helper_annotate_as_pure_1.default)(replacementInitializer);
345
+ // Add the wrapped class directly to the variable declaration
346
+ parentPath.get('init').replaceWith(replacementInitializer);
347
+ },
348
+ },
349
+ };
350
+ }
351
+ exports.default = default_1;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /// <reference types="@angular/compiler-cli/private/babel" />
9
+ import { PluginObj } from '@babel/core';
10
+ /**
11
+ * Provides one or more keywords that if found within the content of a source file indicate
12
+ * that this plugin should be used with a source file.
13
+ *
14
+ * @returns An a string iterable containing one or more keywords.
15
+ */
16
+ export declare function getKeywords(): Iterable<string>;
17
+ /**
18
+ * A babel plugin factory function for adjusting TypeScript emitted enums.
19
+ *
20
+ * @returns A babel plugin object instance.
21
+ */
22
+ export default function (): PluginObj;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.getKeywords = void 0;
14
+ const core_1 = require("@babel/core");
15
+ const helper_annotate_as_pure_1 = __importDefault(require("@babel/helper-annotate-as-pure"));
16
+ /**
17
+ * Provides one or more keywords that if found within the content of a source file indicate
18
+ * that this plugin should be used with a source file.
19
+ *
20
+ * @returns An a string iterable containing one or more keywords.
21
+ */
22
+ function getKeywords() {
23
+ return ['var'];
24
+ }
25
+ exports.getKeywords = getKeywords;
26
+ /**
27
+ * A babel plugin factory function for adjusting TypeScript emitted enums.
28
+ *
29
+ * @returns A babel plugin object instance.
30
+ */
31
+ function default_1() {
32
+ return {
33
+ visitor: {
34
+ VariableDeclaration(path) {
35
+ const { parentPath, node } = path;
36
+ if (node.kind !== 'var' || node.declarations.length !== 1) {
37
+ return;
38
+ }
39
+ const declaration = path.get('declarations')[0];
40
+ if (declaration.node.init) {
41
+ return;
42
+ }
43
+ const declarationId = declaration.node.id;
44
+ if (!core_1.types.isIdentifier(declarationId)) {
45
+ return;
46
+ }
47
+ const hasExport = parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration();
48
+ const origin = hasExport ? parentPath : path;
49
+ const nextStatement = origin.getSibling(+(origin.key ?? 0) + 1);
50
+ if (!nextStatement.isExpressionStatement()) {
51
+ return;
52
+ }
53
+ const nextExpression = nextStatement.get('expression');
54
+ if (!nextExpression.isCallExpression() || nextExpression.node.arguments.length !== 1) {
55
+ return;
56
+ }
57
+ const enumCallArgument = nextExpression.get('arguments')[0];
58
+ if (!enumCallArgument.isLogicalExpression({ operator: '||' })) {
59
+ return;
60
+ }
61
+ const leftCallArgument = enumCallArgument.get('left');
62
+ const rightCallArgument = enumCallArgument.get('right');
63
+ // Check if identifiers match var declaration
64
+ if (!leftCallArgument.isIdentifier() ||
65
+ !nextExpression.scope.bindingIdentifierEquals(leftCallArgument.node.name, declarationId) ||
66
+ !rightCallArgument.isAssignmentExpression()) {
67
+ return;
68
+ }
69
+ const enumCallee = nextExpression.get('callee');
70
+ if (!enumCallee.isFunctionExpression() || enumCallee.node.params.length !== 1) {
71
+ return;
72
+ }
73
+ const parameterId = enumCallee.get('params')[0];
74
+ if (!parameterId.isIdentifier()) {
75
+ return;
76
+ }
77
+ // Check if all enum member values are pure.
78
+ // If not, leave as-is due to potential side efects
79
+ let hasElements = false;
80
+ for (const enumStatement of enumCallee.get('body').get('body')) {
81
+ if (!enumStatement.isExpressionStatement()) {
82
+ return;
83
+ }
84
+ const enumValueAssignment = enumStatement.get('expression');
85
+ if (!enumValueAssignment.isAssignmentExpression() ||
86
+ !enumValueAssignment.get('right').isPure()) {
87
+ return;
88
+ }
89
+ hasElements = true;
90
+ }
91
+ // If there are no enum elements then there is nothing to wrap
92
+ if (!hasElements) {
93
+ return;
94
+ }
95
+ // Update right-side of initializer call argument to remove redundant assignment
96
+ if (rightCallArgument.get('left').isIdentifier()) {
97
+ rightCallArgument.replaceWith(rightCallArgument.get('right'));
98
+ }
99
+ // Add a return statement to the enum initializer block
100
+ enumCallee
101
+ .get('body')
102
+ .node.body.push(core_1.types.returnStatement(core_1.types.cloneNode(parameterId.node)));
103
+ // Remove existing enum initializer
104
+ const enumInitializer = nextExpression.node;
105
+ nextExpression.remove();
106
+ (0, helper_annotate_as_pure_1.default)(enumInitializer);
107
+ // Add the wrapped enum initializer directly to the variable declaration
108
+ declaration.get('init').replaceWith(enumInitializer);
109
+ },
110
+ },
111
+ };
112
+ }
113
+ exports.default = default_1;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ /// <reference types="@angular/compiler-cli/private/babel" />
9
+ import type { PluginObj } from '@babel/core';
10
+ /**
11
+ * Provides one or more keywords that if found within the content of a source file indicate
12
+ * that this plugin should be used with a source file.
13
+ *
14
+ * @returns An a string iterable containing one or more keywords.
15
+ */
16
+ export declare function getKeywords(): Iterable<string>;
17
+ /**
18
+ * A babel plugin factory function for eliding the Angular class metadata function (`ɵsetClassMetadata`).
19
+ *
20
+ * @returns A babel plugin object instance.
21
+ */
22
+ export default function (): PluginObj;