-
Notifications
You must be signed in to change notification settings - Fork 1
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
Babel plugin #9
Comments
Neeeat! I'm not quite sure how it handles brackets though. I think I think one thing you could do is to bubble up the What do you think? |
Heya, glad you liked it! Yeah, I think constructs like Though, with a nearest non-calling group bubbling there might be a problem, as Without changing the babel's syntax parsing (which I think is more troublesome), we could try the Also, currently the plugin handles the pipes // special case, implicit grouping
let a = 42 |> _ + 1; // ≈ 42 + 1;
typeof a; // 'number';
// no special case, explicitly placing bubble point:
let a = 42 |> { _ + 1 }; // ≈ 42 + 1;
typeof a; // 'number';
// no special case, bubbling to the top of the expression
let a = 42 |> _ + 1; // ≈ x => (x + 1)(42);
typeof a; // 'function';
a('param'); // runtime error
// no special case, no implicit bubbling
let a = 42 |> _ + 1; // parsing error .
Great catch! I'll have to check that out, thx! . Please, share your thoughts. |
I think not having special cases is a better starting position. I think if something can be added later and it makes sense to add it later, it should be added later. So I believe that having no bubbling and implicit grouping would be the best at first. |
I was wrong, |
Since let a = ~ _ + 1; similar to your proposed And after a while, I think it works: a = ~ _;
assert(a(42) === 42);
a = ~ _ + 1;
assert(a(41) === 42);
a = ~ _(40) + 1;
assert(a(inc) === 42);
a = [1,2,3].map(~ _ + 1).join();
assert(a === '2,3,4');
a = [1,2,3].filter(~ _ % 2).map(~ _ + 1).join()
assert(a === '2,4');
// in pipe LHS, the ~ marker is required
a = ~ _ |> inc
assert(a(42) === 43)
// without a marker babel will throw
a = _ |> inc // INVALID: _ is unbound
// RHS can have explicit or implicit grouping
a = 40 |> ~ _ + 1 |> _ + 1
assert(a === 42) Here is the babel playground with new syntax. Please, note that I haven't covered or tested multiple placeholders, nested |
Hey, great work on the proposal!
I created a babel plugin with simpler rules ("simpler", not "better"!), exploring no prefix partial expressions:
You can play with it in the babel playground.
And here's the plugin repository where I described some rules and how it integrates with the pipeline operator.
Maybe it can help pushing the proposal further.
The text was updated successfully, but these errors were encountered: