Merge pull request #751 from gebilaoxiong/remove-unnecessary-return
chore: remove unnecessary return
This commit is contained in:
commit
6fc9af52ca
@ -215,12 +215,15 @@ export default class Tokenizer extends LocationParser {
|
||||
this.state.octalPosition = null;
|
||||
this.state.start = this.state.pos;
|
||||
this.state.startLoc = this.state.curPosition();
|
||||
if (this.state.pos >= this.input.length) return this.finishToken(tt.eof);
|
||||
if (this.state.pos >= this.input.length) {
|
||||
this.finishToken(tt.eof);
|
||||
return;
|
||||
}
|
||||
|
||||
if (curContext.override) {
|
||||
return curContext.override(this);
|
||||
curContext.override(this);
|
||||
} else {
|
||||
return this.readToken(this.fullCharCodeAtPos());
|
||||
this.readToken(this.fullCharCodeAtPos());
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,9 +231,9 @@ export default class Tokenizer extends LocationParser {
|
||||
// Identifier or keyword. '\uXXXX' sequences are allowed in
|
||||
// identifiers, so '\' also dispatches to that.
|
||||
if (isIdentifierStart(code) || code === 92 /* '\' */) {
|
||||
return this.readWord();
|
||||
this.readWord();
|
||||
} else {
|
||||
return this.getTokenFromCode(code);
|
||||
this.getTokenFromCode(code);
|
||||
}
|
||||
}
|
||||
|
||||
@ -398,17 +401,18 @@ export default class Tokenizer extends LocationParser {
|
||||
readToken_dot(): void {
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next >= 48 && next <= 57) {
|
||||
return this.readNumber(true);
|
||||
this.readNumber(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const next2 = this.input.charCodeAt(this.state.pos + 2);
|
||||
if (next === 46 && next2 === 46) {
|
||||
// 46 = dot '.'
|
||||
this.state.pos += 3;
|
||||
return this.finishToken(tt.ellipsis);
|
||||
this.finishToken(tt.ellipsis);
|
||||
} else {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.dot);
|
||||
this.finishToken(tt.dot);
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,14 +420,15 @@ export default class Tokenizer extends LocationParser {
|
||||
// '/'
|
||||
if (this.state.exprAllowed) {
|
||||
++this.state.pos;
|
||||
return this.readRegexp();
|
||||
this.readRegexp();
|
||||
return;
|
||||
}
|
||||
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === 61) {
|
||||
return this.finishOp(tt.assign, 2);
|
||||
this.finishOp(tt.assign, 2);
|
||||
} else {
|
||||
return this.finishOp(tt.slash, 1);
|
||||
this.finishOp(tt.slash, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,34 +450,45 @@ export default class Tokenizer extends LocationParser {
|
||||
type = tt.assign;
|
||||
}
|
||||
|
||||
return this.finishOp(type, width);
|
||||
this.finishOp(type, width);
|
||||
}
|
||||
|
||||
readToken_pipe_amp(code: number): void {
|
||||
// '|&'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === code)
|
||||
return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2);
|
||||
|
||||
if (next === code) {
|
||||
this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (code === 124) {
|
||||
// '|>'
|
||||
if (next === 62) {
|
||||
return this.finishOp(tt.pipeline, 2);
|
||||
this.finishOp(tt.pipeline, 2);
|
||||
return;
|
||||
} else if (next === 125 && this.hasPlugin("flow")) {
|
||||
// '|}'
|
||||
return this.finishOp(tt.braceBarR, 2);
|
||||
this.finishOp(tt.braceBarR, 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (next === 61) return this.finishOp(tt.assign, 2);
|
||||
return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1);
|
||||
|
||||
if (next === 61) {
|
||||
this.finishOp(tt.assign, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1);
|
||||
}
|
||||
|
||||
readToken_caret(): void {
|
||||
// '^'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === 61) {
|
||||
return this.finishOp(tt.assign, 2);
|
||||
this.finishOp(tt.assign, 2);
|
||||
} else {
|
||||
return this.finishOp(tt.bitwiseXOR, 1);
|
||||
this.finishOp(tt.bitwiseXOR, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,15 +506,17 @@ export default class Tokenizer extends LocationParser {
|
||||
// A `-->` line comment
|
||||
this.skipLineComment(3);
|
||||
this.skipSpace();
|
||||
return this.nextToken();
|
||||
this.nextToken();
|
||||
return;
|
||||
}
|
||||
return this.finishOp(tt.incDec, 2);
|
||||
this.finishOp(tt.incDec, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
if (next === 61) {
|
||||
return this.finishOp(tt.assign, 2);
|
||||
this.finishOp(tt.assign, 2);
|
||||
} else {
|
||||
return this.finishOp(tt.plusMin, 1);
|
||||
this.finishOp(tt.plusMin, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -510,9 +528,12 @@ export default class Tokenizer extends LocationParser {
|
||||
if (next === code) {
|
||||
size =
|
||||
code === 62 && this.input.charCodeAt(this.state.pos + 2) === 62 ? 3 : 2;
|
||||
if (this.input.charCodeAt(this.state.pos + size) === 61)
|
||||
return this.finishOp(tt.assign, size + 1);
|
||||
return this.finishOp(tt.bitShift, size);
|
||||
if (this.input.charCodeAt(this.state.pos + size) === 61) {
|
||||
this.finishOp(tt.assign, size + 1);
|
||||
return;
|
||||
}
|
||||
this.finishOp(tt.bitShift, size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
@ -525,7 +546,8 @@ export default class Tokenizer extends LocationParser {
|
||||
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
||||
this.skipLineComment(4);
|
||||
this.skipSpace();
|
||||
return this.nextToken();
|
||||
this.nextToken();
|
||||
return;
|
||||
}
|
||||
|
||||
if (next === 61) {
|
||||
@ -533,36 +555,39 @@ export default class Tokenizer extends LocationParser {
|
||||
size = 2;
|
||||
}
|
||||
|
||||
return this.finishOp(tt.relational, size);
|
||||
this.finishOp(tt.relational, size);
|
||||
}
|
||||
|
||||
readToken_eq_excl(code: number): void {
|
||||
// '=!'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === 61)
|
||||
return this.finishOp(
|
||||
if (next === 61) {
|
||||
this.finishOp(
|
||||
tt.equality,
|
||||
this.input.charCodeAt(this.state.pos + 2) === 61 ? 3 : 2,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (code === 61 && next === 62) {
|
||||
// '=>'
|
||||
this.state.pos += 2;
|
||||
return this.finishToken(tt.arrow);
|
||||
this.finishToken(tt.arrow);
|
||||
return;
|
||||
}
|
||||
return this.finishOp(code === 61 ? tt.eq : tt.bang, 1);
|
||||
this.finishOp(code === 61 ? tt.eq : tt.bang, 1);
|
||||
}
|
||||
|
||||
readToken_question() {
|
||||
readToken_question(): void {
|
||||
// '?'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
const next2 = this.input.charCodeAt(this.state.pos + 2);
|
||||
if (next === 46 && !(next2 >= 48 && next2 <= 57)) {
|
||||
// '.' not followed by a number
|
||||
this.state.pos += 2;
|
||||
return this.finishToken(tt.questionDot);
|
||||
this.finishToken(tt.questionDot);
|
||||
} else {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.question);
|
||||
this.finishToken(tt.question);
|
||||
}
|
||||
}
|
||||
|
||||
@ -575,7 +600,8 @@ export default class Tokenizer extends LocationParser {
|
||||
this.state.classLevel > 0
|
||||
) {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.hash);
|
||||
this.finishToken(tt.hash);
|
||||
return;
|
||||
} else {
|
||||
this.raise(
|
||||
this.state.pos,
|
||||
@ -587,70 +613,95 @@ export default class Tokenizer extends LocationParser {
|
||||
// by a digit or another two dots.
|
||||
|
||||
case 46: // '.'
|
||||
return this.readToken_dot();
|
||||
this.readToken_dot();
|
||||
return;
|
||||
|
||||
// Punctuation tokens.
|
||||
case 40:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.parenL);
|
||||
this.finishToken(tt.parenL);
|
||||
return;
|
||||
case 41:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.parenR);
|
||||
this.finishToken(tt.parenR);
|
||||
return;
|
||||
case 59:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.semi);
|
||||
this.finishToken(tt.semi);
|
||||
return;
|
||||
case 44:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.comma);
|
||||
this.finishToken(tt.comma);
|
||||
return;
|
||||
case 91:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.bracketL);
|
||||
this.finishToken(tt.bracketL);
|
||||
return;
|
||||
case 93:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.bracketR);
|
||||
this.finishToken(tt.bracketR);
|
||||
return;
|
||||
|
||||
case 123:
|
||||
if (
|
||||
this.hasPlugin("flow") &&
|
||||
this.input.charCodeAt(this.state.pos + 1) === 124
|
||||
) {
|
||||
return this.finishOp(tt.braceBarL, 2);
|
||||
this.finishOp(tt.braceBarL, 2);
|
||||
} else {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.braceL);
|
||||
this.finishToken(tt.braceL);
|
||||
}
|
||||
return;
|
||||
|
||||
case 125:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.braceR);
|
||||
this.finishToken(tt.braceR);
|
||||
return;
|
||||
|
||||
case 58:
|
||||
if (
|
||||
this.hasPlugin("functionBind") &&
|
||||
this.input.charCodeAt(this.state.pos + 1) === 58
|
||||
) {
|
||||
return this.finishOp(tt.doubleColon, 2);
|
||||
this.finishOp(tt.doubleColon, 2);
|
||||
} else {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.colon);
|
||||
this.finishToken(tt.colon);
|
||||
}
|
||||
return;
|
||||
|
||||
case 63:
|
||||
return this.readToken_question();
|
||||
this.readToken_question();
|
||||
return;
|
||||
case 64:
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.at);
|
||||
this.finishToken(tt.at);
|
||||
return;
|
||||
|
||||
case 96: // '`'
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.backQuote);
|
||||
this.finishToken(tt.backQuote);
|
||||
return;
|
||||
|
||||
case 48: {
|
||||
// '0'
|
||||
const next = this.input.charCodeAt(this.state.pos + 1);
|
||||
if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number
|
||||
if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number
|
||||
if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number
|
||||
// '0x', '0X' - hex number
|
||||
if (next === 120 || next === 88) {
|
||||
this.readRadixNumber(16);
|
||||
return;
|
||||
}
|
||||
// '0o', '0O' - octal number
|
||||
if (next === 111 || next === 79) {
|
||||
this.readRadixNumber(8);
|
||||
return;
|
||||
}
|
||||
// '0b', '0B' - binary number
|
||||
if (next === 98 || next === 66) {
|
||||
this.readRadixNumber(2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Anything else beginning with a digit is an integer, octal
|
||||
// number, or float.
|
||||
@ -663,12 +714,14 @@ export default class Tokenizer extends LocationParser {
|
||||
case 55:
|
||||
case 56:
|
||||
case 57: // 1-9
|
||||
return this.readNumber(false);
|
||||
this.readNumber(false);
|
||||
return;
|
||||
|
||||
// Quotes produce strings.
|
||||
case 34:
|
||||
case 39: // '"', "'"
|
||||
return this.readString(code);
|
||||
this.readString(code);
|
||||
return;
|
||||
|
||||
// Operators are parsed inline in tiny state machines. '=' (61) is
|
||||
// often referred to. `finishOp` simply skips the amount of
|
||||
@ -676,33 +729,41 @@ export default class Tokenizer extends LocationParser {
|
||||
// of the type given by its first argument.
|
||||
|
||||
case 47: // '/'
|
||||
return this.readToken_slash();
|
||||
this.readToken_slash();
|
||||
return;
|
||||
|
||||
case 37:
|
||||
case 42: // '%*'
|
||||
return this.readToken_mult_modulo(code);
|
||||
this.readToken_mult_modulo(code);
|
||||
return;
|
||||
|
||||
case 124:
|
||||
case 38: // '|&'
|
||||
return this.readToken_pipe_amp(code);
|
||||
this.readToken_pipe_amp(code);
|
||||
return;
|
||||
|
||||
case 94: // '^'
|
||||
return this.readToken_caret();
|
||||
this.readToken_caret();
|
||||
return;
|
||||
|
||||
case 43:
|
||||
case 45: // '+-'
|
||||
return this.readToken_plus_min(code);
|
||||
this.readToken_plus_min(code);
|
||||
return;
|
||||
|
||||
case 60:
|
||||
case 62: // '<>'
|
||||
return this.readToken_lt_gt(code);
|
||||
this.readToken_lt_gt(code);
|
||||
return;
|
||||
|
||||
case 61:
|
||||
case 33: // '=!'
|
||||
return this.readToken_eq_excl(code);
|
||||
this.readToken_eq_excl(code);
|
||||
return;
|
||||
|
||||
case 126: // '~'
|
||||
return this.finishOp(tt.tilde, 1);
|
||||
this.finishOp(tt.tilde, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
this.raise(
|
||||
@ -714,7 +775,7 @@ export default class Tokenizer extends LocationParser {
|
||||
finishOp(type: TokenType, size: number): void {
|
||||
const str = this.input.slice(this.state.pos, this.state.pos + size);
|
||||
this.state.pos += size;
|
||||
return this.finishToken(type, str);
|
||||
this.finishToken(type, str);
|
||||
}
|
||||
|
||||
readRegexp(): void {
|
||||
@ -751,7 +812,8 @@ export default class Tokenizer extends LocationParser {
|
||||
if (!validFlags.test(mods))
|
||||
this.raise(start, "Invalid regular expression flag");
|
||||
}
|
||||
return this.finishToken(tt.regexp, {
|
||||
|
||||
this.finishToken(tt.regexp, {
|
||||
pattern: content,
|
||||
flags: mods,
|
||||
});
|
||||
@ -848,10 +910,11 @@ export default class Tokenizer extends LocationParser {
|
||||
|
||||
if (isBigInt) {
|
||||
const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
|
||||
return this.finishToken(tt.bigint, str);
|
||||
this.finishToken(tt.bigint, str);
|
||||
return;
|
||||
}
|
||||
|
||||
return this.finishToken(tt.num, val);
|
||||
this.finishToken(tt.num, val);
|
||||
}
|
||||
|
||||
// Read an integer, octal integer, or floating-point number.
|
||||
@ -901,7 +964,8 @@ export default class Tokenizer extends LocationParser {
|
||||
const str = this.input.slice(start, this.state.pos).replace(/[_n]/g, "");
|
||||
|
||||
if (isBigInt) {
|
||||
return this.finishToken(tt.bigint, str);
|
||||
this.finishToken(tt.bigint, str);
|
||||
return;
|
||||
}
|
||||
|
||||
let val;
|
||||
@ -916,7 +980,7 @@ export default class Tokenizer extends LocationParser {
|
||||
} else {
|
||||
val = parseInt(str, 8);
|
||||
}
|
||||
return this.finishToken(tt.num, val);
|
||||
this.finishToken(tt.num, val);
|
||||
}
|
||||
|
||||
// Read a string value, interpreting backslash-escapes.
|
||||
@ -971,7 +1035,7 @@ export default class Tokenizer extends LocationParser {
|
||||
}
|
||||
}
|
||||
out += this.input.slice(chunkStart, this.state.pos++);
|
||||
return this.finishToken(tt.string, out);
|
||||
this.finishToken(tt.string, out);
|
||||
}
|
||||
|
||||
// Reads template string tokens.
|
||||
@ -992,14 +1056,17 @@ export default class Tokenizer extends LocationParser {
|
||||
if (this.state.pos === this.state.start && this.match(tt.template)) {
|
||||
if (ch === 36) {
|
||||
this.state.pos += 2;
|
||||
return this.finishToken(tt.dollarBraceL);
|
||||
this.finishToken(tt.dollarBraceL);
|
||||
return;
|
||||
} else {
|
||||
++this.state.pos;
|
||||
return this.finishToken(tt.backQuote);
|
||||
this.finishToken(tt.backQuote);
|
||||
return;
|
||||
}
|
||||
}
|
||||
out += this.input.slice(chunkStart, this.state.pos);
|
||||
return this.finishToken(tt.template, containsInvalid ? null : out);
|
||||
this.finishToken(tt.template, containsInvalid ? null : out);
|
||||
return;
|
||||
}
|
||||
if (ch === 92) {
|
||||
// '\'
|
||||
@ -1179,7 +1246,7 @@ export default class Tokenizer extends LocationParser {
|
||||
type = keywordTypes[word];
|
||||
}
|
||||
|
||||
return this.finishToken(type, word);
|
||||
this.finishToken(type, word);
|
||||
}
|
||||
|
||||
braceIsBlock(prevType: TokenType): boolean {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user