🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

postcss-css-variables

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-css-variables - npm Package Compare versions

Comparing version

to
0.3.7

# v0.3.7 - 2015-5-27
- Fix #7: Support for child combinator
- Added tests for child combinator coverage
# v0.3.6 - 2015-5-21

@@ -3,0 +8,0 @@

// PostCSS CSS Variables (postcss-css-variables)
// v0.3.6
// v0.3.7
//

@@ -68,3 +68,3 @@ // https://github.com/MadLittleMods/postcss-css-variables

/* * /
/* */
try {

@@ -247,3 +247,3 @@ /* */

/* * /
/* */
}

@@ -250,0 +250,0 @@ catch(e) {

@@ -1,6 +0,6 @@

// Unit Tests: https://regex101.com/r/oP0fM9/13
// Unit Tests: https://regex101.com/r/oP0fM9/15
//
// It is a shame the regex has to be this long. Maybe a CSS selector parser would be better.
// We could almost use `/\b\s(?![><+~][\s]+?)/` to split the selector but this doesn't work with attribute selectors
var RE_SELECTOR_DESCENDANT_SPLIT = (/(.*?(?:(?:\[[^\]]+\]|(?![><+~\s]).)+)(?:(?:(?:\s(?!>>))|(?:\t(?!>>))|(?:\s?>>\s?))(?!\s+))(?![><+~][\s]+?))/);
var RE_SELECTOR_DESCENDANT_SPLIT = (/(.*?(?:(?:\([^\)]+\)|\[[^\]]+\]|(?![><+~\s]).)+)(?:(?:(?:\s(?!>>))|(?:\t(?!>>))|(?:\s?>>\s?))(?!\s+))(?![><+~][\s]+?))/);

@@ -7,0 +7,0 @@

