Skip to content

Compile atrules in advance #44

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

Merged
merged 1 commit into from
Mar 2, 2014
Merged
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
32 changes: 15 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = function(css, options){
node.position = new Position(start);
whitespace();
return node;
}
};
}

function Position(start) {
Expand Down Expand Up @@ -428,37 +428,35 @@ module.exports = function(css, options){
* Parse import
*/

function atimport() {
return _atrule('import');
}
var atimport = _compileAtrule('import');

/**
* Parse charset
*/

function atcharset() {
return _atrule('charset');
}
var atcharset = _compileAtrule('charset');

/**
* Parse namespace
*/

function atnamespace() {
return _atrule('namespace')
}
var atnamespace = _compileAtrule('namespace');

/**
* Parse non-block at-rules
*/

function _atrule(name) {
var pos = position();
var m = match(new RegExp('^@' + name + ' *([^;\\n]+);'));
if (!m) return;
var ret = { type: name };
ret[name] = trim(m[1]);
return pos(ret);

function _compileAtrule(name) {
var re = new RegExp('^@' + name + ' *([^;\\n]+);');
return function() {
var pos = position();
var m = match(re);
if (!m) return;
var ret = { type: name };
ret[name] = m[1].trim();
return pos(ret);
}
}

/**
Expand Down