Types for pipeline operator (smart proposal) (#9122)

This commit is contained in:
Thiago Arrais 2018-12-13 02:58:58 -03:00 committed by Nicolò Ribaudo
parent f4eec5ca79
commit 731182eee4
11 changed files with 139 additions and 0 deletions

View File

@ -151,3 +151,15 @@ export function BigIntLiteral(node: Object) {
}
this.token(node.value);
}
export function PipelineTopicExpression(node: Object) {
this.print(node.expression, node);
}
export function PipelineBareFunction(node: Object) {
this.print(node.callee, node);
}
export function PipelinePrimaryTopicReference() {
this.token("#");
}

View File

@ -0,0 +1 @@
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;

View File

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

View File

@ -0,0 +1 @@
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;

View File

@ -0,0 +1,8 @@
value |> # + 1;
value |> 1 + #;
value |> do {
#;
};
value |> do {
if (yes) #;
};

View File

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

View File

@ -0,0 +1,8 @@
value |> # + 1;
value |> 1 + #;
value |> do {
#;
};
value |> do {
if (yes) #;
};

View File

@ -675,6 +675,24 @@ export function assertOptionalMemberExpression(
): void {
assert("OptionalMemberExpression", node, opts);
}
export function assertPipelineTopicExpression(
node: Object,
opts?: Object = {},
): void {
assert("PipelineTopicExpression", node, opts);
}
export function assertPipelineBareFunction(
node: Object,
opts?: Object = {},
): void {
assert("PipelineBareFunction", node, opts);
}
export function assertPipelinePrimaryTopicReference(
node: Object,
opts?: Object = {},
): void {
assert("PipelinePrimaryTopicReference", node, opts);
}
export function assertOptionalCallExpression(
node: Object,
opts?: Object = {},

View File

@ -612,6 +612,18 @@ export function OptionalMemberExpression(...args: Array<any>): Object {
return builder("OptionalMemberExpression", ...args);
}
export { OptionalMemberExpression as optionalMemberExpression };
export function PipelineTopicExpression(...args: Array<any>): Object {
return builder("PipelineTopicExpression", ...args);
}
export { PipelineTopicExpression as pipelineTopicExpression };
export function PipelineBareFunction(...args: Array<any>): Object {
return builder("PipelineBareFunction", ...args);
}
export { PipelineBareFunction as pipelineBareFunction };
export function PipelinePrimaryTopicReference(...args: Array<any>): Object {
return builder("PipelinePrimaryTopicReference", ...args);
}
export { PipelinePrimaryTopicReference as pipelinePrimaryTopicReference };
export function OptionalCallExpression(...args: Array<any>): Object {
return builder("OptionalCallExpression", ...args);
}

View File

@ -89,6 +89,30 @@ defineType("OptionalMemberExpression", {
},
});
defineType("PipelineTopicExpression", {
builder: ["expression"],
visitor: ["expression"],
fields: {
expression: {
validate: assertNodeType("Expression"),
},
},
});
defineType("PipelineBareFunction", {
builder: ["callee"],
visitor: ["callee"],
fields: {
callee: {
validate: assertNodeType("Expression"),
},
},
});
defineType("PipelinePrimaryTopicReference", {
aliases: ["Expression"],
});
defineType("OptionalCallExpression", {
visitor: ["callee", "arguments", "typeParameters", "typeArguments"],
builder: ["callee", "arguments", "optional"],

View File

@ -2131,6 +2131,54 @@ export function isOptionalMemberExpression(
return false;
}
export function isPipelineTopicExpression(
node: Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "PipelineTopicExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isPipelineBareFunction(node: Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "PipelineBareFunction") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isPipelinePrimaryTopicReference(
node: Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "PipelinePrimaryTopicReference") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isOptionalCallExpression(node: Object, opts?: Object): boolean {
if (!node) return false;
@ -3164,6 +3212,7 @@ export function isExpression(node: Object, opts?: Object): boolean {
"AwaitExpression" === nodeType ||
"BindExpression" === nodeType ||
"OptionalMemberExpression" === nodeType ||
"PipelinePrimaryTopicReference" === nodeType ||
"OptionalCallExpression" === nodeType ||
"Import" === nodeType ||
"DoExpression" === nodeType ||