Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export function parseValue(value) {
}

export function parseList(list) {
return `(${list
const listContent = list
.map(value => parseValue(value))
.join(',')})`;
.join(',');
return listContent ? `(${listContent},)` : `()`;
}

export function parseMap(map) {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures-json5/empty-lists/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'variables.json5';

body {
color: type-of($colors);
}
3 changes: 3 additions & 0 deletions test/fixtures-json5/empty-lists/variables.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
'colors': [], // Empty array
}
5 changes: 5 additions & 0 deletions test/fixtures-json5/one-element-lists/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'variables.json5';

body {
color: type-of($colors);
}
3 changes: 3 additions & 0 deletions test/fixtures-json5/one-element-lists/variables.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
'colors': ['#c33'], // Array with one item
}
5 changes: 5 additions & 0 deletions test/fixtures/empty-lists/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'variables.json';

body {
color: type-of($colors);
}
3 changes: 3 additions & 0 deletions test/fixtures/empty-lists/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"colors": []
}
5 changes: 5 additions & 0 deletions test/fixtures/one-element-lists/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'variables.json';

body {
color: type-of($colors);
}
3 changes: 3 additions & 0 deletions test/fixtures/one-element-lists/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"colors": ["#c33"]
}
42 changes: 39 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ describe('Import type test (JSON)', function() {
expect(result.css.toString()).to.eql(EXPECTATION);
});

it('imports one element lists correctly', function() {
let result = sass.renderSync({
file: './test/fixtures/one-element-lists/style.scss',
importer: jsonImporter(),
});

expect(result.css.toString()).to.eql('body {\n color: list; }\n');
});

it('imports empty lists correctly', function() {
let result = sass.renderSync({
file: './test/fixtures/empty-lists/style.scss',
importer: jsonImporter(),
});

expect(result.css.toString()).to.eql('body {\n color: list; }\n');
});

it('imports maps', function() {
let result = sass.renderSync({
file: './test/fixtures/maps/style.scss',
Expand Down Expand Up @@ -174,6 +192,24 @@ describe('Import type test (JSON5)', function() {
expect(result.css.toString()).to.eql(EXPECTATION);
});

it('imports one element lists correctly', function() {
let result = sass.renderSync({
file: './test/fixtures-json5/one-element-lists/style.scss',
importer: jsonImporter(),
});

expect(result.css.toString()).to.eql('body {\n color: list; }\n');
});

it('imports empty lists correctly', function() {
let result = sass.renderSync({
file: './test/fixtures-json5/empty-lists/style.scss',
importer: jsonImporter(),
});

expect(result.css.toString()).to.eql('body {\n color: list; }\n');
});

it('imports maps', function() {
let result = sass.renderSync({
file: './test/fixtures-json5/maps/style.scss',
Expand Down Expand Up @@ -279,11 +315,11 @@ describe('Import type test (JSON5)', function() {
});

describe('parseValue', function() {
it('returns comma-separated items wrapped in parentheses for an array', function() {
expect(parseValue(['some', 'entries'])).to.eql('(some,entries)');
it('returns comma-separated items wrapped in parentheses with trailing comma for an array', function() {
expect(parseValue(['some', 'entries'])).to.eql('(some,entries,)');
});

it('calls comma-separated key value pairs wrapped in parentheses for an object', function() {
it('returns comma-separated key value pairs wrapped in parentheses for an object', function() {
expect(parseValue({'key1': 'value1', 'key2': 'value2'})).to.eql('(key1: value1,key2: value2)');
});

Expand Down