stylecow-plugin-nested-rules
Advanced tools
Comparing version 3.0.0 to 3.1.0
55
index.js
@@ -21,11 +21,3 @@ module.exports = function (stylecow) { | ||
selectors.forEach(function (selector) { | ||
var mergedSelector = parentSelector.clone(); | ||
merge(mergedSelector, selector[0].clone()); | ||
selector.slice(1).forEach(function (element) { | ||
mergedSelector.push(element.clone()); | ||
}); | ||
mergedSelectors.push(mergedSelector); | ||
mergedSelectors.push(merge(parentSelector.clone(), selector.clone())); | ||
}); | ||
@@ -46,27 +38,40 @@ }); | ||
function merge (selector, element) { | ||
if (element[0].name !== '&') { | ||
return selector.push(element); | ||
function merge (selector, appendedSelector) { | ||
var firstElement = appendedSelector.shift(); | ||
// html { .foo { => html .foo | ||
if (firstElement.type !== 'Combinator') { | ||
var separator = new stylecow.Combinator(); | ||
separator.name = ' '; | ||
selector.push(separator); | ||
selector.push(firstElement); | ||
} | ||
// html { >.foo { => html>.foo | ||
else if (firstElement.name !== '&') { | ||
selector.push(firstElement); | ||
} | ||
element[0].remove(); | ||
// .foo { &html { => html.foo | ||
else if (appendedSelector.length && (appendedSelector[0].is({ | ||
type: 'Keyword', | ||
name: /^\w/ | ||
}))) { | ||
firstElement = appendedSelector.shift(); | ||
if (element.length) { | ||
var prevElement = selector.slice(-1)[0]; | ||
var curr = element.shift(); | ||
var combinators = selector.children('Combinator'); | ||
if (curr.is({ | ||
type: 'Keyword', | ||
name: /^\w/ | ||
})) { | ||
prevElement.unshift(curr); | ||
if (combinators.length) { | ||
combinators.pop().after(firstElement); | ||
} else { | ||
prevElement.push(curr); | ||
selector.unshift(firstElement); | ||
} | ||
} | ||
element.forEach(function (child) { | ||
prevElement.push(element); | ||
}); | ||
while (appendedSelector[0]) { | ||
selector.push(appendedSelector[0]); | ||
} | ||
return selector; | ||
} | ||
}; |
{ | ||
"name": "stylecow-plugin-nested-rules", | ||
"description": "Stylecow plugin to add support for nested rules.", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"author": "Oscar Otero <oom@oscarotero.com>", | ||
@@ -12,4 +12,7 @@ "homepage": "https://github.com/stylecow/stylecow-plugin-nested-rules", | ||
}, | ||
"devDependencies": { | ||
"stylecow": "*" | ||
}, | ||
"main": "index.js", | ||
"license": "MIT" | ||
} |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
6451
8
157
1
1