stylecow-plugin-nested-rules
Advanced tools
Comparing version 5.0.0 to 5.0.1
83
index.js
@@ -5,29 +5,15 @@ "use strict"; | ||
//Merge nested rules | ||
tasks.addTask({ | ||
filter: 'Rule', | ||
fn: function (parentRule) { | ||
var index = parentRule.index(), offset = 1; | ||
fn: resolveNested | ||
}); | ||
parentRule | ||
.getChild('Block') | ||
.getChildren() | ||
.forEach(function (child) { | ||
// resolve nested @media | ||
if (child.type === 'AtRule' && child.name === 'media') { | ||
nestedRuleMedia(parentRule, child, index + offset); | ||
++offset; | ||
} | ||
// resolve nested rules | ||
else if (child.type === 'Rule') { | ||
nestedRule(parentRule, child, index + offset); | ||
++offset; | ||
} | ||
}); | ||
//remove the rule if it's empty | ||
if (!parentRule.getChild('Block').length) { | ||
parentRule.remove(); | ||
} | ||
} | ||
//Merge nested @nest | ||
tasks.addTask({ | ||
filter: { | ||
type: 'AtRule', | ||
name: 'nest' | ||
}, | ||
fn: resolveNested | ||
}); | ||
@@ -54,2 +40,37 @@ | ||
function resolveNested(parentRule) { | ||
var index = parentRule.index(), offset = 1; | ||
parentRule | ||
.getChild('Block') | ||
.getChildren() | ||
.forEach(function (child) { | ||
if (child.type === 'AtRule') { | ||
// resolve nested @media | ||
if (child.name === 'media') { | ||
nestedRuleMedia(parentRule, child, index + offset); | ||
++offset; | ||
} | ||
// resolve @nested at-rules | ||
else if (child.name === 'nest') { | ||
nestedRule(parentRule, child, index + offset); | ||
++offset; | ||
} | ||
} | ||
// resolve nested rules | ||
else if (child.type === 'Rule') { | ||
nestedRule(parentRule, child, index + offset); | ||
++offset; | ||
} | ||
}); | ||
//remove the rule if it's empty | ||
if (!parentRule.getChild('Block').length) { | ||
parentRule.remove(); | ||
} | ||
} | ||
function nestedRuleMedia(parentRule, media, parentRuleIndex) { | ||
@@ -111,2 +132,14 @@ var rule = new stylecow.Rule(); | ||
selectors.replaceWith(mergedSelectors); | ||
//@nest | ||
if (rule.type === 'AtRule') { | ||
let tmpRule = new stylecow.Rule(); | ||
while (rule.length) { | ||
tmpRule.push(rule.shift()); | ||
} | ||
rule.remove(); | ||
rule = tmpRule; | ||
} | ||
parentRule.getParent().splice(parentRuleIndex, 0, rule); | ||
@@ -116,3 +149,3 @@ } | ||
function mergeSelector (selector, appendedSelector) { | ||
var joinCombinator = appendedSelector.getChild({ | ||
var joinCombinator = appendedSelector.get({ | ||
type: 'Combinator', | ||
@@ -119,0 +152,0 @@ name: '&' |
{ | ||
"name": "stylecow-plugin-nested-rules", | ||
"description": "Stylecow plugin to add support for nested rules.", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"engines": { | ||
@@ -16,4 +16,4 @@ "node": ">=4.0" | ||
"devDependencies": { | ||
"mocha": "^2.3.2", | ||
"stylecow-core": "^2.0.0", | ||
"mocha": "^2.3.3", | ||
"stylecow-core": "^2.0.2", | ||
"stylecow-plugin-custom-media": "^2.0.0" | ||
@@ -20,0 +20,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66397
25
2449