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

When Plato is parsing Javascript that is using the elvis operator '?' it throws exceptions #116

Open
IcodeNet opened this issue Jan 28, 2021 · 9 comments

Comments

@IcodeNet
Copy link

IcodeNet commented Jan 28, 2021

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

@cxn-mkalinovits
Copy link

Do you have any luck with this?

@Nantris
Copy link

Nantris commented Jun 1, 2021

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.

@the-simian
Copy link
Owner

@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

@the-simian
Copy link
Owner

could be related to #108 , which was also about the "elvis operator"/ optional chaning

@Nantris
Copy link

Nantris commented Jun 2, 2021

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.

@the-simian
Copy link
Owner

@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.

@Nantris
Copy link

Nantris commented Jun 2, 2021

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 Webpack@5.x 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.

@Nantris
Copy link

Nantris commented Jun 14, 2021

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.

@niefz
Copy link

niefz commented Oct 21, 2022

I fixed by replace "typhonjs-escomplex": "0.0.12" with "typhonjs-escomplex": "0.1.0". @slapbox

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

5 participants