Skip to content

Commit

Permalink
Prevent error if property block has no value (level 0) (#1061)
Browse files Browse the repository at this point in the history
The tokenizer will parse a property like `width: ;`, but the property
helper for level 0 (i.e. minification only) was not accounting for
properties without a value and would throw a TypeError if the value
was missing

With this change, the property helper now checks for a missing property
value before trying to access it
  • Loading branch information
clarkdave authored and jakubpawlowicz committed Mar 13, 2019
1 parent 887ac0e commit dc728a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/writer/helpers.js
Expand Up @@ -77,7 +77,9 @@ function lastPropertyIndex(tokens) {
function property(context, tokens, position, lastPropertyAt) {
var store = context.store;
var token = tokens[position];
var isPropertyBlock = token[2][0] == Token.PROPERTY_BLOCK;

var propertyValue = token[2];
var isPropertyBlock = propertyValue && propertyValue[0] === Token.PROPERTY_BLOCK;

var needsSemicolon;
if ( context.format ) {
Expand Down Expand Up @@ -111,7 +113,9 @@ function property(context, tokens, position, lastPropertyAt) {
case Token.PROPERTY:
store(context, token[1]);
store(context, colon(context));
value(context, token);
if (propertyValue) {
value(context, token);
}
store(context, needsSemicolon ? semicolon(context, Breaks.AfterProperty, isLast) : emptyCharacter);
break;
case Token.RAW:
Expand Down
8 changes: 8 additions & 0 deletions test/optimizer/level-0/optimizations-test.js
Expand Up @@ -11,4 +11,12 @@ vows.describe('level 0')
]
}, { level: 0 })
)
.addBatch(
optimizerContext('empty properties', {
'are written': [
'a{color:#f00;font-weight:;background:red}',
'a{color:#f00;font-weight:;background:red}'
]
}, { level: 0 })
)
.export(module);

0 comments on commit dc728a8

Please sign in to comment.