Skip to content

Commit 7fc0a23

Browse files
Merge pull request #2 from ember-codemods/suchita/prefix
Fix the inline prefix issue and added an option for default prefixing
2 parents e554c23 + 2f08b8e commit 7fc0a23

File tree

14 files changed

+1688
-830
lines changed

14 files changed

+1688
-830
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
*.log
2+
*.log
3+
.DS_Store

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ A codemod for transforming your ember app code to start using `@tracked` propert
2020
npx ember-tracked-properties-codemod path/of/files/ or/some**/*glob.hbs
2121
```
2222

23-
23+
The codemod accepts the following options:
24+
25+
| Option | Value | Default | Details |
26+
| --------------------- | ------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
27+
| `--always-prefix` | boolean | `true` | Always prefix `@tracked` inline |
2428

2529
## Contributing
2630

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ember-tracked-properties-codemod",
33
"description": "A codemod for transforming your ember app code to start using `@tracked` properties.",
4-
"version": "0.1.0",
4+
"version": "0.2.0",
55
"author": {
66
"name": "Suchita Doshi",
77
"email": "[email protected]",
@@ -14,10 +14,14 @@
1414
},
1515
"bin": "./bin/cli.js",
1616
"keywords": [
17-
"codemod-cli"
17+
"codemod-cli",
18+
"codemods",
19+
"ember",
20+
"ember-codemod",
21+
"ember-tracked-properties"
1822
],
1923
"dependencies": {
20-
"codemod-cli": "^0.2.7"
24+
"codemod-cli": "^2.1.0"
2125
},
2226
"devDependencies": {
2327
"@babel/plugin-proposal-class-properties": "^7.7.4",

transforms/tracked-properties/README.md

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ npx ember-tracked-properties-codemod path/of/files/ or/some**/*glob.hbs
99
## Input / Output
1010

1111
<!--FIXTURES_TOC_START-->
12-
* [basic](#basic)
13-
* [chained-complex-computed](#chained-complex-computed)
14-
* [chained-computed](#chained-computed)
15-
* [complex](#complex)
16-
* [with-tracked](#with-tracked)
17-
<!--FIXTURES_TOC_END-->
12+
13+
- [basic](#basic)
14+
- [basic-with-prefix-false](#basic-with-prefix-false)
15+
- [chained-complex-computed](#chained-complex-computed)
16+
- [chained-computed](#chained-computed)
17+
- [complex](#complex)
18+
- [with-tracked](#with-tracked)
19+
<!--FIXTURES_TOC_END-->
1820

1921
## <!--FIXTURES_CONTENT_START-->
2022

@@ -44,6 +46,44 @@ import { tracked } from '@glimmer/tracking';
4446
import Component from '@ember/component';
4547
import { computed, get } from '@ember/object';
4648

49+
export default class Foo extends Component {
50+
bar;
51+
@tracked baz = 'barBaz';
52+
53+
get bazInfo() {
54+
return `Name: ${get(this, 'baz')}`;
55+
}
56+
}
57+
```
58+
59+
---
60+
61+
<a id="basic-with-prefix-false">**basic-with-prefix-false ({alwaysPrefix: `false`})**</a>
62+
63+
**Input** (<small>[basic-with-prefix-false.input.js](__testfixtures__/basic-with-prefix-false.input.js)</small>):
64+
65+
```js
66+
import Component from '@ember/component';
67+
import { computed, get } from '@ember/object';
68+
69+
export default class Foo extends Component {
70+
bar;
71+
baz = 'barBaz';
72+
73+
@computed('baz')
74+
get bazInfo() {
75+
return `Name: ${get(this, 'baz')}`;
76+
}
77+
}
78+
```
79+
80+
**Output** (<small>[basic-with-prefix-false.output.js](__testfixtures__/basic-with-prefix-false.output.js)</small>):
81+
82+
```js
83+
import { tracked } from '@glimmer/tracking';
84+
import Component from '@ember/component';
85+
import { computed, get } from '@ember/object';
86+
4787
export default class Foo extends Component {
4888
bar;
4989
@tracked
@@ -91,8 +131,7 @@ import Component from '@ember/component';
91131
import { computed, get } from '@ember/object';
92132

93133
export default class Foo extends Component {
94-
@tracked
95-
firstName = 'Foo';
134+
@tracked firstName = 'Foo';
96135
@tracked lastName;
97136
@tracked phone;
98137
zipcode;
@@ -147,8 +186,7 @@ import Component from '@ember/component';
147186
import { computed, get } from '@ember/object';
148187

149188
export default class Foo extends Component {
150-
@tracked
151-
foo = 'bar';
189+
@tracked foo = 'bar';
152190
baz;
153191

154192
get fooBar() {
@@ -250,7 +288,6 @@ export default class Foo extends Component {
250288
return `Name: ${get(this, 'baz')}`;
251289
}
252290
}
253-
254291
```
255292

256293
**Output** (<small>[with-tracked.output.js](__testfixtures__/with-tracked.output.js)</small>):
@@ -262,14 +299,12 @@ import { computed, get } from '@ember/object';
262299

263300
export default class Foo extends Component {
264301
@tracked bar;
265-
@tracked
266-
baz = 'barBaz';
302+
@tracked baz = 'barBaz';
267303

268304
get bazInfo() {
269305
return `Name: ${get(this, 'baz')}`;
270306
}
271307
}
272-
273308
```
274309

275-
---
310+
---
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Component from '@ember/component';
2+
import { computed, get } from '@ember/object';
3+
4+
export default class Foo extends Component {
5+
bar;
6+
baz = 'barBaz';
7+
8+
@computed('baz')
9+
get bazInfo() {
10+
return `Name: ${get(this, 'baz')}`;
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"alwaysPrefix": "false"
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { tracked } from '@glimmer/tracking';
2+
import Component from '@ember/component';
3+
import { computed, get } from '@ember/object';
4+
5+
export default class Foo extends Component {
6+
bar;
7+
@tracked
8+
baz = 'barBaz';
9+
10+
get bazInfo() {
11+
return `Name: ${get(this, 'baz')}`;
12+
}
13+
}

transforms/tracked-properties/__testfixtures__/basic.output.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { computed, get } from '@ember/object';
44

55
export default class Foo extends Component {
66
bar;
7-
@tracked
8-
baz = 'barBaz';
7+
@tracked baz = 'barBaz';
98

109
get bazInfo() {
1110
return `Name: ${get(this, 'baz')}`;

transforms/tracked-properties/__testfixtures__/chained-computed.output.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import Component from '@ember/component';
33
import { computed, get } from '@ember/object';
44

55
export default class Foo extends Component {
6-
@tracked
7-
foo = 'bar';
6+
@tracked foo = 'bar';
87
baz;
98

109
get fooBar() {

transforms/tracked-properties/__testfixtures__/complex.output.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import Component from '@ember/component';
33
import { computed, get } from '@ember/object';
44

55
export default class Foo extends Component {
6-
@tracked
7-
firstName = 'Foo';
6+
@tracked firstName = 'Foo';
87
@tracked lastName;
98
@tracked phone;
109
zipcode;

0 commit comments

Comments
 (0)