-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Support 'shebang' ( #!/usr/bin/boa ) #1555
Comments
For anyone who wants to tackle this. The pertinent code is in: boa/boa/src/syntax/lexer/mod.rs Lines 106 to 114 in 08f232f
Ideally we would eagerly try to match "#!" with the lexer and, if it does match, jump to the next line. You can see an example on how to do this in the boa/boa/src/syntax/lexer/comment.rs Lines 23 to 47 in 8f590d7
However, if implementing the logic inside boa/boa/src/syntax/lexer/mod.rs Lines 176 to 286 in 08f232f
matching for "#!" but only if |
I don't think we should change the parser or the lexer. "shebang" is no valid JS, and I don't think our engine should treat it as a "comment". Our engine could be executing JS from any input, and we must be spec compliant. But, I see the benefit of having this in the Boa executable when providing a file as the input source. I would just change the way this executable works by checking if the first line is a shebang. If it is, then remove that first line from the input sent to the engine. This would make the executable compatible with this, but the engine would only accept valid JS. |
Ah, then just skipping directly the Lines 94 to 97 in 26e1497
here: Lines 818 to 842 in f9a82b4
and here: Lines 784 to 802 in f9a82b4
we would need to skip the first bytes of |
I think it's even better if we do the change only in |
I thought of that, but then a user downloading a js script from some page and using boa as an interpreter in some Rust application would fail, wouldn't it? I think that's not ideal, and I wouldn't want to force the user to manage the shebang manually when making a simple check and skip should be easy for us. |
I think that is out of the scope of our engine. We have a JS engine that must only accept spec compliant strings. Then, we provide a CLI tool that we can customize to allow for a particular use case that makes sense. If someone else wants to use our engine in their tool and allow for this, I guess they should add the specific support they need. In the case we want to really change the engine, this should be an optional, opt-in feature. |
I'd agree if it weren't for the fact that Firefox and Chrome support the shebang on their engines. Also, I think importing a module that has a shebang at the beginning would break, even if the user is just using |
OK, then let's add it as an optional, opt-in feature :) |
Uhm, change of plans. |
I can try to take a crack at this one if it still needs to be done. Since there seemed to be some discussion, is there a preferred place to do this (boa-cli vs. lexing and parsing). |
Originally we were going to implement it on boa-cli, but seeing the spec will change to support it in the language grammar, it must be done on the lexer/parser |
I made a Pull Request for the attempt I put together. It does catch the Hashbang off my example file from what I can tell. Not sure if there's anymore functionality that should be/needs to be built for it though. Currently, it treats the Hashbang like a TokenKind::Comment and moves the lexer onto the next token. |
Feature
Support - that is ignore - the unix shebang, e.g.
#!/usr/bin/boa
This is something nodejs and deno both do: they just ignore the unix-style shebang, and this is sometimes required to execute scripts written for either.
Example code
The text was updated successfully, but these errors were encountered: