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

[BUG] Spread operator in script causing "unexpected token ..." compiler error #2700

Closed
1 of 7 tasks
lxndrdagreat opened this issue Jun 4, 2019 · 2 comments
Closed
1 of 7 tasks
Labels

Comments

@lxndrdagreat
Copy link

Help us to manage our issues by answering the following:

  1. Describe your issue:

When using the spread operator in my tag's script block, I get an error when compiling:

description: "Unexpected token ..."
index: 290
lineNumber: 21
column: 11
__proto__: Error: Line 21: Unexpected token ... at e.constructError (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:287660) at e.createError (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:287860) at e.unexpectedTokenError (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:225276) at e.throwUnexpectedToken (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:225480) at e.parseObjectPropertyKey (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:235331) at e.parseObjectProperty (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:235971) at e.parseObjectInitializer (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:237376) at e.inheritCoverGrammar (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:230191) at e.parsePrimaryExpression (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:232004) at e.inheritCoverGrammar (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:230191)
message: "Line 21: Unexpected token ..."
stack: "Error: Line 21: Unexpected token ...↵    at e.constructError (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:287660)↵    at e.createError (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:287860)↵    at e.unexpectedTokenError (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:225276)↵    at e.throwUnexpectedToken (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:225480)↵    at e.parseObjectPropertyKey (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:235331)↵    at e.parseObjectProperty (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:235971)↵    at e.parseObjectInitializer (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:237376)↵    at e.inheritCoverGrammar (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:230191)↵    at e.parsePrimaryExpression (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:232004)↵    at e.inheritCoverGrammar (https://cdn.jsdelivr.net/npm/riot@4/riot+compiler.min.js:1:230191)"
__proto__: Object
  1. Can you reproduce the issue?

Reproduce by using the spread operator on objects within the script block for the tag:

onBeforeMount(props, state) {
        const data = {
          alpha: 'a',
          beta: 'b',
          gamma: 'g'
        };
        const data2 = {
          delta: 'd',
          epsilon: 'e'
        };
        
        // The use of spread here will cause the error.
        const allData = {
          ... data,
          ... data2
        };
      }

Plunkr example of the bug

  1. On which browser/OS does the issue appear?

I'm compiling tags via the rollup plugin (on Windows), but I have also been able to reproduce with the browser compiler (seen in example above). My stack is Gulp, Rollup, the Riot Rollup plugin, and the Babel Rollup plugin.

  1. Which version of Riot does it affect?

Riot 4

  1. How would you tag this issue?
  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
@GianlucaGuarini
Copy link
Member

It's an esprima issue that is used in the @riotjs/compiler thank you for reporting it. I am on it and I will fix it asap

@GianlucaGuarini
Copy link
Member

Fixed in Riot.js@4.0.5 https://next.plnkr.co/edit/Y12fBchgsdW5RgQU thank you!

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

No branches or pull requests

2 participants