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

Lexer: SyntaxError: unexpected nonexistent ( #4283

Closed
1j01 opened this issue Jul 16, 2016 · 6 comments
Closed

Lexer: SyntaxError: unexpected nonexistent ( #4283

1j01 opened this issue Jul 16, 2016 · 6 comments

Comments

@1j01
Copy link

1j01 commented Jul 16, 2016

When missing a comma in an object literal, you get SyntaxError: unexpected ( even though there's no parentheses.

console.log {search, users, contacts users_to_display}

From what I know of how CoffeeScript works, it's inserting a parenthesis for a function call to contacts making for the terrible error message.
(So I ended up looking for an extra parenthesis somewhere in some file.)

This is fixed in redux. Is there a path for fixing problems like this that come from the rewriter?

@lydell
Copy link
Collaborator

lydell commented Jul 16, 2016

$ node -p 'require("coffee-script").tokens("{f a}")'
[ [ '{',
    '{',
    { first_line: 0, first_column: 0, last_line: 0, last_column: 0 } ],
  [ 'IDENTIFIER',
    'f',
    { first_line: 0, first_column: 1, last_line: 0, last_column: 1 },
    variable: true,
    spaced: true ],
  [ 'CALL_START',
    '(',
    { first_line: 0, first_column: 1, last_line: 0, last_column: 1 },
    generated: true ],
  [ 'IDENTIFIER',
    'a',
    { first_line: 0, first_column: 3, last_line: 0, last_column: 3 },
    variable: true ],
  [ 'CALL_END',
    ')',
    { first_line: 0, first_column: 3, last_line: 0, last_column: 3 },
    generated: true,
    origin: [ '', 'end of input', [Object] ] ],
  [ '}',
    '}',
    { first_line: 0, first_column: 4, last_line: 0, last_column: 4 } ],
  [ 'TERMINATOR',
    '\n',
    { first_line: 0, first_column: 5, last_line: 0, last_column: 5 } ] ]

The generate: true bit tells us that the ( has been generated by CoffeeScript, by the rewriter.

My guess is that the token comes from here. Passing the origin parameter to the generate function on that line (just like it is done a few lines further down) might be the solution.

@anodynos
Copy link

anodynos commented Jul 16, 2016

This code console.log {search, users, contacts users_to_display} isnt valid - what would it transpile to console.log({search: search, users: users, ?????}); ?

The console.log {search, users, contacts: contacts users_to_display} works as expected.

@1j01
Copy link
Author

1j01 commented Jul 17, 2016

@anodynos Yes, the code has a syntax error. The issue is with the error message.
The correct code would be console.log {search, users, contacts, users_to_display} (a very useful pattern when logging several things)

@vendethiel
Copy link
Collaborator

@lydell yes, that seems to be the solution

@yyny
Copy link

yyny commented Oct 15, 2016

@1j01 The error message actually comes from CoffeeScript right, not the compiled JavaScript? (For anyone not able to test it themselves, if this issue is still not fixed)

@1j01
Copy link
Author

1j01 commented Oct 15, 2016

@YoYoYonnY Yes, it's from CoffeeScript.

C:\Users\Isaiah>coffee -v
CoffeeScript version 1.11.1

C:\Users\Isaiah>coffee -e "console.log {search, users, contacts users_to_display}"
[stdin]:1:36: error: unexpected (
console.log {search, users, contacts users_to_display}
                                   ^

@GeoffreyBooth GeoffreyBooth changed the title SyntaxError: unexpected nonexistent ( Lexer: SyntaxError: unexpected nonexistent ( May 6, 2017
helixbass added a commit to helixbass/copheescript that referenced this issue Jun 25, 2017
lydell added a commit that referenced this issue Jun 26, 2017
…t_call

Fix #4283: error message for implicit call
@lydell lydell added the fixed label Jun 26, 2017
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

6 participants