Skip to content

refactor(transloco): tree-shake errors#823

Merged
shaharkazaz merged 1 commit intojsverse:masterfrom
arturovt:refactor/tree-shake-errors
Apr 17, 2026
Merged

refactor(transloco): tree-shake errors#823
shaharkazaz merged 1 commit intojsverse:masterfrom
arturovt:refactor/tree-shake-errors

Conversation

@arturovt
Copy link
Copy Markdown
Collaborator

@arturovt arturovt commented Jan 2, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Introduced standardized translation error codes and a formatted error message helper.
    • Added safe dev-mode checks to prevent runtime failures and reduced non-dev console noise.
  • Chores

    • Updated runtime dev-mode detection and added build annotations for more robust packaging.
  • Tests

    • Strengthened tests to assert specific error types and explicit dev-mode behaviors.

@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from 4914fc3 to 09bf888 Compare January 2, 2025 11:16
@arturovt arturovt marked this pull request as ready for review January 2, 2025 11:19
@shaharkazaz shaharkazaz force-pushed the master branch 5 times, most recently from c068fa2 to d2ade9f Compare January 6, 2025 00:03
@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from 09bf888 to ccbf79a Compare April 3, 2026 10:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Error Code Infrastructure
libs/transloco/src/lib/transloco-error-code.ts
Added exported const enum TranslocoErrorCode (4 members) and formatTranslocoError(code: TranslocoErrorCode): string returning formatted error tokens.
Core InjectionToken guards
libs/transloco/src/lib/transloco-lang.ts, libs/transloco/src/lib/transloco-scope.ts, libs/transloco/src/lib/transloco.loader.ts, libs/transloco/src/lib/transloco.interceptor.ts, libs/transloco/src/lib/transloco-loading-template.ts, libs/transloco/src/lib/transloco.config.ts, libs/transloco/src/lib/transloco-testing.module.ts, libs/transloco/src/lib/transloco.transpiler.ts, libs/transloco/src/lib/transloco-missing-handler.ts
Replaced direct ngDevMode ? ... : '' uses with guarded typeof ngDevMode !== 'undefined' && ngDevMode ? ... : '' for InjectionToken descriptions and adjusted dev-mode conditionals.
Service & Error handling
libs/transloco/src/lib/transloco.service.ts
Refactored TranslationLoadError (readonly name, dev-only message, Object.setPrototypeOf fix) and switched console error/log guards to check guarded ngDevMode.
Transpiler & functional-call handling
libs/transloco/src/lib/transloco.transpiler.ts
Introduced module-level functionalCallRegExp, reused in transpile, and changed non-dev error messages to use formatTranslocoError(TranslocoErrorCode.FunctionalTranspilerInvalidSyntax).
Fallback & Preload behavior
libs/transloco/src/lib/transloco-fallback-strategy.ts, libs/transloco-preload-langs/src/lib/preload-langs.service.ts
Fallback error messages use formatTranslocoError(...) outside dev mode; preload logging and fallback logging gates switched from prodMode to guarded ngDevMode checks.
Locale / Transformers / Messageformat / Persist tokens
libs/transloco-locale/..., libs/transloco-locale/src/lib/transloco-locale.transformers.ts, libs/transloco-messageformat/..., libs/transloco-persist-lang/..., libs/transloco-persist-translations/...
Multiple InjectionToken description strings now use guarded ngDevMode checks; selected tokens annotated with /* @PURE */. No API signature changes.
tsconfig updates
libs/transloco-locale/tsconfig.lib.json, libs/transloco-messageformat/tsconfig.lib.json, libs/transloco-persist-lang/tsconfig.lib.json, libs/transloco-persist-translations/tsconfig.lib.json, libs/transloco-preload-langs/tsconfig.lib.json
Added "../../@types/angular-globals" to compilerOptions.types for several libraries.
Tests
libs/transloco/src/lib/tests/default-missing-handler.spec.ts, libs/transloco/src/lib/tests/service/fallbacks.spec.ts
Tests now temporarily set/restore globalThis['ngDevMode'] for production-mode assertions and assert caught error is instance of TranslationLoadError in fallback test.

Possibly related PRs

