diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-04 18:45:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-04 18:45:51 +0800 |
commit | a6873a38590a9176c607bcdbff726daa93e1fec7 (patch) | |
tree | a23ff4a6df34716529d7d62b70289284c9e1f411 /lib/parse.js | |
parent | 7a6d452b548c8b7783b226f646e814d6cb0cf32b (diff) | |
download | tracifyjs-a6873a38590a9176c607bcdbff726daa93e1fec7.tar.gz tracifyjs-a6873a38590a9176c607bcdbff726daa93e1fec7.zip |
forbid block-scoped `AST_Defun` in strict mode (#2718)
Diffstat (limited to 'lib/parse.js')
-rw-r--r-- | lib/parse.js | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/parse.js b/lib/parse.js index 03455348..001587bc 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -800,7 +800,7 @@ function parse($TEXT, options) { function embed_tokens(parser) { return function() { var start = S.token; - var expr = parser(); + var expr = parser.apply(null, arguments); var end = prev(); expr.start = start; expr.end = end; @@ -815,7 +815,7 @@ function parse($TEXT, options) { } }; - var statement = embed_tokens(function() { + var statement = embed_tokens(function(strict_defun) { handle_regexp(); switch (S.token.type) { case "string": @@ -901,6 +901,9 @@ function parse($TEXT, options) { return for_(); case "function": + if (!strict_defun && S.input.has_directive("use strict")) { + croak("In strict mode code, functions can only be declared at top level or immediately within another function."); + } next(); return function_(AST_Defun); @@ -1083,7 +1086,7 @@ function parse($TEXT, options) { S.input.push_directives_stack(); S.in_loop = 0; S.labels = []; - var body = block_(); + var body = block_(true); if (S.input.has_directive("use strict")) { if (name) strict_verify_symbol(name); argnames.forEach(strict_verify_symbol); @@ -1112,12 +1115,12 @@ function parse($TEXT, options) { }); }; - function block_() { + function block_(strict_defun) { expect("{"); var a = []; while (!is("punc", "}")) { if (is("eof")) unexpected(); - a.push(statement()); + a.push(statement(strict_defun)); } next(); return a; @@ -1630,7 +1633,7 @@ function parse($TEXT, options) { var body = []; S.input.push_directives_stack(); while (!is("eof")) - body.push(statement()); + body.push(statement(true)); S.input.pop_directives_stack(); var end = prev(); var toplevel = options.toplevel; |