From 94a17419d4c21bccba27d994e9d385177c8609fe Mon Sep 17 00:00:00 2001 From: gebilaoxiong Date: Mon, 9 Oct 2017 00:48:40 +0800 Subject: [PATCH] chore: remove unnecessary return --- src/tokenizer/index.js | 219 +++++++++++++++++++++++++++-------------- 1 file changed, 143 insertions(+), 76 deletions(-) diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 10ffb8861e..281ec74587 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -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 { // `