Support pipeline proposal flag in @babel/parser (#8291)
This commit is contained in:
@@ -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") &&
|
||||
@@ -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.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
{
|
||||
"plugins": ["nullishCoalescingOperator", "pipelineOperator"]
|
||||
"plugins": ["nullishCoalescingOperator", ["pipelineOperator", { "proposal": "minimal" }]]
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"],
|
||||
"throws": "Unexpected token, expected \";\" (1:10)"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"],
|
||||
"throws": "Unexpected token, expected \";\" (1:8)"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
["pipelineOperator", { "proposal": "invalid" }]
|
||||
],
|
||||
"throws": "'pipelineOperator' requires 'proposal' option whose value should be one of: minimal"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
@@ -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" }]
|
||||
]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["pipelineOperator"]
|
||||
}
|
||||
Reference in New Issue
Block a user