Skip to content

Commit 56156f7

Browse files
vankopevilebottnawi
authored andcommitted
refactor: toString method in favor of polymorphism (postcss#208)
1 parent 42339b1 commit 56156f7

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

src/selectors/className.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ export default class ClassName extends Node {
2727
return this._value;
2828
}
2929

30-
toString () {
31-
return [
32-
this.rawSpaceBefore,
33-
String('.' + this.stringifyProperty("value")),
34-
this.rawSpaceAfter,
35-
].join('');
30+
valueToString () {
31+
return '.' + super.valueToString();
3632
}
3733
}

src/selectors/id.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ export default class ID extends Node {
77
this.type = IDType;
88
}
99

10-
toString () {
11-
return [
12-
this.rawSpaceBefore,
13-
String('#' + this.stringifyProperty("value")),
14-
this.rawSpaceAfter,
15-
].join('');
10+
valueToString () {
11+
return '#' + super.valueToString();
1612
}
1713
}

src/selectors/namespace.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ export default class Namespace extends Node {
5252
}
5353
}
5454

55-
toString () {
56-
return [
57-
this.rawSpaceBefore,
58-
this.qualifiedName(this.stringifyProperty("value")),
59-
this.rawSpaceAfter,
60-
].join('');
55+
valueToString () {
56+
return this.qualifiedName(super.valueToString());
6157
}
6258
};

src/selectors/node.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default class Node {
124124
}
125125

126126
/**
127-
*
127+
*
128128
* @param {number} line The number (starting with 1)
129129
* @param {number} column The column number (starting with 1)
130130
*/
@@ -177,10 +177,14 @@ export default class Node {
177177
this.raws.spaces.after = raw;
178178
}
179179

180+
valueToString () {
181+
return String(this.stringifyProperty("value"));
182+
}
183+
180184
toString () {
181185
return [
182186
this.rawSpaceBefore,
183-
String(this.stringifyProperty("value")),
187+
this.valueToString(),
184188
this.rawSpaceAfter,
185189
].join('');
186190
}

0 commit comments

Comments
 (0)