Skip to content

Commit 2383f84

Browse files
committed
Cleanup
1 parent 6026249 commit 2383f84

File tree

7 files changed

+54
-82
lines changed

7 files changed

+54
-82
lines changed

lib/__tests__/__snapshots__/transform.js.snap

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`classic components basic 1`] = `
55
66
export default Component.extend({
77
});
8-
8+
99
~~~~~~~~~~
1010
foo
1111
~~~~~~~~~~
@@ -15,21 +15,21 @@ foo
1515
export default Component.extend({
1616
tagName: \\"\\"
1717
});
18-
18+
1919
~~~~~~~~~~
2020
<div ...attributes>
2121
foo
2222
</div>
2323
=========="
2424
`;
2525
26-
exports[`handles \`ariaRole\` correctly 1`] = `
26+
exports[`classic components handles \`ariaRole\` correctly 1`] = `
2727
"==========
2828
2929
export default Component.extend({
3030
ariaRole: 'button',
3131
});
32-
32+
3333
~~~~~~~~~~
3434
foo
3535
~~~~~~~~~~
@@ -39,21 +39,21 @@ foo
3939
export default Component.extend({
4040
tagName: \\"\\",
4141
});
42-
42+
4343
~~~~~~~~~~
4444
<div role=\\"button\\" ...attributes>
4545
foo
4646
</div>
4747
=========="
4848
`;
4949
50-
exports[`handles \`attributeBindings\` correctly 1`] = `
50+
exports[`classic components handles \`attributeBindings\` correctly 1`] = `
5151
"==========
5252
5353
export default Component.extend({
5454
attributeBindings: ['foo', 'bar:baz'],
5555
});
56-
56+
5757
~~~~~~~~~~
5858
foo
5959
~~~~~~~~~~
@@ -63,7 +63,7 @@ foo
6363
export default Component.extend({
6464
tagName: \\"\\",
6565
});
66-
66+
6767
~~~~~~~~~~
6868
<div foo={{this.foo}} baz={{this.bar}} ...attributes>
6969
foo
@@ -77,7 +77,7 @@ exports[`classic components handles \`classNameBindings\` correctly 1`] = `
7777
export default Component.extend({
7878
classNameBindings: ['a:b', 'x:y:z', 'foo::bar'],
7979
});
80-
80+
8181
~~~~~~~~~~
8282
foo
8383
~~~~~~~~~~
@@ -87,7 +87,7 @@ foo
8787
export default Component.extend({
8888
tagName: \\"\\",
8989
});
90-
90+
9191
~~~~~~~~~~
9292
<div class=\\"{{if this.a \\"b\\"}} {{if this.x \\"y\\" \\"z\\"}} {{unless this.foo \\"bar\\"}}\\" ...attributes>
9393
foo
@@ -101,7 +101,7 @@ exports[`classic components handles \`classNames\` correctly 1`] = `
101101
export default Component.extend({
102102
classNames: ['foo', 'bar:baz'],
103103
});
104-
104+
105105
~~~~~~~~~~
106106
foo
107107
~~~~~~~~~~
@@ -111,7 +111,7 @@ foo
111111
export default Component.extend({
112112
tagName: \\"\\",
113113
});
114-
114+
115115
~~~~~~~~~~
116116
<div class=\\"foo bar:baz\\" ...attributes>
117117
foo
@@ -125,7 +125,7 @@ exports[`classic components handles \`elementId\` correctly 1`] = `
125125
export default Component.extend({
126126
elementId: 'qux',
127127
});
128-
128+
129129
~~~~~~~~~~
130130
foo
131131
~~~~~~~~~~
@@ -135,7 +135,7 @@ foo
135135
export default Component.extend({
136136
tagName: \\"\\",
137137
});
138-
138+
139139
~~~~~~~~~~
140140
<div id=\\"qux\\" ...attributes>
141141
foo
@@ -149,7 +149,7 @@ exports[`classic components handles \`hasComponentCSS\` option correctly 1`] = `
149149
export default Component.extend({
150150
classNames: ['foo', 'bar:baz'],
151151
});
152-
152+
153153
~~~~~~~~~~
154154
foo
155155
~~~~~~~~~~
@@ -159,7 +159,7 @@ foo
159159
export default Component.extend({
160160
tagName: \\"\\",
161161
});
162-
162+
163163
~~~~~~~~~~
164164
<div class=\\"{{styleNamespace}} foo bar:baz\\" ...attributes>
165165
foo
@@ -173,7 +173,7 @@ exports[`classic components handles single \`classNames\` item correctly 1`] = `
173173
export default Component.extend({
174174
classNames: ['foo'],
175175
});
176-
176+
177177
~~~~~~~~~~
178178
foo
179179
~~~~~~~~~~
@@ -183,7 +183,7 @@ foo
183183
export default Component.extend({
184184
tagName: \\"\\",
185185
});
186-
186+
187187
~~~~~~~~~~
188188
<div class=\\"foo\\" ...attributes>
189189
foo
@@ -223,7 +223,7 @@ exports[`classic components replaces existing \`tagName\` 1`] = `
223223
export default Component.extend({
224224
tagName: 'span',
225225
});
226-
226+
227227
~~~~~~~~~~
228228
foo
229229
~~~~~~~~~~
@@ -233,7 +233,7 @@ foo
233233
export default Component.extend({
234234
tagName: \\"\\",
235235
});
236-
236+
237237
~~~~~~~~~~
238238
<span ...attributes>
239239
foo
@@ -246,7 +246,7 @@ exports[`native components basic 1`] = `
246246
247247
export default class FooComponent extends Component {
248248
}
249-
249+
250250
~~~~~~~~~~
251251
foo
252252
~~~~~~~~~~
@@ -257,7 +257,7 @@ foo
257257
@tagName(\\"\\")
258258
export default class FooComponent extends Component {
259259
}
260-
260+
261261
~~~~~~~~~~
262262
<div ...attributes>
263263
foo
@@ -334,7 +334,7 @@ exports[`native components handles \`@attributeBindings\` correctly 1`] = `
334334
@attributeBindings('foo', 'bar:baz')
335335
export default class FooComponent extends Component {
336336
}
337-
337+
338338
~~~~~~~~~~
339339
foo
340340
~~~~~~~~~~
@@ -346,7 +346,7 @@ foo
346346
@tagName(\\"\\")
347347
export default class FooComponent extends Component {
348348
}
349-
349+
350350
~~~~~~~~~~
351351
<div foo={{this.foo}} baz={{this.bar}} ...attributes>
352352
foo
@@ -449,7 +449,7 @@ exports[`native components handles \`elementId\` correctly 1`] = `
449449
export default class FooComponent extends Component {
450450
elementId = 'qux';
451451
}
452-
452+
453453
~~~~~~~~~~
454454
foo
455455
~~~~~~~~~~
@@ -459,7 +459,7 @@ foo
459459
import { tagName } from \\"@ember-decorators/component\\";
460460
@tagName(\\"\\")
461461
export default class FooComponent extends Component {}
462-
462+
463463
~~~~~~~~~~
464464
<div id=\\"qux\\" ...attributes>
465465
foo
@@ -557,7 +557,7 @@ exports[`native components replaces existing \`tagName\` 1`] = `
557557
@tagName('span')
558558
export default class FooComponent extends Component {
559559
}
560-
560+
561561
~~~~~~~~~~
562562
foo
563563
~~~~~~~~~~
@@ -569,7 +569,7 @@ foo
569569
@tagName(\\"\\")
570570
export default class FooComponent extends Component {
571571
}
572-
572+
573573
~~~~~~~~~~
574574
<span ...attributes>
575575
foo

lib/__tests__/transform.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,20 @@ describe('classic components', function() {
111111
expect(generateSnapshot(source, template)).toMatchSnapshot();
112112
});
113113

114-
test('handles `ariaRole` correctly', () => {
115-
let source = `
114+
test('handles `ariaRole` correctly', () => {
115+
let source = `
116116
export default Component.extend({
117117
ariaRole: 'button',
118118
});
119119
`;
120120

121-
let template = `foo`;
122-
123-
expect(generateSnapshot(source, template)).toMatchSnapshot();
124-
});
125-
126-
test('throws if `Component.extend({ ... })` is not found', () => {
127-
let source = `
128-
export default class extends Component {
129-
}
130-
`;
121+
let template = `foo`;
131122

132-
expect(() => transform(source, '')).toThrowErrorMatchingInlineSnapshot(
133-
`"Unsupported component type. Only classic components (\`Component.extend({ ... }\`) are supported currently."`
134-
);
135-
});
123+
expect(generateSnapshot(source, template)).toMatchSnapshot();
124+
});
136125

