Skip to content

Commit

Permalink
Support pipeline proposal flag in @babel/parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mAAdhaTTah committed Jul 9, 2018
1 parent dd6da3b commit cf84792
Show file tree
Hide file tree
Showing 42 changed files with 95 additions and 33 deletions.
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 (1:0)"
}

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.

0 comments on commit cf84792

Please sign in to comment.