Skip to content

Commit

Permalink
feat(struct): add separator info to list
Browse files Browse the repository at this point in the history
  • Loading branch information
roblan committed Nov 4, 2017
1 parent 1eb9af1 commit 2e44151
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ $variable: 1px solid black;
```js
{
type: 'SassList',
commaSeparator: false,
value: [
{
type: 'SassNumber',
Expand All @@ -381,6 +382,28 @@ $variable: 1px solid black;
}
```

*Or when it's comma separated*

```scss
$variable: tahoma, arial;
```
```js
{
type: 'SassList',
commaSeparator: true,
value: [
{
type: 'SassString',
value: 'tahoma'
},
{
type: 'SassString',
value: 'arial'
}
]
}
```

##### SassMap
*SassMaps contains recursive types as an object with matching field names*

Expand Down Expand Up @@ -471,4 +494,4 @@ Generate changelog using `npm install -g conventional-changelog` and `npm run ch
5. `npm run changelog`
6. Commit package.json and CHANGELOG.md files
7. Tag
8. Push
8. Push
6 changes: 3 additions & 3 deletions src/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function makeValue(sassValue) {
},
};

case sass.types.Null:
case sass.types.Null:
return { value: null };

case sass.types.List:
Expand All @@ -36,7 +36,7 @@ function makeValue(sassValue) {
for(let i = 0; i < listLength; i++) {
listValue.push(createStructuredValue(sassValue.getValue(i)));
}
return { value: listValue };
return { value: listValue, commaSeparator: sassValue.getSeparator() };

case sass.types.Map:
const mapLength = sassValue.getLength();
Expand All @@ -57,7 +57,7 @@ function makeValue(sassValue) {
* Create a structured value definition from a sassValue object
*/
export function createStructuredValue(sassValue) {
const value = Object.assign({
const value = Object.assign({
type: sassValue.constructor.name,
}, makeValue(sassValue));

Expand Down
21 changes: 19 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function verifyBasic(rendered, sourceFile, explicit, mixed) {
expect(rendered.vars.global).to.have.property('$number2');
expect(rendered.vars.global).to.have.property('$color');
expect(rendered.vars.global).to.have.property('$list');
expect(rendered.vars.global).to.have.property('$listComma');
expect(rendered.vars.global).to.have.property('$string');
expect(rendered.vars.global).to.have.property('$boolean');
expect(rendered.vars.global).to.have.property('$null');
Expand Down Expand Up @@ -72,11 +73,27 @@ function verifyBasic(rendered, sourceFile, explicit, mixed) {
expect(rendered.vars.global.$list.value[2].value.b).to.equal(0);
expect(rendered.vars.global.$list.value[2].value.a).to.equal(1);
expect(rendered.vars.global.$list.value[2].value.hex).to.equal('#000000');
expect(rendered.vars.global.$list.value[2].type).to.equal('SassColor');
expect(rendered.vars.global.$list.value[2].type).to.equal('SassColor');
expect(rendered.vars.global.$list.commaSeparator).to.equal(false);
if(explicit) {
expect(rendered.vars.global.$list.declarations[0].flags.global).to.equal(true);
}

expect(rendered.vars.global.$listComma.value).to.have.length(2);
expect(rendered.vars.global.$listComma.type).to.equal('SassList');
expect(rendered.vars.global.$listComma.sources).to.have.length(1);
expect(rendered.vars.global.$listComma.sources[0]).to.equal(normalizePath(sourceFile));
expect(rendered.vars.global.$listComma.declarations).to.have.length(1);
expect(rendered.vars.global.$listComma.declarations[0].expression).to.equal(`tahoma, arial${ explicit ? ' !global' : ''}`);
expect(rendered.vars.global.$listComma.value[0].value).to.equal('tahoma');
expect(rendered.vars.global.$listComma.value[0].type).to.equal('SassString');
expect(rendered.vars.global.$listComma.value[1].value).to.equal('arial');
expect(rendered.vars.global.$listComma.value[1].type).to.equal('SassString');
expect(rendered.vars.global.$listComma.commaSeparator).to.equal(true);
if(explicit) {
expect(rendered.vars.global.$listComma.declarations[0].flags.global).to.equal(true);
}

expect(rendered.vars.global.$string.value).to.equal('string');
expect(rendered.vars.global.$string.type).to.equal('SassString');
expect(rendered.vars.global.$string.sources).to.have.length(1);
Expand Down Expand Up @@ -177,4 +194,4 @@ describe('basic-mixed', () => {
});
});
});
});
});
3 changes: 2 additions & 1 deletion test/sass/basic-explicit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ div {
$number2: $number1 * 2 !global;
$color: get-color() !global;
$list: 1px solid black !global;
$listComma: tahoma, arial !global;
$string: 'string' !global;
$boolean: true !global;
$null: null !global;
$map: (
number: 2em,
string: 'mapstring'
) !global;
}
}
3 changes: 2 additions & 1 deletion test/sass/basic-implicit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ $number1: 100px;
$number2: $number1 * 2;
$color: get-color();
$list: 1px solid black;
$listComma: tahoma, arial;
$string: 'string';
$boolean: true;
$null: null;
$map: (
number: 2em,
string: 'mapstring'
);
);
3 changes: 2 additions & 1 deletion test/sass/basic-mixed.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


$list: 1px solid black;
$listComma: tahoma, arial;
$string: 'string';
$map: (
number: 2em,
Expand All @@ -24,4 +25,4 @@ div {
}

$boolean: true;
$null: null;
$null: null;
3 changes: 2 additions & 1 deletion test/sass/comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ $number1: 100px;
$number2: $number1 * 2; // Comment
$color: red;
/* $list: 1px solid black;
$listComma: tahoma, arial;
$string: 'string';
$map: (
number: 2em,
// blah
string: 'mapstring'
); */

// $test: 250px;
// $test: 250px;

0 comments on commit 2e44151

Please sign in to comment.