diff --git a/lib/css-tools.js b/lib/css-tools.js
index 4b1e77fb..6517892b 100644
--- a/lib/css-tools.js
+++ b/lib/css-tools.js
@@ -15,7 +15,7 @@ var csstree = require('css-tree'),
function flattenToSelectors(cssAst) {
var selectors = [];
- csstree.walkRules(cssAst, function(node) {
+ csstree.walk(cssAst, {visit: 'Rule', enter: function(node) {
if (node.type !== 'Rule') {
return;
}
@@ -43,7 +43,7 @@ function flattenToSelectors(cssAst) {
selectors.push(selector);
});
- });
+ }});
return selectors;
}
@@ -65,7 +65,7 @@ function filterByMqs(selectors, useMqs) {
var mqStr = mqName;
if (selector.atrule.expression &&
selector.atrule.expression.children.first().type === 'MediaQueryList') {
- var mqExpr = csstree.translate(selector.atrule.expression);
+ var mqExpr = csstree.generate(selector.atrule.expression);
mqStr = [mqName, mqExpr].join(' ');
}
@@ -82,7 +82,7 @@ function filterByMqs(selectors, useMqs) {
*/
function filterByPseudos(selectors, usePseudos) {
return selectors.filter(function(selector) {
- var pseudoSelectorsStr = csstree.translate({
+ var pseudoSelectorsStr = csstree.generate({
type: 'Selector',
children: new List().fromArray(selector.pseudos.map(function(pseudo) {
return pseudo.item.data;
@@ -165,7 +165,7 @@ function sortSelectors(selectors) {
*/
function csstreeToStyleDeclaration(declaration) {
var propertyName = declaration.property,
- propertyValue = csstree.translate(declaration.value),
+ propertyValue = csstree.generate(declaration.value),
propertyPriority = (declaration.important ? 'important' : '');
return {
name: propertyName,
diff --git a/lib/svgo/css-style-declaration.js b/lib/svgo/css-style-declaration.js
index 4bb987cd..fb6d7811 100644
--- a/lib/svgo/css-style-declaration.js
+++ b/lib/svgo/css-style-declaration.js
@@ -127,8 +127,14 @@ CSSStyleDeclaration.prototype._loadCssText = function() {
var self = this;
declarations.children.each(function(declaration) {
- var styleDeclaration = csstools.csstreeToStyleDeclaration(declaration);
- self.setProperty(styleDeclaration.name, styleDeclaration.value, styleDeclaration.priority);
+ try {
+ var styleDeclaration = csstools.csstreeToStyleDeclaration(declaration);
+ self.setProperty(styleDeclaration.name, styleDeclaration.value, styleDeclaration.priority);
+ } catch(styleError) {
+ if(styleError.message !== 'Unknown node type: undefined') {
+ self.parseError = styleError;
+ }
+ }
});
};
diff --git a/package.json b/package.json
index 8b689f6c..676171fd 100644
--- a/package.json
+++ b/package.json
@@ -53,7 +53,7 @@
"colors": "~1.1.2",
"css-select": "~1.3.0-rc0",
"css-select-base-adapter": "~0.1.0",
- "css-tree": "1.0.0-alpha25",
+ "css-tree": "1.0.0-alpha.28",
"css-url-regex": "^1.1.0",
"csso": "^3.5.0",
"js-yaml": "~3.10.0",
diff --git a/plugins/inlineStyles.js b/plugins/inlineStyles.js
index 8573649a..e4f65e00 100644
--- a/plugins/inlineStyles.js
+++ b/plugins/inlineStyles.js
@@ -103,7 +103,7 @@ exports.fn = function(document, opts) {
// match selectors
for (selector of sortedSelectors) {
- var selectorStr = csstree.translate(selector.item.data),
+ var selectorStr = csstree.generate(selector.item.data),
selectedEls = null;
try {
@@ -143,7 +143,7 @@ exports.fn = function(document, opts) {
}
// merge declarations
- csstree.walkDeclarations(selector.rule, function(styleCsstreeDeclaration) {
+ csstree.walk(selector.rule, {visit: 'Declaration', enter: function(styleCsstreeDeclaration) {
// existing inline styles have higher priority
// no inline styles, external styles, external styles used
@@ -155,7 +155,7 @@ exports.fn = function(document, opts) {
return;
}
selectedEl.style.setProperty(styleDeclaration.name, styleDeclaration.value, styleDeclaration.priority);
- });
+ }});
}
if (opts.removeMatchedSelectors && selector.selectedEls !== null && selector.selectedEls.length > 0) {
@@ -202,7 +202,7 @@ exports.fn = function(document, opts) {
// clean up now empty elements
for (var style of styles) {
- csstree.walkRules(style.cssAst, function(node, item, list) {
+ csstree.walk(style.cssAst, {visit: 'Rule', enter: function(node, item, list) {
// clean up atrules without any rulesets left
if (node.type === 'Atrule' &&
// only Atrules containing rulesets
@@ -217,7 +217,7 @@ exports.fn = function(document, opts) {
node.prelude.children.isEmpty()) {
list.remove(item);
}
- });
+ }});
if (style.cssAst.children.isEmpty()) {
@@ -237,7 +237,7 @@ exports.fn = function(document, opts) {
// update existing, left over
diff --git a/test/plugins/inlineStyles.13.svg b/test/plugins/inlineStyles.13.svg
index 5c7b3961..6bb9b8bd 100644
--- a/test/plugins/inlineStyles.13.svg
+++ b/test/plugins/inlineStyles.13.svg
@@ -61,7 +61,7 @@