Can strict parameters shadow strict function names?
Mark S. Miller wrote:
var foo = function bar(bar) {'use strict'};
On all version of Safari/JSC I just tested, this code gives a SyntaxError: Invalid parameters or function name in strict mode.
On all versions of Chrome/v8 and FF/SpiderMonkey I just tested, this code is accepted without error.
Which behavior is incorrect?
This appears to be a bug in Safari/JSC.
Is this an ES5 vs ES2015 issue?
No, both ES5 es5.github.io/#x13.1 and ES6 www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors
only have a syntax error if there are duplicate parameter names, regardless of the name of the function.
We are running into this when loading the output of a minifier as strict code.
Guess you should file a bug there - it a) doesn't make sense to name a function expression (does it ever in minified code) and use the same name for a parameter b) it should not fail in real-world engines even if the spec says something else.
, Bergi
On 9 June 2016 at 19:58, Bergi <a.d.bergi at web.de> wrote:
Mark S. Miller wrote:
var foo = function bar(bar) {'use strict'};
On all version of Safari/JSC I just tested, this code gives a SyntaxError: Invalid parameters or function name in strict mode.
On all versions of Chrome/v8 and FF/SpiderMonkey I just tested, this code is accepted without error.
Which behavior is incorrect?
This appears to be a bug in Safari/JSC.
Is this an ES5 vs ES2015 issue?
No, both ES5 es5.github.io/#x13.1 and ES6 < www.ecma-international.org/ecma-262/6.0/#sec-function-definitions-static-semantics-early-errors> only have a syntax error if there are duplicate parameter names, regardless of the name of the function.
In particular, the function name is in its own singleton scope outside the parameter scope. My guess is that this semantics was chosen so that collision doesn't differ between function declarations and expressions.
Yes, they can. The JSC behavior is incorrect.
The possibility of shadowing function expression names by parameters (or other local declarations) exists as far back as ES3. When strict mode was added in ES5 we didn’t include any restrictions
I filed <bugs.webkit.org/show_bug.cgi?id=158575, bugs.webkit.org/show_bug.cgi?id=158575> “ES6: Reusing function name as a parameter name shouldn't throw Syntax Error”.
var foo = function bar(bar) {'use strict'};
On all version of Safari/JSC I just tested, this code gives a SyntaxError: Invalid parameters or function name in strict mode.
On all versions of Chrome/v8 and FF/SpiderMonkey I just tested, this code is accepted without error.
Which behavior is incorrect? Is this an ES5 vs ES2015 issue? Are there currently any existing bug reports about this? Any test262 tests?
We are running into this when loading the output of a minifier as strict code.