Types for pipeline operator (smart proposal) (#9122)
This commit is contained in:
parent
f4eec5ca79
commit
731182eee4
@ -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("#");
|
||||
}
|
||||
|
||||
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;
|
||||
3
packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/types/PipelineBareFunction/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
|
||||
}
|
||||
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/types/PipelineBareFunction/output.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
let result = "hello" |> doubleSay |> text.capitalize |> a.b.exclaim;
|
||||
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js
vendored
Normal file
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/input.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
value |> # + 1;
|
||||
value |> 1 + #;
|
||||
value |> do {
|
||||
#;
|
||||
};
|
||||
value |> do {
|
||||
if (yes) #;
|
||||
};
|
||||
3
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json
vendored
Normal file
3
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": [["pipelineOperator", { "proposal": "smart" }], "doExpressions"]
|
||||
}
|
||||
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js
vendored
Normal file
8
packages/babel-generator/test/fixtures/types/PipelineTopicExpression/output.js
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
value |> # + 1;
|
||||
value |> 1 + #;
|
||||
value |> do {
|
||||
#;
|
||||
};
|
||||
value |> do {
|
||||
if (yes) #;
|
||||
};
|
||||
@ -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 = {},
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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"],
|
||||
|
||||
@ -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 ||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user