diff --git a/ng-annotate-main.js b/ng-annotate-main.js index b5dba04..f95f3be 100644 --- a/ng-annotate-main.js +++ b/ng-annotate-main.js @@ -771,7 +771,7 @@ function judgeInjectArraySuspect(path, ctx) { path = jumpOverIife(path); node = path.node; - if (t.isClass(node)){ + if (t.isClass(node) || t.isClassExpression(node)){ if (!node.id) { node.id = path.scope.generateUidIdentifier('ngInjectAnonymousClass'); } diff --git a/nginject.js b/nginject.js index 2685788..df4b789 100644 --- a/nginject.js +++ b/nginject.js @@ -274,6 +274,11 @@ function inspectClassMethod(path, ctx){ addSuspect(ancestor, ctx, !annotation); return; } + + if (ancestor.isVariableDeclaration()) { + addSuspect(ancestor, ctx, !annotation); + return; + } } } diff --git a/tests/es6.js b/tests/es6.js index 1dfb59e..adeff76 100644 --- a/tests/es6.js +++ b/tests/es6.js @@ -146,6 +146,27 @@ module.exports = { _ngInjectAnonymousClass.$inject = ["$timeout"]; ` }, + { + name: "class assigned to a var", + explicit: true, + noES5: true, + input: ` + let Foo = class Foo { + constructor($element) { + 'ngInject'; + } + }; + `, + expected: ` + let Foo = class Foo { + constructor($element) { + 'ngInject'; + } + }; + + Foo.$inject = ["$element"]; + ` + }, { name: "annotated constructor", explicit: true,