-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Comments
It's invalid JavaScript, so you have to strip that comment before parsing (that's what ESLint does). |
@nzakas - yeah, that's exactly what I stated. It would still be nice to not have to have a pre-process to do that. |
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 |
@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. |
It seems like we probably need the special logic anyway for parsers that don't support the option. |
There is a stage 3 proposal to support hashbangs in the language, should this issue be re-opened? |
Proposal reached stage 4, so it will eventually be in acorn (acornjs/acorn#1134). |
This is now supported in espree v9.4.0 with |
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.
The text was updated successfully, but these errors were encountered: