es6-plato
es6-plato copied to clipboard
When Plato is parsing Javascript that is using the elvis operator '?' it throws exceptions
return nounDict[freq?.toLowerCase()];
the following javascript cannot be parsed. I will try an update the packages to the latest versions.
I have the feeling it will fix it.
ta
Do you have any luck with this?
Works for us under ESLint rules:
.eslintrc.js
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021,
allowImportExportEverywhere: true,
ecmaFeatures: {
jsx: true,
impliedStrict: true,
},
},
and it might also be necessary to update your babel.config.js or equivalent file. I'm guessing the Babel parser is automatically using that file.
babel.config.js
"plugins": [
"@babel/plugin-proposal-optional-chaining",
]
Technically that ? is called the optional chaining operator.
If that doesn't do the trick I can look through our config a bit more to try to figure out if there's something we've added to handle this.
@IcodeNet did @Slapbox 's fix work? I am considering closing this one if its actually ok. If I don't hear back I'll assume its ok afterall
could be related to #108 , which was also about the "elvis operator"/ optional chaning
I've added a bit to that proposed remedy. I'm guessing that the babel.config.js file is utilized by the Babel parser, so be sure you have the @babel/plugin-proposal-optional-chaining installed and in your Babel config.
Whatever the issue, something in our config definitely fixes it and I'm happy to help anyone get it working.
The only thing in our codebase that really trips the parser up is that we use top level await.
@Slapbox are you using rollup with that, or webpack 5? For a long time top level wasn't really worth supporting because even if you parsed it, couldn't use it. Decorators have also had a tumultuous history as well.
Webpack 5 here. Honestly it's still kind of a pain even for us, but less painful than writing self-executing async functions.
There's no way they were worth using before this year. You probably already know that [email protected] supports them via its "experiments.".
Strangely, for all the errors ES6-Plato throws while parsing code containing top level awaits, it still seems to complete fine. I need to check the output for one of those specific files when I can though and report back. We only use top-level in a couple files.
Hmmm... Our "fix" may not actually work. Looks like it still fails to parse those files. I'm honestly not sure how I could have overlooked it, but I can't get it working by moving backwards in our commit history so I have to assume human error here.
I fixed by replace "typhonjs-escomplex": "0.0.12" with "typhonjs-escomplex": "0.1.0". @Slapbox