Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-tree

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-tree - npm Package Compare versions

Comparing version 1.0.0-alpha.34 to 1.0.0-alpha.35

6

CHANGELOG.md

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

## 1.0.0-alpha.35 (October 7, 2019)
- Walker
- Changed implementation to avoid runtime compilation due to CSP issues (see #91, #109)
- Added `find()`, `findLast()` and `findAll()` methods (e.g. `csstree.find(ast, node => node.type === 'ClassSelector')`)
## 1.0.0-alpha.34 (July 27, 2019)

@@ -2,0 +8,0 @@

4

lib/syntax/create.js

@@ -51,2 +51,6 @@ var List = require('../common/List');

find: walk.find,
findLast: walk.findLast,
findAll: walk.findAll,
clone: clone,

@@ -53,0 +57,0 @@ fromPlainObject: convert.fromPlainObject,

98

lib/walker/create.js

@@ -81,32 +81,39 @@ var hasOwnProperty = Object.prototype.hasOwnProperty;

function createTypeIterator(config, reverse) {
var fields = reverse ? config.fields.slice().reverse() : config.fields;
var body = fields.map(function(field) {
var ref = 'node.' + field.name;
var line;
var fields = config.fields.slice();
var contextName = config.context;
var useContext = typeof contextName === 'string';
if (field.type === 'list') {
line = reverse
? ref + '.forEachRight(walk);'
: ref + '.forEach(walk);';
} else {
line = 'walk(' + ref + ');';
}
if (reverse) {
fields.reverse();
}
if (field.nullable) {
line = 'if (' + ref + ') {\n ' + line + '}';
return function(node, context, walk) {
var prevContextValue;
if (useContext) {
prevContextValue = context[contextName];
context[contextName] = node;
}
return line;
});
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var ref = node[field.name];
if (config.context) {
body = [].concat(
'var old = context.' + config.context + ';',
'context.' + config.context + ' = node;',
body,
'context.' + config.context + ' = old;'
);
}
if (!field.nullable || ref) {
if (field.type === 'list') {
if (reverse) {
ref.forEachRight(walk);
} else {
ref.forEach(walk);
}
} else {
walk(ref);
}
}
}
return new Function('node', 'context', 'walk', body.join('\n'));
if (useContext) {
context[contextName] = prevContextValue;
}
};
}

@@ -152,3 +159,3 @@

return function walk(root, options) {
var walk = function(root, options) {
function walkNode(node, item, list) {

@@ -216,2 +223,43 @@ enter.call(context, node, item, list);

};
walk.find = function(ast, fn) {
var found = null;
walk(ast, function(node, item, list) {
if (found === null && fn.call(this, node, item, list)) {
found = node;
}
});
return found;
};
walk.findLast = function(ast, fn) {
var found = null;
walk(ast, {
reverse: true,
enter: function(node, item, list) {
if (found === null && fn.call(this, node, item, list)) {
found = node;
}
}
});
return found;
};
walk.findAll = function(ast, fn) {
var found = [];
walk(ast, function(node, item, list) {
if (fn.call(this, node, item, list)) {
found.push(node);
}
});
return found;
};
return walk;
};
{
"name": "css-tree",
"version": "1.0.0-alpha.34",
"version": "1.0.0-alpha.35",
"description": "CSSTree is a tool set to work with CSS, including fast detailed parser (string->AST), walker (AST traversal), generator (AST->string) and lexer (validation and matching) based on knowledge of spec and browser implementations",
"author": "Roman Dvornov <rdvornov@gmail.com> (https://github.com/lahmatiy)",
"license": "MIT",
"repository": "csstree/csstree",
"keywords": [

@@ -17,16 +20,2 @@ "css",

],
"homepage": "https://github.com/csstree/csstree",
"author": "Roman Dvornov <rdvornov@gmail.com> (https://github.com/lahmatiy)",
"maintainers": [
{
"name": "Roman Dvornov",
"email": "rdvornov@gmail.com",
"github-username": "lahmatiy"
}
],
"license": "MIT",
"repository": "csstree/csstree",
"bugs": {
"url": "https://github.com/csstree/csstree/issues"
},
"main": "./lib/index",

@@ -63,3 +52,3 @@ "browser": {

"coverage": "istanbul cover _mocha -- -R min",
"prepublish": "npm run build",
"prepublishOnly": "npm run build",
"travis": "npm run lint-and-test && npm run coveralls",

@@ -88,8 +77,5 @@ "coveralls": "istanbul cover _mocha --report lcovonly -- -R min && cat ./coverage/lcov.info | coveralls",

"data",
"dist/csstree.js",
"lib",
"CHANGELOG.md",
"LICENSE",
"README.md"
"dist",
"lib"
]
}

Sorry, the diff of this file is too big to display

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