Skip to content

Commit eacaf01

Browse files
ssutarpzuraq
authored andcommitted
Add quotes option to handle single/double quotes (#43)
#42
1 parent 774d2eb commit eacaf01

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Program comments
3+
*/
4+
const Foo = Test.extend(MyMixin, {
5+
/**
6+
* Property comments
7+
*/
8+
prop: 'defaultValue',
9+
boolProp: true,
10+
numProp: 123,
11+
[MY_VAL]: 'val',
12+
queryParams: {},
13+
someVal,
14+
15+
/**
16+
* Method comments
17+
*/
18+
method() {
19+
// do things
20+
},
21+
22+
otherMethod: function() {},
23+
24+
get accessor() {
25+
return this._value;
26+
},
27+
28+
set accessor(value) {
29+
this._value = value;
30+
},
31+
32+
anotherMethod() {
33+
this._super(...arguments);
34+
}
35+
});
36+
37+
const Foo = EmberObject.extend(MixinA, MixinB);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"quotes": "single"
3+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Program comments
3+
*/
4+
class Foo extends Test.extend(MyMixin) {
5+
/**
6+
* Property comments
7+
*/
8+
prop = 'defaultValue';
9+
10+
boolProp = true;
11+
numProp = 123;
12+
[MY_VAL] = 'val';
13+
queryParams = {};
14+
someVal = someVal;
15+
16+
/**
17+
* Method comments
18+
*/
19+
method() {
20+
// do things
21+
}
22+
23+
otherMethod() {}
24+
25+
get accessor() {
26+
return this._value;
27+
}
28+
29+
set accessor(value) {
30+
this._value = value;
31+
}
32+
33+
anotherMethod() {
34+
super.anotherMethod(...arguments);
35+
}
36+
}
37+
38+
class Foo extends EmberObject.extend(MixinA, MixinB) {}

transforms/ember-object/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ module.exports = function transformer(file, api, opts) {
66
const options = Object.assign({}, opts, getOptions());
77
let { source, path } = file;
88

9-
const root = j(source);
9+
let transformOptions = {};
10+
11+
if (options.quotes || options.quote) {
12+
transformOptions.quote = options.quotes || options.quote;
13+
}
1014

11-
replaceEmberObjectExpressions(j, root, path, options);
15+
const root = j(source);
1216

13-
return root.toSource();
17+
const replaced = replaceEmberObjectExpressions(j, root, path, options);
18+
if (replaced) {
19+
source = root.toSource(transformOptions);
20+
}
21+
return source;
1422
};
1523

1624
// Set the parser, needed for supporting decorators

transforms/helpers/parse-helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ function replaceEmberObjectExpressions(j, root, filePath, options = {}) {
606606
updateLayoutImportDeclaration(j, root, layoutName);
607607
logger.info(`[${filePath}]: SUCCESS`);
608608
}
609+
return transformed;
609610
}
610611

611612
module.exports = {

0 commit comments

Comments
 (0)