Skip to content

Commit f3a7829

Browse files
authored
refactor(core): tree-shake unused injection tokens (#833)
`new` expressions are not dropped by default, because they are considered side-effectful.
1 parent 345181e commit f3a7829

10 files changed

+38
-31
lines changed

libs/transloco/src/lib/transloco-fallback-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Inject, Injectable, InjectionToken } from '@angular/core';
33
import { TRANSLOCO_CONFIG, TranslocoConfig } from './transloco.config';
44

55
export const TRANSLOCO_FALLBACK_STRATEGY =
6-
new InjectionToken<TranslocoFallbackStrategy>(
6+
/* @__PURE__ */ new InjectionToken<TranslocoFallbackStrategy>(
77
ngDevMode ? 'TRANSLOCO_FALLBACK_STRATEGY' : '',
88
);
99

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InjectionToken } from '@angular/core';
22

3-
export const TRANSLOCO_LANG = new InjectionToken<string>(
3+
export const TRANSLOCO_LANG = /* @__PURE__ */ new InjectionToken<string>(
44
ngDevMode ? 'TRANSLOCO_LANG' : '',
55
);

libs/transloco/src/lib/transloco-loading-template.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { InjectionToken } from '@angular/core';
22

33
import { Content } from './template-handler';
44

5-
export const TRANSLOCO_LOADING_TEMPLATE = new InjectionToken<Content>(
6-
ngDevMode ? 'TRANSLOCO_LOADING_TEMPLATE' : '',
7-
);
5+
export const TRANSLOCO_LOADING_TEMPLATE =
6+
/* @__PURE__ */ new InjectionToken<Content>(
7+
ngDevMode ? 'TRANSLOCO_LOADING_TEMPLATE' : '',
8+
);

libs/transloco/src/lib/transloco-missing-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { TranslocoConfig } from './transloco.config';
44
import { HashMap } from './utils/type.utils';
55

66
export const TRANSLOCO_MISSING_HANDLER =
7-
new InjectionToken<TranslocoMissingHandlerData>(
7+
/* @__PURE__ */ new InjectionToken<TranslocoMissingHandlerData>(
88
ngDevMode ? 'TRANSLOCO_MISSING_HANDLER' : '',
99
);
1010

libs/transloco/src/lib/transloco-scope.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { InjectionToken } from '@angular/core';
22

33
import { TranslocoScope } from './transloco.types';
44

5-
export const TRANSLOCO_SCOPE = new InjectionToken<TranslocoScope>(
6-
ngDevMode ? 'TRANSLOCO_SCOPE' : '',
7-
);
5+
export const TRANSLOCO_SCOPE =
6+
/* @__PURE__ */ new InjectionToken<TranslocoScope>(
7+
ngDevMode ? 'TRANSLOCO_SCOPE' : '',
8+
);

libs/transloco/src/lib/transloco-testing.module.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ export interface TranslocoTestingOptions {
2222
langs?: HashMap<Translation>;
2323
}
2424

25-
const TRANSLOCO_TEST_LANGS = new InjectionToken<HashMap<Translation>>(
26-
'TRANSLOCO_TEST_LANGS - Available testing languages',
27-
);
28-
const TRANSLOCO_TEST_OPTIONS = new InjectionToken<TranslocoTestingOptions>(
29-
'TRANSLOCO_TEST_OPTIONS - Testing options',
30-
);
25+
const TRANSLOCO_TEST_LANGS = /* @__PURE__ */ new InjectionToken<
26+
HashMap<Translation>
27+
>('TRANSLOCO_TEST_LANGS - Available testing languages');
28+
const TRANSLOCO_TEST_OPTIONS =
29+
/* @__PURE__ */ new InjectionToken<TranslocoTestingOptions>(
30+
'TRANSLOCO_TEST_OPTIONS - Testing options',
31+
);
3132

3233
@Injectable()
3334
export class TestingLoader implements TranslocoLoader {

libs/transloco/src/lib/transloco.config.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ export interface TranslocoConfig {
2323
};
2424
}
2525

26-
export const TRANSLOCO_CONFIG = new InjectionToken<TranslocoConfig>(
27-
ngDevMode ? 'TRANSLOCO_CONFIG' : '',
28-
{
29-
providedIn: 'root',
30-
factory: () => defaultConfig,
31-
},
32-
);
26+
export const TRANSLOCO_CONFIG =
27+
/* @__PURE__ */ new InjectionToken<TranslocoConfig>(
28+
ngDevMode ? 'TRANSLOCO_CONFIG' : '',
29+
{
30+
providedIn: 'root',
31+
factory: () => defaultConfig,
32+
},
33+
);
3334

3435
export const defaultConfig: TranslocoConfig = {
3536
defaultLang: 'en',

libs/transloco/src/lib/transloco.interceptor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Injectable, InjectionToken } from '@angular/core';
22

33
import { Translation } from './transloco.types';
44

5-
export const TRANSLOCO_INTERCEPTOR = new InjectionToken<TranslocoInterceptor>(
6-
ngDevMode ? 'TRANSLOCO_INTERCEPTOR' : '',
7-
);
5+
export const TRANSLOCO_INTERCEPTOR =
6+
/* @__PURE__ */ new InjectionToken<TranslocoInterceptor>(
7+
ngDevMode ? 'TRANSLOCO_INTERCEPTOR' : '',
8+
);
89

910
export interface TranslocoInterceptor {
1011
preSaveTranslation(translation: Translation, lang: string): Translation;

libs/transloco/src/lib/transloco.loader.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class DefaultLoader implements TranslocoLoader {
2222
}
2323
}
2424

25-
export const TRANSLOCO_LOADER = new InjectionToken<TranslocoLoader>(
26-
ngDevMode ? 'TRANSLOCO_LOADER' : '',
27-
);
25+
export const TRANSLOCO_LOADER =
26+
/* @__PURE__ */ new InjectionToken<TranslocoLoader>(
27+
ngDevMode ? 'TRANSLOCO_LOADER' : '',
28+
);

libs/transloco/src/lib/transloco.transpiler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {
1010
import { HashMap } from './utils/type.utils';
1111
import { getValue, setValue } from './utils/object.utils';
1212

13-
export const TRANSLOCO_TRANSPILER = new InjectionToken<TranslocoTranspiler>(
14-
ngDevMode ? 'TRANSLOCO_TRANSPILER' : '',
15-
);
13+
export const TRANSLOCO_TRANSPILER =
14+
/* @__PURE__ */ new InjectionToken<TranslocoTranspiler>(
15+
ngDevMode ? 'TRANSLOCO_TRANSPILER' : '',
16+
);
1617

1718
export interface TranslocoTranspiler {
1819
transpile(params: TranspileParams): any;

0 commit comments

Comments
 (0)