Skip to content

Commit

Permalink
perf(common): make NgLocalization token tree-shakable (angular#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 angular#45118
  • Loading branch information
AndrewKushnir committed Mar 1, 2022
1 parent e8fd452 commit f752f2f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 109 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 @@ -503,6 +503,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": 450840,
"main": 450239,
"polyfills": 37297,
"styles": 70379,
"light-theme": 77582,
Expand Down
12 changes: 6 additions & 6 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": 124282,
"polyfills": 37226
}
}
Expand All @@ -24,7 +24,7 @@
"master": {
"uncompressed": {
"runtime": 1105,
"main": 131882,
"main": 131270,
"polyfills": 37248
}
}
Expand All @@ -33,7 +33,7 @@
"master": {
"uncompressed": {
"runtime": 929,
"main": 124544,
"main": 123958,
"polyfills": 37933
}
}
Expand All @@ -42,7 +42,7 @@
"master": {
"uncompressed": {
"runtime": 2835,
"main": 231381,
"main": 230780,
"polyfills": 37244,
"src_app_lazy_lazy_module_ts": 795
}
Expand All @@ -52,7 +52,7 @@
"master": {
"uncompressed": {
"runtime": 1063,
"main": 158556,
"main": 155607,
"polyfills": 36975
}
}
Expand All @@ -61,7 +61,7 @@
"master": {
"uncompressed": {
"runtime": 1070,
"main": 158300,
"main": 155563,
"polyfills": 37242
}
}
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 @@ -242,18 +242,12 @@
{
"name": "LEAVE_TOKEN_REGEX"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -326,12 +320,6 @@
{
"name": "NULL_REMOVED_QUERIED_STATE"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModuleRef"
},
Expand Down Expand Up @@ -374,9 +362,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -848,9 +833,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1085,9 +1067,6 @@
{
"name": "listenOnPlayer"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1352,9 +1331,6 @@
{
"name": "transition"
},
{
"name": "u"
},
{
"name": "unwrapRNode"
},
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 @@ -902,9 +887,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1205,9 +1187,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1517,9 +1496,6 @@
{
"name": "trackByIdentity"
},
{
"name": "u"
},
{
"name": "unwrapRNode"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,12 @@
{
"name": "KeyEventsPlugin"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -317,12 +311,6 @@
{
"name": "NgForm"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModel"
},
Expand Down Expand Up @@ -371,9 +359,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -872,9 +857,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1169,9 +1151,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1499,9 +1478,6 @@
{
"name": "trackByIdentity"
},
{
"name": "u"
},
{
"name": "unwrapRNode"
},
Expand Down

0 comments on commit f752f2f

Please sign in to comment.