Skip to content

Commit 05d50b8

Browse files
AndrewKushnirthePunderWoman
authored andcommitted
perf(common): make NgLocalization token tree-shakable (#45118)
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
1 parent c8e4d62 commit 05d50b8

9 files changed

Lines changed: 16 additions & 107 deletions

File tree

goldens/public-api/common/common.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ export class NgLocaleLocalization extends NgLocalization {
507507
export abstract class NgLocalization {
508508
// (undocumented)
509509
abstract getPluralCategory(value: any, locale?: string): string;
510+
// (undocumented)
511+
static ɵfac: i0.ɵɵFactoryDeclaration<NgLocalization, never>;
512+
// (undocumented)
513+
static ɵprov: i0.ɵɵInjectableDeclaration<NgLocalization>;
510514
}
511515

512516
// @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": 450179,
18+
"main": 449672,
1919
"polyfills": 33869,
2020
"styles": 70416,
2121
"light-theme": 77582,

goldens/size-tracking/integration-payloads.json

Lines changed: 4 additions & 4 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": 124515,
77
"polyfills": 33824
88
}
99
}
@@ -42,7 +42,7 @@
4242
"master": {
4343
"uncompressed": {
4444
"runtime": 2835,
45-
"main": 233348,
45+
"main": 232814,
4646
"polyfills": 33842,
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": 156042,
5656
"polyfills": 33804
5757
}
5858
}
@@ -61,7 +61,7 @@
6161
"master": {
6262
"uncompressed": {
6363
"runtime": 1070,
64-
"main": 158300,
64+
"main": 155753,
6565
"polyfills": 33814
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
@@ -239,18 +239,12 @@
239239
{
240240
"name": "LEAVE_TOKEN_REGEX"
241241
},
242-
{
243-
"name": "LOCALE_DATA"
244-
},
245242
{
246243
"name": "LOCALE_ID2"
247244
},
248245
{
249246
"name": "LifecycleHooksFeature"
250247
},
251-
{
252-
"name": "LocaleDataIndex"
253-
},
254248
{
255249
"name": "MODIFIER_KEYS"
256250
},
@@ -323,12 +317,6 @@
323317
{
324318
"name": "NULL_REMOVED_QUERIED_STATE"
325319
},
326-
{
327-
"name": "NgLocaleLocalization"
328-
},
329-
{
330-
"name": "NgLocalization"
331-
},
332320
{
333321
"name": "NgModuleRef"
334322
},
@@ -371,9 +359,6 @@
371359
{
372360
"name": "PlatformRef"
373361
},
374-
{
375-
"name": "Plural"
376-
},
377362
{
378363
"name": "R3Injector"
379364
},
@@ -851,9 +836,6 @@
851836
{
852837
"name": "getLViewParent"
853838
},
854-
{
855-
"name": "getLocaleData"
856-
},
857839
{
858840
"name": "getNativeByTNode"
859841
},
@@ -1082,9 +1064,6 @@
10821064
{
10831065
"name": "listenOnPlayer"
10841066
},
1085-
{
1086-
"name": "locale_en_default"
1087-
},
10881067
{
10891068
"name": "lookupTokenUsingModuleInjector"
10901069
},
@@ -1349,9 +1328,6 @@
13491328
{
13501329
"name": "transition"
13511330
},
1352-
{
1353-
"name": "u"
1354-
},
13551331
{
13561332
"name": "uniqueIdCounter"
13571333
},

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
},
@@ -905,9 +890,6 @@
905890
{
906891
"name": "getLViewParent"
907892
},
908-
{
909-
"name": "getLocaleData"
910-
},
911893
{
912894
"name": "getNativeByTNode"
913895
},
@@ -1199,9 +1181,6 @@
11991181
{
12001182
"name": "leaveViewLight"
12011183
},
1202-
{
1203-
"name": "locale_en_default"
1204-
},
12051184
{
12061185
"name": "lookupTokenUsingModuleInjector"
12071186
},
@@ -1511,9 +1490,6 @@
15111490
{
15121491
"name": "trackByIdentity"
15131492
},
1514-
{
1515-
"name": "u"
1516-
},
15171493
{
15181494
"name": "uniqueIdCounter"
15191495
},

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
@@ -209,18 +209,12 @@
209209
{
210210
"name": "KeyEventsPlugin"
211211
},
212-
{
213-
"name": "LOCALE_DATA"
214-
},
215212
{
216213
"name": "LOCALE_ID2"
217214
},
218215
{
219216
"name": "LifecycleHooksFeature"
220217
},
221-
{
222-
"name": "LocaleDataIndex"
223-
},
224218
{
225219
"name": "MODIFIER_KEYS"
226220
},
@@ -314,12 +308,6 @@
314308
{
315309
"name": "NgForm"
316310
},
317-
{
318-
"name": "NgLocaleLocalization"
319-
},
320-
{
321-
"name": "NgLocalization"
322-
},
323311
{
324312
"name": "NgModel"
325313
},
@@ -368,9 +356,6 @@
368356
{
369357
"name": "PlatformRef"
370358
},
371-
{
372-
"name": "Plural"
373-
},
374359
{
375360
"name": "R3Injector"
376361
},
@@ -869,9 +854,6 @@
869854
{
870855
"name": "getLViewParent"
871856
},
872-
{
873-
"name": "getLocaleData"
874-
},
875857
{
876858
"name": "getNativeByTNode"
877859
},
@@ -1160,9 +1142,6 @@
11601142
{
11611143
"name": "leaveViewLight"
11621144
},
1163-
{
1164-
"name": "locale_en_default"
1165-
},
11661145
{
11671146
"name": "lookupTokenUsingModuleInjector"
11681147
},
@@ -1490,9 +1469,6 @@
14901469
{
14911470
"name": "trackByIdentity"
14921471
},
1493-
{
1494-
"name": "u"
1495-
},
14961472
{
14971473
"name": "uniqueIdCounter"
14981474
},

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@
251251
{
252252
"name": "KeyEventsPlugin"
253253
},
254-
{
255-
"name": "LOCALE_DATA"
256-
},
257254
{
258255
"name": "LOCALE_ID2"
259256
},
@@ -275,9 +272,6 @@
275272
{
276273
"name": "LoadedRouterConfig"
277274
},
278-
{
279-
"name": "LocaleDataIndex"
280-
},
281275
{
282276
"name": "Location"
283277
},
@@ -371,12 +365,6 @@
371365
{
372366
"name": "NavigationStart"
373367
},
374-
{
375-
"name": "NgLocaleLocalization"
376-
},
377-
{
378-
"name": "NgLocalization"
379-
},
380368
{
381369
"name": "NgModuleFactory"
382370
},
@@ -443,9 +431,6 @@
443431
{
444432
"name": "PlatformRef"
445433
},
446-
{
447-
"name": "Plural"
448-
},
449434
{
450435
"name": "Position"
451436
},
@@ -1220,9 +1205,6 @@
12201205
{
12211206
"name": "getLViewParent"
12221207
},
1223-
{
1224-
"name": "getLocaleData"
1225-
},
12261208
{
12271209
"name": "getNativeByTNode"
12281210
},
@@ -1517,9 +1499,6 @@
15171499
{
15181500
"name": "leaveViewLight"
15191501
},
1520-
{
1521-
"name": "locale_en_default"
1522-
},
15231502
{
15241503
"name": "locateDirectiveOrProvider"
15251504
},
@@ -1892,9 +1871,6 @@
18921871
{
18931872
"name": "tree"
18941873
},
1895-
{
1896-
"name": "u"
1897-
},
18981874
{
18991875
"name": "uniqueIdCounter"
19001876
},

0 commit comments

Comments
 (0)