Suggested reviewers

  • shaharkazaz
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is empty; no content was provided by the author to explain the changes, objectives, or context. Add a comprehensive description explaining why errors are being made tree-shakeable, the implementation approach (ngDevMode checks, new error module), and any migration notes for users.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: refactoring to make errors tree-shakeable in the Transloco library.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from ccbf79a to 701319b Compare April 3, 2026 10:24
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 3, 2026

Open in StackBlitz

@jsverse/transloco

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco@823

@jsverse/transloco-locale

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-locale@823

@jsverse/transloco-messageformat

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-messageformat@823

@jsverse/transloco-optimize

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-optimize@823

@jsverse/transloco-persist-lang

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-lang@823

@jsverse/transloco-persist-translations

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-persist-translations@823

@jsverse/transloco-preload-langs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-preload-langs@823

@jsverse/transloco-schematics

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-schematics@823

@jsverse/transloco-scoped-libs

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-scoped-libs@823

@jsverse/transloco-utils

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-utils@823

@jsverse/transloco-validator

npm i https://pkg.pr.new/jsverse/transloco/@jsverse/transloco-validator@823

commit: f056c7d

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
libs/transloco/src/lib/transloco.config.ts (1)

8-9: prodMode deprecation is only half-applied.

Core now keys off ngDevMode, but libs/transloco-persist-lang/src/lib/persist-lang.service.ts:70-80 and libs/transloco-preload-langs/src/lib/preload-langs.service.ts:20-35 still branch on service.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

📥 Commits

Reviewing files that changed from the base of the PR and between f646640 and 701319b.

📒 Files selected for processing (12)
  • libs/transloco/src/lib/transloco-error-code.ts
  • libs/transloco/src/lib/transloco-fallback-strategy.ts
  • libs/transloco/src/lib/transloco-lang.ts
  • libs/transloco/src/lib/transloco-loading-template.ts
  • libs/transloco/src/lib/transloco-missing-handler.ts
  • libs/transloco/src/lib/transloco-scope.ts
  • libs/transloco/src/lib/transloco-testing.module.ts
  • libs/transloco/src/lib/transloco.config.ts
  • libs/transloco/src/lib/transloco.interceptor.ts
  • libs/transloco/src/lib/transloco.loader.ts
  • libs/transloco/src/lib/transloco.service.ts
  • libs/transloco/src/lib/transloco.transpiler.ts

Comment thread libs/transloco/src/lib/transloco-missing-handler.ts
Comment thread libs/transloco/src/lib/transloco.service.ts
Comment thread libs/transloco/src/lib/transloco.transpiler.ts
Comment thread libs/transloco/src/lib/transloco-error-code.ts
Comment thread libs/transloco/src/lib/transloco-fallback-strategy.ts
@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from 701319b to bf2243a Compare April 5, 2026 13:10
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
libs/transloco/src/lib/transloco.service.ts (1)

100-105: ⚠️ Potential issue | 🔴 Critical

Assign the base TranslationLoadError message.

Line 102 evaluates the template literal but never assigns it to message, so non-scope failures still throw with message === '' 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

📥 Commits

Reviewing files that changed from the base of the PR and between 701319b and bf2243a.

📒 Files selected for processing (24)
  • libs/transloco-locale/src/lib/transloco-locale.config.ts
  • libs/transloco-locale/src/lib/transloco-locale.transformers.ts
  • libs/transloco-locale/tsconfig.lib.json
  • libs/transloco-messageformat/src/lib/messageformat.config.ts
  • libs/transloco-messageformat/tsconfig.lib.json
  • libs/transloco-persist-lang/src/lib/persist-lang.config.ts
  • libs/transloco-persist-lang/src/lib/persist-lang.service.ts
  • libs/transloco-persist-lang/tsconfig.lib.json
  • libs/transloco-persist-translations/src/lib/transloco-persist-translations.config.ts
  • libs/transloco-persist-translations/tsconfig.lib.json
  • libs/transloco-preload-langs/src/lib/preload-langs.service.ts
  • libs/transloco-preload-langs/tsconfig.lib.json
  • libs/transloco/src/lib/transloco-error-code.ts
  • libs/transloco/src/lib/transloco-fallback-strategy.ts
  • libs/transloco/src/lib/transloco-lang.ts
  • libs/transloco/src/lib/transloco-loading-template.ts
  • libs/transloco/src/lib/transloco-missing-handler.ts
  • libs/transloco/src/lib/transloco-scope.ts
  • libs/transloco/src/lib/transloco-testing.module.ts
  • libs/transloco/src/lib/transloco.config.ts
  • libs/transloco/src/lib/transloco.interceptor.ts
  • libs/transloco/src/lib/transloco.loader.ts
  • libs/transloco/src/lib/transloco.service.ts
  • libs/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

