Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Syntax error in directive does not throw exception #15056

Closed
derfsubterfuge opened this issue Aug 24, 2016 · 3 comments · Fixed by #15057
Closed

Syntax error in directive does not throw exception #15056

derfsubterfuge opened this issue Aug 24, 2016 · 3 comments · Fixed by #15057

Comments

@derfsubterfuge
Copy link

Do you want to request a feature or report a bug?
I am reporting a bug.

What is the current behavior?
If a directive is missing a comma in a particular position, no exception is thrown into the console and the directive does not work. Here is an example, where the missing comma is at the end of line 8 of the JavaScript section:
Working directive: https://jsfiddle.net/derfsubterfuge/y9xd3mdb/
Broken directive: https://jsfiddle.net/derfsubterfuge/2nfy6b4c/1/

The example is using Angular 1.5.8. I have attempted this on Fedora 24 for both Chrome 52.0.2743.116 (64-bit) and Firefox 48.0 (64-bit).

What is the expected behavior?
I would expect a syntax error to be thrown in the console and not swallowed.

@Narretz
Copy link
Contributor

Narretz commented Aug 24, 2016

This is not an Angular specific problem and also not a syntax error. When you do console.log('string' [function(){}]); you will get undefined. It must be some strange Javascript parsing thing. We could throw an error though if the .directive fn is called with undefined.

@gkalpak
Copy link
Member

gkalpak commented Aug 25, 2016

As @Narretz said, this is valid JS syntax and results into calling .directive(undefined). Fwiw, it is equivalent to:

var obj = '...';
var propName = (function () {}).toString();
myModule.directive(obj[propName]);

@derfsubterfuge
Copy link
Author

Ah, that makes sense. JavaScript has so many weird things that you can do.

Narretz added a commit to Narretz/angular.js that referenced this issue Aug 28, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
petebacondarwin pushed a commit to petebacondarwin/angular.js that referenced this issue Nov 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants