Skip to content

Commit

Permalink
fix(@angular/build): support import attributes in JavaScript transformer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
clydin committed Jul 2, 2024
1 parent 355ae1a commit 2dc51d5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@babel/generator": "7.24.7",
"@babel/helper-annotate-as-pure": "7.24.7",
"@babel/helper-split-export-declaration": "7.24.7",
"@babel/plugin-syntax-import-attributes": "7.24.7",
"@babel/plugin-transform-async-generator-functions": "7.24.7",
"@babel/plugin-transform-async-to-generator": "7.24.7",
"@babel/plugin-transform-runtime": "7.24.7",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ts_library(
"@npm//@babel/core",
"@npm//@babel/helper-annotate-as-pure",
"@npm//@babel/helper-split-export-declaration",
"@npm//@babel/plugin-syntax-import-attributes",
"@npm//@inquirer/confirm",
"@npm//@types/babel__core",
"@npm//@types/less",
Expand Down
1 change: 1 addition & 0 deletions packages/angular/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@babel/core": "7.24.7",
"@babel/helper-annotate-as-pure": "7.24.7",
"@babel/helper-split-export-declaration": "7.24.7",
"@babel/plugin-syntax-import-attributes": "7.24.7",
"@inquirer/confirm": "3.1.12",
"@vitejs/plugin-basic-ssl": "1.1.0",
"ansi-colors": "4.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ async function transformWithBabel(
options.sourcemap &&
(!!options.thirdPartySourcemaps || !/[\\/]node_modules[\\/]/.test(filename));

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

// Lazy load the linker plugin only when linking is required
if (shouldLink) {
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ __metadata:
"@babel/core": "npm:7.24.7"
"@babel/helper-annotate-as-pure": "npm:7.24.7"
"@babel/helper-split-export-declaration": "npm:7.24.7"
"@babel/plugin-syntax-import-attributes": "npm:7.24.7"
"@inquirer/confirm": "npm:3.1.12"
"@vitejs/plugin-basic-ssl": "npm:1.1.0"
ansi-colors: "npm:4.1.3"
Expand Down Expand Up @@ -657,6 +658,7 @@ __metadata:
"@babel/generator": "npm:7.24.7"
"@babel/helper-annotate-as-pure": "npm:7.24.7"
"@babel/helper-split-export-declaration": "npm:7.24.7"
"@babel/plugin-syntax-import-attributes": "npm:7.24.7"
"@babel/plugin-transform-async-generator-functions": "npm:7.24.7"
"@babel/plugin-transform-async-to-generator": "npm:7.24.7"
"@babel/plugin-transform-runtime": "npm:7.24.7"
Expand Down Expand Up @@ -1487,7 +1489,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-syntax-import-attributes@npm:^7.24.7":
"@babel/plugin-syntax-import-attributes@npm:7.24.7, @babel/plugin-syntax-import-attributes@npm:^7.24.7":
version: 7.24.7
resolution: "@babel/plugin-syntax-import-attributes@npm:7.24.7"
dependencies:
Expand Down

0 comments on commit 2dc51d5

Please sign in to comment.