Skip to content

Commit

Permalink
perf(common): make NgLocalization token tree-shakable (#45118)
Browse files Browse the repository at this point in the history
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.

PR Close #45118
  • Loading branch information
AndrewKushnir authored and thePunderWoman committed Mar 1, 2022
1 parent c8e4d62 commit 05d50b8
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 107 deletions.
4 changes: 4 additions & 0 deletions goldens/public-api/common/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<NgLocalization, never>;
// (undocumented)
static ɵprov: i0.ɵɵInjectableDeclaration<NgLocalization>;
}

// @public
Expand Down
2 changes: 1 addition & 1 deletion goldens/size-tracking/aio-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"master": {
"uncompressed": {
"runtime": 4343,
"main": 450179,
"main": 449672,
"polyfills": 33869,
"styles": 70416,
"light-theme": 77582,
Expand Down
8 changes: 4 additions & 4 deletions goldens/size-tracking/integration-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"master": {
"uncompressed": {
"runtime": 1083,
"main": 126218,
"main": 124515,
"polyfills": 33824
}
}
Expand Down Expand Up @@ -42,7 +42,7 @@
"master": {
"uncompressed": {
"runtime": 2835,
"main": 233348,
"main": 232814,
"polyfills": 33842,
"src_app_lazy_lazy_module_ts": 795
}
Expand All @@ -52,7 +52,7 @@
"master": {
"uncompressed": {
"runtime": 1063,
"main": 158556,
"main": 156042,
"polyfills": 33804
}
}
Expand All @@ -61,7 +61,7 @@
"master": {
"uncompressed": {
"runtime": 1070,
"main": 158300,
"main": 155753,
"polyfills": 33814
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/common_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/**
Expand All @@ -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 {
}
7 changes: 5 additions & 2 deletions packages/common/src/i18n/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 0 additions & 24 deletions packages/core/test/bundling/animations/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,12 @@
{
"name": "LEAVE_TOKEN_REGEX"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -323,12 +317,6 @@
{
"name": "NULL_REMOVED_QUERIED_STATE"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModuleRef"
},
Expand Down Expand Up @@ -371,9 +359,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -851,9 +836,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1082,9 +1064,6 @@
{
"name": "listenOnPlayer"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1349,9 +1328,6 @@
{
"name": "transition"
},
{
"name": "u"
},
{
"name": "uniqueIdCounter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,12 @@
{
"name": "KeyEventsPlugin"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -326,12 +320,6 @@
{
"name": "NgForOf"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModuleFactory2"
},
Expand Down Expand Up @@ -374,9 +362,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -905,9 +890,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1199,9 +1181,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1511,9 +1490,6 @@
{
"name": "trackByIdentity"
},
{
"name": "u"
},
{
"name": "uniqueIdCounter"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,12 @@
{
"name": "KeyEventsPlugin"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -314,12 +308,6 @@
{
"name": "NgForm"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModel"
},
Expand Down Expand Up @@ -368,9 +356,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -869,9 +854,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1160,9 +1142,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1490,9 +1469,6 @@
{
"name": "trackByIdentity"
},
{
"name": "u"
},
{
"name": "uniqueIdCounter"
},
Expand Down
24 changes: 0 additions & 24 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@
{
"name": "KeyEventsPlugin"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
Expand All @@ -275,9 +272,6 @@
{
"name": "LoadedRouterConfig"
},
{
"name": "LocaleDataIndex"
},
{
"name": "Location"
},
Expand Down Expand Up @@ -371,12 +365,6 @@
{
"name": "NavigationStart"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModuleFactory"
},
Expand Down Expand Up @@ -443,9 +431,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "Position"
},
Expand Down Expand Up @@ -1220,9 +1205,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1517,9 +1499,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "locateDirectiveOrProvider"
},
Expand Down Expand Up @@ -1892,9 +1871,6 @@
{
"name": "tree"
},
{
"name": "u"
},
{
"name": "uniqueIdCounter"
},
Expand Down

0 comments on commit 05d50b8

Please sign in to comment.