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

Bug: keys not extracted from typescript files after an explicit coercion expression #192

Closed
1 task done
dalyl-zero opened this issue Apr 19, 2024 · 2 comments
Closed
1 task done

Comments

@dalyl-zero
Copy link

dalyl-zero commented Apr 19, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is this a regression?

Yes

Current behavior

Strings passed to a translate call that follow a coercion expression or some other expression containing <> are not extracted.

import {Component} from "@angular/core";
import {translate} from "@jsverse/transloco";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})
export class AppComponent {
  constructor() {
    translate("This first key will be extracted");
  }

  getString(): string
  {
    return "5";
  }

  extractionProblem(): void
  {
    translate("This second key will be extracted");
    const foo = <string>this.getString();
    translate("This third key will NOT be extracted");
  }
}

Expected behavior

All strings should be extracted

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/~/github.com/dalyl-zero/transloco-bug-report

Transloco Config

No response

Debug Logs

No response

Please provide the environment you discovered this bug in

Transloco: 7.1.0
Transloco Keys Manager: 4.1.0
Angular: 17.3.0
Node: 18.13.0
Package Manager: 
OS: Windows/Mac

Additional context

This does not happen on transloco-keys-manager 3.8.0 and is independent of the version of Transloco

I would like to make a pull request for this bug

No

@dalyl-zero dalyl-zero changed the title Bug: keys not extracted from typescript files after explicit coercion expression Bug: keys not extracted from typescript files after an explicit coercion expression Apr 19, 2024
@IvanoAlvino
Copy link

Also stumbled upon this issue!
It is very sneaky, it ignores the remaining part of the file from key extractor perspective, with no clear errors so it can be overlooked very easily.

@shaharkazaz
Copy link
Collaborator

The issue was that the TypeScript prefix cast operator, the AST thinks this is a JSX element, and that's also the original reason why the as operator was introduced back in v1.6.
Nice catch 👍

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

No branches or pull requests

3 participants