i18next-scanner icon indicating copy to clipboard operation
i18next-scanner copied to clipboard

Unable to parse classes with decorators

Open AStoker opened this issue 4 years ago • 5 comments

Version

  • i18next: 11.10.2
  • i18next-scanner: 2.10.3

Configuration

{
            sort: true,
            removeUnusedKeys: true,
            defaultValue: '__NEEDS_TRANSLATION__',
            lngs: ["en", "es", "fr", "pt"],
            attr: {
                list: ['i18n', 't']
            },
            func: {
                list: ['this.i18n.tr', 'i18n.tr']
            },
            ns: ["translation", "settings"],
            defaultNs: "translation",
            resource: {
                loadPath: '../../locales/{{lng}}/{{ns}}.json',
                savePath: '{{lng}}/toTranslate_{{ns}}.json'
            }
}

I have a simple aurelia application (framework doesn't matter) that uses a decorator on a class to do dependency injection.

...
@inject(I18N)
class App {
   constructor(i18n) {
      this.i18n = i18n;
   }
}

When this file is scanned, I get an error (the '@' symbol on line 20 is the decorator):

i18next-scanner: Unable to parse Trans component from "E:\\WebApplication\\src\\app.js"
    SyntaxError: Unexpected character '@' (20:0)

This used to work just fine back in version 2.9.2, but since 2.10.0 every version has this kind of problem. I am expecting the scanner to still be able to scan these files.

AStoker avatar Feb 17 '20 20:02 AStoker

Hello, I also encountered the same problem, do you have a solution?

moweiwei avatar Apr 24 '20 07:04 moweiwei

Nope, I've had to revert back to a previous version to get this to work. Just locked it to that specific version.

AStoker avatar Apr 29 '20 13:04 AStoker

Hi, I've just tried to do this and have the same problem, also installed 2.9,2 instead of 4.0.0 and still have problem with decorators. I used to do this as well.

Is there a way to get acorn to use an es7 plugin so that it parses @ or a way to skip them through some added function? I'd love to be able to use this.

madwill avatar Jul 11 '22 20:07 madwill

Hi, I've just tried to do this and have the same problem, also installed 2.9,2 instead of 4.0.0 and still have problem with decorators. I used to do this as well.

Is there a way to get acorn to use an es7 plugin so that it parses @ or a way to skip them through some added function? I'd love to be able to use this.

I have the same problem. Asking chatgpt3.5 for help also failed to solve the problem. Thank you very much.

xsfxtsxxr avatar Dec 13 '23 16:12 xsfxtsxxr

Any ideas how to solve this?

stoefln avatar Feb 19 '24 12:02 stoefln