feat: add support for PartialApplication (#6397)
parent
80260555c9
commit
9a0bdf71cb
|
@ -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])
|
#### JavaScript: More readable parentheses for new-call ([#6412] by [@bakkot])
|
||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
|
@ -995,6 +1031,7 @@ class A {
|
||||||
[#6340]: https://github.com/prettier/prettier/pull/6340
|
[#6340]: https://github.com/prettier/prettier/pull/6340
|
||||||
[#6377]: https://github.com/prettier/prettier/pull/6377
|
[#6377]: https://github.com/prettier/prettier/pull/6377
|
||||||
[#6381]: https://github.com/prettier/prettier/pull/6381
|
[#6381]: https://github.com/prettier/prettier/pull/6381
|
||||||
|
[#6397]: https://github.com/prettier/prettier/pull/6397
|
||||||
[#6404]: https://github.com/prettier/prettier/pull/6404
|
[#6404]: https://github.com/prettier/prettier/pull/6404
|
||||||
[#6411]: https://github.com/prettier/prettier/pull/6411
|
[#6411]: https://github.com/prettier/prettier/pull/6411
|
||||||
[#6412]: https://github.com/prettier/prettier/pull/6412
|
[#6412]: https://github.com/prettier/prettier/pull/6412
|
||||||
|
|
|
@ -39,7 +39,8 @@ function babelOptions(extraOptions, extraPlugins) {
|
||||||
"throwExpressions",
|
"throwExpressions",
|
||||||
"logicalAssignment",
|
"logicalAssignment",
|
||||||
"classPrivateMethods",
|
"classPrivateMethods",
|
||||||
"v8intrinsic"
|
"v8intrinsic",
|
||||||
|
"partialApplication"
|
||||||
].concat(extraPlugins)
|
].concat(extraPlugins)
|
||||||
},
|
},
|
||||||
extraOptions
|
extraOptions
|
||||||
|
|
|
@ -3506,6 +3506,9 @@ function printPathNoParens(path, options, print, args) {
|
||||||
" as ",
|
" as ",
|
||||||
path.call(print, "alias")
|
path.call(print, "alias")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
case "ArgumentPlaceholder":
|
||||||
|
return "?";
|
||||||
default:
|
default:
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
throw new Error("unknown type: " + JSON.stringify(n.type));
|
throw new Error("unknown type: " + JSON.stringify(n.type));
|
||||||
|
|
|
@ -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\`.
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
`;
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname, ["babel"]);
|
|
@ -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`.
|
Loading…
Reference in New Issue