feat: add support for PartialApplication (#6397)

master
JounQin 2019-10-17 21:45:24 +08:00 committed by Evilebot Tnawi
parent 80260555c9
commit 9a0bdf71cb
6 changed files with 84 additions and 1 deletions

View File

@ -44,6 +44,42 @@ const link = <a href="example.com">http://example.com</a>;
-->
#### JavaScript: add support for PartialApplication ([#6397] by [@JounQin])
Previous versions would not be able to format this syntax, this has been fixed in this version.
<!-- prettier-ignore -->
```js
const addOne = add(1, ?); // apply from the left
addOne(2); // 3
const addTen = add(?, 10); // apply from the right
addTen(2); // 12
// with pipeline
let newScore = player.score
|> add(7, ?)
|> clamp(0, 100, ?); // shallow stack, the pipe to `clamp` is the same frame as the pipe to `add`.
// Output (Prettier stable)
SyntaxError: Unexpected token (1:23)
> 1 | const addOne = add(1, ?); // apply from the left
| ^
2 | addOne(2); // 3
3 |
4 | const addTen = add(?, 10); // apply from the right
// Output (Prettier master)
const addOne = add(1, ?); // apply from the left
addOne(2); // 3
const addTen = add(?, 10); // apply from the right
addTen(2); // 12
// with pipeline
let newScore = player.score |> add(7, ?) |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`.
```
#### JavaScript: More readable parentheses for new-call ([#6412] by [@bakkot])
<!-- prettier-ignore -->
@ -995,6 +1031,7 @@ class A {
[#6340]: https://github.com/prettier/prettier/pull/6340
[#6377]: https://github.com/prettier/prettier/pull/6377
[#6381]: https://github.com/prettier/prettier/pull/6381
[#6397]: https://github.com/prettier/prettier/pull/6397
[#6404]: https://github.com/prettier/prettier/pull/6404
[#6411]: https://github.com/prettier/prettier/pull/6411
[#6412]: https://github.com/prettier/prettier/pull/6412

View File

@ -39,7 +39,8 @@ function babelOptions(extraOptions, extraPlugins) {
"throwExpressions",
"logicalAssignment",
"classPrivateMethods",
"v8intrinsic"
"v8intrinsic",
"partialApplication"
].concat(extraPlugins)
},
extraOptions

View File

@ -3506,6 +3506,9 @@ function printPathNoParens(path, options, print, args) {
" as ",
path.call(print, "alias")
]);
case "ArgumentPlaceholder":
return "?";
default:
/* istanbul ignore next */
throw new Error("unknown type: " + JSON.stringify(n.type));

View File

@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`test.js 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
const addOne = add(1, ?); // apply from the left
addOne(2); // 3
const addTen = add(?, 10); // apply from the right
addTen(2); // 12
// with pipeline
let newScore = player.score
|> add(7, ?)
|> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`.
=====================================output=====================================
const addOne = add(1, ?); // apply from the left
addOne(2); // 3
const addTen = add(?, 10); // apply from the right
addTen(2); // 12
// with pipeline
let newScore = player.score |> add(7, ?) |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`.
================================================================================
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, ["babel"]);

View File

@ -0,0 +1,10 @@
const addOne = add(1, ?); // apply from the left
addOne(2); // 3
const addTen = add(?, 10); // apply from the right
addTen(2); // 12
// with pipeline
let newScore = player.score
|> add(7, ?)
|> clamp(0, 100, ?); // shallow stack, the pipe to `clamp` is the same frame as the pipe to `add`.