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..9af4cf036c75 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 bug parse two ^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); } // '@'