Skip to content

Commit 35d5931

Browse files
committed
Merge pull request #44 from fb55/patch-1
Compile atrules in advance
2 parents e3bfc4b + 35029a6 commit 35d5931

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

index.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function(css, options){
3737
node.position = new Position(start);
3838
whitespace();
3939
return node;
40-
}
40+
};
4141
}
4242

4343
function Position(start) {
@@ -428,37 +428,35 @@ module.exports = function(css, options){
428428
* Parse import
429429
*/
430430

431-
function atimport() {
432-
return _atrule('import');
433-
}
431+
var atimport = _compileAtrule('import');
434432

435433
/**
436434
* Parse charset
437435
*/
438436

439-
function atcharset() {
440-
return _atrule('charset');
441-
}
437+
var atcharset = _compileAtrule('charset');
442438

443439
/**
444440
* Parse namespace
445441
*/
446442

447-
function atnamespace() {
448-
return _atrule('namespace')
449-
}
443+
var atnamespace = _compileAtrule('namespace');
450444

451445
/**
452446
* Parse non-block at-rules
453447
*/
454448

455-
function _atrule(name) {
456-
var pos = position();
457-
var m = match(new RegExp('^@' + name + ' *([^;\\n]+);'));
458-
if (!m) return;
459-
var ret = { type: name };
460-
ret[name] = trim(m[1]);
461-
return pos(ret);
449+
450+
function _compileAtrule(name) {
451+
var re = new RegExp('^@' + name + ' *([^;\\n]+);');
452+
return function() {
453+
var pos = position();
454+
var m = match(re);
455+
if (!m) return;
456+
var ret = { type: name };
457+
ret[name] = m[1].trim();
458+
return pos(ret);
459+
}
462460
}
463461

464462
/**

0 commit comments

Comments
 (0)