Skip to content

Commit ac0b559

Browse files
committed
Filter out as value for a variable
1 parent 3fadd78 commit ac0b559

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
dist/
33
*.sublime*
44
.idea/
5+
*.iml

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
3+
## 3.1.6
4+
* Filter out `#` as value for a variable
5+
26
## 3.1.5
37
* Reverts `3.1.4`. We aren't able to find a way to support automatic handling of values containing `,` that isn't full of edge cases. The recommendation remains to wrap such values in single quotes if they're meant to be interpreted as strings.
48

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function isJSONfile(url) {
4343
export function transformJSONtoSass(json) {
4444
return Object.keys(json)
4545
.filter(key => isValidKey(key))
46+
.filter(key => json[key] !== '#')
4647
.map(key => `$${key}: ${parseValue(json[key])};`)
4748
.join('\n');
4849
}

test/fixtures-json5/invalid-variables/variables.json5

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
"@not-valid": "123", // Not valid because of the leading @
44
":not-valid": "123", // Not valid because of the leading :
55
"$not-valid": "123", // Not valid because of the leading $
6+
"invalid-value": "#", // Not valid because of `#` as value
67
}

test/fixtures/invalid-variables/variables.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"colors": "",
33
"@not-valid": "123",
44
":not-valid": "123",
5-
"$not-valid": "123"
5+
"$not-valid": "123",
6+
"invalid-value": "#"
67
}

test/index.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ describe('Import type test (JSON)', function() {
118118

119119
expect(result.css.toString()).to.eql('body {\n color: ""; }\n');
120120
});
121+
122+
it('filters out `#` as variable value', function() {
123+
let result = sass.renderSync({
124+
file: './test/fixtures-json5/invalid-variables/style.scss',
125+
importer: jsonImporter,
126+
});
127+
128+
expect(result.css.toString()).to.eql('body {\n color: ""; }\n');
129+
});
121130
});
122131

123132
describe('Import type test (JSON5)', function() {
@@ -210,6 +219,15 @@ describe('Import type test (JSON5)', function() {
210219

211220
expect(result.css.toString()).to.eql('body {\n color: ""; }\n');
212221
});
222+
223+
it('filters out `#` as variable value', function() {
224+
let result = sass.renderSync({
225+
file: './test/fixtures-json5/invalid-variables/style.scss',
226+
importer: jsonImporter,
227+
});
228+
229+
expect(result.css.toString()).to.eql('body {\n color: ""; }\n');
230+
});
213231
});
214232

215233
describe('parseValue', function() {
@@ -226,8 +244,9 @@ describe('parseValue', function() {
226244
});
227245

228246
it('returns the raw value if not an array, object or empty string', function() {
229-
expect(123).to.eql(123);
247+
expect(parseValue(123)).to.eql(123);
230248
});
249+
231250
it('can parse nested maps with invalid keys', function() {
232251
const nestedWithInvalid = {
233252
inner: {

0 commit comments

Comments
 (0)