From c4a6943f4e135c7127995ec36190702fabd10a32 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Thu, 18 Feb 2021 05:19:04 -0800 Subject: [PATCH] duplicate arg checks "use strict" in body --- internal/js_parser/js_parser.go | 2 +- internal/js_parser/js_parser_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/js_parser/js_parser.go b/internal/js_parser/js_parser.go index 21d03c2bc10..7ccede80778 100644 --- a/internal/js_parser/js_parser.go +++ b/internal/js_parser/js_parser.go @@ -8977,7 +8977,7 @@ func (p *parser) visitArgs(args []js_ast.Arg, opts visitArgsOpts) { // the same BindingIdentifier in a FormalParameterList is only allowed for // functions which have simple parameter lists and which are not defined in // strict mode code." - if opts.isUniqueFormalParameters || !hasSimpleArgs || p.isStrictMode() { + if opts.isUniqueFormalParameters || hasUseStrict || !hasSimpleArgs || p.isStrictMode() { duplicateArgCheck = make(map[string]bool) } diff --git a/internal/js_parser/js_parser_test.go b/internal/js_parser/js_parser_test.go index 1c693b3934c..33d3675aac9 100644 --- a/internal/js_parser/js_parser_test.go +++ b/internal/js_parser/js_parser_test.go @@ -257,6 +257,12 @@ func TestStrictMode(t *testing.T) { expectPrinted(t, "({ f: function*(a, a) {} })", "({f: function* (a, a) {\n}});\n") expectPrinted(t, "({ f: async function(a, a) {} })", "({f: async function(a, a) {\n}});\n") + expectParseError(t, "function f(a, a) { 'use strict' }", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") + expectParseError(t, "function *f(a, a) { 'use strict' }", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") + expectParseError(t, "async function f(a, a) { 'use strict' }", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") + expectParseError(t, "(function(a, a) { 'use strict' })", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") + expectParseError(t, "(function*(a, a) { 'use strict' })", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") + expectParseError(t, "(async function(a, a) { 'use strict' })", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") expectParseError(t, "function f(a, [a]) {}", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") expectParseError(t, "function f([a], a) {}", ": error: \"a\" cannot be bound multiple times in the same parameter list\n") expectParseError(t, "'use strict'; function f(a, a) {}", ": error: \"a\" cannot be bound multiple times in the same parameter list\n")