Skip to content

Commit

Permalink
Added a hack to the CSSOM parser that starts a new CSSStyleRule if a …
Browse files Browse the repository at this point in the history
…property gets redefined within the same rule. Also, do the inverse when serializing a CSSStyleSheet. This is a temporary workaround until NV#16 gets resolved.

Cherry-picked from 65e0b93.

Conflicts:
	package.json
  • Loading branch information
papandreou committed Sep 25, 2015
1 parent e491792 commit 1977ab6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/CSSStyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,21 @@ CSSOM.CSSStyleSheet.prototype.toString = function() {
var result = "";
var rules = this.cssRules;
for (var i=0; i<rules.length; i++) {
result += rules[i].cssText + "\n";
if (rules[i].type === 1) {
result += rules[i].selectorText + " {";
if (rules[i].style) {
result += rules[i].style.cssText;
}
while (i + 1 < rules.length && rules[i + 1].selectorText === rules[i].selectorText) {
i += 1;
if (rules[i].style) {
result += " " + rules[i].style.cssText;
}
}
result += "}\n";
} else {
result += rules[i].cssText + "\n";
}
}
return result;
};
Expand Down
18 changes: 18 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ CSSOM.parse = function parse(token) {
case ";":
switch (state) {
case "value":
// Hack: Start a new CSSStyleRule if a property gets redefined.
// Temporary workaround until https://github.com/NV/CSSOM/issues/16 gets resolved
if (styleRule.style.getPropertyValue(name)) {
styleRule.__ends = i;
currentScope.cssRules.push(styleRule);
styleRule = new CSSOM.CSSStyleRule;
styleRule.selectorText = currentScope.cssRules[currentScope.cssRules.length - 1].selectorText;
styleRule.__starts = i;
}
styleRule.style.setProperty(name, buffer.trim(), priority);
priority = "";
buffer = "";
Expand All @@ -301,6 +310,15 @@ CSSOM.parse = function parse(token) {
case "}":
switch (state) {
case "value":
// Hack: Start a new CSSStyleRule if a property gets redefined.
// Temporary workaround until https://github.com/NV/CSSOM/issues/16 gets resolved
if (styleRule.style.getPropertyValue(name)) {
styleRule.__ends = i;
currentScope.cssRules.push(styleRule);
styleRule = new CSSOM.CSSStyleRule;
styleRule.selectorText = currentScope.cssRules[currentScope.cssRules.length - 1].selectorText;
styleRule.__starts = i;
}
styleRule.style.setProperty(name, buffer.trim(), priority);
priority = "";
/* falls through */
Expand Down

0 comments on commit 1977ab6

Please sign in to comment.