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 d4fdd45
Show file tree
Hide file tree
Showing 42 changed files with 75 additions and 33 deletions.
14 changes: 14 additions & 0 deletions packages/babel-parser/src/plugin-utils.js
Expand Up @@ -18,6 +18,8 @@ export function hasPlugin(plugins: PluginList, name: string): boolean {
});
}

const PIPELINE_PROPOSALS = ["minimal"];

export function validatePlugins(plugins: PluginList) {
if (
hasPlugin(plugins, "decorators") &&
Expand All @@ -31,6 +33,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(
this.getPluginOption("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 d4fdd45

Please sign in to comment.