replace simple regex's with simple string comparisons

This commit is contained in:
Luke Page
2015-03-15 10:24:41 +00:00
parent d04e1d7464
commit f8de5bcb16
2 changed files with 25 additions and 55 deletions

View File

@@ -43,7 +43,7 @@ var Parser = function Parser(context, imports, fileInfo) {
function expect(arg, msg, index) {
// some older browsers return typeof 'function' for RegExp
var result = (Object.prototype.toString.call(arg) === '[object Function]') ? arg.call(parsers) : parserInput.$(arg);
var result = (Object.prototype.toString.call(arg) === '[object Function]') ? arg.call(parsers) : parserInput.$re(arg);
if (result) {
return result;
}
@@ -411,7 +411,7 @@ var Parser = function Parser(context, imports, fileInfo) {
parserInput.autoCommentAbsorb = false;
if (parserInput.currentChar() !== 'u' || !parserInput.$re(/^url\(/)) {
if (!parserInput.$str("url(")) {
parserInput.autoCommentAbsorb = true;
return;
}
@@ -549,7 +549,9 @@ var Parser = function Parser(context, imports, fileInfo) {
extend: function(isRule) {
var elements, e, index = parserInput.i, option, extendList, extend;
if (!(isRule ? parserInput.$re(/^&:extend\(/) : parserInput.$re(/^:extend\(/))) { return; }
if (!parserInput.$str(isRule ? "&:extend(" : ":extend(")) {
return;
}
do {
option = null;
@@ -811,7 +813,7 @@ var Parser = function Parser(context, imports, fileInfo) {
parserInput.commentStore.length = 0;
if (parserInput.$re(/^when/)) { // Guard
if (parserInput.$str("when")) { // Guard
cond = expect(parsers.conditions, 'expected condition');
}
@@ -960,7 +962,7 @@ var Parser = function Parser(context, imports, fileInfo) {
selector: function (isLess) {
var index = parserInput.i, elements, extendList, c, e, allExtends, when, condition;
while ((isLess && (extendList = this.extend())) || (isLess && (when = parserInput.$re(/^when/))) || (e = this.element())) {
while ((isLess && (extendList = this.extend())) || (isLess && (when = parserInput.$str("when"))) || (e = this.element())) {
if (when) {
condition = expect(this.conditions, 'expected condition');
} else if (condition) {
@@ -1165,7 +1167,7 @@ var Parser = function Parser(context, imports, fileInfo) {
if ((path = this.entities.quoted() || this.entities.url())) {
features = this.mediaFeatures();
if (!parserInput.$(';')) {
if (!parserInput.$char(';')) {
parserInput.i = index;
error("missing semi-colon or unrecognised media features on import");
}
@@ -1273,7 +1275,7 @@ var Parser = function Parser(context, imports, fileInfo) {
debugInfo = getDebugInfo(parserInput.i);
}
if (parserInput.$re(/^@media/)) {
if (parserInput.$str("@media")) {
features = this.mediaFeatures();
rules = this.block();
@@ -1511,7 +1513,7 @@ var Parser = function Parser(context, imports, fileInfo) {
var entities = this.entities, index = parserInput.i, negate = false,
a, b, c, op;
if (parserInput.$re(/^not/)) { negate = true; }
if (parserInput.$str("not")) { negate = true; }
expectChar('(');
a = this.addition() || entities.keyword() || entities.quoted();
if (a) {
@@ -1527,7 +1529,7 @@ var Parser = function Parser(context, imports, fileInfo) {
c = new(tree.Condition)('=', a, new(tree.Keyword)('true'), index, negate);
}
expectChar(')');
return parserInput.$re(/^and/) ? new(tree.Condition)('and', c, this.condition()) : c;
return parserInput.$str("and") ? new(tree.Condition)('and', c, this.condition()) : c;
}
},