Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ng-annotate-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
5 changes: 5 additions & 0 deletions nginject.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ function inspectClassMethod(path, ctx){
addSuspect(ancestor, ctx, !annotation);
return;
}

if (ancestor.isVariableDeclaration()) {
addSuspect(ancestor, ctx, !annotation);
return;
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down