Skip to content

Commit 0d32859

Browse files
author
Andrew Schmadel
committed
allow anonymous classes to be annotated
fixes #24
1 parent e277f0d commit 0d32859

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

ng-annotate-main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ function judgeInjectArraySuspect(path, ctx) {
750750
node = path.node;
751751

752752
if (t.isClass(node)){
753+
if (!node.id) {
754+
node.id = path.scope.generateUidIdentifier('ngInjectAnonymousClass');
755+
}
753756
declaratorName = node.id.name;
754757
node = getConstructor(node);
755758
}

tests/es6.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ module.exports = {
123123
svc.foo = 'bar';
124124
`
125125
},
126+
{
127+
name: "exported anonymous class",
128+
explicit: true,
129+
noES5: true,
130+
input: `
131+
export default class {
132+
constructor($timeout) {
133+
'ngInject';
134+
return 'foo';
135+
}
136+
}
137+
`,
138+
expected: `
139+
export default class _ngInjectAnonymousClass {
140+
constructor($timeout) {
141+
'ngInject';
142+
143+
return 'foo';
144+
}
145+
}
146+
_ngInjectAnonymousClass.$inject = ['$timeout'];
147+
`
148+
},
126149
{
127150
name: "annotated constructor",
128151
explicit: true,

0 commit comments

Comments
 (0)