schmod / babel-plugin-angularjs-annotate

Add Angular 1.x dependency injection annotations to ES6 code
http://schmod.github.io/babel-plugin-angularjs-annotate
MIT License
240 stars 29 forks source link

crashes with illegal component declaration #11

Closed schmod closed 8 years ago

schmod commented 8 years ago

An "illegal" component declaration causes the plugin to crash and exit. We should tolerate this gracefully.

angular.module('foo').component({})

causes the plugin to exit with:

unknown: Cannot set property '$chained' of undefined
punmechanic commented 8 years ago

It doesn't just crash with an illegal declaration, unfortunately. The following code also caused this issue for me (I wrote it out of laziness..)

const components = {
  someName: someComponentObject
}

const ngModule = angular.module('components', [])
Object.keys(components).forEach((name) => ngModule.component(name, components[name]))
schmod commented 8 years ago

@danpantry I've fixed things so your example no longer crashes, but you're definitely going to need to add explicit annotations to that source for it to be annotated.

punmechanic commented 8 years ago

This example shouldn't need any annotations at all - components cannot be annotated as they are just objects. controllers of components, sure

schmod commented 8 years ago

True! But those controllers are indeed going to need explicit annotations.