Skip to content

Commit 20b9e61

Browse files
author
Robert Jackson
committed
Migrate this.inject.controller() to this.owner.lookup.
1 parent 2e9e63f commit 20b9e61

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

__testfixtures__/ember-qunit-codemod/inject.input.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ test('it exists', function(assert) {
77
this.inject.service('foo');
88
this.inject.service('foo', { as: 'bar' });
99
});
10+
11+
test('it works for controllers', function(assert) {
12+
this.inject.controller('foo');
13+
this.inject.controller('foo', { as: 'bar' });
14+
});

__testfixtures__/ember-qunit-codemod/inject.output.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ module('Unit | Service | FooBar', function(hooks) {
88
this.foo = this.owner.lookup('service:foo');
99
this.bar = this.owner.lookup('service:foo');
1010
});
11+
12+
test('it works for controllers', function(assert) {
13+
this.foo = this.owner.lookup('controller:foo');
14+
this.bar = this.owner.lookup('controller:foo');
15+
});
1116
});

ember-qunit-codemod.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ function updateInjectCalls(j, root) {
285285
root
286286
.find(j.CallExpression, {
287287
callee: {
288+
type: 'MemberExpression',
288289
object: {
289290
object: {
290291
type: 'ThisExpression',
@@ -293,13 +294,10 @@ function updateInjectCalls(j, root) {
293294
name: 'inject',
294295
},
295296
},
296-
property: {
297-
name: 'service',
298-
},
299297
},
300298
})
301299
.forEach(p => {
302-
let injectType = 'service';
300+
let injectType = p.node.callee.property.name;
303301
let injectedName = p.node.arguments[0].value;
304302
let localName = injectedName;
305303
if (p.node.arguments[1]) {

0 commit comments

Comments
 (0)