var escapeStringRegexp = require('escape-string-regexp');
var isPieceIsAlwaysAncestorSelector = require('./is-piece-always-ancestor-selector');
var isPieceAlwaysAncestorSelector = require('./is-piece-always-ancestor-selector');
var generateDirectDescendantPiecesFromSelector = require('./generate-direct-descendant-pieces-from-selector');
// Given the nodes scope, and the target scope,
// Is the node in the same or under the target scope (cascade wise)
//
// Another way to think about it: Can the target cascade properties to the node?
//
// For scope-lists see: `generateScopeList`
var isUnderScope = function(nodeScopeList, scopeNodeScopeList) {
var matchesScope = scopeNodeScopeList.some(function(scopeNodeScopePieces) {
function asdfqwer(nodeScopeList, scopeNodeScopeList) {
var currentPieceOffset;
var scopePieceIndex;
// Check each comma separated piece of the complex selector
var doesMatchScope = scopeNodeScopeList.some(function(scopeNodeScopePieces) {
return nodeScopeList.some(function(nodeScopePieces) {
var currentPieceOffset;
var wasEveryPieceFound = scopeNodeScopePieces.every(function(scopePiece) {
currentPieceOffset = null;
var wasEveryPieceFound = true;
// scopeNodeScopePieces.every(function(scopePiece) {
for(scopePieceIndex = 0; scopePieceIndex < scopeNodeScopePieces.length; scopePieceIndex++) {
var scopePiece = scopeNodeScopePieces[scopePieceIndex];
var pieceOffset = currentPieceOffset || 0;
var foundIndex = -1;
var firstAlwaysAncestorPieceIndex = -1;
// Look through the remaining pieces(start from the offset)
var piecesWeCanMatch = nodeScopePieces.slice(pieceOffset);
piecesWeCanMatch.some(function(nodeScopePiece, index) {
var overallIndex = pieceOffset + index;
//piecesWeCanMatch.some(function(nodeScopePiece, index) {
for(var nodeScopePieceIndex = 0; nodeScopePieceIndex < piecesWeCanMatch.length; nodeScopePieceIndex++) {
var nodeScopePiece = piecesWeCanMatch[nodeScopePieceIndex];
var overallIndex = pieceOffset + nodeScopePieceIndex;
if(firstAlwaysAncestorPieceIndex < 0 && isPieceIsAlwaysAncestorSelector(nodeScopePiece)) {
firstAlwaysAncestorPieceIndex = overallIndex;
}
// Find the scope piece at the end of the node selector
// Last-occurence
if(new RegExp(escapeStringRegexp(scopePiece) + '$').test(nodeScopePiece)) {
if(
// If the part on the end of the piece itself matches:
// scopePiece `.bar` matches node `.bar`
// scopePiece `.bar` matches node `.foo + .bar`
new RegExp(escapeStringRegexp(scopePiece) + '$').test(nodeScopePiece)
) {
foundIndex = overallIndex;
// Escape
return true;
break;
}
return false;
});
// If the scope piece is a always-ancestor, then it is valid no matter what
if(foundIndex < 0 && isPieceIsAlwaysAncestorSelector(scopePiece)) {
foundIndex = pieceOffset + 1;
// If the scope piece is a always-ancestor, then it is valid no matter what
//
// Or the node scope piece could be an always-ancestor selector itself
// And we only want the first occurence so we can keep matching future scope pieces
if(isPieceAlwaysAncestorSelector(scopePiece) || isPieceAlwaysAncestorSelector(nodeScopePiece)) {
foundIndex = overallIndex;
break;
}
// Handle any direct descendant operators in each piece
var directDescendantPieces = generateDirectDescendantPiecesFromSelector(nodeScopePiece);
if(directDescendantPieces.length > 1) {
var ddNodeScopeList = [].concat([directDescendantPieces]);
var ddScopeList = [].concat([
scopeNodeScopePieces
.slice(scopePieceIndex)
.reduce(function(prevScopePieces, scopePiece) {
return prevScopePieces.concat(generateDirectDescendantPiecesFromSelector(scopePiece));
}, [])
]);
var result = asdfqwer(ddNodeScopeList, ddScopeList);
// If it matches completely
// or there are still more pieces to match in the future
if(result.doesMatchScope || scopePieceIndex+1 < scopeNodeScopePieces.length) {
foundIndex = overallIndex;
// -1 because the fo loop increments at the top
scopePieceIndex += result.scopePieceIndex-1;
}
break;
}
if(directDescendantPieces.length > 1) {
var asdf = scopeNodeScopePieces.slice(scopePieceIndex);
}
}
// The piece could be a always-ancestor selector itself
// And we only want the first occurence so we can keep matching future scope pieces
else if(foundIndex < 0 && firstAlwaysAncestorPieceIndex > 0) {
foundIndex = firstAlwaysAncestorPieceIndex;
}
var isFurther = foundIndex > pieceOffset || (foundIndex >= 0 && currentPieceOffset === undefined);
var isFurther = foundIndex >= pieceOffset;
currentPieceOffset = foundIndex;
return isFurther;
});
currentPieceOffset = foundIndex+1;
wasEveryPieceFound = wasEveryPieceFound && isFurther;
if(!wasEveryPieceFound) {
break;
}
}
return wasEveryPieceFound;

@@ -58,5 +102,23 @@ });

return matchesScope;
return {
doesMatchScope: doesMatchScope,
nodeScopePieceIndex: currentPieceOffset-1,
scopePieceIndex: scopePieceIndex
};
}
// Given the nodes scope, and the target scope,
// Is the node in the same or under the target scope (cascade wise)
//
// Another way to think about it: Can the target scope cascade properties to the node?
//
// For scope-lists see: `generateScopeList`
var isUnderScope = function isUnderScope(nodeScopeList, scopeNodeScopeList) {
return asdfqwer(nodeScopeList, scopeNodeScopeList).doesMatchScope;
};
module.exports = isUnderScope;

@@ -20,2 +20,4 @@ var resolveValue = require('./resolve-value');

// Grab the balue for this declarations

@@ -22,0 +24,0 @@ var valueResults = _logResolveValueResult(resolveValue(decl, map));

@@ -21,3 +21,3 @@ var generateScopeList = require('./generate-scope-list');

// This means, feel free to run everything through this function
var resolveValue = function(decl, map, _debugIsInternal) {
var resolveValue = function(decl, map, /*internal debugging*/_debugIsInternal) {

@@ -35,3 +35,2 @@ var resultantValue = decl.value;

// Resolve any var(...) substitutons

@@ -55,3 +54,3 @@ var isResultantValueUndefined = false;

//console.log(debugIndent, 'isNodeUnderScope', isNodeUnderScope(decl.parent, varDeclMapItem.parent), varDeclMapItem.decl.value);
if(

@@ -58,0 +57,0 @@ isNodeUnderScope(decl.parent, varDeclMapItem.parent) &&

{
"name": "postcss-css-variables",
"version": "0.3.6",
"version": "0.3.7",
"description": "PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation",

@@ -19,6 +19,6 @@ "keywords": [

"extend": "^2.0.1",
"postcss": "^4.1.5"
"postcss": "^4.1.11"
},
"devDependencies": {
"bluebird": "^2.9.25",
"bluebird": "^2.9.26",
"chai": "^2.3.0",

@@ -28,5 +28,5 @@ "chai-as-promised": "^5.0.0",

"gulp": "^3.8.11",
"gulp-eslint": "^0.11.1",
"gulp-mocha": "^2.0.1",
"mocha": "^2.2.4"
"gulp-eslint": "^0.12.0",
"gulp-mocha": "^2.1.0",
"mocha": "^2.2.5"
},

@@ -33,0 +33,0 @@ "scripts": {

@@ -11,3 +11,3 @@ [![npm version](https://badge.fury.io/js/postcss-css-variables.svg)](http://badge.fury.io/js/postcss-css-variables) [![Build Status](https://travis-ci.org/MadLittleMods/postcss-css-variables.svg)](https://travis-ci.org/MadLittleMods/postcss-css-variables)

## Latest Version: v0.3.6
## Latest Version: v0.3.7
### [Changelog](https://github.com/MadLittleMods/postcss-css-variables/blob/master/CHANGELOG.md)

@@ -14,0 +14,0 @@