Fix ignoring previous strict mode after twice "use strict"

For example:

    var foo = function () {
      "use strict";
      "use strict";
      // there is inside of strict mode,
      // so `0123` (octal number) occurs a syntax error.
    };
    // there is outside of strict mode,
    0123; // so left is valid syntax.
    // however:
    //   SyntaxError: Invalid number (8:0)

I fixed it and add the test case.
This commit is contained in:
TSUYUSATO Kitsune
2015-12-19 08:14:51 +09:00
parent 2304ce0b4a
commit 8d8f75a5b8
3 changed files with 232 additions and 1 deletions

View File

@@ -464,7 +464,7 @@ pp.parseBlockBody = function (node, allowDirectives, topLevel, end) {
let directive = this.stmtToDirective(stmt);
node.directives.push(directive);
if (directive.value.value === "use strict") {
if (oldStrict === undefined && directive.value.value === "use strict") {
oldStrict = this.state.strict;
this.setStrict(true);