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

Unexpected character '#' #283

Closed
coreybutler opened this issue Jul 14, 2016 · 8 comments
Closed

Unexpected character '#' #283

coreybutler opened this issue Jul 14, 2016 · 8 comments
Labels

Comments

@coreybutler
Copy link

I know it's probably not the intended use, but I was trying to parse a node file with this and received this error. The node script is designed to be a command line tool, and espree is complaining about the shebang (#!/usr/bin/env node).

Stack Trace:

SyntaxError: Unexpected character '#'
    at Parser.instance.raise.instance.raiseRecoverable (node_modules/espree/espree.js:390:19)
    at Parser.pp.getTokenFromCode (node_modules/acorn/dist/acorn.js:2831:8)
    at Parser.pp.readToken (node_modules/acorn/dist/acorn.js:2526:15)
    at Parser.pp.nextToken (node_modules/acorn/dist/acorn.js:2518:71)
    at Parser.parse (node_modules/acorn/dist/acorn.js:1631:10)
    at Object.parse (node_modules/acorn/dist/acorn.js:885:44)
    at Object.parse (node_modules/espree/espree.js:715:21)

This is pretty easily fixed by stripping the first line out, but it requires an extra pre-processing step. It'd be nice to either throw a warning or ignore these (or both) without crashing the process.

@nzakas
Copy link
Member

nzakas commented Jul 15, 2016

It's invalid JavaScript, so you have to strip that comment before parsing (that's what ESLint does).

@nzakas nzakas closed this as completed Jul 15, 2016
@coreybutler
Copy link
Author

@nzakas - yeah, that's exactly what I stated. It would still be nice to not have to have a pre-process to do that.

@walshie4
Copy link

walshie4 commented Apr 8, 2019

FWIW it looks like acorn supports skipping this. You'll just need to make sure this option gets passed in - https://github.com/acornjs/acorn/blob/dfcdbe4014cee1996129a8275bae28380cccd20c/acorn/src/state.js#L78

@platinumazure
Copy link
Member

@eslint/eslint-team What do you think about this comment? On the one hand it doesn't seem critical to implement, but on the other hand, we could dogfood it in ESLint and get rid of some special logic.

@not-an-aardvark
Copy link
Member

It seems like we probably need the special logic anyway for parsers that don't support the option.

@silverwind
Copy link

There is a stage 3 proposal to support hashbangs in the language, should this issue be re-opened?

@silverwind
Copy link

Proposal reached stage 4, so it will eventually be in acorn (acornjs/acorn#1134).

@mdjermanovic
Copy link
Member

This is now supported in espree v9.4.0 with ecmaVersion: 2023.

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

8 participants