From f3e759cd03e575239b521a577d53ca8d6c400c64 Mon Sep 17 00:00:00 2001 From: r-e-d Date: Tue, 30 Sep 2014 10:58:21 +0200 Subject: [PATCH] Strict mode incorrectly reset after function --- acorn.js | 6 +++--- test/tests.js | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/acorn.js b/acorn.js index 8d4760d520..24b7ff5bef 100644 --- a/acorn.js +++ b/acorn.js @@ -302,7 +302,7 @@ function initParserState() { lastStart = lastEnd = tokPos; if (options.locations) lastEndLoc = new Position; - inFunction = inGenerator = strict = null; + inFunction = inGenerator = strict = false; labels = []; readToken(); } @@ -1752,7 +1752,7 @@ // function bodies). function parseBlock(allowStrict) { - var node = startNode(), first = true, strict = false, oldStrict; + var node = startNode(), first = true, oldStrict; node.body = []; expect(_braceL); while (!eat(_braceR)) { @@ -1764,7 +1764,7 @@ } first = false; } - if (strict && !oldStrict) setStrict(false); + if (oldStrict === false) setStrict(false); return finishNode(node, "BlockStatement"); } diff --git a/test/tests.js b/test/tests.js index 40069ee697..c39aa3cde6 100644 --- a/test/tests.js +++ b/test/tests.js @@ -27285,6 +27285,9 @@ testFail("(function a(eval) { \"use strict\"; })", testFail("(function a(package) { \"use strict\"; })", "Defining 'package' in strict mode (1:12)"); +testFail("\"use strict\";function foo(){\"use strict\";}function bar(){var v = 015}", + "Invalid number (1:65)"); + testFail("var this = 10;", "Unexpected token (1:4)"); testFail("throw\n10;", "Illegal newline after throw (1:5)");