Skip to content

Commit

Permalink
Remove unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 1, 2022
1 parent 91cb4b2 commit 8101e2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
24 changes: 1 addition & 23 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -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:
Expand Down
30 changes: 16 additions & 14 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -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) {
Expand All @@ -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.
Expand All @@ -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);
}
// '@'
Expand Down

0 comments on commit 8101e2b

Please sign in to comment.