Skip to content

Commit

Permalink
[[FIX]] Enforce UniqueFormalParameters for methods
Browse files Browse the repository at this point in the history
That this correction does not require a modification to the Test262
expectations file is an indication of missing coverage in that project.
New tests have been submitted there, as well [1].

[1] tc39/test262#2043
  • Loading branch information
jugglinmike authored and rwaldron committed Jan 25, 2019
1 parent 29cab1f commit 280d36b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/scope-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,10 @@ var scopeManager = function(state, predefined, exported, declared) {
// > FormalParameterList is false and BoundNames of FormalParameterList
// > contains any duplicate elements.
var isSimple = state.funct['(hasSimpleParams)'];
// Method definitions are defined in terms of UniqueFormalParameters, so
// they cannot support duplicate parameter names regardless of strict
// mode.
var isMethod = state.funct["(method)"];

if (!currentFunctParamScope["(params)"]) {
return;
Expand All @@ -560,7 +564,7 @@ var scopeManager = function(state, predefined, exported, declared) {
var label = currentFunctParamScope["(labels)"][labelName];

if (label.duplicated) {
if (isStrict || isArrow || !isSimple) {
if (isStrict || isArrow || isMethod || !isSimple) {
warning("E011", label["(token)"], labelName);
} else if (state.option.shadow !== true) {
warning("W004", label["(token)"], labelName);
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6105,6 +6105,18 @@ conciseMethods.nameIsNotLocalVar = function (test) {
test.done();
};

conciseMethods.uniqueFormalParameters = function (test) {
TestRun(test, "adjacent")
.addError(1, 15, "'a' has already been declared.")
.test("void { method(a, a) {} };", { esversion: 6 });

TestRun(test, "separated")
.addError(1, 15, "'b' has already been declared.")
.test("void { method(b, c, b) {} };", { esversion: 6 });

test.done();
};

exports["object short notation: basic"] = function (test) {
var code = [
"var foo = 42;",
Expand Down Expand Up @@ -6612,6 +6624,18 @@ exports["computed class methods aren't duplicate"] = function (test) {
test.done();
};

exports["class method UniqueFormalParameters"] = function (test) {
TestRun(test, "adjacent")
.addError(1, 18, "'a' has already been declared.")
.test("class C { method(a, a) {} }", { esversion: 6 });

TestRun(test, "separated")
.addError(1, 18, "'b' has already been declared.")
.test("class C { method(b, c, b) {} }", { esversion: 6 });

test.done();
};

exports["class method this"] = function (test) {
var code = [
"class C {",
Expand Down

0 comments on commit 280d36b

Please sign in to comment.