Skip to content

Commit 6ac2225

Browse files
committed
Merge pull request #2 from jonathantneal/update/postcss-5
Update to utilize PostCSS 5
2 parents a961907 + 03881ae commit 6ac2225

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.0.0
4+
- [Updated to PostCSS 5](https://github.com/travco/postcss-extend/releases/tag/v1.0.0)
5+
36
## v0.4.3
47
- [Antipattern CSS detection and warning, and media-cross-media warning](https://github.com/travco/postcss-extend/releases/tag/v0.4.3)
58

index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
1313

1414
// /*DEBUG*/ appendout('./test/debugout.txt', '\n----------------------------------------');
1515

16-
css.eachAtRule(function(atRule) {
16+
css.walkAtRules(function(atRule) {
1717
if (definingAtRules.indexOf(atRule.name) !== -1) {
1818
processDefinition(atRule);
1919
} else if (extendingAtRules.indexOf(atRule.name) !== -1) {
@@ -23,7 +23,7 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
2323

2424
//Selectively disclude silents and placeholders, find unused,
2525
//and exclude from the final output
26-
css.eachRule(function(targetNode) {
26+
css.walkRules(function(targetNode) {
2727
var tgtSaved = targetNode.selectors;
2828
var selectorAccumulator;
2929
for (var i = 0; i < tgtSaved.length; i++) {
@@ -34,7 +34,7 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
3434
selectorAccumulator.push(tgtSaved[i]);
3535
}
3636
} else if (tgtSaved.length === 1) {
37-
targetNode.removeSelf();
37+
targetNode.remove();
3838
// /*DEBUG*/ } else {
3939
// /*DEBUG*/ appendout('./test/debugout.txt', '\nSifted out placeholder/silent ' + tgtSaved[i]);
4040
}
@@ -47,35 +47,35 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
4747
//simplification process to find definitions in the future
4848
function processDefinition(atRule) {
4949
if (isBadDefinitionLocation(atRule)) {
50-
atRule.removeSelf();
50+
atRule.remove();
5151
return;
5252
}
5353
var definition = postcss.rule();
5454

5555
//Manually copy styling properties (semicolon, whitespace)
5656
//to newly created and cloned nodes,
5757
//cf. https://github.com/postcss/postcss/issues/85
58-
definition.semicolon = atRule.semicolon;
58+
definition.raws.semicolon = atRule.raws.semicolon;
5959
atRule.nodes.forEach(function(node) {
6060
if (isBadDefinitionNode(node)) return;
6161
var clone = node.clone();
62-
clone.before = node.before;
63-
clone.after = node.after;
64-
clone.between = node.between;
62+
clone.raws.before = node.raws.before;
63+
clone.raws.after = node.raws.after;
64+
clone.raws.between = node.raws.between;
6565
definition.append(clone);
6666
});
6767
definition.selector = '@define-placeholder ' + atRule.params.toString();
6868
// /*DEBUG*/ appendout('./test/debugout.txt', '\nDeclaring placeholder : ' + definition.selector);
6969
atRule.parent.insertBefore(atRule, definition);
70-
atRule.removeSelf();
70+
atRule.remove();
7171
}
7272

7373
function processExtension(atRule) {
7474
if (isBadExtension(atRule)) {
7575
if (!atRule.parent.nodes.length || (atRule.parent.nodes.length === 1 && atRule.parent.type !== 'root')) {
76-
atRule.parent.removeSelf();
76+
atRule.parent.remove();
7777
} else {
78-
atRule.removeSelf();
78+
atRule.remove();
7979
}
8080
return;
8181
}
@@ -88,7 +88,7 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
8888
};
8989

9090
if (!hasMediaAncestor(atRule)) {
91-
css.eachRule(function(targetNode) {
91+
css.walkRules(function(targetNode) {
9292
var tgtSaved = targetNode.selectors;
9393
//Strip all @define-placeholders and save slug-selectors present in tgtSaved
9494
for (var i = 0; i < tgtSaved.length; i++) {
@@ -152,7 +152,7 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
152152
// /*DEBUG*/ appendout('./test/debugout.txt', '\nAttempting to fetch declarations for ' + atRule.params + '...');
153153
var backFirstTargetNode;
154154
var targetNodeArray = [];
155-
css.eachRule(function(subRule) {
155+
css.walkRules(function(subRule) {
156156
//create a back-is-top stack so that we can efficiently operate on nodes in reverse
157157
//thus retaining priority when copying declarations if there are multiple matches
158158
if (!hasMediaAncestor(subRule) || subRule.parent === atRule.parent.parent) {
@@ -241,9 +241,9 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
241241
}
242242
if (atRule.parent !== undefined) {
243243
if (!atRule.parent.nodes.length || atRule.parent.nodes.length === 1) {
244-
atRule.parent.removeSelf();
244+
atRule.parent.remove();
245245
} else {
246-
atRule.removeSelf();
246+
atRule.remove();
247247
}
248248
}
249249
}
@@ -324,12 +324,12 @@ module.exports = postcss.plugin('postcss-simple-extend', function simpleExtend()
324324
var clone = node.clone();
325325
//For lack of a better way to analyse how much tabbing is required:
326326
if (nodeOrigin.parent === nodeDest.parent) {
327-
clone.before = node.before;
327+
clone.raws.before = node.raws.before;
328328
} else {
329-
clone.before = node.before + '\t';
329+
clone.raws.before = node.raws.before + '\t';
330330
}
331-
clone.after = node.after;
332-
clone.between = node.between;
331+
clone.raws.after = node.raws.after;
332+
clone.raws.between = node.raws.between;
333333
nodeDest.append(clone);
334334
});
335335
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"email": "[email protected]"
66
},
77
"license": "MIT",
8-
"version": "0.4.3",
8+
"version": "1.0.0",
99
"description": "As close to cssnext @extend as possible for PostCSS",
1010
"homepage": "https://github.com/travco/postcss-extend",
1111
"repository": {
@@ -32,7 +32,7 @@
3232
"test": "rm -f test/debugout.txt && npm run lint && tape test"
3333
},
3434
"dependencies": {
35-
"postcss": "^4.1.0"
35+
"postcss": "^5.0.4"
3636
},
3737
"devDependencies": {
3838
"eslint": "0.18.0",

0 commit comments

Comments
 (0)