Bug 106176
Summary: | Non-helpful SyntaxError message for duplicate parameters in strict mode | ||
---|---|---|---|
Product: | WebKit | Reporter: | André Bargull <andre.bargull> |
Component: | JavaScriptCore | Assignee: | Saam Barati <saam> |
Status: | UNCONFIRMED | ||
Severity: | Normal | CC: | fpizlo, ggaren, joepeck, ngockhanhlam87, oliver, saam |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
André Bargull
The current SyntaxError message isn't really that helpful.
test cases:
---
> function f(a,a){'use strict'}
Exception: SyntaxError: Unexpected token '}'
> function f(a,a){'use strict'; ''}
Exception: SyntaxError: Unexpected string ''
> function f(a,a){'use strict'; return a}
Exception: SyntaxError: Return statements are only valid inside functions
---
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Joseph Pecoraro
Things are slightly better now. It would still be nice if it said duplicate parameters though. Current state of things (r207235):
js> function f(a,a){'use strict'}
Invalid parameters or function name in strict mode.:1
js> function f(a,a){'use strict'; ''}
Invalid parameters or function name in strict mode.:1
js> function f(a,a){'use strict'; return a}
Invalid parameters or function name in strict mode.:1
Joseph Pecoraro
Compare to our error message for classes and arrow functions which force the stricter parsing, these are more helpful because they even note the duplicate parameter:
js> (class { f(a,a){} })
Cannot declare a parameter named 'a' in strict mode as it has already been declared.:1
js> (class { f(a,a){''} })
Cannot declare a parameter named 'a' in strict mode as it has already been declared.:1
js> (class { f(a,a){return a} })
Cannot declare a parameter named 'a' in strict mode as it has already been declared.:1
js> (a,a) => {}
Duplicate parameter 'a' not allowed in an arrow function.:1
js> (a,a) => {''}
Duplicate parameter 'a' not allowed in an arrow function.:1
js> (a,a) => {return a}
Duplicate parameter 'a' not allowed in an arrow function.:1
Saam Barati
Weird I thought we had code that said it's invalid because of duplicate parameters when we parse "use strict". I'll look into it