From 35029a6e7e0890b7f25ed544238c22a2d7ddcabd Mon Sep 17 00:00:00 2001 From: fb55 Date: Sat, 1 Mar 2014 11:24:15 +0100 Subject: [PATCH] Compile atrules in advance --- index.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 88dd62a..128043a 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ module.exports = function(css, options){ node.position = new Position(start); whitespace(); return node; - } + }; } function Position(start) { @@ -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); + } } /**