Skip to content

Commit 2a3090c

Browse files
authored
Merge pull request #60 from dfreeman/handle-nodeless-rules
Don't crash on rules without child nodes
2 parents 9e0439a + bda1d1c commit 2a3090c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,12 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
264264
throw rule.error('Selector "' + Tokenizer.stringify(selector) + '" is not pure ' +
265265
'(pure selectors must contain at least one local class or id)');
266266
}
267-
rule.nodes.forEach(function(decl) {
268-
localizeDecl(decl, context);
269-
});
267+
// Less-syntax mixins parse as rules with no nodes
268+
if (rule.nodes) {
269+
rule.nodes.forEach(function(decl) {
270+
localizeDecl(decl, context);
271+
});
272+
}
270273
rule.selector = Tokenizer.stringify(newSelector);
271274
});
272275
};

test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ var tests = [
389389
should: 'not crash on atrule without nodes',
390390
input: '@charset "utf-8";',
391391
expected: '@charset "utf-8";'
392+
},
393+
{
394+
should: 'not crash on a rule without nodes',
395+
input: (function() {
396+
var inner = postcss.rule({ selector: '.b', ruleWithoutBody: true });
397+
var outer = postcss.rule({ selector: '.a' }).push(inner);
398+
var root = postcss.root().push(outer);
399+
inner.nodes = undefined;
400+
return root;
401+
})(),
402+
// postcss-less's stringify would honor `ruleWithoutBody` and omit the trailing `{}`
403+
expected: ':local(.a) {\n :local(.b) {}\n}'
392404
}
393405

394406
];

0 commit comments

Comments
 (0)