CSSLint: more microoptimizations
This commit is contained in:
parent
37f7f1898f
commit
afbee9d68f
|
@ -4817,8 +4817,8 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
|
||||||
var c,
|
var c,
|
||||||
reader = this._reader,
|
reader = this._reader,
|
||||||
token = null,
|
token = null,
|
||||||
startLine = reader.getLine(),
|
startLine = reader._line,
|
||||||
startCol = reader.getCol();
|
startCol = reader._col;
|
||||||
|
|
||||||
c = reader.read();
|
c = reader.read();
|
||||||
|
|
||||||
|
@ -4826,6 +4826,18 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
|
||||||
while (c) {
|
while (c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Potential tokens:
|
||||||
|
* - S
|
||||||
|
*/
|
||||||
|
case ' ':
|
||||||
|
case '\n':
|
||||||
|
case '\r':
|
||||||
|
case '\t':
|
||||||
|
case '\f':
|
||||||
|
token = this.whitespaceToken(c, startLine, startCol);
|
||||||
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Potential tokens:
|
* Potential tokens:
|
||||||
* - COMMENT
|
* - COMMENT
|
||||||
|
@ -5001,14 +5013,6 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
|
||||||
token = this.numberToken(c, startLine, startCol);
|
token = this.numberToken(c, startLine, startCol);
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/*
|
|
||||||
* Potential tokens:
|
|
||||||
* - S
|
|
||||||
*/
|
|
||||||
if (isWhitespace(c)) {
|
|
||||||
token = this.whitespaceToken(c, startLine, startCol);
|
|
||||||
} else
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Potential tokens:
|
* Potential tokens:
|
||||||
* - IDENT
|
* - IDENT
|
||||||
|
@ -5362,27 +5366,12 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
|
||||||
* @method notToken
|
* @method notToken
|
||||||
*/
|
*/
|
||||||
notOrAnyToken: function(first, startLine, startCol) {
|
notOrAnyToken: function(first, startLine, startCol) {
|
||||||
var reader = this._reader,
|
var reader = this._reader;
|
||||||
text = first;
|
var func = reader.readMatch(/not\(|(-(moz|webkit)-)?any\(/iy);
|
||||||
|
if (func) {
|
||||||
reader.mark();
|
return this.createToken(func[1] === 'n' || func[1] === 'N' ? Tokens.NOT : Tokens.ANY,
|
||||||
text += reader.readCount(4);
|
first + func, startLine, startCol);
|
||||||
|
|
||||||
if (text.toLowerCase() === ":not(") {
|
|
||||||
return this.createToken(Tokens.NOT, text, startLine, startCol);
|
|
||||||
}
|
}
|
||||||
if (text.toLowerCase() === ":any(") {
|
|
||||||
return this.createToken(Tokens.ANY, text, startLine, startCol);
|
|
||||||
}
|
|
||||||
text += reader.readCount(5);
|
|
||||||
if (text.toLowerCase() === ":-moz-any(") {
|
|
||||||
return this.createToken(Tokens.ANY, text, startLine, startCol);
|
|
||||||
}
|
|
||||||
text += reader.readCount(3);
|
|
||||||
if (text.toLowerCase() === ":-webkit-any(") {
|
|
||||||
return this.createToken(Tokens.ANY, text, startLine, startCol);
|
|
||||||
}
|
|
||||||
reader.reset();
|
|
||||||
return this.charToken(first, startLine, startCol);
|
return this.charToken(first, startLine, startCol);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -5587,18 +5576,9 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
|
||||||
},
|
},
|
||||||
|
|
||||||
readWhitespace: function() {
|
readWhitespace: function() {
|
||||||
var reader = this._reader,
|
return this._reader.readMatch(/\s*/);
|
||||||
whitespace = "",
|
|
||||||
c = reader.peek();
|
|
||||||
|
|
||||||
while (isWhitespace(c)) {
|
|
||||||
reader.read();
|
|
||||||
whitespace += c;
|
|
||||||
c = reader.peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
return whitespace;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
readNumber: function(first) {
|
readNumber: function(first) {
|
||||||
const tail = this._reader.readMatch(
|
const tail = this._reader.readMatch(
|
||||||
first === "." ? /\d+(e[+-]?\d+)?/y :
|
first === "." ? /\d+(e[+-]?\d+)?/y :
|
||||||
|
@ -5685,25 +5665,22 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
|
||||||
|
|
||||||
readName: function(first) {
|
readName: function(first) {
|
||||||
var reader = this._reader,
|
var reader = this._reader,
|
||||||
ident = first || "",
|
ident = [first || ''];
|
||||||
c;
|
|
||||||
|
|
||||||
for (c = reader.peek(); c; c = reader.peek()) {
|
do {
|
||||||
if (c === "\\") {
|
var chunk = reader.readMatch(/[-_\da-zA-Z\u00A0-\uFFFF]*/y);
|
||||||
if (/^[^\r\n\f]$/.test(reader.peek(2))) {
|
ident.push(chunk)
|
||||||
ident += this.readEscape(reader.read(), true);
|
reader.mark();
|
||||||
} else {
|
var c = reader.read();
|
||||||
// Bad escape sequence.
|
if (c === "\\" && /^[^\r\n\f]$/.test(reader.peek())) {
|
||||||
break;
|
ident.push(this.readEscape(c, true));
|
||||||
}
|
|
||||||
} else if (isNameChar(c)) {
|
|
||||||
ident += reader.read();
|
|
||||||
} else {
|
} else {
|
||||||
|
reader.reset();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} while (true);
|
||||||
|
|
||||||
return ident;
|
return ident.length > 2 ? ident.join('') : ident.length > 1 ? ident[0] + ident[1] : ident[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
readEscape: function(first, unescape) {
|
readEscape: function(first, unescape) {
|
||||||
|
@ -6715,10 +6692,10 @@ EventTarget.prototype = {
|
||||||
throw new Error("Event object missing 'type' property.");
|
throw new Error("Event object missing 'type' property.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._listeners[event.type]) {
|
var listeners = this._listeners[event.type];
|
||||||
|
if (listeners) {
|
||||||
//create a copy of the array and use that so listeners can't chane
|
//create a copy of the array and use that so listeners can't chane
|
||||||
var listeners = this._listeners[event.type].concat();
|
listeners = listeners.slice();
|
||||||
for (var i=0, len=listeners.length; i < len; i++) {
|
for (var i=0, len=listeners.length; i < len; i++) {
|
||||||
listeners[i].call(this, event);
|
listeners[i].call(this, event);
|
||||||
}
|
}
|
||||||
|
@ -7280,15 +7257,10 @@ TokenStreamBase.prototype = {
|
||||||
* @method match
|
* @method match
|
||||||
*/
|
*/
|
||||||
match: function(tokenTypes, channel) {
|
match: function(tokenTypes, channel) {
|
||||||
|
var isArray = Array.isArray(tokenTypes);
|
||||||
//always convert to an array, makes things easier
|
|
||||||
if (!(tokenTypes instanceof Array)) {
|
|
||||||
tokenTypes = [tokenTypes];
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
var tt = this.get(channel);
|
var tt = this.get(channel);
|
||||||
if (tokenTypes.includes(tt)) {
|
if (isArray ? tokenTypes.includes(tt) : tt === tokenTypes) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} while (tt === this._tokenData.COMMENT && this.LA(0) !== 0);
|
} while (tt === this._tokenData.COMMENT && this.LA(0) !== 0);
|
||||||
|
@ -7308,17 +7280,9 @@ TokenStreamBase.prototype = {
|
||||||
* @method mustMatch
|
* @method mustMatch
|
||||||
*/
|
*/
|
||||||
mustMatch: function(tokenTypes) {
|
mustMatch: function(tokenTypes) {
|
||||||
|
|
||||||
var token;
|
|
||||||
|
|
||||||
//always convert to an array, makes things easier
|
|
||||||
if (!(tokenTypes instanceof Array)) {
|
|
||||||
tokenTypes = [tokenTypes];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.match(tokenTypes)) {
|
if (!this.match(tokenTypes)) {
|
||||||
token = this.LT(1);
|
var token = this.LT(1);
|
||||||
const info = this._tokenData[tokenTypes[0]];
|
const info = this._tokenData[Array.isArray(tokenTypes) ? tokenTypes[0] : tokenTypes];
|
||||||
throw new SyntaxError("Expected " + (info.text || info.name) +
|
throw new SyntaxError("Expected " + (info.text || info.name) +
|
||||||
" at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
|
" at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user