Skip to content

Commit

Permalink
duplicate arg checks "use strict" in body
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 18, 2021
1 parent ef31c4f commit c4a6943
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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' }", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "function *f(a, a) { 'use strict' }", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "async function f(a, a) { 'use strict' }", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "(function(a, a) { 'use strict' })", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "(function*(a, a) { 'use strict' })", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "(async function(a, a) { 'use strict' })", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "function f(a, [a]) {}", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "function f([a], a) {}", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
expectParseError(t, "'use strict'; function f(a, a) {}", "<stdin>: error: \"a\" cannot be bound multiple times in the same parameter list\n")
Expand Down

0 comments on commit c4a6943

Please sign in to comment.