meumobi / infomobi-v2

http://meumobi.github.io/infomobi
2 stars 6 forks source link

SyntaxError: Strict mode does not allow function declarations in a lexically nested statement #256

Closed vdias38 closed 7 years ago

vdias38 commented 7 years ago

On iOS, the app raises following error on launch: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement.

Following code, from src/js/controllers/main_controller.js is responsible for the exception:

if (AuthService.isAuthenticated()) {
  ...
  function fulfill(response) {
  ...
  }
}
vdias38 commented 7 years ago

This issue only occurs on debug mode. Maybe because of uglify if debug is false. A discussion on eslint forum advices about this behaviour, only on Safari.

This can be fixed by changing the code to this: if (true) { const test = function() { } test(); }

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 rule. This rule would disallow such function declarations.

vdias38 commented 7 years ago

I've added the no-inner-declarations rule on ng-meumobi-utils