Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pipeline proposal flag in @babel/parser #8291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/babel-parser/src/plugin-utils.js
Expand Up @@ -18,6 +18,28 @@ export function hasPlugin(plugins: PluginList, name: string): boolean {
});
}

export function getPluginOption(
plugins: PluginList,
name: string,
option: string,
) {
const plugin = plugins.find(plugin => {
if (Array.isArray(plugin)) {
return plugin[0] === name;
} else {
return plugin === name;
}
});

if (plugin && Array.isArray(plugin)) {
return plugin[1][option];
}

return null;
}

const PIPELINE_PROPOSALS = ["minimal"];

export function validatePlugins(plugins: PluginList) {
if (
hasPlugin(plugins, "decorators") &&
Expand All @@ -31,6 +53,18 @@ export function validatePlugins(plugins: PluginList) {
if (hasPlugin(plugins, "flow") && hasPlugin(plugins, "typescript")) {
throw new Error("Cannot combine flow and typescript plugins.");
}

if (
hasPlugin(plugins, "pipelineOperator") &&
!PIPELINE_PROPOSALS.includes(
getPluginOption(plugins, "pipelineOperator", "proposal"),
)
) {
throw new Error(
"'pipelineOperator' requires 'proposal' option whose value should be one of: " +
PIPELINE_PROPOSALS.join(", "),
);
}
}

// These plugins are defined using a mixin which extends the parser class.
Expand Down
@@ -1,4 +1,3 @@
{
"plugins": ["nullishCoalescingOperator", "pipelineOperator"]
"plugins": ["nullishCoalescingOperator", ["pipelineOperator", { "proposal": "minimal" }]]
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,6 @@
{
"plugins": [
["pipelineOperator", { "proposal": "invalid" }]
],
"throws": "'pipelineOperator' requires 'proposal' option whose value should be one of: minimal"
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,6 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
],
"throws": "Unexpected token, expected \";\" (1:10)"
}
@@ -0,0 +1,6 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
],
"throws": "Unexpected token, expected \";\" (1:8)"
}
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}
@@ -1,4 +1,6 @@
{
"plugins": ["pipelineOperator"],
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
],
"throws": "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal (2:14)"
}
@@ -1,4 +1,6 @@
{
"plugins": ["pipelineOperator"],
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
],
"throws": "Unexpected \"await\" after pipeline body; await must have parentheses in minimal proposal (2:14)"
}
@@ -0,0 +1 @@
a |> b
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}
@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

This file was deleted.

This file was deleted.