Skip to content

Commit

Permalink
Types for pipeline operator (smart proposal)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoarrais committed Dec 10, 2018
1 parent d1d3c82 commit c7f816b
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/babel-generator/src/generators/types.js
Expand Up @@ -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("#");
}
@@ -0,0 +1 @@
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
}
@@ -0,0 +1 @@
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;
@@ -0,0 +1,8 @@
value |> # + 1;
value |> 1 + #;
value |> do {
#;
};
value |> do {
if (yes) #;
};
@@ -0,0 +1,3 @@
{
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
}
@@ -0,0 +1,8 @@
value |> # + 1;
value |> 1 + #;
value |> do {
#;
};
value |> do {
if (yes) #;
};
18 changes: 18 additions & 0 deletions packages/babel-types/src/asserts/generated/index.js
Expand Up @@ -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 = {},
Expand Down
12 changes: 12 additions & 0 deletions packages/babel-types/src/builders/generated/index.js
Expand Up @@ -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);
}
Expand Down
24 changes: 24 additions & 0 deletions packages/babel-types/src/definitions/experimental.js
Expand Up @@ -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"],
Expand Down
49 changes: 49 additions & 0 deletions packages/babel-types/src/validators/generated/index.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ||
Expand Down

0 comments on commit c7f816b

Please sign in to comment.