Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues#83 #84

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ CSSOM.parse = function parse(token) {
"importRule-begin": true,
"importRule": true,
"atBlock": true,
'documentRule-begin': true
'documentRule-begin': true,
"value-parenthesis": true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't used anywhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this used in test ".gradient{background: -moz-linear-gradient(/);/top, #1E5799 0%, #7db9e8 100%)}"
I think, this is correct for this test

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see.

};

var styleSheet = new CSSOM.CSSStyleSheet();
Expand Down Expand Up @@ -146,6 +147,7 @@ CSSOM.parse = function parse(token) {
state = "atBlock";
mediaRule = new CSSOM.CSSMediaRule();
mediaRule.__starts = i;
mediaRule.parentRule = parentRule || null;
i += "media".length;
buffer = "";
break;
Expand Down Expand Up @@ -187,6 +189,7 @@ CSSOM.parse = function parse(token) {
state = "before-name";
} else if (state === "atBlock") {
mediaRule.media.mediaText = buffer.trim();
mediaRule.__isValidMediaQuery = /^(\s|\/\*)/.test(token.slice(mediaRule.__starts + '@media'.length, i));
currentScope = parentRule = mediaRule;
mediaRule.parentStyleSheet = styleSheet;
buffer = "";
Expand Down Expand Up @@ -330,9 +333,12 @@ CSSOM.parse = function parse(token) {
}
currentScope.__ends = i + 1;
// Nesting rules aren't supported yet
styleSheet.cssRules.push(currentScope);
currentScope = styleSheet;
parentRule = null;
if(!(currentScope instanceof CSSOM.CSSMediaRule) || currentScope.__isValidMediaQuery) {
(currentScope.parentRule || styleSheet).cssRules.push(currentScope);
}
delete currentScope.__isValidMediaQuery;
currentScope = currentScope.parentRule || styleSheet;
parentRule = parentRule.parentRule || null;
buffer = "";
state = "before-selector";
break;
Expand Down
32 changes: 32 additions & 0 deletions spec/parse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,38 @@ var TESTS = [
return result;
})()
},
{
input: "@-moz-document url-prefix() {@media only screen{.qwe{}}}",
result: (function() {
var result = {
cssRules: [
{
parentRule: null,
matcher: ["url-prefix()"],
cssRules: [
{
media: ["only screen"],
cssRules: [
{
selectorText: ".qwe",
style: []
}
]
}
]
}
],
parentStyleSheet: null
};
result.cssRules[0].parentStyleSheet = result;
result.cssRules[0].cssRules[0].parentRule = result.cssRules[0];
result.cssRules[0].cssRules[0].parentStyleSheet = result;
result.cssRules[0].cssRules[0].cssRules[0].parentRule = result.cssRules[0].cssRules[0];
result.cssRules[0].cssRules[0].cssRules[0].parentStyleSheet = result;
result.cssRules[0].cssRules[0].cssRules[0].style.parentRule = result.cssRules[0].cssRules[0].cssRules[0];
return result;
})()
},
{
input: "a{}@-moz-document/**/url-prefix(http://www.w3.org/Style/){body { color: purple; background: yellow; }}",
result: (function(){
Expand Down