improve compatibility with use strict (#5440)

This commit is contained in:
Alex Lam S.L
2022-05-14 05:15:54 +01:00
committed by GitHub
parent 8946c87011
commit e31bbe329a
6 changed files with 441 additions and 37 deletions

View File

@@ -636,8 +636,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
next_token.add_directive = function(directive) {
S.directive_stack[S.directive_stack.length - 1].push(directive);
if (S.directives[directive]) S.directives[directive]++;
else S.directives[directive] = 1;
S.directives[directive] = (S.directives[directive] || 0) + 1;
}
next_token.push_directives_stack = function() {
@@ -1340,8 +1339,6 @@ function parse($TEXT, options) {
var loop = S.in_loop;
var labels = S.labels;
++S.in_function;
S.in_directives = true;
S.input.push_directives_stack();
S.in_loop = 0;
S.labels = [];
if (is("punc", "{")) {
@@ -1352,8 +1349,6 @@ function parse($TEXT, options) {
handle_regexp();
value = maybe_assign();
}
var is_strict = S.input.has_directive("use strict");
S.input.pop_directives_stack();
--S.in_function;
S.in_loop = loop;
S.labels = labels;
@@ -1367,7 +1362,7 @@ function parse($TEXT, options) {
value: value,
end: prev(),
});
if (is_strict) node.each_argname(strict_verify_symbol);
if (S.input.has_directive("use strict")) node.each_argname(strict_verify_symbol);
return node;
}
@@ -1412,7 +1407,7 @@ function parse($TEXT, options) {
name: name,
argnames: argnames,
rest: argnames.rest || null,
body: body
body: body,
});
if (is_strict) {
if (name) strict_verify_symbol(name);