From 6668b7349f8fc38e2cd9a6c07da264c1be8bfaa3 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 | 25 ++-------------- packages/babel-parser/src/tokenizer/index.js | 30 ++++++++++--------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index f67d56160d64..b3b51a16f194 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1204,30 +1204,11 @@ 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: { + return this.parseTopicReference("hack"); } - case tt.doubleAt: case tt.bitwiseXOR: case tt.modulo: case tt.hash: { diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 699a51691533..de4c628868ad 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) { @@ -728,11 +724,15 @@ export default class Tokenizer extends ParserErrors { this.finishOp(tt.xorAssign, 2); } // '^^' - 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. + else if ( + next === charCodes.caret && + // If the ^^ token is not enabled, we don't throw but parse two single ^s + // because it could be a ^ hack token followed by a ^ binary operator. + this.hasPlugin([ + "pipelineOperator", + { proposal: "hack", topicToken: "^^" }, + ]) + ) { this.finishOp(tt.doubleCaret, 2); // `^^^` is forbidden and must be separated by a space. @@ -751,11 +751,13 @@ export default class Tokenizer extends ParserErrors { const next = this.input.charCodeAt(this.state.pos + 1); // '@@' - 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. + if ( + next === charCodes.atSign && + this.hasPlugin([ + "pipelineOperator", + { proposal: "hack", topicToken: "@@" }, + ]) + ) { this.finishOp(tt.doubleAt, 2); } // '@'