Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transloco): tree-shake injection token names in production #821

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libs/transloco/src/lib/transloco-fallback-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { Inject, Injectable, InjectionToken } from '@angular/core';
import { TRANSLOCO_CONFIG, TranslocoConfig } from './transloco.config';

export const TRANSLOCO_FALLBACK_STRATEGY =
new InjectionToken<TranslocoFallbackStrategy>('TRANSLOCO_FALLBACK_STRATEGY');
new InjectionToken<TranslocoFallbackStrategy>(
typeof ngDevMode !== 'undefined' && ngDevMode
? 'TRANSLOCO_FALLBACK_STRATEGY'
: '',
);

export interface TranslocoFallbackStrategy {
getNextLangs(failedLang: string): string[];
Expand Down
4 changes: 3 additions & 1 deletion libs/transloco/src/lib/transloco-lang.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InjectionToken } from '@angular/core';

export const TRANSLOCO_LANG = new InjectionToken<string>('TRANSLOCO_LANG');
export const TRANSLOCO_LANG = new InjectionToken<string>(
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LANG' : '',
);
4 changes: 3 additions & 1 deletion libs/transloco/src/lib/transloco-loading-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import { InjectionToken } from '@angular/core';
import { Content } from './template-handler';

export const TRANSLOCO_LOADING_TEMPLATE = new InjectionToken<Content>(
'TRANSLOCO_LOADING_TEMPLATE',
typeof ngDevMode !== 'undefined' && ngDevMode
? 'TRANSLOCO_LOADING_TEMPLATE'
: '',
);
6 changes: 5 additions & 1 deletion libs/transloco/src/lib/transloco-missing-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { TranslocoConfig } from './transloco.config';
import { HashMap } from './types';

export const TRANSLOCO_MISSING_HANDLER =
new InjectionToken<TranslocoMissingHandlerData>('TRANSLOCO_MISSING_HANDLER');
new InjectionToken<TranslocoMissingHandlerData>(
typeof ngDevMode !== 'undefined' && ngDevMode
? 'TRANSLOCO_MISSING_HANDLER'
: '',
);

export interface TranslocoMissingHandlerData extends TranslocoConfig {
activeLang: string;
Expand Down
2 changes: 1 addition & 1 deletion libs/transloco/src/lib/transloco-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { InjectionToken } from '@angular/core';
import { TranslocoScope } from './types';

export const TRANSLOCO_SCOPE = new InjectionToken<TranslocoScope>(
'TRANSLOCO_SCOPE',
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_SCOPE' : '',
);
2 changes: 1 addition & 1 deletion libs/transloco/src/lib/transloco.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface TranslocoConfig {
}

export const TRANSLOCO_CONFIG = new InjectionToken<TranslocoConfig>(
'TRANSLOCO_CONFIG',
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_CONFIG' : '',
{
providedIn: 'root',
factory: () => defaultConfig,
Expand Down
2 changes: 1 addition & 1 deletion libs/transloco/src/lib/transloco.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { InjectionToken, Injectable } from '@angular/core';
import { Translation } from './types';

export const TRANSLOCO_INTERCEPTOR = new InjectionToken<TranslocoInterceptor>(
'TRANSLOCO_INTERCEPTOR',
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_INTERCEPTOR' : '',
);

export interface TranslocoInterceptor {
Expand Down
2 changes: 1 addition & 1 deletion libs/transloco/src/lib/transloco.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export class DefaultLoader implements TranslocoLoader {
}

export const TRANSLOCO_LOADER = new InjectionToken<TranslocoLoader>(
'TRANSLOCO_LOADER',
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_LOADER' : '',
);
2 changes: 1 addition & 1 deletion libs/transloco/src/lib/transloco.transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from './transloco.config';

export const TRANSLOCO_TRANSPILER = new InjectionToken<TranslocoTranspiler>(
'TRANSLOCO_TRANSPILER',
typeof ngDevMode !== 'undefined' && ngDevMode ? 'TRANSLOCO_TRANSPILER' : '',
);

export interface TranslocoTranspiler {
Expand Down
8 changes: 8 additions & 0 deletions libs/transloco/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ export interface LoadOptions {
failedCounter?: number;
inlineLoader?: InlineLoader;
}

/** @internal */
declare global {
// Indicates whether the application is operating in development mode.
// `ngDevMode` is a global flag set by Angular CLI.
// https://github.com/angular/angular-cli/blob/9b883fe28862c96720c7899b431174e9b47ad7e4/packages/angular/build/src/tools/esbuild/application-code-bundle.ts#L604
const ngDevMode: boolean;
}
Loading