137-
test('throws if `Component.extend({ ... })` argument is not found', () => {
138-
let source = `
126+
test('throws if `Component.extend({ ... })` argument is not found', () => {
127+
let source = `
139128
export default Component.extend();
140129
`;
141130

@@ -215,22 +204,22 @@ test('throws if `Component.extend({ ... })` argument is not found', () => {
215204
);
216205
});
217206

218-
test('throws if component is using a computed property for `ariaRole`', () => {
219-
let source = `
207+
test('throws if component is using a computed property for `ariaRole`', () => {
208+
let source = `
220209
export default Component.extend({
221210
ariaRole: computed(function() {
222211
return 'button';
223212
}),
224213
});
225214
`;
226215

227-
expect(() => transform(source, '')).toThrowErrorMatchingInlineSnapshot(
228-
`"Codemod does not support computed properties for \`ariaRole\`."`
229-
);
230-
});
216+
expect(() => transform(source, '')).toThrowErrorMatchingInlineSnapshot(
217+
`"Codemod does not support computed properties for \`ariaRole\`."`
218+
);
219+
});
231220

232-
test('multi-line template', () => {
233-
let source = `export default Component.extend({});`;
221+
test('multi-line template', () => {
222+
let source = `export default Component.extend({});`;
234223

235224
let template = `
236225
{{#if this.foo}}

lib/transform/native.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ module.exports = function transformNativeComponent(root, options) {
122122
// set `@tagName('')`
123123
addClassDecorator(exportDefaultDeclaration, 'tagName', [j.stringLiteral('')]);
124124
ensureImport(root, 'tagName', '@ember-decorators/component');
125-
// let tagNamePath = j(classBody)
126-
// .find(j.ClassProperty)
127-
// // .filter(path => path.parentPath === properties)
128-
// .filter(path => isProperty(path, 'tagName'));
129-
//
130-
// if (tagNamePath.length === 1) {
131-
// j(tagNamePath.get('value')).replaceWith(j.stringLiteral(''));
132-
// } else {
133-
// classBody.unshift(j.classProperty(j.identifier('tagName'), j.stringLiteral('')));
134-
// }
135125

136126
// remove `elementId`, `attributeBindings`, `classNames` and `classNameBindings`
137127
j(classBody)

lib/transform/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { indentLines } = require('../utils/classic');
1+
const { indentLines } = require('../utils/template');
22

33
const templateRecast = require('ember-template-recast');
44

lib/utils/classic.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ function findClassNameBindings(properties) {
9191
return classNameBindings;
9292
}
9393

94-
function indentLines(content) {
95-
return content
96-
.split('\n')
97-
.map(it => ` ${it}`)
98-
.join('\n');
99-
}
100-
10194
module.exports = {
10295
isProperty,
10396
isMethod,
@@ -109,5 +102,4 @@ module.exports = {
109102
findClassNameBindings,
110103
findElementId,
111104
findTagName,
112-
indentLines,
113105
};

lib/utils/native.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,6 @@ function removeDecorator(root, classDeclaration, name, source) {
178178
}
179179
}
180180

181-
function indentLines(content) {
182-
return content
183-
.split('\n')
184-
.map(it => ` ${it}`)
185-
.join('\n');
186-
}
187-
188181
function ensureImport(root, name, source) {
189182
let body = root.get().value.program.body;
190183

@@ -225,7 +218,6 @@ function removeImport(root, name, source) {
225218
.remove();
226219

227220
if (declaration.get().value.specifiers.length === 0) {
228-
// console.log(root.get('program', 'body'))
229221
declaration.remove();
230222
}
231223
}
@@ -278,5 +270,4 @@ module.exports = {
278270
removeDecorator,
279271
ensureImport,
280272
removeImport,
281-
indentLines,
282273
};

lib/utils/template.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function indentLines(content) {
2+
return content
3+
.split('\n')
4+
.map(it => ` ${it}`)
5+
.join('\n');
6+
}
7+
8+
module.exports = {
9+
indentLines,
10+
};

0 commit comments

Comments
 (0)