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.

(cherry picked from commit 2dc51d5)
  • Loading branch information
clydin committed Jul 2, 2024
1 parent c6fc020 commit 3091956
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 25 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.11",
"@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
63 changes: 39 additions & 24 deletions 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.11"
"@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 Expand Up @@ -2998,9 +3000,11 @@ __metadata:
linkType: hard

"@inquirer/type@npm:^1.3.3":
version: 1.3.3
resolution: "@inquirer/type@npm:1.3.3"
checksum: 10c0/84048694410bb5b2c55dc4e48da6369ce942b9e8f8016d15ef63ab3f9873832a56cc12a50582b5b2b626821bfe29973dfcc19edc90f58490b51df1f4d9d0a074
version: 1.4.0
resolution: "@inquirer/type@npm:1.4.0"
dependencies:
mute-stream: "npm:^1.0.0"
checksum: 10c0/927b46eef9195523a5c4d9467fa43dcd8fde6376131c777012dd899b96b5f5c0d7276e03379f61d3209206e65ef82dc45b129eb79fb4dfe61de29d7aed437cd4
languageName: node
linkType: hard

Expand Down Expand Up @@ -5430,12 +5434,12 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:*, @types/node@npm:>=10.0.0, @types/node@npm:^20.14.6":
version: 20.14.8
resolution: "@types/node@npm:20.14.8"
"@types/node@npm:*, @types/node@npm:>=10.0.0, @types/node@npm:^20.14.9":
version: 20.14.9
resolution: "@types/node@npm:20.14.9"
dependencies:
undici-types: "npm:~5.26.4"
checksum: 10c0/06d4643fa3b179b41fe19f9c75c240278ca1f7a313b3b837bc36ea119499c7ad77f06bbe72694ac04aa91ec77fe747baa09b889f4c435450c1724a26bd55f160
checksum: 10c0/911ffa444dc032897f4a23ed580c67903bd38ea1c5ec99b1d00fa10b83537a3adddef8e1f29710cbdd8e556a61407ed008e06537d834e48caf449ce59f87d387
languageName: node
linkType: hard

Expand All @@ -5455,12 +5459,12 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^20.14.9":
version: 20.14.9
resolution: "@types/node@npm:20.14.9"
"@types/node@npm:^20.14.6":
version: 20.14.8
resolution: "@types/node@npm:20.14.8"
dependencies:
undici-types: "npm:~5.26.4"
checksum: 10c0/911ffa444dc032897f4a23ed580c67903bd38ea1c5ec99b1d00fa10b83537a3adddef8e1f29710cbdd8e556a61407ed008e06537d834e48caf449ce59f87d387
checksum: 10c0/06d4643fa3b179b41fe19f9c75c240278ca1f7a313b3b837bc36ea119499c7ad77f06bbe72694ac04aa91ec77fe747baa09b889f4c435450c1724a26bd55f160
languageName: node
linkType: hard

Expand Down Expand Up @@ -10926,7 +10930,7 @@ __metadata:
languageName: node
linkType: hard

"https-proxy-agent@npm:7.0.4, https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.2, https-proxy-agent@npm:^7.0.3":
"https-proxy-agent@npm:7.0.4, https-proxy-agent@npm:^7.0.2":
version: 7.0.4
resolution: "https-proxy-agent@npm:7.0.4"
dependencies:
Expand All @@ -10936,7 +10940,7 @@ __metadata:
languageName: node
linkType: hard

"https-proxy-agent@npm:7.0.5":
"https-proxy-agent@npm:7.0.5, https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.3":
version: 7.0.5
resolution: "https-proxy-agent@npm:7.0.5"
dependencies:
Expand Down Expand Up @@ -12022,14 +12026,14 @@ __metadata:
languageName: node
linkType: hard

