From a024bea6b4498c1e5dd8c1614932ef3d901c8804 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 9 Nov 2023 17:20:54 +0100 Subject: [PATCH] Support hashbang (#1417) Support hashbang syntax at the start of a script --- src/org/mozilla/javascript/TokenStream.java | 9 +++++++++ .../org/mozilla/javascript/tests/Test262SuiteTest.java | 1 - testsrc/test262.properties | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/org/mozilla/javascript/TokenStream.java b/src/org/mozilla/javascript/TokenStream.java index 15ad0ae5a0..2e5292d5ba 100644 --- a/src/org/mozilla/javascript/TokenStream.java +++ b/src/org/mozilla/javascript/TokenStream.java @@ -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; diff --git a/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java b/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java index 6c6e9e4be7..61c2e6c8eb 100644 --- a/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java +++ b/testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java @@ -111,7 +111,6 @@ public class Test262SuiteTest { "String.prototype.matchAll", "Symbol.matchAll", "tail-call-optimization", - "hashbang", "u180e")); static { diff --git a/testsrc/test262.properties b/testsrc/test262.properties index b381849907..fccf6b8a1e 100644 --- a/testsrc/test262.properties +++ b/testsrc/test262.properties @@ -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]}