Skip to content

Commit 2dc51d5

Browse files
committed
fix(@angular/build): support import attributes in JavaScript transformer
The babel-based JavaScript transformer currently requires a syntax plugin to support import attributes. Import attributes are otherwise supported in application code. However, in production builds the JavaScript transformations such as the build optimizer passes would fail on code that contain any import attributes. The inclusion of the babel syntax plugin removes this problem. Once babel provides built-in support for this syntax feature, the plugin can be removed.
1 parent 355ae1a commit 2dc51d5

File tree

5 files changed

+9
-2
lines changed

5 files changed

+9
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@babel/generator": "7.24.7",
7474
"@babel/helper-annotate-as-pure": "7.24.7",
7575
"@babel/helper-split-export-declaration": "7.24.7",
76+
"@babel/plugin-syntax-import-attributes": "7.24.7",
7677
"@babel/plugin-transform-async-generator-functions": "7.24.7",
7778
"@babel/plugin-transform-async-to-generator": "7.24.7",
7879
"@babel/plugin-transform-runtime": "7.24.7",

packages/angular/build/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ ts_library(
6767
"@npm//@babel/core",
6868
"@npm//@babel/helper-annotate-as-pure",
6969
"@npm//@babel/helper-split-export-declaration",
70+
"@npm//@babel/plugin-syntax-import-attributes",
7071
"@npm//@inquirer/confirm",
7172
"@npm//@types/babel__core",
7273
"@npm//@types/less",

packages/angular/build/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@babel/core": "7.24.7",
2424
"@babel/helper-annotate-as-pure": "7.24.7",
2525
"@babel/helper-split-export-declaration": "7.24.7",
26+
"@babel/plugin-syntax-import-attributes": "7.24.7",
2627
"@inquirer/confirm": "3.1.12",
2728
"@vitejs/plugin-basic-ssl": "1.1.0",
2829
"ansi-colors": "4.1.3",

packages/angular/build/src/tools/esbuild/javascript-transformer-worker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ async function transformWithBabel(
6060
options.sourcemap &&
6161
(!!options.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));
6262

63-
const plugins: PluginItem[] = [];
63+
// @ts-expect-error Import attribute syntax plugin does not currently have type definitions
64+
const { default: importAttributePlugin } = await import('@babel/plugin-syntax-import-attributes');
65+
const plugins: PluginItem[] = [importAttributePlugin];
6466

6567
// Lazy load the linker plugin only when linking is required
6668
if (shouldLink) {

yarn.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ __metadata:
399399
"@babel/core": "npm:7.24.7"
400400
"@babel/helper-annotate-as-pure": "npm:7.24.7"
401401
"@babel/helper-split-export-declaration": "npm:7.24.7"
402+
"@babel/plugin-syntax-import-attributes": "npm:7.24.7"
402403
"@inquirer/confirm": "npm:3.1.12"
403404
"@vitejs/plugin-basic-ssl": "npm:1.1.0"
404405
ansi-colors: "npm:4.1.3"
@@ -657,6 +658,7 @@ __metadata:
657658
"@babel/generator": "npm:7.24.7"
658659
"@babel/helper-annotate-as-pure": "npm:7.24.7"
659660
"@babel/helper-split-export-declaration": "npm:7.24.7"
661+
"@babel/plugin-syntax-import-attributes": "npm:7.24.7"
660662
"@babel/plugin-transform-async-generator-functions": "npm:7.24.7"
661663
"@babel/plugin-transform-async-to-generator": "npm:7.24.7"
662664
"@babel/plugin-transform-runtime": "npm:7.24.7"
@@ -1487,7 +1489,7 @@ __metadata:
14871489
languageName: node
14881490
linkType: hard
14891491

1490-
"@babel/plugin-syntax-import-attributes@npm:^7.24.7":
1492+
"@babel/plugin-syntax-import-attributes@npm:7.24.7, @babel/plugin-syntax-import-attributes@npm:^7.24.7":
14911493
version: 7.24.7
14921494
resolution: "@babel/plugin-syntax-import-attributes@npm:7.24.7"
14931495
dependencies:

0 commit comments

Comments
 (0)