Comment thread libs/transloco/src/lib/transloco.service.ts
@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from bf2243a to bc5496b Compare April 5, 2026 13:26
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
libs/transloco/src/lib/transloco.transpiler.ts (1)

194-209: ⚠️ Potential issue | 🟡 Minor

Guard the error type before accessing .message.

Line 199 accesses (e as Error).message.includes('NullInjectorError') without verifying that e is actually an Error instance. If a custom transpiler function throws a primitive (string, number) or plain object, this will cause a secondary TypeError that 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

📥 Commits

Reviewing files that changed from the base of the PR and between bf2243a and bc5496b.

📒 Files selected for processing (26)
  • libs/transloco-locale/src/lib/transloco-locale.config.ts
  • libs/transloco-locale/src/lib/transloco-locale.transformers.ts
  • libs/transloco-locale/tsconfig.lib.json
  • libs/transloco-messageformat/src/lib/messageformat.config.ts
  • libs/transloco-messageformat/tsconfig.lib.json
  • libs/transloco-persist-lang/src/lib/persist-lang.config.ts
  • libs/transloco-persist-lang/src/lib/persist-lang.service.ts
  • libs/transloco-persist-lang/tsconfig.lib.json
  • libs/transloco-persist-translations/src/lib/transloco-persist-translations.config.ts
  • libs/transloco-persist-translations/tsconfig.lib.json
  • libs/transloco-preload-langs/src/lib/preload-langs.service.ts
  • libs/transloco-preload-langs/tsconfig.lib.json
  • libs/transloco/src/lib/tests/default-missing-handler.spec.ts
  • libs/transloco/src/lib/tests/service/fallbacks.spec.ts
  • libs/transloco/src/lib/transloco-error-code.ts
  • libs/transloco/src/lib/transloco-fallback-strategy.ts
  • libs/transloco/src/lib/transloco-lang.ts
  • libs/transloco/src/lib/transloco-loading-template.ts
  • libs/transloco/src/lib/transloco-missing-handler.ts
  • libs/transloco/src/lib/transloco-scope.ts
  • libs/transloco/src/lib/transloco-testing.module.ts
  • libs/transloco/src/lib/transloco.config.ts
  • libs/transloco/src/lib/transloco.interceptor.ts
  • libs/transloco/src/lib/transloco.loader.ts
  • libs/transloco/src/lib/transloco.service.ts
  • libs/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

Comment thread libs/transloco/src/lib/transloco.config.ts Outdated
Comment thread libs/transloco-persist-lang/tsconfig.lib.json
Comment thread libs/transloco/src/lib/tests/default-missing-handler.spec.ts
@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from bc5496b to 2790476 Compare April 14, 2026 20:58
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc5496b and 2790476.

