Skip to content
This repository was archived by the owner on May 19, 2018. It is now read-only.

Pipeline Operator proposal #742

Merged
merged 1 commit into from
Sep 29, 2017
Merged

Pipeline Operator proposal #742

merged 1 commit into from
Sep 29, 2017

Conversation

hzoo
Copy link
Member

@hzoo hzoo commented Sep 28, 2017

Ref babel/proposals#29
Taken from babel/babel#3159 by @gilbert
Spec: https://github.com/tc39/proposal-pipeline-operator/pull/51/files

need more tests

  • precedence
  • with arrow function 10 |> x => x + 1;
  • chaining a |> b |> c
  • multline
let result = "hello"
  |> doubleSay
  |> capitalize
  |> exclaim;
let newScore = person.score
  |> double
  |> _ => add(7, _)
  |> _ => boundScore(0, 100, _);

@hzoo hzoo changed the title pipelineOperator proposal Pipeline Operator proposal Sep 28, 2017
@hzoo hzoo requested a review from littledan September 28, 2017 13:02
if (code === 124) {
// '|>'
if (next === 62) {
this.expectPlugin("pipelineOperator");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we usually expect in the not-tokenizer part?

@@ -411,9 +411,17 @@ export default class Tokenizer extends LocationParser {
const next = this.input.charCodeAt(this.state.pos + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ok now

@@ -0,0 +1 @@
a |> b
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More examples, especially arrows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@hzoo hzoo merged commit d2e06a9 into master Sep 29, 2017
@jridgewell jridgewell deleted the pipeline branch September 29, 2017 03:25
@@ -61,7 +61,7 @@ export class TokenType {
this.isAssign = !!conf.isAssign;
this.prefix = !!conf.prefix;
this.postfix = !!conf.postfix;
this.binop = conf.binop || null;
this.binop = conf.binop === 0 ? 0 : conf.binop || null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be nice with ?? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, should be easy to add/use here (would be good to find this kind of code on github/codebase and then do a codemod)

if (node.operator === "|>") {
this.expectPlugin("pipelineOperator");
// Support syntax such as 10 |> x => x + 1
this.state.potentialArrowAt = startPos;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the current draft spec has this logic. I couldn't figure out how to put it into the grammar. Right now, x |> y => z would be a syntax error. But it's clearly useful--i'll think more about the spec.

Copy link
Member Author

@hzoo hzoo Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants