Safari has not been broken. This is a correct behavior in ES5. ES5 disallows function declarations on blocks (except function bodies). On the other hand, ES2015 (ES6) has relaxed this restriction.
I'd like to recommend a use of no-inner-declarations <http://eslint.org/docs/rules/no-inner-declarations> rule. This rule would disallow such function declarations. 2016年7月14日(木) 4:59 Robin Ward <[email protected]>: > Recently we broke Safari in production because code I'd written that > looked like this: > > ```javascript > if (true) { > function test() { > } > test(); > } > ``` > > In Chrome and Firefox the above works well, but in Safari you get an > error: `SyntaxError: Strict mode does not allow function declarations in a > lexically nested statement.` > > This can be fixed by changing the code to this: > > > ```javascript > if (true) { > const test = function() { > } > test(); > } > ``` > > I looked for a rule in ESLint to prevent the first (bad) code from running > but I can't find one. The closest seems to be `func-style` which locks you > into one or the other, but what I'm actually looking for is the ability to > raise an error when Safari would. > > Is there anything in ESLint to do this? Is there a way to propose this if > not? > > -- > You received this message because you are subscribed to the Google Groups > "ESLint" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "ESLint" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
