Skip to content

Commit

Permalink
Fix preact/debug accessing attributes that don't have toString (#754)
Browse files Browse the repository at this point in the history
* Fix accessing attributes that don't inherit Object

* Use object's toString if it exists

* Fix spacing

* Fix spacing

* Fix spacing
  • Loading branch information
pluscubed authored and developit committed Aug 20, 2017
1 parent 0a88752 commit 68fa510
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions debug/index.js
Expand Up @@ -70,7 +70,17 @@ if (process.env.NODE_ENV === 'development') {

if (attributes) {
props = Object.keys(attributes).map(attr => {
return `${attr}=${JSON.stringify(attributes[attr] + '')}`;
const attrValue = attributes[attr];
let attrValueString;

// If it is an object but doesn't have toString(), use Object.toString
if (Object(attrValue) === attrValue && !attrValue.toString) {
attrValueString = Object.prototype.toString.call(attrValue);
} else {
attrValueString = attrValue + '';
}

return `${attr}=${JSON.stringify(attrValueString)}`;
});
}

Expand All @@ -82,4 +92,4 @@ if (process.env.NODE_ENV === 'development') {
};

require('preact/devtools');
}
}

0 comments on commit 68fa510

Please sign in to comment.