Skip to content

Commit

Permalink
Adding @-moz-document to the lexer and parser. Fixes stylus#436
Browse files Browse the repository at this point in the history
  • Loading branch information
iaman committed Sep 17, 2012
1 parent d708fca commit 86ef561
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Lexer.prototype = {
|| this.scope()
|| this.extends()
|| this.media()
|| this.mozdocument()
|| this.comment()
|| this.newline()
|| this.escaped()
Expand Down Expand Up @@ -461,6 +462,18 @@ Lexer.prototype = {
}
},

/**
* '@-moz-document' ([^{\n]+)
*/

mozdocument: function() {
var captures;
if (captures = /^@-moz-document[ \t]*([^\/{\n]+)/.exec(this.str)) {
this.skip(captures);
return new Token('-moz-document', captures[1].trim());
}
},

/**
* '@scope' ([^{\n]+)
*/
Expand Down
1 change: 1 addition & 0 deletions lib/nodes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exports.Property = require('./property');
exports.Selector = require('./selector');
exports.Expression = require('./expression');
exports.Arguments = require('./arguments');
exports.MozDocument = require('./mozdocument');

/**
* Singletons.
Expand Down
19 changes: 19 additions & 0 deletions lib/nodes/mozdocument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var Node = require('./node')
, nodes = require('./');

var MozDocument = module.exports = function MozDocument(val){
Node.call(this);
this.val = val;
};

MozDocument.prototype.__proto__ = Node.prototype;

MozDocument.prototype.clone = function(){
var clone = new MozDocument(this.val);
clone.block = this.block.clone();
return clone;
};

MozDocument.prototype.toString = function(){
return '@-moz-document ' + this.val;
}
18 changes: 18 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ Parser.prototype = {
case 'function':
case 'font-face':
case 'media':
case '-moz-document':
case 'for':
return true;
}
Expand Down Expand Up @@ -530,6 +531,8 @@ Parser.prototype = {
return this.keyframes();
case 'font-face':
return this.fontface();
case '-moz-document':
return this.mozdocument();
case 'comment':
case 'selector':
case 'literal':
Expand Down Expand Up @@ -735,6 +738,19 @@ Parser.prototype = {
return media;
},

/**
* @-moz-document block
*/

mozdocument: function(){
var val = this.expect('-moz-document').val
, mozdocument = new nodes.MozDocument(val);
this.state.push('-moz-document');
mozdocument.block = this.block(mozdocument, false);
this.state.pop();
return mozdocument;
},

/**
* fontface
*/
Expand Down Expand Up @@ -942,6 +958,7 @@ Parser.prototype = {
// Part of a selector
case 'root':
case 'media':
case '-moz-document':
case 'font-face':
return this.selector();
case 'function':
Expand All @@ -963,6 +980,7 @@ Parser.prototype = {
case 'for':
case 'page':
case 'media':
case '-moz-document':
case 'font-face':
case 'selector':
case 'function':
Expand Down
14 changes: 14 additions & 0 deletions lib/visitor/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Compiler.prototype.visitBlock = function(block){
this.visit(node);
break;
case 'media':
case '-moz-document':
case 'import':
case 'fontface':
this.visit(node);
Expand Down Expand Up @@ -182,6 +183,19 @@ Compiler.prototype.visitMedia = function(media){
this.buf += '}' + (this.compress ? '' : '\n');
};

/**
* Visit MozDocument.
*/

Compiler.prototype.visitMozDocument = function(mozdocument){
this.buf += '@-moz-document ' + mozdocument.val;
this.buf += this.compress ? '{' : ' {\n';
++this.indents;
this.visit(mozdocument.block);
--this.indents;
this.buf += '}' + (this.compress ? '' : '\n');
};

/**
* Visit Page.
*/
Expand Down
9 changes: 9 additions & 0 deletions lib/visitor/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ Evaluator.prototype.visitMedia = function(media){
return media;
};

/**
* Visit MozDocument.
*/

Evaluator.prototype.visitMozDocument = function(mozdocument){
mozdocument.block = this.visit(mozdocument.block);
return mozdocument;
};

/**
* Visit FontFace.
*/
Expand Down
5 changes: 5 additions & 0 deletions test/cases/moz-document.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@-moz-document url-prefix() {
.inline-button {
padding-right: 0px;
}
}
3 changes: 3 additions & 0 deletions test/cases/moz-document.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@-moz-document url-prefix()
.inline-button
padding-right 0px

0 comments on commit 86ef561

Please sign in to comment.