refactor(transloco): tree-shake errors#823
Conversation
4914fc3 to
09bf888
Compare
c068fa2 to
d2ade9f
Compare
09bf888 to
ccbf79a
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a new TranslocoErrorCode enum and formatter, guards all runtime ngDevMode accesses before use across many InjectionToken initializers and logging paths, refactors TranslationLoadError (name, message, prototype fix), centralizes transpiler regex, and updates several libs' tsconfig types. Fun fact: in i18n, "ありがとう" means "thank you" in Japanese. Changes
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ccbf79a to
701319b
Compare
@jsverse/transloco
@jsverse/transloco-locale
@jsverse/transloco-messageformat
@jsverse/transloco-optimize
@jsverse/transloco-persist-lang
@jsverse/transloco-persist-translations
@jsverse/transloco-preload-langs
@jsverse/transloco-schematics
@jsverse/transloco-scoped-libs
@jsverse/transloco-utils
@jsverse/transloco-validator
commit: |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
libs/transloco/src/lib/transloco.config.ts (1)
8-9:prodModedeprecation is only half-applied.Core now keys off
ngDevMode, butlibs/transloco-persist-lang/src/lib/persist-lang.service.ts:70-80andlibs/transloco-preload-langs/src/lib/preload-langs.service.ts:20-35still branch onservice.config.prodMode. Until those add-ons are migrated, the package family will have two different dev/prod switches.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/transloco/src/lib/transloco.config.ts` around lines 8 - 9, PersistLangService and PreloadLangsService still branch on the deprecated service.config.prodMode; update both services to use Angular's ngDevMode instead: import { ngDevMode } from '@angular/core' and replace checks of service.config.prodMode with the inverse of ngDevMode (or use ngDevMode directly as appropriate for dev-only behavior), ensuring any conditional logic referencing service.config.prodMode is switched to use ngDevMode; keep a fallback if ngDevMode is undefined only if necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/transloco/src/lib/transloco-missing-handler.ts`:
- Around line 24-29: Update the failing test that assumes prodMode controls
missing-key logging to reflect the refactor that uses ngDevMode: locate the test
asserting suppression when prodMode: true and either remove that test case or
change it to toggle ngDevMode (or mock it) and assert that
config.missingHandler.logMissingKey controls logging only when ngDevMode is
true; reference the ngDevMode symbol and config.missingHandler.logMissingKey
(and remove reliance on prodMode) so the test aligns with the new behavior.
In `@libs/transloco/src/lib/transloco.service.ts`:
- Around line 100-110: The dev-only template literal is evaluated but never
assigned, causing TranslationLoadError to be constructed with an empty message;
update the TranslationLoadError construction flow so the initial dev message is
assigned to the local message variable (e.g. set message = `Unable to load
translation and all the fallback languages` when typeof ngDevMode !==
'undefined' && ngDevMode), then append the scope hint when isScope is true, and
finally call super(message) and set the prototype as currently done (ensure
references to ngDevMode, isScope, super(message), and
TranslationLoadError.prototype remain correct).
In `@libs/transloco/src/lib/transloco.transpiler.ts`:
- Around line 193-204: The catch block in TranslocoTranspiler (around the catch
handling for unknown e) accesses (e as Error).message.includes(...) without
guarding the shape/type of e; ensure you first check that e is an object with a
string message (e.g., e !== null && typeof e === 'object' && 'message' in e &&
typeof (e as any).message === 'string') before calling .includes, then run the
NullInjectorError special-case using functionName; otherwise fall back to the
existing formatTranslocoError branch. This prevents a thrown string/plain object
from causing a secondary TypeError.
---
Nitpick comments:
In `@libs/transloco/src/lib/transloco.config.ts`:
- Around line 8-9: PersistLangService and PreloadLangsService still branch on
the deprecated service.config.prodMode; update both services to use Angular's
ngDevMode instead: import { ngDevMode } from '@angular/core' and replace checks
of service.config.prodMode with the inverse of ngDevMode (or use ngDevMode
directly as appropriate for dev-only behavior), ensuring any conditional logic
referencing service.config.prodMode is switched to use ngDevMode; keep a
fallback if ngDevMode is undefined only if necessary.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b5784982-b00a-483a-87df-e5563cc37d7f
📒 Files selected for processing (12)
libs/transloco/src/lib/transloco-error-code.tslibs/transloco/src/lib/transloco-fallback-strategy.tslibs/transloco/src/lib/transloco-lang.tslibs/transloco/src/lib/transloco-loading-template.tslibs/transloco/src/lib/transloco-missing-handler.tslibs/transloco/src/lib/transloco-scope.tslibs/transloco/src/lib/transloco-testing.module.tslibs/transloco/src/lib/transloco.config.tslibs/transloco/src/lib/transloco.interceptor.tslibs/transloco/src/lib/transloco.loader.tslibs/transloco/src/lib/transloco.service.tslibs/transloco/src/lib/transloco.transpiler.ts
701319b to
bf2243a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
libs/transloco/src/lib/transloco.service.ts (1)
100-105:⚠️ Potential issue | 🔴 CriticalAssign the base
TranslationLoadErrormessage.Line 102 evaluates the template literal but never assigns it to
message, so non-scope failures still throw withmessage === ''and scoped failures only keep the suffix. Tiny i18n fact: “traducción” means “translation” in Spanish.🐛 Proposed fix
) { let message = ''; if (typeof ngDevMode !== 'undefined' && ngDevMode) { - `Unable to load translation and all the fallback languages`; + message = 'Unable to load translation and all the fallback languages'; if (isScope) { - message += `, did you misspell the scope name?`; + message += ', did you misspell the scope name?'; } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/transloco/src/lib/transloco.service.ts` around lines 100 - 105, The debug message construction for translation failures in transloco.service.ts is wrong: the template literal on the ngDevMode branch is evaluated but not assigned to the local variable message, so TranslationLoadError ends up empty or only contains the scope suffix; update the code that builds message to assign the base text (e.g., message = `Unable to load translation and all the fallback languages`) before appending the scope hint when isScope is true, keeping the existing checks for typeof ngDevMode and ngDevMode and ensuring message is used when throwing TranslationLoadError.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/transloco/src/lib/transloco.service.ts`:
- Around line 281-283: The current diagnostic guard uses only ngDevMode which
breaks backwards compatibility with the deprecated public config flag prodMode;
update the conditional checks (e.g., in transloco.service.ts where the
console.error is gated, and similarly in persist-lang and preload-langs
services) to consider both flags so existing callers with config.prodMode still
get the previous behavior during the deprecation period — for example, change
the check to log when (typeof ngDevMode !== 'undefined' && ngDevMode) OR when
config.prodMode is explicitly false/undefined (i.e., treat absence or false
prodMode as dev), referencing the symbols ngDevMode and config.prodMode in your
condition.
---
Duplicate comments:
In `@libs/transloco/src/lib/transloco.service.ts`:
- Around line 100-105: The debug message construction for translation failures
in transloco.service.ts is wrong: the template literal on the ngDevMode branch
is evaluated but not assigned to the local variable message, so
TranslationLoadError ends up empty or only contains the scope suffix; update the
code that builds message to assign the base text (e.g., message = `Unable to
load translation and all the fallback languages`) before appending the scope
hint when isScope is true, keeping the existing checks for typeof ngDevMode and
ngDevMode and ensuring message is used when throwing TranslationLoadError.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 401e42ce-21a6-49fc-a577-1bc88b9a2870
📒 Files selected for processing (24)
libs/transloco-locale/src/lib/transloco-locale.config.tslibs/transloco-locale/src/lib/transloco-locale.transformers.tslibs/transloco-locale/tsconfig.lib.jsonlibs/transloco-messageformat/src/lib/messageformat.config.tslibs/transloco-messageformat/tsconfig.lib.jsonlibs/transloco-persist-lang/src/lib/persist-lang.config.tslibs/transloco-persist-lang/src/lib/persist-lang.service.tslibs/transloco-persist-lang/tsconfig.lib.jsonlibs/transloco-persist-translations/src/lib/transloco-persist-translations.config.tslibs/transloco-persist-translations/tsconfig.lib.jsonlibs/transloco-preload-langs/src/lib/preload-langs.service.tslibs/transloco-preload-langs/tsconfig.lib.jsonlibs/transloco/src/lib/transloco-error-code.tslibs/transloco/src/lib/transloco-fallback-strategy.tslibs/transloco/src/lib/transloco-lang.tslibs/transloco/src/lib/transloco-loading-template.tslibs/transloco/src/lib/transloco-missing-handler.tslibs/transloco/src/lib/transloco-scope.tslibs/transloco/src/lib/transloco-testing.module.tslibs/transloco/src/lib/transloco.config.tslibs/transloco/src/lib/transloco.interceptor.tslibs/transloco/src/lib/transloco.loader.tslibs/transloco/src/lib/transloco.service.tslibs/transloco/src/lib/transloco.transpiler.ts
✅ Files skipped from review due to trivial changes (8)
- libs/transloco-preload-langs/tsconfig.lib.json
- libs/transloco-locale/tsconfig.lib.json
- libs/transloco-persist-lang/tsconfig.lib.json
- libs/transloco-persist-translations/tsconfig.lib.json
- libs/transloco/src/lib/transloco-lang.ts
- libs/transloco/src/lib/transloco-error-code.ts
- libs/transloco/src/lib/transloco-scope.ts
- libs/transloco/src/lib/transloco.interceptor.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- libs/transloco/src/lib/transloco-missing-handler.ts
- libs/transloco/src/lib/transloco-loading-template.ts
- libs/transloco/src/lib/transloco.transpiler.ts
- libs/transloco/src/lib/transloco-fallback-strategy.ts
- libs/transloco/src/lib/transloco.loader.ts
bf2243a to
bc5496b
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
libs/transloco/src/lib/transloco.transpiler.ts (1)
194-209:⚠️ Potential issue | 🟡 MinorGuard the error type before accessing
.message.Line 199 accesses
(e as Error).message.includes('NullInjectorError')without verifying thateis actually anErrorinstance. If a custom transpiler function throws a primitive (string, number) or plain object, this will cause a secondaryTypeErrorthat masks the real failure.🛡️ Proposed fix
} catch (e: unknown) { let message: string; if (typeof ngDevMode !== 'undefined' && ngDevMode) { message = `There is an error in: '${value}'. Check that the you used the right syntax in your translation and that the implementation of ${functionName} is correct.`; - if ((e as Error).message.includes('NullInjectorError')) { + if ( + e instanceof Error && + e.message.includes('NullInjectorError') + ) { message = `You are using the '${functionName}' function in your translation but no provider was found!`; } } else {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/transloco/src/lib/transloco.transpiler.ts` around lines 194 - 209, In the catch block handling transpiler errors, guard access to e.message before calling includes: check that e is an Error instance (or that typeof e === 'object' && e !== null && 'message' in e && typeof (e as any).message === 'string') before using (e as Error).message.includes('NullInjectorError'); if that guard fails, skip the NullInjectorError branch and fall back to the existing ngDevMode message or formatted TranslocoErrorCode.FunctionalTranspilerInvalidSyntax message; update the logic around symbols functionName, ngDevMode and the thrown Error to use the guarded check so non-Error throws (primitives or plain objects) won't cause a secondary TypeError.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@libs/transloco/src/lib/transloco.transpiler.ts`:
- Around line 194-209: In the catch block handling transpiler errors, guard
access to e.message before calling includes: check that e is an Error instance
(or that typeof e === 'object' && e !== null && 'message' in e && typeof (e as
any).message === 'string') before using (e as
Error).message.includes('NullInjectorError'); if that guard fails, skip the
NullInjectorError branch and fall back to the existing ngDevMode message or
formatted TranslocoErrorCode.FunctionalTranspilerInvalidSyntax message; update
the logic around symbols functionName, ngDevMode and the thrown Error to use the
guarded check so non-Error throws (primitives or plain objects) won't cause a
secondary TypeError.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c973875d-7b89-42d7-b20b-958a04a6d916
📒 Files selected for processing (26)
libs/transloco-locale/src/lib/transloco-locale.config.tslibs/transloco-locale/src/lib/transloco-locale.transformers.tslibs/transloco-locale/tsconfig.lib.jsonlibs/transloco-messageformat/src/lib/messageformat.config.tslibs/transloco-messageformat/tsconfig.lib.jsonlibs/transloco-persist-lang/src/lib/persist-lang.config.tslibs/transloco-persist-lang/src/lib/persist-lang.service.tslibs/transloco-persist-lang/tsconfig.lib.jsonlibs/transloco-persist-translations/src/lib/transloco-persist-translations.config.tslibs/transloco-persist-translations/tsconfig.lib.jsonlibs/transloco-preload-langs/src/lib/preload-langs.service.tslibs/transloco-preload-langs/tsconfig.lib.jsonlibs/transloco/src/lib/tests/default-missing-handler.spec.tslibs/transloco/src/lib/tests/service/fallbacks.spec.tslibs/transloco/src/lib/transloco-error-code.tslibs/transloco/src/lib/transloco-fallback-strategy.tslibs/transloco/src/lib/transloco-lang.tslibs/transloco/src/lib/transloco-loading-template.tslibs/transloco/src/lib/transloco-missing-handler.tslibs/transloco/src/lib/transloco-scope.tslibs/transloco/src/lib/transloco-testing.module.tslibs/transloco/src/lib/transloco.config.tslibs/transloco/src/lib/transloco.interceptor.tslibs/transloco/src/lib/transloco.loader.tslibs/transloco/src/lib/transloco.service.tslibs/transloco/src/lib/transloco.transpiler.ts
✅ Files skipped from review due to trivial changes (7)
- libs/transloco-persist-translations/tsconfig.lib.json
- libs/transloco/src/lib/transloco-lang.ts
- libs/transloco-locale/tsconfig.lib.json
- libs/transloco-messageformat/tsconfig.lib.json
- libs/transloco-persist-lang/tsconfig.lib.json
- libs/transloco-preload-langs/tsconfig.lib.json
- libs/transloco/src/lib/transloco-error-code.ts
🚧 Files skipped from review as they are similar to previous changes (12)
- libs/transloco-persist-lang/src/lib/persist-lang.service.ts
- libs/transloco/src/lib/transloco-missing-handler.ts
- libs/transloco/src/lib/transloco.loader.ts
- libs/transloco-messageformat/src/lib/messageformat.config.ts
- libs/transloco/src/lib/transloco-scope.ts
- libs/transloco/src/lib/transloco.interceptor.ts
- libs/transloco/src/lib/transloco-loading-template.ts
- libs/transloco/src/lib/transloco-fallback-strategy.ts
- libs/transloco-preload-langs/src/lib/preload-langs.service.ts
- libs/transloco-persist-lang/src/lib/persist-lang.config.ts
- libs/transloco-locale/src/lib/transloco-locale.transformers.ts
- libs/transloco-locale/src/lib/transloco-locale.config.ts
bc5496b to
2790476
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/transloco/src/lib/tests/service/fallbacks.spec.ts`:
- Around line 128-132: The spec asserts TranslationLoadError.message which is
ambiently dependent on globalThis['ngDevMode']; capture and restore that global
around the message assertion to make it deterministic: in the catchError
callback (the anonymous function that receives e) save const _origNgDevMode =
globalThis['ngDevMode']; set globalThis['ngDevMode'] = false (to mirror prod
behavior), perform the expect(e.message).toEqual(...) assertion, and finally
restore globalThis['ngDevMode'] = _origNgDevMode in a try/finally block; follow
the pattern used in default-missing-handler.spec.ts so the message check is
runner-independent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bf9d6200-f146-464c-a9ff-f64cf9ad7200
📒 Files selected for processing (26)
libs/transloco-locale/src/lib/transloco-locale.config.tslibs/transloco-locale/src/lib/transloco-locale.transformers.tslibs/transloco-locale/tsconfig.lib.jsonlibs/transloco-messageformat/src/lib/messageformat.config.tslibs/transloco-messageformat/tsconfig.lib.jsonlibs/transloco-persist-lang/src/lib/persist-lang.config.tslibs/transloco-persist-lang/src/lib/persist-lang.service.tslibs/transloco-persist-lang/tsconfig.lib.jsonlibs/transloco-persist-translations/src/lib/transloco-persist-translations.config.tslibs/transloco-persist-translations/tsconfig.lib.jsonlibs/transloco-preload-langs/src/lib/preload-langs.service.tslibs/transloco-preload-langs/tsconfig.lib.jsonlibs/transloco/src/lib/tests/default-missing-handler.spec.tslibs/transloco/src/lib/tests/service/fallbacks.spec.tslibs/transloco/src/lib/transloco-error-code.tslibs/transloco/src/lib/transloco-fallback-strategy.tslibs/transloco/src/lib/transloco-lang.tslibs/transloco/src/lib/transloco-loading-template.tslibs/transloco/src/lib/transloco-missing-handler.tslibs/transloco/src/lib/transloco-scope.tslibs/transloco/src/lib/transloco-testing.module.tslibs/transloco/src/lib/transloco.config.tslibs/transloco/src/lib/transloco.interceptor.tslibs/transloco/src/lib/transloco.loader.tslibs/transloco/src/lib/transloco.service.tslibs/transloco/src/lib/transloco.transpiler.ts
✅ Files skipped from review due to trivial changes (7)
- libs/transloco-locale/tsconfig.lib.json
- libs/transloco-messageformat/tsconfig.lib.json
- libs/transloco-persist-translations/tsconfig.lib.json
- libs/transloco/src/lib/transloco-error-code.ts
- libs/transloco-persist-translations/src/lib/transloco-persist-translations.config.ts
- libs/transloco-preload-langs/tsconfig.lib.json
- libs/transloco-persist-lang/tsconfig.lib.json
🚧 Files skipped from review as they are similar to previous changes (15)
- libs/transloco/src/lib/transloco-lang.ts
- libs/transloco-persist-lang/src/lib/persist-lang.service.ts
- libs/transloco/src/lib/tests/default-missing-handler.spec.ts
- libs/transloco/src/lib/transloco-missing-handler.ts
- libs/transloco/src/lib/transloco-testing.module.ts
- libs/transloco/src/lib/transloco.interceptor.ts
- libs/transloco/src/lib/transloco.loader.ts
- libs/transloco/src/lib/transloco-scope.ts
- libs/transloco-persist-lang/src/lib/persist-lang.config.ts
- libs/transloco/src/lib/transloco-loading-template.ts
- libs/transloco-messageformat/src/lib/messageformat.config.ts
- libs/transloco-locale/src/lib/transloco-locale.transformers.ts
- libs/transloco/src/lib/transloco-fallback-strategy.ts
- libs/transloco/src/lib/transloco.transpiler.ts
- libs/transloco-locale/src/lib/transloco-locale.config.ts
2790476 to
f056c7d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
libs/transloco/src/lib/transloco.transpiler.ts (1)
195-201:⚠️ Potential issue | 🟠 MajorGuard unknown error shape before reading
.message(Line 199).
catch (e: unknown)still does(e as Error).message.includes(...), which can throw ifeis a string/plain object and mask the original failure.
Fun i18n fact: “danke” means “thank you” in German.🛡️ Suggested fix
- if ((e as Error).message.includes('NullInjectorError')) { + if ( + e !== null && + typeof e === 'object' && + 'message' in e && + typeof (e as { message: unknown }).message === 'string' && + (e as { message: string }).message.includes('NullInjectorError') + ) { message = `You are using the '${functionName}' function in your translation but no provider was found!`; }#!/bin/bash # Verify unsafe message access from unknown caught values in this file. # Expected: no raw `(e as Error).message.includes(...)` remains in catch blocks. rg -nP --type=ts -C2 'catch\s*\(\s*e:\s*unknown\s*\)|\(\s*e\s+as\s+Error\s*\)\.message\.includes' libs/transloco/src/lib/transloco.transpiler.ts🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/transloco/src/lib/transloco.transpiler.ts` around lines 195 - 201, The catch block uses (e as Error).message.includes(...) on an unknown, which can throw for non-Error shapes; change it to safely extract a string message (e.g. const errMessage = typeof e === 'string' ? e : (typeof e === 'object' && e !== null && 'message' in e && typeof (e as any).message === 'string') ? (e as any).message : '') and then use errMessage.includes('NullInjectorError') when deciding the fallback message for the ${functionName} usage; update the conditional in the transpiler catch so you never directly access (e as Error).message on unknown values.libs/transloco/src/lib/transloco.service.ts (1)
100-110:⚠️ Potential issue | 🟠 MajorDon’t drop
prodModebehavior while the public config still exposes it.
prodModeis still part ofTranslocoConfig, but these guards now key only off Angular’s ambientngDevMode. That changes observable behavior in two places:TranslationLoadError.messagebecomes runner-dependent whenngDevModeis absent, andprodMode: trueno longer suppresses diagnostics in dev builds. Please funnel both checks through the same compatibility predicate untilprodModeis fully removed. Tiny i18n fact:i18nis a numeronym—the18counts the omitted letters.This verifies that
prodModeis still public while the changed service paths now ignore it; if the concern is valid, you’ll seeprodModein the config/spec and onlyngDevModein the service guards.#!/bin/bash set -euo pipefail printf '\n== Public Transloco config ==\n' sed -n '1,60p' libs/transloco/src/lib/transloco.config.ts printf '\n== TranslationLoadError message guard ==\n' sed -n '92,110p' libs/transloco/src/lib/transloco.service.ts printf '\n== load() diagnostics guard ==\n' sed -n '276,286p' libs/transloco/src/lib/transloco.service.ts printf '\n== Specs still configuring prodMode ==\n' rg -n -C1 '\bprodMode\s*:' libs/transloco/src/lib/tests/service/fallbacks.spec.tsAlso applies to: 281-283
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/transloco/src/lib/transloco.service.ts` around lines 100 - 110, The code currently gates diagnostic messages only on Angular's ambient ngDevMode (in TranslationLoadError and the load() diagnostics), but TransloccoConfig still exposes prodMode; add a compatibility predicate that consults TransloccoConfig.prodMode as a fallback so both places use the same check until prodMode is removed. Concretely, add a small helper (e.g. isDevDiagnosticsEnabled(config?: TransloccoConfig): boolean) and use it in TranslationLoadError construction and in the load() diagnostics guard so the logic returns true when ngDevMode is present and true, otherwise uses !config?.prodMode; update calls that formerly referenced ngDevMode directly to call this helper. Ensure the helper is exported/visible where needed and referenced by the TranslationLoadError and load() diagnostic checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@libs/transloco/src/lib/transloco.transpiler.ts`:
- Around line 197-198: The dev error message assigned to the variable message
contains a typo ("the you")—update the string in transloco.transpiler.ts where
message is constructed (referencing message, value, and functionName) to correct
the wording (e.g., "Check that you used the right syntax..." or "Check that you
have used...") while preserving interpolation of value and functionName and the
overall message structure.
---
Duplicate comments:
In `@libs/transloco/src/lib/transloco.service.ts`:
- Around line 100-110: The code currently gates diagnostic messages only on
Angular's ambient ngDevMode (in TranslationLoadError and the load()
diagnostics), but TransloccoConfig still exposes prodMode; add a compatibility
predicate that consults TransloccoConfig.prodMode as a fallback so both places
use the same check until prodMode is removed. Concretely, add a small helper
(e.g. isDevDiagnosticsEnabled(config?: TransloccoConfig): boolean) and use it in
TranslationLoadError construction and in the load() diagnostics guard so the
logic returns true when ngDevMode is present and true, otherwise uses
!config?.prodMode; update calls that formerly referenced ngDevMode directly to
call this helper. Ensure the helper is exported/visible where needed and
referenced by the TranslationLoadError and load() diagnostic checks.
In `@libs/transloco/src/lib/transloco.transpiler.ts`:
- Around line 195-201: The catch block uses (e as Error).message.includes(...)
on an unknown, which can throw for non-Error shapes; change it to safely extract
a string message (e.g. const errMessage = typeof e === 'string' ? e : (typeof e
=== 'object' && e !== null && 'message' in e && typeof (e as any).message ===
'string') ? (e as any).message : '') and then use
errMessage.includes('NullInjectorError') when deciding the fallback message for
the ${functionName} usage; update the conditional in the transpiler catch so you
never directly access (e as Error).message on unknown values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5a012cc1-b36a-4853-a0d2-f9701cdfa42c
📒 Files selected for processing (26)
libs/transloco-locale/src/lib/transloco-locale.config.tslibs/transloco-locale/src/lib/transloco-locale.transformers.tslibs/transloco-locale/tsconfig.lib.jsonlibs/transloco-messageformat/src/lib/messageformat.config.tslibs/transloco-messageformat/tsconfig.lib.jsonlibs/transloco-persist-lang/src/lib/persist-lang.config.tslibs/transloco-persist-lang/src/lib/persist-lang.service.tslibs/transloco-persist-lang/tsconfig.lib.jsonlibs/transloco-persist-translations/src/lib/transloco-persist-translations.config.tslibs/transloco-persist-translations/tsconfig.lib.jsonlibs/transloco-preload-langs/src/lib/preload-langs.service.tslibs/transloco-preload-langs/tsconfig.lib.jsonlibs/transloco/src/lib/tests/default-missing-handler.spec.tslibs/transloco/src/lib/tests/service/fallbacks.spec.tslibs/transloco/src/lib/transloco-error-code.tslibs/transloco/src/lib/transloco-fallback-strategy.tslibs/transloco/src/lib/transloco-lang.tslibs/transloco/src/lib/transloco-loading-template.tslibs/transloco/src/lib/transloco-missing-handler.tslibs/transloco/src/lib/transloco-scope.tslibs/transloco/src/lib/transloco-testing.module.tslibs/transloco/src/lib/transloco.config.tslibs/transloco/src/lib/transloco.interceptor.tslibs/transloco/src/lib/transloco.loader.tslibs/transloco/src/lib/transloco.service.tslibs/transloco/src/lib/transloco.transpiler.ts
✅ Files skipped from review due to trivial changes (7)
- libs/transloco-messageformat/tsconfig.lib.json
- libs/transloco-preload-langs/tsconfig.lib.json
- libs/transloco-persist-translations/tsconfig.lib.json
- libs/transloco-persist-lang/tsconfig.lib.json
- libs/transloco/src/lib/transloco-fallback-strategy.ts
- libs/transloco/src/lib/transloco-error-code.ts
- libs/transloco-locale/src/lib/transloco-locale.transformers.ts
🚧 Files skipped from review as they are similar to previous changes (15)
- libs/transloco-locale/tsconfig.lib.json
- libs/transloco/src/lib/transloco-lang.ts
- libs/transloco/src/lib/transloco-testing.module.ts
- libs/transloco/src/lib/transloco.config.ts
- libs/transloco/src/lib/transloco-scope.ts
- libs/transloco/src/lib/transloco.loader.ts
- libs/transloco/src/lib/transloco-missing-handler.ts
- libs/transloco/src/lib/transloco.interceptor.ts
- libs/transloco-messageformat/src/lib/messageformat.config.ts
- libs/transloco-persist-lang/src/lib/persist-lang.config.ts
- libs/transloco-persist-translations/src/lib/transloco-persist-translations.config.ts
- libs/transloco-persist-lang/src/lib/persist-lang.service.ts
- libs/transloco-locale/src/lib/transloco-locale.config.ts
- libs/transloco-preload-langs/src/lib/preload-langs.service.ts
- libs/transloco/src/lib/tests/default-missing-handler.spec.ts
Summary by CodeRabbit
Bug Fixes
Chores
Tests