Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Duplicate parameter checking #325

Closed
nzakas opened this issue Oct 8, 2015 · 4 comments
Closed

Duplicate parameter checking #325

nzakas opened this issue Oct 8, 2015 · 4 comments

Comments

@nzakas
Copy link
Contributor

nzakas commented Oct 8, 2015

Any strict-mode function with duplicate parameters is considered an error in ES6, so this:

(a, a) => 42;

Throws an error in Esprima and Espree. Are you open to supporting duplicate parameter checking in Acorn?

@marijnh
Copy link
Member

marijnh commented Oct 8, 2015

There is already duplicate parameter checking (see for example function(a, a) { "use strict"; }), but it looks like that is not kicking in in this case. If you want to look into it, that'd be great. (If not, I'll do so next week.)

@rwaldron
Copy link

rwaldron commented Oct 8, 2015

This issue report isn't wrong, but I think you'll both appreciate some specific clarity here: Arrow functions are not strict mode by default, but they do have a supplemental grammar that must be used for their formal parameters. The supplemental syntax here: http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions uses StrictFormalParameters, which makes duplicate params a syntax error. It's an important distinction, because it means things like...

let a = (x) => y = x; // will pollute the global scope
let b = (arguments) => arguments; // no error
let c = (eval) => eval; // no error

@nzakas
Copy link
Contributor Author

nzakas commented Oct 8, 2015

@rwaldron Thanks for the clarification, you've saved me time digging through the spec because I had noticed the code I was using wasn't in strict mode. Very helpful.

@marijnh I'll take a look at this.

@rwaldron
Copy link

rwaldron commented Oct 8, 2015

Glad I could be helpful! :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants