From dd456e3ad52de2ffbeca9866f02d0f0f09c56ab8 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 11 Nov 2013 11:25:59 +0100 Subject: [PATCH] Fix bug causing comments after 'use strict' to be handled twice Closes #76 --- acorn.js | 2 +- index.html | 2 +- test/tests.js | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/acorn.js b/acorn.js index 0f525ee3a5..e03f6f2e2e 100644 --- a/acorn.js +++ b/acorn.js @@ -976,7 +976,7 @@ function setStrict(strct) { strict = strct; - tokPos = lastEnd; + tokPos = tokStart; if (options.locations) { while (tokPos < tokLineStart) { tokLineStart = input.lastIndexOf("\n", tokLineStart - 2) + 1; diff --git a/index.html b/index.html index 18d4291ef6..8b53efce15 100644 --- a/index.html +++ b/index.html @@ -697,7 +697,7 @@ precedence levels that JavaScript defines.

}

Enter strict mode. Re-reads the next token to please pedantic tests ("use strict"; 010; -- should fail).

  function setStrict(strct) {
     strict = strct;
-    tokPos = lastEnd;
+    tokPos = tokStart;
     if (options.locations) {
       while (tokPos < tokLineStart) {
         tokLineStart = input.lastIndexOf("\n", tokLineStart - 2) + 1;
diff --git a/test/tests.js b/test/tests.js
index c9a080eef0..efce0b4122 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -26956,3 +26956,10 @@ testFail("throw\n10;", "Illegal newline after throw (1:5)");
     }
   );
 })();
+
+(function() {
+  var comments = 0;
+  testAssert("\nfunction plop() {\n'use strict';\n/* Comment */\n}", function() {
+    if (comments != 1) return "Comment after strict counted twice.";
+  }, {onComment: function() {++comments;}});
+})();