Skip to content

Commit 8c7d3f3

Browse files
authored
Merge pull request #5 from rwjblue/migrate-this._element
Migrate `this._element` to `this.element`.
2 parents d355e9f + c76447c commit 8c7d3f3

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

__testfixtures__/ember-qunit-codemod/module-for-component.input.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ test('it happens', function() {
99
this.render(hbs`derp`);
1010
});
1111

12-
test('it happens with comments', function() {
12+
test('it happens with comments', function(assert) {
1313
// comments above this.render are preserved
1414
this.render(hbs`derp`);
15+
16+
assert.equal(this._element.textContent, 'derp');
1517
});
1618

1719
test('multiple renders', function() {

__testfixtures__/ember-qunit-codemod/module-for-component.output.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ module('Integration | Component | FooBar', function(hooks) {
99
await render(hbs`derp`);
1010
});
1111

12-
test('it happens with comments', async function() {
12+
test('it happens with comments', async function(assert) {
1313
// comments above this.render are preserved
1414
await render(hbs`derp`);
15+
16+
assert.equal(this.element.textContent, 'derp');
1517
});
1618

1719
test('multiple renders', async function() {

ember-qunit-codemod.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,19 @@ function updateModuleForToNestedModule(j, root) {
177177
return [moduleInvocation, callback.body.body, setupType];
178178
}
179179

180-
function processRenderingTest(expression) {
181-
let isTest = j.match(expression, { expression: { callee: { name: 'test' } } });
180+
function processRenderingTest(testExpression) {
181+
let isTest = j.match(testExpression, { expression: { callee: { name: 'test' } } });
182182
if (!isTest) {
183183
return;
184184
}
185185

186186
// mark the test function as an async function
187-
expression.expression.arguments[1].async = true;
187+
testExpression.expression.arguments[1].async = true;
188+
let testExpressionCollection = j(testExpression);
188189

189190
// Transform to await render() or await clearRender()
190191
['render', 'clearRender'].forEach(type => {
191-
findTestHelperUsageOf(j, j(expression), type).forEach(p => {
192+
findTestHelperUsageOf(j, testExpressionCollection, type).forEach(p => {
192193
let expression = p.get('expression');
193194

194195
let awaitExpression = j.awaitExpression(
@@ -197,6 +198,21 @@ function updateModuleForToNestedModule(j, root) {
197198
expression.replace(awaitExpression);
198199
});
199200
});
201+
202+
// Migrate `this._element` -> `this.element`
203+
testExpressionCollection
204+
.find(j.MemberExpression, {
205+
object: {
206+
type: 'ThisExpression',
207+
},
208+
property: {
209+
name: '_element',
210+
},
211+
})
212+
.forEach(p => {
213+
let property = p.get('property');
214+
property.node.name = 'element';
215+
});
200216
}
201217

202218
let programPath = root.get('program');

0 commit comments

Comments
 (0)