Skip to content

Commit b4a12a9

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-angular): update babel package usage and types based on current versions
Newer versions of the babel packages allow for removing some types packages as well as some helper packages. The `@babel/template` package export used within the CLI is accessible from the `@babel/core` package which allows removal of `@babel/template` as a direct dependency. Also, the `@babel/plugin-proposal-async-generator-functions` package has been transitioned to `@babel/plugin-transform-async-generator-functions` due to async generators being merged into the ECMAScript standard. Minor code cleanup based on the type cleanup was also performed in the build optimizer babel passes.
1 parent f437545 commit b4a12a9

File tree

10 files changed

+32
-36
lines changed

10 files changed

+32
-36
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@
8080
"@babel/generator": "7.22.15",
8181
"@babel/helper-annotate-as-pure": "7.22.5",
8282
"@babel/helper-split-export-declaration": "7.22.6",
83-
"@babel/plugin-proposal-async-generator-functions": "7.20.7",
83+
"@babel/plugin-transform-async-generator-functions": "7.22.5",
8484
"@babel/plugin-transform-async-to-generator": "7.22.5",
8585
"@babel/plugin-transform-runtime": "7.22.15",
8686
"@babel/preset-env": "7.22.15",
8787
"@babel/runtime": "7.22.15",
88-
"@babel/template": "7.22.15",
8988
"@bazel/bazelisk": "1.18.0",
9089
"@bazel/buildifier": "6.3.3",
9190
"@bazel/concatjs": "5.8.1",
@@ -95,7 +94,6 @@
9594
"@rollup/plugin-commonjs": "^25.0.0",
9695
"@rollup/plugin-node-resolve": "^13.0.5",
9796
"@types/babel__core": "7.20.1",
98-
"@types/babel__template": "7.4.1",
9997
"@types/browser-sync": "^2.27.0",
10098
"@types/browserslist": "^4.15.0",
10199
"@types/express": "^4.16.0",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,13 @@ ts_library(
137137
"@npm//@babel/generator",
138138
"@npm//@babel/helper-annotate-as-pure",
139139
"@npm//@babel/helper-split-export-declaration",
140-
"@npm//@babel/plugin-proposal-async-generator-functions",
140+
"@npm//@babel/plugin-transform-async-generator-functions",
141141
"@npm//@babel/plugin-transform-async-to-generator",
142142
"@npm//@babel/plugin-transform-runtime",
143143
"@npm//@babel/preset-env",
144144
"@npm//@babel/runtime",
145-
"@npm//@babel/template",
146145
"@npm//@discoveryjs/json-ext",
147146
"@npm//@types/babel__core",
148-
"@npm//@types/babel__template",
149147
"@npm//@types/browser-sync",
150148
"@npm//@types/browserslist",
151149
"@npm//@types/inquirer",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
"@babel/generator": "7.22.15",
1515
"@babel/helper-annotate-as-pure": "7.22.5",
1616
"@babel/helper-split-export-declaration": "7.22.6",
17-
"@babel/plugin-proposal-async-generator-functions": "7.20.7",
17+
"@babel/plugin-transform-async-generator-functions": "7.22.5",
1818
"@babel/plugin-transform-async-to-generator": "7.22.5",
1919
"@babel/plugin-transform-runtime": "7.22.15",
2020
"@babel/preset-env": "7.22.15",
2121
"@babel/runtime": "7.22.15",
22-
"@babel/template": "7.22.15",
2322
"@discoveryjs/json-ext": "0.5.7",
2423
"@ngtools/webpack": "0.0.0-PLACEHOLDER",
2524
"@vitejs/plugin-basic-ssl": "1.0.1",

packages/angular_devkit/build_angular/src/babel-bazel.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,3 @@ declare module '@babel/core' {
1515
declare module '@babel/generator' {
1616
export { default } from '@types/babel__generator';
1717
}
18-
declare module '@babel/traverse' {
19-
export { default } from '@types/babel__traverse';
20-
}
21-
declare module '@babel/template' {
22-
export { default } from '@types/babel__template';
23-
}

packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function analyzeClassSiblings(
105105
const wrapStatementPaths: NodePath<types.Statement>[] = [];
106106
let hasPotentialSideEffects = false;
107107
for (let i = 1; ; ++i) {
108-
const nextStatement = origin.getSibling(+origin.key + i);
108+
const nextStatement = origin.getSibling(+(origin.key ?? 0) + i);
109109
if (!nextStatement.isExpressionStatement()) {
110110
break;
111111
}
@@ -213,7 +213,7 @@ export default function (): PluginObj {
213213
// to a subsequent statement to prevent a JavaScript syntax error.
214214
ExportDefaultDeclaration(path: NodePath<types.ExportDefaultDeclaration>, state: PluginPass) {
215215
const declaration = path.get('declaration');
216-
if (!declaration.isClassDeclaration()) {
216+
if (!declaration.isClassDeclaration() || !declaration.node.id) {
217217
return;
218218
}
219219

@@ -232,7 +232,8 @@ export default function (): PluginObj {
232232
const { node: classNode, parentPath } = path;
233233
const { wrapDecorators } = state.opts as { wrapDecorators: boolean };
234234

235-
if (visitedClasses.has(classNode)) {
235+
// Skip if already visited or has no name
236+
if (visitedClasses.has(classNode) || !classNode.id) {
236237
return;
237238
}
238239

packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function (): PluginObj {
4646
const hasExport =
4747
parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration();
4848
const origin = hasExport ? parentPath : path;
49-
const nextStatement = origin.getSibling(+origin.key + 1);
49+
const nextStatement = origin.getSibling(+(origin.key ?? 0) + 1);
5050
if (!nextStatement.isExpressionStatement()) {
5151
return;
5252
}

packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export default function (api: unknown, options: ApplicationPresetOptions) {
242242
// Always transform async/await to support Zone.js
243243
plugins.push(
244244
require('@babel/plugin-transform-async-to-generator').default,
245-
require('@babel/plugin-proposal-async-generator-functions').default,
245+
require('@babel/plugin-transform-async-generator-functions').default,
246246
);
247247
needRuntimeTransform = true;
248248
}

packages/angular_devkit/build_angular/src/typings.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ declare module '@babel/helper-annotate-as-pure' {
1414

1515
declare module '@babel/helper-split-export-declaration' {
1616
export default function splitExportDeclaration(
17-
exportDeclaration: import('@babel/traverse').NodePath<
17+
exportDeclaration: import('@babel/core').NodePath<
1818
import('@babel/types').ExportDefaultDeclaration
1919
>,
2020
): void;

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111
NodePath,
1212
ParseResult,
1313
parseSync,
14+
template as templateBuilder,
1415
transformAsync,
1516
transformFromAstSync,
1617
traverse,
1718
types,
1819
} from '@babel/core';
19-
import templateBuilder from '@babel/template';
2020
import * as fs from 'fs/promises';
2121
import * as path from 'path';
2222
import { workerData } from 'worker_threads';

yarn.lock

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@
122122
tslib "^2.3.0"
123123

124124
"@angular/bazel@https://github.com/angular/bazel-builds.git#209efddd1c2cac304183971c2259e70a4a7b5f7b":
125-
version "17.0.0-next.3+sha-05762b9"
126-
uid "209efddd1c2cac304183971c2259e70a4a7b5f7b"
125+
version "17.0.0-next.3"
127126
resolved "https://github.com/angular/bazel-builds.git#209efddd1c2cac304183971c2259e70a4a7b5f7b"
128127
dependencies:
129128
"@microsoft/api-extractor" "^7.24.2"
@@ -140,7 +139,6 @@
140139

141140
"@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#a870de5389e6533dd007b46512942249e7c82e95":
142141
version "0.0.0-c95355fd247d8003f18dcd2f1a410b906566cab6"
143-
uid a870de5389e6533dd007b46512942249e7c82e95
144142
resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#a870de5389e6533dd007b46512942249e7c82e95"
145143
dependencies:
146144
"@angular-devkit/build-angular" "16.2.0-rc.1"
@@ -301,7 +299,6 @@
301299

302300
"@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#3e0d49e91578f0aa9ff6972ef7979df18c126c68":
303301
version "0.0.0-c95355fd247d8003f18dcd2f1a410b906566cab6"
304-
uid "3e0d49e91578f0aa9ff6972ef7979df18c126c68"
305302
resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#3e0d49e91578f0aa9ff6972ef7979df18c126c68"
306303
dependencies:
307304
"@yarnpkg/lockfile" "^1.1.0"
@@ -820,6 +817,16 @@
820817
dependencies:
821818
"@babel/helper-plugin-utils" "^7.22.5"
822819

820+
"@babel/plugin-transform-async-generator-functions@7.22.5":
821+
version "7.22.5"
822+
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.22.5.tgz#7336356d23380eda9a56314974f053a020dab0c3"
823+
integrity sha512-gGOEvFzm3fWoyD5uZq7vVTD57pPJ3PczPUD/xCFGjzBpUosnklmXyKnGQbbbGs1NPNPskFex0j93yKbHt0cHyg==
824+
dependencies:
825+
"@babel/helper-environment-visitor" "^7.22.5"
826+
"@babel/helper-plugin-utils" "^7.22.5"
827+
"@babel/helper-remap-async-to-generator" "^7.22.5"
828+
"@babel/plugin-syntax-async-generators" "^7.8.4"
829+
823830
"@babel/plugin-transform-async-generator-functions@^7.22.15", "@babel/plugin-transform-async-generator-functions@^7.22.7":
824831
version "7.22.15"
825832
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.22.15.tgz#3b153af4a6b779f340d5b80d3f634f55820aefa3"
@@ -1436,15 +1443,6 @@
14361443
dependencies:
14371444
regenerator-runtime "^0.13.11"
14381445

1439-
"@babel/template@7.22.15", "@babel/template@^7.22.15", "@babel/template@^7.22.5":
1440-
version "7.22.15"
1441-
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
1442-
integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==
1443-
dependencies:
1444-
"@babel/code-frame" "^7.22.13"
1445-
"@babel/parser" "^7.22.15"
1446-
"@babel/types" "^7.22.15"
1447-
14481446
"@babel/template@7.22.5":
14491447
version "7.22.5"
14501448
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.5.tgz#0c8c4d944509875849bd0344ff0050756eefc6ec"
@@ -1454,6 +1452,15 @@
14541452
"@babel/parser" "^7.22.5"
14551453
"@babel/types" "^7.22.5"
14561454

1455+
"@babel/template@^7.22.15", "@babel/template@^7.22.5":
1456+
version "7.22.15"
1457+
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
1458+
integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==
1459+
dependencies:
1460+
"@babel/code-frame" "^7.22.13"
1461+
"@babel/parser" "^7.22.15"
1462+
"@babel/types" "^7.22.15"
1463+
14571464
"@babel/traverse@^7.22.15", "@babel/traverse@^7.22.17", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.8":
14581465
version "7.22.17"
14591466
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.17.tgz#b23c203ab3707e3be816043081b4a994fcacec44"
@@ -3301,7 +3308,7 @@
33013308
dependencies:
33023309
"@babel/types" "^7.0.0"
33033310

3304-
"@types/babel__template@*", "@types/babel__template@7.4.1":
3311+
"@types/babel__template@*":
33053312
version "7.4.1"
33063313
resolved "https://registry.yarnpkg.com/@types/babel__template/-/babel__template-7.4.1.tgz#3d1a48fd9d6c0edfd56f2ff578daed48f36c8969"
33073314
integrity sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==
@@ -11079,7 +11086,6 @@ sass@1.66.1, sass@^1.55.0:
1107911086

1108011087
"sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.9.1-linux.tar.gz":
1108111088
version "0.0.0"
11082-
uid "9310bc860f7870a1f872b11c4dc6073a1ad34e5e"
1108311089
resolved "https://saucelabs.com/downloads/sc-4.9.1-linux.tar.gz#9310bc860f7870a1f872b11c4dc6073a1ad34e5e"
1108411090

1108511091
saucelabs@^1.5.0:

0 commit comments

Comments
 (0)