Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for pipeline operator #9122

Merged
merged 1 commit into from Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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