Skip to content

Commit f5f7e14

Browse files
committed
Fix failing if getApplicableNode() receive no node #21
1 parent 0cdf35f commit f5f7e14

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 1.4.1
6+
* Fix issue with a rule content starting with a comment and follow by a rule. Error happens if config has any option except `sort-order`. #21
7+
58
## 1.4.0
69
* Added `preserve-empty-lines-between-children-rules`, which preserve empty lines between children rules and preserve empty lines for comments between children rules. #20
710

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,14 @@ function getApplicableNode(lookFor, node) {
185185
// find if there any rules before, and skip the comments
186186
var prevNode = node.prev();
187187

188-
if (prevNode.type === lookFor) {
189-
return node;
190-
}
188+
if (prevNode) {
189+
if (prevNode.type === lookFor) {
190+
return node;
191+
}
191192

192-
if (prevNode.type === 'comment') {
193-
return getApplicableNode(lookFor, prevNode);
193+
if (prevNode.type === 'comment') {
194+
return getApplicableNode(lookFor, prevNode);
195+
}
194196
}
195197

196198
return false;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-sorting",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "PostCSS plugin to sort rules content with specified order.",
55
"keywords": [
66
"postcss",

test/fixtures/issue-21.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.form-subsection-tbl .tbl-name {
2+
/* obscure stuff */
3+
#page & {
4+
width: 166px;
5+
}
6+
}

test/fixtures/issue-21.expected.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.form-subsection-tbl .tbl-name {
2+
/* obscure stuff */
3+
#page & {
4+
width: 166px;
5+
}
6+
}

test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ test('Should preserve empty lines between children rules and don\'t create unnee
252252
});
253253
});
254254

255+
test('Should not fail if getApplicableNode() receive no node. Issue #21', t => {
256+
return run(t, 'issue-21', {
257+
'empty-lines-between-children-rules': 1
258+
});
259+
});
260+
255261
// test('Should sort LESS files', t => {
256262
// return run(t, 'less.less', {}, 'less');
257263
// });

0 commit comments

Comments
 (0)