Support pipeline proposal flag in @babel/parser (#8291)

This commit is contained in:
James DiGioia
2018-07-09 16:59:56 -04:00
committed by Henry Zhu
parent 10910a10f5
commit 19a1705293
42 changed files with 95 additions and 33 deletions

View File

@@ -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.

View File

@@ -1,4 +1,3 @@
{
"plugins": ["nullishCoalescingOperator", "pipelineOperator"]
"plugins": ["nullishCoalescingOperator", ["pipelineOperator", { "proposal": "minimal" }]]
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["pipelineOperator"],
"throws": "Unexpected token, expected \";\" (1:10)"
}

View File

@@ -1,4 +0,0 @@
{
"plugins": ["pipelineOperator"],
"throws": "Unexpected token, expected \";\" (1:8)"
}

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}

View File

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

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -0,0 +1,6 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
],
"throws": "Unexpected token, expected \";\" (1:10)"
}

View File

@@ -0,0 +1,6 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
],
"throws": "Unexpected token, expected \";\" (1:8)"
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -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)"
}

View File

@@ -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)"
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -0,0 +1,5 @@
{
"plugins": [
["pipelineOperator", { "proposal": "minimal" }]
]
}

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}

View File

@@ -1,3 +0,0 @@
{
"plugins": ["pipelineOperator"]
}