-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
i18next-scanner optional chaining throwing error #178
Comments
Related to acornjs/acorn#891 So far the only way is to replace Acorn with Babel. |
We had a similar problem, however it seems to be a issue with trans components only. It's working fine for functions. You don't really need optional chaining for the trans components in order to get the translations, so we did a workaround that replaces the optional chaining for trans components. Create a customTransform where you handle trans components. // removes optional chaining const transOptions = { component: 'Trans', i18nKey: 'i18nKey', defaultsKey: 'defaults' }; parser.parseTransFromString(transContent, transOptions, (key, value) => { |
here is complete transform function based on @krini comment transform: function transform(file, enc, done) {
const parser = this.parser;
let content = fs.readFileSync(file.path, enc);
const regex = /\?\.\[/g;
let transContent = content.replace(regex, '[');
const regex1 = /\?\./g;
transContent = transContent.replace(regex1, '.');
console.log(transContent)
const transOptions = { component: 'Trans', i18nKey: 'i18nKey', defaultsKey: 'defaults' };
parser.parseTransFromString(transContent, transOptions, (key, value) => {
parser.set(key || value.defaultValue, value.defaultValue);
});
done();
} |
@cheton The AcronJS optional chaining support landed few days back. Do you think this issue can be addressed now. |
@cheton Extremely sorry. This is by no means meant to bother you. I think you might be busy with other stuff. If you have some time to just provide some pointers on how to move ahead, i think i can work on this on my free time. |
I tried as you said, but the error is still exsit. Can you give me some help? My "i18next-scanner-config.js" is as follows:
|
3/3-21 I'm running the scanner with
In my options trans is set to false because it is transformed in customTransform
|
I had the same problem which is resolved since I've updated to 3.0.0. As you can read in the release notes: "Update Acorn to 8.0 to support new syntax features" Could someone else confirm that the update resolves the problem? If so please close this issue. |
The problem is also resovled for me after updated to 3.0.0 and modify the
|
@austinhc-ibm I can confirm that updating the 18next-scanner to latest 3.0.0 will ensure that the scanner can handle modern JS when parsing Trans components. |
I can also confirm this works fine.
|
Hello,
We were trying optional chaining in our code but it seems the i18next-scanner does not like the syntax. Any suggestions how to work around this temporarily or is there an easy fix?
Kind regards
Version
Error
i18next-scanner: Unable to parse Trans component from src\app.jsx
SyntaxError: Unexpected token (28:19)
Code it crashes on:
`
const test = null;
console.log(test?.name);
`
The text was updated successfully, but these errors were encountered: