Socket
Socket
Sign inDemoInstall

stylecow-plugin-nested-rules

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stylecow-plugin-nested-rules - npm Package Compare versions

Comparing version 5.0.0 to 5.0.1

tests/cases/nest-atrule/ast.json

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 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc