Skip to content

Commit

Permalink
Fix #820 (#821)
Browse files Browse the repository at this point in the history
* Add test for inlineStyles plugin/CSSStyleDeclaration API.

* Adjust test.

* Always initialize element attrs with empty object.
Improve code.
  • Loading branch information
strarsis authored and GreLI committed Oct 31, 2017
1 parent 80ed684 commit 471aec5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/svgo/css-style-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ var CSSStyleDeclaration = function(node) {


CSSStyleDeclaration.prototype.hasStyle = function() {
this.styleAttr = { // empty style attr
'name': 'style',
'value': null
};

this.addStyleHandler();
};

Expand All @@ -33,6 +28,11 @@ CSSStyleDeclaration.prototype.hasStyle = function() {

CSSStyleDeclaration.prototype.addStyleHandler = function() {

this.styleAttr = { // empty style attr
'name': 'style',
'value': null
};

Object.defineProperty(this.parentNode.attrs, 'style', {
get: this.getStyleAttr.bind(this),
set: this.setStyleAttr.bind(this),
Expand Down
7 changes: 3 additions & 4 deletions lib/svgo/svg2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ module.exports = function(data, callback) {
var elem = {
elem: data.name,
prefix: data.prefix,
local: data.local
local: data.local,
attrs: {}
};

elem.class = new CSSClassList(elem);
elem.style = new CSSStyleDeclaration(elem);

if (Object.keys(data.attributes).length) {
elem.attrs = {};


for (var name in data.attributes) {

if (name === 'class') { // has class attribute
Expand Down
18 changes: 18 additions & 0 deletions test/plugins/inlineStyles.17.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 471aec5

Please sign in to comment.