Skip to content

Commit

Permalink
Make pipeline body available to scoping visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoarrais committed Apr 9, 2019
1 parent 155e217 commit 6738d16
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/babel-generator/src/generators/types.js
Expand Up @@ -156,6 +156,10 @@ export function BigIntLiteral(node: Object) {
this.token(node.value);
}

export function PipelineBody(node: Object) {
this.print(node.body, node);
}

export function PipelineTopicExpression(node: Object) {
this.print(node.expression, node);
}
Expand Down
@@ -1,6 +1,7 @@
const y = 2;
const f = (x) => x
|> (y) => y + 1
// parenthised until parser is fixed
const f = (x) => (x
|> (y) => y + 1)
|> (z) => z * y

const g = (x) => x
Expand All @@ -10,8 +11,6 @@ const g = (x) => x
}
)

// bug: scope for the pipelinebody (???) does not consider the third y as a reference to the first

const h = (x) => x
|> (y => (
y + 1
Expand All @@ -27,4 +26,4 @@ const i = (x) => x
expect(f(1)).toBe(4);
expect(g(1)).toBe(2);
expect(h(1)).toBe(2);
// expect(i(1)).toBe(2);
expect(i(1)).toBe(2);
3 changes: 3 additions & 0 deletions packages/babel-types/src/asserts/generated/index.js
Expand Up @@ -702,6 +702,9 @@ export function assertPipelinePrimaryTopicReference(
): void {
assert("PipelinePrimaryTopicReference", node, opts);
}
export function assertPipelineBody(node: Object, opts?: Object = {}): void {
assert("PipelineBody", node, opts);
}
export function assertOptionalCallExpression(
node: Object,
opts?: Object = {},
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-types/src/builders/generated/index.js
Expand Up @@ -632,6 +632,10 @@ export function PipelinePrimaryTopicReference(...args: Array<any>): Object {
return builder("PipelinePrimaryTopicReference", ...args);
}
export { PipelinePrimaryTopicReference as pipelinePrimaryTopicReference };
export function PipelineBody(...args: Array<any>): Object {
return builder("PipelineBody", ...args);
}
export { PipelineBody as pipelineBody };
export function OptionalCallExpression(...args: Array<any>): Object {
return builder("OptionalCallExpression", ...args);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-types/src/definitions/experimental.js
Expand Up @@ -115,6 +115,10 @@ defineType("PipelinePrimaryTopicReference", {
aliases: ["Expression"],
});

defineType("PipelineBody", {
visitor: ["body"],
});

defineType("OptionalCallExpression", {
visitor: ["callee", "arguments", "typeParameters", "typeArguments"],
builder: ["callee", "arguments", "optional"],
Expand Down
14 changes: 14 additions & 0 deletions packages/babel-types/src/validators/generated/index.js
Expand Up @@ -2228,6 +2228,20 @@ export function isPipelinePrimaryTopicReference(

return false;
}
export function isPipelineBody(node: ?Object, opts?: Object): boolean {
if (!node) return false;

const nodeType = node.type;
if (nodeType === "PipelineBody") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}

return false;
}
export function isOptionalCallExpression(
node: ?Object,
opts?: Object,
Expand Down

0 comments on commit 6738d16

Please sign in to comment.