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

Template string variables in JSX raises "Unexpected token ILLEGAL" #95

Closed
BenoitZugmeyer opened this issue Mar 14, 2015 · 25 comments
Closed

Comments

@BenoitZugmeyer
Copy link

This is a regression from espree 0.12.0.

var espree = require('espree');

espree.parse('<foo bar={`${baz}`} />', {
    ecmaFeatures: {
        templateStrings: true,
        jsx: true
    }
});
// Raises: Unexpected token ILLEGAL

The same code without ${baz} is OK

@nzakas
Copy link
Member

nzakas commented Mar 14, 2015

Must have to do with the template string changes.

Just so we're clear, you're saying this is a regression from v1.11.0 that you found in v1.12.0?

@BenoitZugmeyer
Copy link
Author

Oh, yes it is (I mixed up version numbers)

@lencioni
Copy link
Contributor

Sometimes I also see messages like:

182  -1  error  Unexpected quasi
     myProp={

In cases where I am using ES6 template strings in props as well. Not sure if that is the same problem or not. Let me know if you'd like me to open another issue.

@mikesherov
Copy link

@nzakas let me know what you find. My guess is missing curlyStack pop push inside JSX expressions.

@nzakas
Copy link
Member

nzakas commented Mar 19, 2015

Related: jquery/esprima#1145

@mikesherov
Copy link

@lencioni

182  -1  error  Unexpected quasi
     myProp={

Can you provide an actual code snippet that exhibits this bug?

@kentor
Copy link

kentor commented Mar 19, 2015

Hey I'm having this problem as well, and it's breaking my CI build :)

This will reproduce the Unexpected quasi error:

<a>{`${1}`}{``}</a>
  1:11  error  Unexpected quasi {

@mikesherov
Copy link

@nzakas you should be able to take my patch and see if it fixes @kentor 's issue.

@nzakas
Copy link
Member

nzakas commented Mar 19, 2015

Yup. Since we have lookahead2(), I'm anticipating that will do it. Just don't have the time to dig in yet.

@lencioni
Copy link
Contributor

@mikesherov here's a simplified repro case for the Unexpected quasi:

const React = require('react/addons');

const MyComponent = React.createClass({
  render: function() {
    return (
      <div>
        <div myProp={`${this.props.something}`}/>
        <div differentProp={`${this.props.anotherThing}`}/>
      </div>
    );
  }
});

module.exports = MyComponent;

@mikesherov
Copy link

jquery/esprima#1145 has landed with some additional perf improvements.

@nzakas
Copy link
Member

nzakas commented Mar 21, 2015

Working on this.

@nzakas
Copy link
Member

nzakas commented Mar 21, 2015

@mikesherov Yup, these fixes fixed all the issues mentioned in this issue.

@nzakas nzakas closed this as completed in d02deed Mar 21, 2015
nzakas added a commit that referenced this issue Mar 21, 2015
Fix: Template string parsing (fixes #95)
@eprouty
Copy link

eprouty commented May 27, 2015

I just ran npm install eslint@latest and have a .eslintrc that has this in it.

ecmaFeatures": {
    "templateStrings": true,
    "jsx": true
}

But when linting a .jsx file that has the follow line in it <form action='/round', method='POST',role='form'> I get this output...

  8:34  error  Unexpected token ,

✖ 1 problem (1 error, 0 warnings)

Am I missing something needed to get your fixes working @nzakas?

@xjamundx
Copy link
Contributor

I'm not super sharp, but isn't that invalid code?

<form action='/round', method='POST',role='form'>

I got a similar error when putting this through the babel (jsx-compatible) repl:
https://babeljs.io/repl/#?experimental=true&evaluate=true&loose=false&spec=false&playground=false&code=%3Cform%20action%3D'%2Fround'%2C%20method%3D'POST'%2Crole%3D'form'%3E

And from the command-line jsx compiler:

~/dev/eslint (empty-strings) $ jsx test.jsx
Error while reading module test.jsx:
Error: Parse Error: Line 1: Unexpected token ,
    at throwError (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2644:21)
    at throwUnexpected (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:2706:9)
    at parseXJSIdentifier (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:6807:13)
    at parseXJSAttributeName (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:6852:16)
    at parseXJSAttribute (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:6939:16)
    at parseXJSOpeningElement (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:6996:29)
    at parseXJSElement (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:7021:26)
    at parsePrimaryExpression (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:3352:20)
    at parseLeftHandSideExpressionAllowCall (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:3436:61)
    at parsePostfixExpression (/usr/local/lib/node_modules/react-tools/node_modules/jstransform/node_modules/esprima-fb/esprima.js:3476:20)

@eprouty
Copy link

eprouty commented May 27, 2015

Hah, you are correct, that actually was an unexpected token... there shouldn't a , there. Silly mistake on my part.

Also means this linter is working correctly and I was being obstinate! Thanks, and nice work.

@rastalamm
Copy link

Is this fixed?

I am getting a Parsing Error: unexpected token ILLEGAL on the $

`${apiHost}/users/${user.id}/cart`

@nzakas
Copy link
Member

nzakas commented Nov 14, 2015

The issue is still open, so it's not fixed yet.

@ilyavolodin
Copy link
Member

@nzakas This issue is actually closed. It looks like the fix didn't catch all of the cases, or @rastalamm is using an older version without the fix.

@mikesherov
Copy link

@rastalamm, what version are you using? And what is the complete JS you're trying to parse?

@rastalamm
Copy link

@ilyavolodin - I thought the issue was closed!

I ran npm install -g eslint & npm install -g eslint@latest and using version 2.14.7

@rastalamm
Copy link

@mikesherov

function getUserCart(req, ignore, next) {
        var user = req.user;
        request.get(`${apiHost}/carts?user_id=${user.id}`, {json: true}, function (err, httpResponse, cart) {
            if (httpResponse.statusCode === 200) {
                req.cart = cart.CartItems;
            }
            next();
        });
    }

@rastalamm
Copy link

So you guys can actually ignore this!! I am posting on the wrong thread! (Its been a long week)

I was having the issue with the npm package eslint and just noticed this is for espree..

Sorry about that!

@mikesherov
Copy link

You'll wind up back here though. Eslint uses espree

@mikesherov
Copy link

I'll see if this is a bug in latest Esprima. @nzakas I suggest you check this in acorn if you're switching soon anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants