From e52460a0a9145c0eb6804c9aa59a6ba98ba29dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 1 Feb 2022 18:10:37 +0100 Subject: [PATCH] Remove unreachable code --- .../babel-parser/src/parser/expression.js | 24 +-------- packages/babel-parser/src/tokenizer/index.js | 49 +++++++++---------- 2 files changed, 25 insertions(+), 48 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index f67d56160d64..2e0cf1a22b95 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1204,29 +1204,7 @@ export default class ExpressionParser extends LValParser { return this.parseTopicReferenceThenEqualsSign(tt.bitwiseXOR, "^"); } - case tt.doubleCaret: { - const pipeProposal = this.getPluginOption( - "pipelineOperator", - "proposal", - ); - const pluginTopicToken = this.getPluginOption( - "pipelineOperator", - "topicToken", - ); - - // The `^^` token is valid only when: - // the pipe-operator proposal is active, - // its "pipeProposal" is configured as "hack", - // and "topicToken" is configured as "^^". - // If the pipe-operator proposal settles on a token that is not ^^, - // then this token type may be removed. - if (pipeProposal === "hack" && pluginTopicToken === "^^") { - return this.parseTopicReference(pipeProposal); - } else { - throw this.unexpected(); - } - } - + case tt.doubleCaret: case tt.doubleAt: case tt.bitwiseXOR: case tt.modulo: diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 699a51691533..3fc7d58abfd9 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -715,10 +715,6 @@ export default class Tokenizer extends ParserErrors { readToken_caret(): void { const next = this.input.charCodeAt(this.state.pos + 1); - const pipeProposal = this.getPluginOption("pipelineOperator", "proposal"); - const topicToken = this.getPluginOption("pipelineOperator", "topicToken"); - const hackPipeWithDoubleCaretIsActive = - pipeProposal === "hack" && topicToken === "^^"; // '^=' if (next === charCodes.equalsTo && !this.state.inType) { @@ -726,25 +722,28 @@ export default class Tokenizer extends ParserErrors { // If the proposal ends up choosing a different token, // it can be merged with tt.assign. this.finishOp(tt.xorAssign, 2); + return; } + // '^^' - else if (hackPipeWithDoubleCaretIsActive && next === charCodes.caret) { - // `tt.doubleCaret` is only needed to support ^^ - // as a Hack-pipe topic token. - // If the proposal ends up choosing a different token, - // it may be removed. - this.finishOp(tt.doubleCaret, 2); + if (next === charCodes.caret) { + const pipeProposal = this.getPluginOption("pipelineOperator", "proposal"); + const topicToken = this.getPluginOption("pipelineOperator", "topicToken"); + if (pipeProposal === "hack" && topicToken === "^^") { + this.finishOp(tt.doubleCaret, 2); + + // `^^^` is forbidden and must be separated by a space. + const lookaheadCh = this.input.codePointAt(this.state.pos); + if (lookaheadCh === charCodes.caret) { + throw this.unexpected(); + } - // `^^^` is forbidden and must be separated by a space. - const lookaheadCh = this.input.codePointAt(this.state.pos); - if (lookaheadCh === charCodes.caret) { - throw this.unexpected(); + return; } } + // '^' - else { - this.finishOp(tt.bitwiseXOR, 1); - } + this.finishOp(tt.bitwiseXOR, 1); } readToken_atSign(): void { @@ -752,16 +751,16 @@ export default class Tokenizer extends ParserErrors { // '@@' if (next === charCodes.atSign) { - // `tt.doubleAt` is only needed to support @@ - // as a Hack-pipe topic token. - // If the proposal ends up choosing a different token, - // it may be removed. - this.finishOp(tt.doubleAt, 2); + const pipeProposal = this.getPluginOption("pipelineOperator", "proposal"); + const topicToken = this.getPluginOption("pipelineOperator", "topicToken"); + if (pipeProposal === "hack" && topicToken === "@@") { + this.finishOp(tt.doubleAt, 2); + return; + } } + // '@' - else { - this.finishOp(tt.at, 1); - } + this.finishOp(tt.at, 1); } readToken_plus_min(code: number): void {