Skip to content

Commit

Permalink
Support hashbang (mozilla#1417)
Browse files Browse the repository at this point in the history
Support hashbang syntax at the start of a script
  • Loading branch information
p-bakker authored and rbri committed Nov 10, 2023
1 parent 385e382 commit a024bea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/org/mozilla/javascript/TokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,15 @@ final int getToken() throws IOException {
return Token.STRING;
}

if (c == '#'
&& cursor == 1
&& peekChar() == '!'
&& !this.parser.calledByCompileFunction) {
// #! hashbang: only on the first line of a Script, no leading whitespace
skipLine();
return Token.COMMENT;
}

switch (c) {
case ';':
return Token.SEMI;
Expand Down
1 change: 0 additions & 1 deletion testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public class Test262SuiteTest {
"String.prototype.matchAll",
"Symbol.matchAll",
"tail-call-optimization",
"hashbang",
"u180e"));

static {
Expand Down
5 changes: 3 additions & 2 deletions testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2762,8 +2762,9 @@ language/block-scope 68/145 (46.9%)
syntax/redeclaration/var-redeclaration-attempt-after-function.js
syntax/redeclaration/var-redeclaration-attempt-after-generator.js

language/comments 36/52 (69.23%)
hashbang 29/29 (100.0%)
language/comments 9/52 (17.31%)
hashbang/function-constructor.js
hashbang/module.js {unsupported: [module]}
mongolian-vowel-separator-multi.js {unsupported: [u180e]}
mongolian-vowel-separator-single.js {unsupported: [u180e]}
mongolian-vowel-separator-single-eval.js {unsupported: [u180e]}
Expand Down

0 comments on commit a024bea

Please sign in to comment.