Skip to content

Commit 56ca7d3

Browse files
AndrewKushnirthePunderWoman
authored andcommitted
perf(common): make NgLocalization token tree-shakable (#45118) (#45226)
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 PR Close #45226
1 parent e8fd452 commit 56ca7d3

9 files changed

Lines changed: 18 additions & 109 deletions

File tree

goldens/public-api/common/common.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ export class NgLocaleLocalization extends NgLocalization {
503503
export abstract class NgLocalization {
504504
// (undocumented)
505505
abstract getPluralCategory(value: any, locale?: string): string;
506+
// (undocumented)
507+
static ɵfac: i0.ɵɵFactoryDeclaration<NgLocalization, never>;
508+
// (undocumented)
509+
static ɵprov: i0.ɵɵInjectableDeclaration<NgLocalization>;
506510
}
507511

508512
// @public

goldens/size-tracking/aio-payloads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"master": {
1616
"uncompressed": {
1717
"runtime": 4343,
18-
"main": 450840,
18+
"main": 450239,
1919
"polyfills": 37297,
2020
"styles": 70379,
2121
"light-theme": 77582,

goldens/size-tracking/integration-payloads.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"master": {
44
"uncompressed": {
55
"runtime": 1083,
6-
"main": 126218,
6+
"main": 124282,
77
"polyfills": 37226
88
}
99
}
@@ -24,7 +24,7 @@
2424
"master": {
2525
"uncompressed": {
2626
"runtime": 1105,
27-
"main": 131882,
27+
"main": 131270,
2828
"polyfills": 37248
2929
}
3030
}
@@ -33,7 +33,7 @@
3333
"master": {
3434
"uncompressed": {
3535
"runtime": 929,
36-
"main": 124544,
36+
"main": 123958,
3737
"polyfills": 37933
3838
}
3939
}
@@ -42,7 +42,7 @@
4242
"master": {
4343
"uncompressed": {
4444
"runtime": 2835,
45-
"main": 231381,
45+
"main": 230780,
4646
"polyfills": 37244,
4747
"src_app_lazy_lazy_module_ts": 795
4848
}
@@ -52,7 +52,7 @@
5252
"master": {
5353
"uncompressed": {
5454
"runtime": 1063,
55-
"main": 158556,
55+
"main": 155607,
5656
"polyfills": 36975
5757
}
5858
}
@@ -61,7 +61,7 @@
6161
"master": {
6262
"uncompressed": {
6363
"runtime": 1070,
64-
"main": 158300,
64+
"main": 155563,
6565
"polyfills": 37242
6666
}
6767
}

packages/common/src/common_module.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
*/
88

99
import {NgModule} from '@angular/core';
10+
1011
import {COMMON_DIRECTIVES} from './directives/index';
11-
import {NgLocaleLocalization, NgLocalization} from './i18n/localization';
1212
import {COMMON_PIPES} from './pipes/index';
1313

1414

15+
1516
// Note: This does not contain the location providers,
1617
// as they need some platform specific implementations to work.
1718
/**
@@ -30,9 +31,6 @@ import {COMMON_PIPES} from './pipes/index';
3031
@NgModule({
3132
declarations: [COMMON_DIRECTIVES, COMMON_PIPES],
3233
exports: [COMMON_DIRECTIVES, COMMON_PIPES],
33-
providers: [
34-
{provide: NgLocalization, useClass: NgLocaleLocalization},
35-
],
3634
})
3735
export class CommonModule {
3836
}

packages/common/src/i18n/localization.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ import {Inject, Injectable, LOCALE_ID} from '@angular/core';
1010

1111
import {getLocalePluralCase, Plural} from './locale_data_api';
1212

13-
1413
/**
1514
* @publicApi
1615
*/
16+
@Injectable({
17+
providedIn: 'root',
18+
useFactory: (locale: string) => new NgLocaleLocalization(locale),
19+
deps: [LOCALE_ID],
20+
})
1721
export abstract class NgLocalization {
1822
abstract getPluralCategory(value: any, locale?: string): string;
1923
}
2024

21-
2225
/**
2326
* Returns the plural category for a given value.
2427
* - "=value" when the case exists,

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,12 @@
242242
{
243243
"name": "LEAVE_TOKEN_REGEX"
244244
},
245-
{
246-
"name": "LOCALE_DATA"
247-
},
248245
{
249246
"name": "LOCALE_ID2"
250247
},
251248
{
252249
"name": "LifecycleHooksFeature"
253250
},
254-
{
255-
"name": "LocaleDataIndex"
256-
},
257251
{
258252
"name": "MODIFIER_KEYS"
259253
},
@@ -326,12 +320,6 @@
326320
{
327321
"name": "NULL_REMOVED_QUERIED_STATE"
328322
},
329-
{
330-
"name": "NgLocaleLocalization"
331-
},
332-
{
333-
"name": "NgLocalization"
334-
},
335323
{
336324
"name": "NgModuleRef"
337325
},
@@ -374,9 +362,6 @@
374362
{
375363
"name": "PlatformRef"
376364
},
377-
{
378-
"name": "Plural"
379-
},
380365
{
381366
"name": "R3Injector"
382367
},
@@ -848,9 +833,6 @@
848833
{
849834
"name": "getLViewParent"
850835
},
851-
{
852-
"name": "getLocaleData"
853-
},
854836
{
855837
"name": "getNativeByTNode"
856838
},
@@ -1085,9 +1067,6 @@
10851067
{
10861068
"name": "listenOnPlayer"
10871069
},
1088-
{
1089-
"name": "locale_en_default"
1090-
},
10911070
{
10921071
"name": "lookupTokenUsingModuleInjector"
10931072
},
@@ -1352,9 +1331,6 @@
13521331
{
13531332
"name": "transition"
13541333
},
1355-
{
1356-
"name": "u"
1357-
},
13581334
{
13591335
"name": "unwrapRNode"
13601336
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,12 @@
221221
{
222222
"name": "KeyEventsPlugin"
223223
},
224-
{
225-
"name": "LOCALE_DATA"
226-
},
227224
{
228225
"name": "LOCALE_ID2"
229226
},
230227
{
231228
"name": "LifecycleHooksFeature"
232229
},
233-
{
234-
"name": "LocaleDataIndex"
235-
},
236230
{
237231
"name": "MODIFIER_KEYS"
238232
},
@@ -326,12 +320,6 @@
326320
{
327321
"name": "NgForOf"
328322
},
329-
{
330-
"name": "NgLocaleLocalization"
331-
},
332-
{
333-
"name": "NgLocalization"
334-
},
335323
{
336324
"name": "NgModuleFactory2"
337325
},
@@ -374,9 +362,6 @@
374362
{
375363
"name": "PlatformRef"
376364
},
377-
{
378-
"name": "Plural"
379-
},
380365
{
381366
"name": "R3Injector"
382367
},
@@ -902,9 +887,6 @@
902887
{
903888
"name": "getLViewParent"
904889
},
905-
{
906-
"name": "getLocaleData"
907-
},
908890
{
909891
"name": "getNativeByTNode"
910892
},
@@ -1205,9 +1187,6 @@
12051187
{
12061188
"name": "leaveViewLight"
12071189
},
1208-
{
1209-
"name": "locale_en_default"
1210-
},
12111190
{
12121191
"name": "lookupTokenUsingModuleInjector"
12131192
},
@@ -1517,9 +1496,6 @@
15171496
{
15181497
"name": "trackByIdentity"
15191498
},
1520-
{
1521-
"name": "u"
1522-
},
15231499
{
15241500
"name": "unwrapRNode"
15251501
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,12 @@
212212
{
213213
"name": "KeyEventsPlugin"
214214
},
215-
{
216-
"name": "LOCALE_DATA"
217-
},
218215
{
219216
"name": "LOCALE_ID2"
220217
},
221218
{
222219
"name": "LifecycleHooksFeature"
223220
},
224-
{
225-
"name": "LocaleDataIndex"
226-
},
227221
{
228222
"name": "MODIFIER_KEYS"
229223
},
@@ -317,12 +311,6 @@
317311
{
318312
"name": "NgForm"
319313
},
320-
{
321-
"name": "NgLocaleLocalization"
322-
},
323-
{
324-
"name": "NgLocalization"
325-
},
326314
{
327315
"name": "NgModel"
328316
},
@@ -371,9 +359,6 @@
371359
{
372360
"name": "PlatformRef"
373361
},
374-
{
375-
"name": "Plural"
376-
},
377362
{
378363
"name": "R3Injector"
379364
},
@@ -872,9 +857,6 @@
872857
{
873858
"name": "getLViewParent"
874859
},
875-
{
876-
"name": "getLocaleData"
877-
},
878860
{
879861
"name": "getNativeByTNode"
880862
},
@@ -1169,9 +1151,6 @@
11691151
{
11701152
"name": "leaveViewLight"
11711153
},
1172-
{
1173-
"name": "locale_en_default"
1174-
},
11751154
{
11761155
"name": "lookupTokenUsingModuleInjector"
11771156
},
@@ -1499,9 +1478,6 @@
14991478
{
15001479
"name": "trackByIdentity"
15011480
},
1502-
{
1503-
"name": "u"
1504-
},
15051481
{
15061482
"name": "unwrapRNode"
15071483
},

0 commit comments

Comments
 (0)