Skip to content

Commit b5402b6

Browse files
committed
Merge branch 'pr-44' into feature/integrate-undefined-variable-string-pr-44
2 parents d9db4db + ad0fc2c commit b5402b6

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/resolve-decl.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,18 @@ function resolveDecl(decl, map, /*optional*/shouldPreserve, /*optional*/logResol
143143
if(shouldPreserve === true && decl.value !== valueResults.value) {
144144
decl.cloneAfter();
145145
}
146-
147-
// Set the new value after we are done dealing with at-rule stuff
148-
decl.value = valueResults.value;
149-
}
146+
147+
148+
// Set 'undefined' value as a string to avoid making other plugins down the line unhappy
149+
// See #22
150+
if (valueResults.value === undefined) {
151+
valueResults.value = 'undefined';
152+
}
153+
154+
155+
// Set the new value after we are done dealing with at-rule stuff
156+
decl.value = valueResults.value;
157+
}
150158

151159

152160

test/test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@ describe('postcss-css-variables', function() {
186186
describe('missing variable declarations', function() {
187187
test('should work with missing variables', 'missing-variable-usage');
188188
test('should use fallback value if provided with missing variables', 'missing-variable-should-fallback');
189+
it('should use string values for `undefined` values, see #22', function() {
190+
return fs.readFileAsync('./test/fixtures/missing-variable-usage.css', 'utf8')
191+
.then(function(buffer) {
192+
var contents = String(buffer);
193+
return postcss([
194+
cssvariables()
195+
])
196+
.process(contents)
197+
.then(function(result) {
198+
var root = result.root;
199+
var fooRule = root.nodes[0];
200+
expect(fooRule.selector).to.equal('.box-foo');
201+
var colorDecl = fooRule.nodes[0];
202+
expect(colorDecl.value).to.be.a('string');
203+
expect(colorDecl.value).to.be.equal('undefined');
204+
return colorDecl.value;
205+
});
206+
});
207+
});
189208
});
190209

191210
it('should not parse malformed var() declarations', function() {
@@ -207,5 +226,4 @@ describe('postcss-css-variables', function() {
207226
);
208227
});
209228

210-
211229
});

0 commit comments

Comments
 (0)