Comparing version 1.0.0-alpha.34 to 1.0.0-alpha.35
@@ -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 @@ |
@@ -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, |
@@ -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
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
612089
9551
0
1
3