From aac3ffe2acf561c7391a36c3af712990bf446cc5 Mon Sep 17 00:00:00 2001 From: Michael Holloway Date: Mon, 25 Jan 2016 11:58:20 -0500 Subject: [PATCH] Prevent TypeError due to undefined property when parsing styles --- lib/CSSStyleDeclaration.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js index f7cdd42..f6eb666 100644 --- a/lib/CSSStyleDeclaration.js +++ b/lib/CSSStyleDeclaration.js @@ -17,7 +17,10 @@ function parseStyles(s) { parser.addListener("property", function(e) { if (e.invalid) return; // Skip errors result[e.property.text] = e.value.text; - if (e.important) result.important[e.property.text] = e.important; + if (e.important) { + result.important = result.important || {}; + result.important[e.property.text] = e.important; + } }); s = (''+s).replace(/^;/, ''); parser.parseStyleAttribute(s);