mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:57:35 +00:00
LibJS: Implement the 'Hashbang Grammar for JS' proposal
Stage 3 since August 2019 - we already have shebang stripping implemented in js(1), so this removes it from there in favor of adding support to the lexer directly. Most straightforward proposal and implementation I've ever seen :^) https://github.com/tc39/proposal-hashbang
This commit is contained in:
parent
299c3069c1
commit
597cf88c08
3 changed files with 14 additions and 28 deletions
|
@ -308,7 +308,9 @@ bool Lexer::is_line_comment_start(bool line_has_token_yet) const
|
|||
// "-->" is considered a line comment start if the current line is only whitespace and/or
|
||||
// other block comment(s); or in other words: the current line does not have a token or
|
||||
// ongoing line comment yet
|
||||
|| (match('-', '-', '>') && !line_has_token_yet);
|
||||
|| (match('-', '-', '>') && !line_has_token_yet)
|
||||
// https://tc39.es/proposal-hashbang/out.html#sec-updated-syntax
|
||||
|| (match('#', '!') && m_position == 1);
|
||||
}
|
||||
|
||||
bool Lexer::is_block_comment_start() const
|
||||
|
|
|
@ -33,3 +33,12 @@ test("unterminated multi-line comment", () => {
|
|||
expect("/* foo").not.toEval();
|
||||
expect("foo /*").not.toEval();
|
||||
});
|
||||
|
||||
test("hashbang comments", () => {
|
||||
expect("#!").toEvalTo(undefined);
|
||||
expect("#!/bin/js").toEvalTo(undefined);
|
||||
expect("#!\n1").toEvalTo(1);
|
||||
expect(" #!").not.toEval();
|
||||
expect("\n#!").not.toEval();
|
||||
expect("#!\n#!").not.toEval();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue