Skip to content

Commit 6c1a652

Browse files
committed
refactor(@angular/build): address review feedback for top-level await error
- Use `??=` and `.push()` instead of spread for notes - Merge two separate notes into a single note with newline - Use `expect(result?.success).toBeTrue()` and `not.toContain` in test
1 parent 9583d87 commit 6c1a652

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

packages/angular/build/src/builders/application/execute-build.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,14 @@ export async function executeBuild(
167167
if (!isZonelessApp(options.polyfills)) {
168168
for (const error of bundlingResult.errors) {
169169
if (error.text?.startsWith(TOP_LEVEL_AWAIT_ERROR_TEXT)) {
170-
error.notes = [
171-
{
172-
text:
173-
'Top-level await is not supported in applications that use Zone.js. ' +
174-
'Consider removing Zone.js or moving this code into an async function.',
175-
location: null,
176-
},
177-
{
178-
text: 'For more information about zoneless Angular applications, visit: https://angular.dev/guide/zoneless',
179-
location: null,
180-
},
181-
...(error.notes ?? []),
182-
];
170+
error.notes ??= [];
171+
error.notes.push({
172+
text:
173+
'Top-level await is not supported in applications that use Zone.js. ' +
174+
'Consider removing Zone.js or moving this code into an async function. \n' +
175+
'For more information about zoneless Angular applications, visit: https://angular.dev/guide/zoneless',
176+
location: null,
177+
});
183178
}
184179
}
185180
}

packages/angular/build/src/builders/application/tests/behavior/top-level-await-error_spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
5151
});
5252

5353
const { result, logs } = await harness.executeOnce({ outputLogsOnFailure: false });
54-
// Without Zone.js, the build may still fail due to target environment constraints,
55-
// but the error should NOT contain the Zone.js-specific message
56-
const zoneJsErrorPresent = logs.some(
57-
(log) =>
58-
typeof log.message === 'string' &&
59-
log.message.includes('Top-level await is not supported in applications that use Zone.js'),
54+
expect(result?.success).toBeTrue();
55+
expect(logs).not.toContain(
56+
jasmine.objectContaining({
57+
level: 'error',
58+
message: jasmine.stringContaining(
59+
'Top-level await is not supported in applications that use Zone.js',
60+
),
61+
}),
6062
);
61-
expect(zoneJsErrorPresent).toBeFalse();
6263
});
6364
});
6465
});

0 commit comments

Comments
 (0)