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 e52460a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 48 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
49 changes: 24 additions & 25 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -715,53 +715,52 @@ 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) {
// `tt.xorAssign` is only needed to support ^ as a Hack-pipe topic token.
// 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 {
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.
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 {
Expand Down

0 comments on commit e52460a

Please sign in to comment.