Skip to content

Commit

Permalink
parser: Disable Hack pipes + v8intrinsic/placeholders
Browse files Browse the repository at this point in the history
We may reenable combining these again if TC39 ends up deciding to use % as a topic token.
See babel#13416 (comment).
  • Loading branch information
js-choi committed Jun 8, 2021
1 parent dc98f4c commit fa257f5
Show file tree
Hide file tree
Showing 101 changed files with 21 additions and 1,377 deletions.
12 changes: 12 additions & 0 deletions packages/babel-parser/src/plugin-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ export function validatePlugins(plugins: PluginList) {
getPluginOption(plugins, "recordAndTuple", "syntaxType") === "hash";

if (proposal === "hack") {
if (hasPlugin(plugins, "placeholders")) {
throw new Error(
"Cannot combine placeholders plugin and Hack-style pipes.",
);
}

if (hasPlugin(plugins, "v8intrinsic")) {
throw new Error(
"Cannot combine v8intrinsic plugin and Hack-style pipes.",
);
}

const topicToken = getPluginOption(
plugins,
"pipelineOperator",
Expand Down
29 changes: 2 additions & 27 deletions packages/babel-parser/src/plugins/v8intrinsic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
class extends superClass {
parseV8Intrinsic(): N.Expression {
if (this.match(tt.modulo)) {
const start = this.state.start;
const v8IntrinsicStart = this.state.start;
// let the `loc` of Identifier starts from `%`
const node = this.startNode();
this.eat(tt.modulo);
Expand All @@ -18,32 +18,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
return identifier;
}
}

// In this case, the `%` currently being parsed is not followed by an identifier,
// so it therefore cannot be a V8 intrinsic.
// If the `pipelineOperator` plugin is active,
// then the `%` currently being parsed may instead be a topic reference.
const pipeProposal = this.getPluginOption(
"pipelineOperator",
"proposal",
);
if (pipeProposal) {
// A pipe-operator proposal is active,
// although its configuration might not match `%` as a topic token.
// If the pipe-operator plugin’s configuration matches the current token’s type,
// then this will return `node`, will have been finished as a topic reference.
// Otherwise, this will throw a `PipeTopicUnconfiguredToken` error.
return this.finishTopicReference(
node,
start,
pipeProposal,
tt.modulo,
);
} else {
// A pipe-operator proposal is not active.
// Throw a fatal syntax error.
this.unexpected(start);
}
this.unexpected(v8IntrinsicStart);
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit fa257f5

Please sign in to comment.