📒 Files selected for processing (26)
  • libs/transloco-locale/src/lib/transloco-locale.config.ts
  • libs/transloco-locale/src/lib/transloco-locale.transformers.ts
  • libs/transloco-locale/tsconfig.lib.json
  • libs/transloco-messageformat/src/lib/messageformat.config.ts
  • libs/transloco-messageformat/tsconfig.lib.json
  • libs/transloco-persist-lang/src/lib/persist-lang.config.ts
  • libs/transloco-persist-lang/src/lib/persist-lang.service.ts
  • libs/transloco-persist-lang/tsconfig.lib.json
  • libs/transloco-persist-translations/src/lib/transloco-persist-translations.config.ts
  • libs/transloco-persist-translations/tsconfig.lib.json
  • libs/transloco-preload-langs/src/lib/preload-langs.service.ts
  • libs/transloco-preload-langs/tsconfig.lib.json
  • libs/transloco/src/lib/tests/default-missing-handler.spec.ts
  • libs/transloco/src/lib/tests/service/fallbacks.spec.ts
  • libs/transloco/src/lib/transloco-error-code.ts
  • libs/transloco/src/lib/transloco-fallback-strategy.ts
  • libs/transloco/src/lib/transloco-lang.ts
  • libs/transloco/src/lib/transloco-loading-template.ts
  • libs/transloco/src/lib/transloco-missing-handler.ts
  • libs/transloco/src/lib/transloco-scope.ts
  • libs/transloco/src/lib/transloco-testing.module.ts
  • libs/transloco/src/lib/transloco.config.ts
  • libs/transloco/src/lib/transloco.interceptor.ts
  • libs/transloco/src/lib/transloco.loader.ts
  • libs/transloco/src/lib/transloco.service.ts
  • libs/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

Comment thread libs/transloco/src/lib/tests/service/fallbacks.spec.ts
@arturovt arturovt force-pushed the refactor/tree-shake-errors branch from 2790476 to f056c7d Compare April 14, 2026 21:06
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
libs/transloco/src/lib/transloco.transpiler.ts (1)

195-201: ⚠️ Potential issue | 🟠 Major

Guard unknown error shape before reading .message (Line 199).

catch (e: unknown) still does (e as Error).message.includes(...), which can throw if e is 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 | 🟠 Major

Don’t drop prodMode behavior while the public config still exposes it.

prodMode is still part of TranslocoConfig, but these guards now key only off Angular’s ambient ngDevMode. That changes observable behavior in two places: TranslationLoadError.message becomes runner-dependent when ngDevMode is absent, and prodMode: true no longer suppresses diagnostics in dev builds. Please funnel both checks through the same compatibility predicate until prodMode is fully removed. Tiny i18n fact: i18n is a numeronym—the 18 counts the omitted letters.

This verifies that prodMode is still public while the changed service paths now ignore it; if the concern is valid, you’ll see prodMode in the config/spec and only ngDevMode in 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.ts

Also 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2790476 and f056c7d.

📒 Files selected for processing (26)
  • libs/transloco-locale/src/lib/transloco-locale.config.ts
  • libs/transloco-locale/src/lib/transloco-locale.transformers.ts
  • libs/transloco-locale/tsconfig.lib.json
  • libs/transloco-messageformat/src/lib/messageformat.config.ts
  • libs/transloco-messageformat/tsconfig.lib.json
  • libs/transloco-persist-lang/src/lib/persist-lang.config.ts
  • libs/transloco-persist-lang/src/lib/persist-lang.service.ts
  • libs/transloco-persist-lang/tsconfig.lib.json
  • libs/transloco-persist-translations/src/lib/transloco-persist-translations.config.ts
  • libs/transloco-persist-translations/tsconfig.lib.json
  • libs/transloco-preload-langs/src/lib/preload-langs.service.ts
  • libs/transloco-preload-langs/tsconfig.lib.json
  • libs/transloco/src/lib/tests/default-missing-handler.spec.ts
  • libs/transloco/src/lib/tests/service/fallbacks.spec.ts
  • libs/transloco/src/lib/transloco-error-code.ts
  • libs/transloco/src/lib/transloco-fallback-strategy.ts
  • libs/transloco/src/lib/transloco-lang.ts
  • libs/transloco/src/lib/transloco-loading-template.ts
  • libs/transloco/src/lib/transloco-missing-handler.ts
  • libs/transloco/src/lib/transloco-scope.ts
  • libs/transloco/src/lib/transloco-testing.module.ts
  • libs/transloco/src/lib/transloco.config.ts
  • libs/transloco/src/lib/transloco.interceptor.ts
  • libs/transloco/src/lib/transloco.loader.ts
  • libs/transloco/src/lib/transloco.service.ts
  • libs/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

Comment thread libs/transloco/src/lib/transloco.transpiler.ts
@shaharkazaz shaharkazaz merged commit c6ceb6b into jsverse:master Apr 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants