Skip to content

Commit c2ce101

Browse files
committed
Also transform this.registry.register
1 parent 45b7c15 commit c2ce101

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ import { moduleFor, test } from 'ember-qunit';
33
moduleFor('service:foo', 'Unit | Service | Foo', {
44
beforeEach() {
55
this.register('service:thingy', thingy);
6+
this.registry.register('service:thingy', thingy);
67
}
78
});
89

910
test('it happens', function() {
1011
this.register('service:thingy', thingy);
12+
this.registry.register('service:thingy', thingy);
1113
});
1214

1315
moduleFor('service:bar', 'Unit | Service | Bar');
1416

1517
test('it happens again?', function() {
1618
this.register('service:thingy', thingy);
19+
this.registry.register('service:thingy', thingy);
1720
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ module('Unit | Service | Foo', function(hooks) {
66

77
hooks.beforeEach(function() {
88
this.owner.register('service:thingy', thingy);
9+
this.owner.register('service:thingy', thingy);
910
});
1011

1112
test('it happens', function() {
1213
this.owner.register('service:thingy', thingy);
14+
this.owner.register('service:thingy', thingy);
1315
});
1416
});
1517

@@ -18,5 +20,6 @@ module('Unit | Service | Bar', function(hooks) {
1820

1921
test('it happens again?', function() {
2022
this.owner.register('service:thingy', thingy);
23+
this.owner.register('service:thingy', thingy);
2124
});
2225
});

ember-qunit-codemod.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function updateModuleForToNestedModule(j, root) {
242242
}
243243

244244
function updateLookupCalls(j, root) {
245-
return root
245+
root
246246
.find(j.MemberExpression, {
247247
object: {
248248
object: { type: 'ThisExpression' },
@@ -257,7 +257,20 @@ function updateLookupCalls(j, root) {
257257
}
258258

259259
function updateRegisterCalls(j, root) {
260-
return root
260+
root
261+
.find(j.MemberExpression, {
262+
object: {
263+
object: { type: 'ThisExpression' },
264+
property: { name: 'registry' },
265+
},
266+
property: { name: 'register' },
267+
})
268+
.forEach(path => {
269+
let thisDotOwner = j.memberExpression(j.thisExpression(), j.identifier('owner'));
270+
path.replace(j.memberExpression(thisDotOwner, path.value.property));
271+
});
272+
273+
root
261274
.find(j.MemberExpression, {
262275
object: { type: 'ThisExpression' },
263276
property: { name: 'register' },

0 commit comments

Comments
 (0)