"jsonc-parser@npm:3.2.1, jsonc-parser@npm:^3.2.0":
"jsonc-parser@npm:3.2.1":
version: 3.2.1
resolution: "jsonc-parser@npm:3.2.1"
checksum: 10c0/ada66dec143d7f9cb0e2d0d29c69e9ce40d20f3a4cb96b0c6efb745025ac7f9ba647d7ac0990d0adfc37a2d2ae084a12009a9c833dbdbeadf648879a99b9df89
languageName: node
linkType: hard

"jsonc-parser@npm:3.3.1":
"jsonc-parser@npm:3.3.1, jsonc-parser@npm:^3.2.0":
version: 3.3.1
resolution: "jsonc-parser@npm:3.3.1"
checksum: 10c0/269c3ae0a0e4f907a914bf334306c384aabb9929bd8c99f909275ebd5c2d3bc70b9bcd119ad794f339dec9f24b6a4ee9cd5a8ab2e6435e730ad4075388fc2ab6
Expand Down Expand Up @@ -14605,7 +14609,7 @@ __metadata:
languageName: node
linkType: hard

"piscina@npm:4.6.0, piscina@npm:^4.4.0":
"piscina@npm:4.6.0":
version: 4.6.0
resolution: "piscina@npm:4.6.0"
dependencies:
Expand All @@ -14617,7 +14621,7 @@ __metadata:
languageName: node
linkType: hard

"piscina@npm:4.6.1":
"piscina@npm:4.6.1, piscina@npm:^4.4.0":
version: 4.6.1
resolution: "piscina@npm:4.6.1"
dependencies:
Expand Down Expand Up @@ -14777,7 +14781,7 @@ __metadata:
languageName: node
linkType: hard

"postcss@npm:8.4.38, postcss@npm:^8.2.14, postcss@npm:^8.4.23, postcss@npm:^8.4.31, postcss@npm:^8.4.33, postcss@npm:^8.4.38":
"postcss@npm:8.4.38":
version: 8.4.38
resolution: "postcss@npm:8.4.38"
dependencies:
Expand All @@ -14788,6 +14792,17 @@ __metadata:
languageName: node
linkType: hard

"postcss@npm:^8.2.14, postcss@npm:^8.4.23, postcss@npm:^8.4.31, postcss@npm:^8.4.33, postcss@npm:^8.4.38":
version: 8.4.39
resolution: "postcss@npm:8.4.39"
dependencies:
nanoid: "npm:^3.3.7"
picocolors: "npm:^1.0.1"
source-map-js: "npm:^1.2.0"
checksum: 10c0/16f5ac3c4e32ee76d1582b3c0dcf1a1fdb91334a45ad755eeb881ccc50318fb8d64047de4f1601ac96e30061df203f0f2e2edbdc0bfc49b9c57bc9fb9bedaea3
languageName: node
linkType: hard

"preact-render-to-string@npm:^6.2.1":
version: 6.5.5
resolution: "preact-render-to-string@npm:6.5.5"
Expand Down Expand Up @@ -16350,17 +16365,17 @@ __metadata:
linkType: hard

"socks-proxy-agent@npm:^8.0.2, socks-proxy-agent@npm:^8.0.3":
version: 8.0.3
resolution: "socks-proxy-agent@npm:8.0.3"
version: 8.0.4
resolution: "socks-proxy-agent@npm:8.0.4"
dependencies:
agent-base: "npm:^7.1.1"
debug: "npm:^4.3.4"
socks: "npm:^2.7.1"
checksum: 10c0/4950529affd8ccd6951575e21c1b7be8531b24d924aa4df3ee32df506af34b618c4e50d261f4cc603f1bfd8d426915b7d629966c8ce45b05fb5ad8c8b9a6459d
socks: "npm:^2.8.3"
checksum: 10c0/345593bb21b95b0508e63e703c84da11549f0a2657d6b4e3ee3612c312cb3a907eac10e53b23ede3557c6601d63252103494caa306b66560f43af7b98f53957a
languageName: node
linkType: hard

"socks@npm:^2.7.1":
"socks@npm:^2.8.3":
version: 2.8.3
resolution: "socks@npm:2.8.3"
dependencies:
Expand Down

0 comments on commit 3091956

Please sign in to comment.