Skip to content

Commit

Permalink
refactor(core): make zone error messages tree shakable (#46480)
Browse files Browse the repository at this point in the history
Make the error messages tree shakable from the production build to reduce the bundle size.

PR Close #46480
  • Loading branch information
ramthir authored and dylhunn committed Jun 24, 2022
1 parent bfd0450 commit 0f0c5c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions goldens/public-api/core/errors.md
Expand Up @@ -53,6 +53,8 @@ export const enum RuntimeErrorCode {
// (undocumented)
MISSING_LOCALE_DATA = 701,
// (undocumented)
MISSING_ZONEJS = 908,
// (undocumented)
MULTIPLE_COMPONENTS_MATCH = -300,
// (undocumented)
MULTIPLE_PLATFORMS = 400,
Expand All @@ -75,6 +77,8 @@ export const enum RuntimeErrorCode {
// (undocumented)
TYPE_IS_NOT_STANDALONE = 907,
// (undocumented)
UNEXPECTED_ZONE_STATE = 909,
// (undocumented)
UNKNOWN_BINDING = 303,
// (undocumented)
UNKNOWN_ELEMENT = 304,
Expand Down
6 changes: 3 additions & 3 deletions goldens/size-tracking/integration-payloads.json
Expand Up @@ -26,7 +26,7 @@
"cli-hello-world-ivy-i18n": {
"uncompressed": {
"runtime": 926,
"main": 126372,
"main": 125825,
"polyfills": 35252
}
},
Expand Down Expand Up @@ -55,7 +55,7 @@
"standalone-bootstrap": {
"uncompressed": {
"runtime": 1090,
"main": 84237,
"main": 83707,
"polyfills": 33945
}
},
Expand All @@ -68,4 +68,4 @@
"bundle": 1214857
}
}
}
}
2 changes: 2 additions & 0 deletions packages/core/src/errors.ts
Expand Up @@ -71,6 +71,8 @@ export const enum RuntimeErrorCode {
UNSAFE_VALUE_IN_SCRIPT = 905,
MISSING_GENERATED_DEF = 906,
TYPE_IS_NOT_STANDALONE = 907,
MISSING_ZONEJS = 908,
UNEXPECTED_ZONE_STATE = 909,
}

/**
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/zone/ng_zone.ts
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {RuntimeError, RuntimeErrorCode} from '../errors';
import {EventEmitter} from '../event_emitter';
import {global} from '../util/global';
import {noop} from '../util/noop';
Expand Down Expand Up @@ -126,7 +127,9 @@ export class NgZone {
shouldCoalesceRunChangeDetection = false
}) {
if (typeof Zone == 'undefined') {
throw new Error(`In this configuration Angular requires Zone.js`);
throw new RuntimeError(
RuntimeErrorCode.MISSING_ZONEJS,
ngDevMode && `In this configuration Angular requires Zone.js`);
}

Zone.assertZonePatched();
Expand Down Expand Up @@ -159,13 +162,17 @@ export class NgZone {

static assertInAngularZone(): void {
if (!NgZone.isInAngularZone()) {
throw new Error('Expected to be in Angular Zone, but it is not!');
throw new RuntimeError(
RuntimeErrorCode.UNEXPECTED_ZONE_STATE,
ngDevMode && 'Expected to be in Angular Zone, but it is not!');
}
}

static assertNotInAngularZone(): void {
if (NgZone.isInAngularZone()) {
throw new Error('Expected to not be in Angular Zone, but it is!');
throw new RuntimeError(
RuntimeErrorCode.UNEXPECTED_ZONE_STATE,
ngDevMode && 'Expected to not be in Angular Zone, but it is!');
}
}

Expand Down

0 comments on commit 0f0c5c0

Please sign in to comment.