From d80eb8d7ea1d564bbc6f047403c71cdaef0d1bb1 Mon Sep 17 00:00:00 2001 From: arturovt Date: Sat, 1 Feb 2025 08:00:49 +0200 Subject: [PATCH] refactor(core): tree-shake unused injection tokens `new` expressions are not dropped by default, because they are considered side-effectful. --- .../src/lib/transloco-fallback-strategy.ts | 2 +- libs/transloco/src/lib/transloco-lang.ts | 2 +- .../src/lib/transloco-loading-template.ts | 11 ++++++----- .../src/lib/transloco-missing-handler.ts | 2 +- libs/transloco/src/lib/transloco-scope.ts | 7 ++++--- .../transloco/src/lib/transloco-testing.module.ts | 13 +++++++------ libs/transloco/src/lib/transloco.config.ts | 15 ++++++++------- libs/transloco/src/lib/transloco.interceptor.ts | 9 ++++++--- libs/transloco/src/lib/transloco.loader.ts | 7 ++++--- libs/transloco/src/lib/transloco.transpiler.ts | 7 ++++--- 10 files changed, 42 insertions(+), 33 deletions(-) diff --git a/libs/transloco/src/lib/transloco-fallback-strategy.ts b/libs/transloco/src/lib/transloco-fallback-strategy.ts index 52649169..e27174b6 100644 --- a/libs/transloco/src/lib/transloco-fallback-strategy.ts +++ b/libs/transloco/src/lib/transloco-fallback-strategy.ts @@ -3,7 +3,7 @@ import { Inject, Injectable, InjectionToken } from '@angular/core'; import { TRANSLOCO_CONFIG, TranslocoConfig } from './transloco.config'; export const TRANSLOCO_FALLBACK_STRATEGY = - new InjectionToken( + /* @__PURE__ */ new InjectionToken( typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_FALLBACK_STRATEGY' : '', diff --git a/libs/transloco/src/lib/transloco-lang.ts b/libs/transloco/src/lib/transloco-lang.ts index 91a06468..a857db5d 100644 --- a/libs/transloco/src/lib/transloco-lang.ts +++ b/libs/transloco/src/lib/transloco-lang.ts @@ -1,5 +1,5 @@ import { InjectionToken } from '@angular/core'; -export const TRANSLOCO_LANG = new InjectionToken( +export const TRANSLOCO_LANG = /* @__PURE__ */ new InjectionToken( typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LANG' : '', ); diff --git a/libs/transloco/src/lib/transloco-loading-template.ts b/libs/transloco/src/lib/transloco-loading-template.ts index 19e68f95..32772940 100644 --- a/libs/transloco/src/lib/transloco-loading-template.ts +++ b/libs/transloco/src/lib/transloco-loading-template.ts @@ -2,8 +2,9 @@ import { InjectionToken } from '@angular/core'; import { Content } from './template-handler'; -export const TRANSLOCO_LOADING_TEMPLATE = new InjectionToken( - typeof ngDevMode !== 'undefined' && ngDevMode - ? 'TRANSLOCO_LOADING_TEMPLATE' - : '', -); +export const TRANSLOCO_LOADING_TEMPLATE = + /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode + ? 'TRANSLOCO_LOADING_TEMPLATE' + : '', + ); diff --git a/libs/transloco/src/lib/transloco-missing-handler.ts b/libs/transloco/src/lib/transloco-missing-handler.ts index 7bee2a0b..67620f6a 100644 --- a/libs/transloco/src/lib/transloco-missing-handler.ts +++ b/libs/transloco/src/lib/transloco-missing-handler.ts @@ -4,7 +4,7 @@ import { TranslocoConfig } from './transloco.config'; import { HashMap } from './types'; export const TRANSLOCO_MISSING_HANDLER = - new InjectionToken( + /* @__PURE__ */ new InjectionToken( typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_MISSING_HANDLER' : '', diff --git a/libs/transloco/src/lib/transloco-scope.ts b/libs/transloco/src/lib/transloco-scope.ts index ae33fcf8..3204d175 100644 --- a/libs/transloco/src/lib/transloco-scope.ts +++ b/libs/transloco/src/lib/transloco-scope.ts @@ -2,6 +2,7 @@ import { InjectionToken } from '@angular/core'; import { TranslocoScope } from './types'; -export const TRANSLOCO_SCOPE = new InjectionToken( - typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_SCOPE' : '', -); +export const TRANSLOCO_SCOPE = + /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_SCOPE' : '', + ); diff --git a/libs/transloco/src/lib/transloco-testing.module.ts b/libs/transloco/src/lib/transloco-testing.module.ts index 59ceb168..20746a99 100644 --- a/libs/transloco/src/lib/transloco-testing.module.ts +++ b/libs/transloco/src/lib/transloco-testing.module.ts @@ -21,12 +21,13 @@ export interface TranslocoTestingOptions { langs?: HashMap; } -const TRANSLOCO_TEST_LANGS = new InjectionToken>( - 'TRANSLOCO_TEST_LANGS - Available testing languages', -); -const TRANSLOCO_TEST_OPTIONS = new InjectionToken( - 'TRANSLOCO_TEST_OPTIONS - Testing options', -); +const TRANSLOCO_TEST_LANGS = /* @__PURE__ */ new InjectionToken< + HashMap +>('TRANSLOCO_TEST_LANGS - Available testing languages'); +const TRANSLOCO_TEST_OPTIONS = + /* @__PURE__ */ new InjectionToken( + 'TRANSLOCO_TEST_OPTIONS - Testing options', + ); @Injectable() export class TestingLoader implements TranslocoLoader { diff --git a/libs/transloco/src/lib/transloco.config.ts b/libs/transloco/src/lib/transloco.config.ts index a75ee34e..6a7b0e60 100644 --- a/libs/transloco/src/lib/transloco.config.ts +++ b/libs/transloco/src/lib/transloco.config.ts @@ -23,13 +23,14 @@ export interface TranslocoConfig { }; } -export const TRANSLOCO_CONFIG = new InjectionToken( - typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_CONFIG' : '', - { - providedIn: 'root', - factory: () => defaultConfig, - }, -); +export const TRANSLOCO_CONFIG = + /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_CONFIG' : '', + { + providedIn: 'root', + factory: () => defaultConfig, + }, + ); export const defaultConfig: TranslocoConfig = { defaultLang: 'en', diff --git a/libs/transloco/src/lib/transloco.interceptor.ts b/libs/transloco/src/lib/transloco.interceptor.ts index c78bceb9..67f44560 100644 --- a/libs/transloco/src/lib/transloco.interceptor.ts +++ b/libs/transloco/src/lib/transloco.interceptor.ts @@ -2,9 +2,12 @@ import { InjectionToken, Injectable } from '@angular/core'; import { Translation } from './types'; -export const TRANSLOCO_INTERCEPTOR = new InjectionToken( - typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_INTERCEPTOR' : '', -); +export const TRANSLOCO_INTERCEPTOR = + /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode + ? 'TRANSLOCO_INTERCEPTOR' + : '', + ); export interface TranslocoInterceptor { preSaveTranslation(translation: Translation, lang: string): Translation; diff --git a/libs/transloco/src/lib/transloco.loader.ts b/libs/transloco/src/lib/transloco.loader.ts index ae2eea5d..70748b9b 100644 --- a/libs/transloco/src/lib/transloco.loader.ts +++ b/libs/transloco/src/lib/transloco.loader.ts @@ -22,6 +22,7 @@ export class DefaultLoader implements TranslocoLoader { } } -export const TRANSLOCO_LOADER = new InjectionToken( - typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LOADER' : '', -); +export const TRANSLOCO_LOADER = + /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LOADER' : '', + ); diff --git a/libs/transloco/src/lib/transloco.transpiler.ts b/libs/transloco/src/lib/transloco.transpiler.ts index 59bbbffb..0cde542c 100644 --- a/libs/transloco/src/lib/transloco.transpiler.ts +++ b/libs/transloco/src/lib/transloco.transpiler.ts @@ -8,9 +8,10 @@ import { TranslocoConfig, } from './transloco.config'; -export const TRANSLOCO_TRANSPILER = new InjectionToken( - typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_TRANSPILER' : '', -); +export const TRANSLOCO_TRANSPILER = + /* @__PURE__ */ new InjectionToken( + typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_TRANSPILER' : '', + ); export interface TranslocoTranspiler { transpile(params: TranspileParams): any;