From ed86e7b3263b1221b12e82b318ae587e35abdf72 Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Wed, 16 Feb 2022 22:17:59 -0800 Subject: [PATCH] perf(common): make `NgLocalization` token tree-shakable This commit updates the `NgLocalization` token to become tree-shakable (vs using a direct reference to that token in the `providers` section of the `CommonModule`). The `NgLocalization` token is used for apps that use i18n and for other apps it would be excluded from the bundle. --- goldens/public-api/common/common.md | 4 ++++ goldens/size-tracking/aio-payloads.json | 2 +- .../size-tracking/integration-payloads.json | 8 +++---- packages/common/src/common_module.ts | 6 ++--- packages/common/src/i18n/localization.ts | 7 ++++-- .../animations/bundle.golden_symbols.json | 24 ------------------- .../forms_reactive/bundle.golden_symbols.json | 24 ------------------- .../bundle.golden_symbols.json | 24 ------------------- .../router/bundle.golden_symbols.json | 24 ------------------- 9 files changed, 16 insertions(+), 107 deletions(-) diff --git a/goldens/public-api/common/common.md b/goldens/public-api/common/common.md index 19d4c52758ca..5c5cd68eb2ea 100644 --- a/goldens/public-api/common/common.md +++ b/goldens/public-api/common/common.md @@ -507,6 +507,10 @@ export class NgLocaleLocalization extends NgLocalization { export abstract class NgLocalization { // (undocumented) abstract getPluralCategory(value: any, locale?: string): string; + // (undocumented) + static ɵfac: i0.ɵɵFactoryDeclaration; + // (undocumented) + static ɵprov: i0.ɵɵInjectableDeclaration; } // @public diff --git a/goldens/size-tracking/aio-payloads.json b/goldens/size-tracking/aio-payloads.json index af1488132c55..6086c8b71231 100755 --- a/goldens/size-tracking/aio-payloads.json +++ b/goldens/size-tracking/aio-payloads.json @@ -15,7 +15,7 @@ "master": { "uncompressed": { "runtime": 4343, - "main": 450179, + "main": 449672, "polyfills": 33869, "styles": 70416, "light-theme": 77582, diff --git a/goldens/size-tracking/integration-payloads.json b/goldens/size-tracking/integration-payloads.json index dd87eee3d50f..367ef898cf5f 100644 --- a/goldens/size-tracking/integration-payloads.json +++ b/goldens/size-tracking/integration-payloads.json @@ -3,7 +3,7 @@ "master": { "uncompressed": { "runtime": 1083, - "main": 126218, + "main": 124515, "polyfills": 33824 } } @@ -42,7 +42,7 @@ "master": { "uncompressed": { "runtime": 2835, - "main": 233348, + "main": 232814, "polyfills": 33842, "src_app_lazy_lazy_module_ts": 795 } @@ -52,7 +52,7 @@ "master": { "uncompressed": { "runtime": 1063, - "main": 158556, + "main": 156042, "polyfills": 33804 } } @@ -61,7 +61,7 @@ "master": { "uncompressed": { "runtime": 1070, - "main": 158300, + "main": 155753, "polyfills": 33814 } } diff --git a/packages/common/src/common_module.ts b/packages/common/src/common_module.ts index 044e78fc84b1..91d31727d847 100644 --- a/packages/common/src/common_module.ts +++ b/packages/common/src/common_module.ts @@ -7,11 +7,12 @@ */ import {NgModule} from '@angular/core'; + import {COMMON_DIRECTIVES} from './directives/index'; -import {NgLocaleLocalization, NgLocalization} from './i18n/localization'; import {COMMON_PIPES} from './pipes/index'; + // Note: This does not contain the location providers, // as they need some platform specific implementations to work. /** @@ -30,9 +31,6 @@ import {COMMON_PIPES} from './pipes/index'; @NgModule({ declarations: [COMMON_DIRECTIVES, COMMON_PIPES], exports: [COMMON_DIRECTIVES, COMMON_PIPES], - providers: [ - {provide: NgLocalization, useClass: NgLocaleLocalization}, - ], }) export class CommonModule { } diff --git a/packages/common/src/i18n/localization.ts b/packages/common/src/i18n/localization.ts index 532c222500b9..2d4c30e5945a 100644 --- a/packages/common/src/i18n/localization.ts +++ b/packages/common/src/i18n/localization.ts @@ -10,15 +10,18 @@ import {Inject, Injectable, LOCALE_ID} from '@angular/core'; import {getLocalePluralCase, Plural} from './locale_data_api'; - /** * @publicApi */ +@Injectable({ + providedIn: 'root', + useFactory: (locale: string) => new NgLocaleLocalization(locale), + deps: [LOCALE_ID], +}) export abstract class NgLocalization { abstract getPluralCategory(value: any, locale?: string): string; } - /** * Returns the plural category for a given value. * - "=value" when the case exists, diff --git a/packages/core/test/bundling/animations/bundle.golden_symbols.json b/packages/core/test/bundling/animations/bundle.golden_symbols.json index f3973f82dde1..cff6d1f930d0 100644 --- a/packages/core/test/bundling/animations/bundle.golden_symbols.json +++ b/packages/core/test/bundling/animations/bundle.golden_symbols.json @@ -239,18 +239,12 @@ { "name": "LEAVE_TOKEN_REGEX" }, - { - "name": "LOCALE_DATA" - }, { "name": "LOCALE_ID2" }, { "name": "LifecycleHooksFeature" }, - { - "name": "LocaleDataIndex" - }, { "name": "MODIFIER_KEYS" }, @@ -323,12 +317,6 @@ { "name": "NULL_REMOVED_QUERIED_STATE" }, - { - "name": "NgLocaleLocalization" - }, - { - "name": "NgLocalization" - }, { "name": "NgModuleRef" }, @@ -371,9 +359,6 @@ { "name": "PlatformRef" }, - { - "name": "Plural" - }, { "name": "R3Injector" }, @@ -851,9 +836,6 @@ { "name": "getLViewParent" }, - { - "name": "getLocaleData" - }, { "name": "getNativeByTNode" }, @@ -1082,9 +1064,6 @@ { "name": "listenOnPlayer" }, - { - "name": "locale_en_default" - }, { "name": "lookupTokenUsingModuleInjector" }, @@ -1349,9 +1328,6 @@ { "name": "transition" }, - { - "name": "u" - }, { "name": "uniqueIdCounter" }, diff --git a/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json b/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json index b9e2fb26ca98..046586fc690b 100644 --- a/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json @@ -221,18 +221,12 @@ { "name": "KeyEventsPlugin" }, - { - "name": "LOCALE_DATA" - }, { "name": "LOCALE_ID2" }, { "name": "LifecycleHooksFeature" }, - { - "name": "LocaleDataIndex" - }, { "name": "MODIFIER_KEYS" }, @@ -326,12 +320,6 @@ { "name": "NgForOf" }, - { - "name": "NgLocaleLocalization" - }, - { - "name": "NgLocalization" - }, { "name": "NgModuleFactory2" }, @@ -374,9 +362,6 @@ { "name": "PlatformRef" }, - { - "name": "Plural" - }, { "name": "R3Injector" }, @@ -905,9 +890,6 @@ { "name": "getLViewParent" }, - { - "name": "getLocaleData" - }, { "name": "getNativeByTNode" }, @@ -1202,9 +1184,6 @@ { "name": "leaveViewLight" }, - { - "name": "locale_en_default" - }, { "name": "lookupTokenUsingModuleInjector" }, @@ -1514,9 +1493,6 @@ { "name": "trackByIdentity" }, - { - "name": "u" - }, { "name": "uniqueIdCounter" }, diff --git a/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json b/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json index 5eac6303230b..d3be87934b7f 100644 --- a/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json @@ -209,18 +209,12 @@ { "name": "KeyEventsPlugin" }, - { - "name": "LOCALE_DATA" - }, { "name": "LOCALE_ID2" }, { "name": "LifecycleHooksFeature" }, - { - "name": "LocaleDataIndex" - }, { "name": "MODIFIER_KEYS" }, @@ -314,12 +308,6 @@ { "name": "NgForm" }, - { - "name": "NgLocaleLocalization" - }, - { - "name": "NgLocalization" - }, { "name": "NgModel" }, @@ -368,9 +356,6 @@ { "name": "PlatformRef" }, - { - "name": "Plural" - }, { "name": "R3Injector" }, @@ -869,9 +854,6 @@ { "name": "getLViewParent" }, - { - "name": "getLocaleData" - }, { "name": "getNativeByTNode" }, @@ -1163,9 +1145,6 @@ { "name": "leaveViewLight" }, - { - "name": "locale_en_default" - }, { "name": "lookupTokenUsingModuleInjector" }, @@ -1493,9 +1472,6 @@ { "name": "trackByIdentity" }, - { - "name": "u" - }, { "name": "uniqueIdCounter" }, diff --git a/packages/core/test/bundling/router/bundle.golden_symbols.json b/packages/core/test/bundling/router/bundle.golden_symbols.json index bf928dec5975..07146576cd4d 100644 --- a/packages/core/test/bundling/router/bundle.golden_symbols.json +++ b/packages/core/test/bundling/router/bundle.golden_symbols.json @@ -251,9 +251,6 @@ { "name": "KeyEventsPlugin" }, - { - "name": "LOCALE_DATA" - }, { "name": "LOCALE_ID2" }, @@ -275,9 +272,6 @@ { "name": "LoadedRouterConfig" }, - { - "name": "LocaleDataIndex" - }, { "name": "Location" }, @@ -371,12 +365,6 @@ { "name": "NavigationStart" }, - { - "name": "NgLocaleLocalization" - }, - { - "name": "NgLocalization" - }, { "name": "NgModuleFactory" }, @@ -443,9 +431,6 @@ { "name": "PlatformRef" }, - { - "name": "Plural" - }, { "name": "Position" }, @@ -1220,9 +1205,6 @@ { "name": "getLViewParent" }, - { - "name": "getLocaleData" - }, { "name": "getNativeByTNode" }, @@ -1517,9 +1499,6 @@ { "name": "leaveViewLight" }, - { - "name": "locale_en_default" - }, { "name": "locateDirectiveOrProvider" }, @@ -1892,9 +1871,6 @@ { "name": "tree" }, - { - "name": "u" - }, { "name": "uniqueIdCounter" },