JPeer264 / node-rename-css-selectors

📝 Rename css classes and id's in files
MIT License
65 stars 9 forks source link

Unexpected token ... #16

Closed klimashkin closed 6 years ago

klimashkin commented 6 years ago

Seems it fails on javascript files that use object rest/spread.

[23:46:18] Error: Line 1: Unexpected token ...
  at ErrorHandler.constructError (/node_modules/recast/node_modules/esprima/dist/esprima.js:5004:22)
  at ErrorHandler.createError (/node_modules/recast/node_modules/esprima/dist/esprima.js:5020:27)
  at JSXParser.Parser.unexpectedTokenError (/node_modules/recast/node_modules/esprima/dist/esprima.js:1985:39)
  at JSXParser.Parser.throwUnexpectedToken (/node_modules/recast/node_modules/esprima/dist/esprima.js:1995:21)
  at JSXParser.Parser.parseObjectPropertyKey (/node_modules/recast/node_modules/esprima/dist/esprima.js:2492:33)
  at JSXParser.Parser.parseObjectProperty (/node_modules/recast/node_modules/esprima/dist/esprima.js:2527:25)
  at JSXParser.Parser.parseObjectInitializer (/node_modules/recast/node_modules/esprima/dist/esprima.js:2595:35)
  at JSXParser.Parser.inheritCoverGrammar (/node_modules/recast/node_modules/esprima/dist/esprima.js:2278:37)
  at JSXParser.Parser.parsePrimaryExpression (/node_modules/recast/node_modules/esprima/dist/esprima.js:2347:38)
  at JSXParser.parsePrimaryExpression (/node_modules/recast/node_modules/esprima/dist/esprima.js:466:97)

Espree can be updated to version 4, or to fix that in espree 3, option experimentalObjectRestSpread: true can be passed

klimashkin commented 6 years ago

In general it would be great to have a way to pass options from processJs to espree directly (add some espreeOptions param), because sometimes we want to stop transpiling some ES20XX features without waiting for a whole ES20XX spec to be finalized, as browsers start supporting it

JPeer264 commented 6 years ago

@klimashkin thanks for your issue. Oh yes passing the options to espree directly would be great indeed. I will work on that as soon as I have time 👍

klimashkin commented 6 years ago

Probably as a fast fix you could release minor update of node-rcs-core that will require espree as ^4.0.0-rc.0 || ^4.0.0. Spec will not be changing and seems like they just wait it to be published to bump final 4.0.0

JPeer264 commented 6 years ago

The problem is, I just checked, I am not using espree (it was accidentally in the dependencies). I use recast which is using esprima under the hood. I now have to think about the solution right now, as I can switch the parsers from recast. I hope I will find a general solution

klimashkin commented 6 years ago

Oh, my bad, I was sure I saw espree in the source. I think problem with esprima is that it's jquery project that is not really maintained anymore. espree is better because it uses acorn, which is being developed pretty good.

JPeer264 commented 6 years ago

Yap, I thought about the same. I think espree is the way to go.

JPeer264 commented 6 years ago

With v2.0.0 it should be fixed, and your options are now added. For that, please check out the parserOptions.

klimashkin commented 6 years ago

Awesome, it works! Thank you!