Preserve parens with keyof, enforce parens with arrows with type params (#2503)
* Force parens around argument of simple arrow function if type annotation is present * Preserve parens inside keyof operatormaster
parent
b3a4785cec
commit
d62d1c5c56
|
@ -8,7 +8,7 @@ module.exports = {
|
|||
testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$",
|
||||
testPathIgnorePatterns: ["tests/new_react", "tests/more_react"],
|
||||
collectCoverage: ENABLE_COVERAGE,
|
||||
collectCoverageFrom: ["src/**/*.js", "index.js"],
|
||||
collectCoverageFrom: ["src/**/*.js", "index.js", "!<rootDir>/node_modules/"],
|
||||
coveragePathIgnorePatterns: [
|
||||
"<rootDir>/src/doc-debug.js",
|
||||
"<rootDir>/src/clean-ast.js",
|
||||
|
|
|
@ -346,13 +346,15 @@ FastPath.prototype.needsParens = function(options) {
|
|||
}
|
||||
|
||||
case "TSParenthesizedType": {
|
||||
const grandParent = this.getParentNode(1);
|
||||
if (
|
||||
(parent.type === "TypeParameter" ||
|
||||
parent.type === "VariableDeclarator" ||
|
||||
parent.type === "TypeAnnotation" ||
|
||||
parent.type === "GenericTypeAnnotation") &&
|
||||
(node.typeAnnotation.type === "TypeAnnotation" &&
|
||||
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType")
|
||||
node.typeAnnotation.typeAnnotation.type !== "TSFunctionType" &&
|
||||
grandParent.type !== "TSTypeOperator")
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -3126,6 +3126,7 @@ function canPrintParamsWithoutParens(node) {
|
|||
return (
|
||||
node.params.length === 1 &&
|
||||
!node.rest &&
|
||||
!node.typeParameters &&
|
||||
node.params[0].type === "Identifier" &&
|
||||
!node.params[0].typeAnnotation &&
|
||||
!node.params[0].comments &&
|
||||
|
|
|
@ -379,3 +379,10 @@ const initializeSnapshotState = (
|
|||
) => new SnapshotState(testFile, update, testPath, expand);
|
||||
|
||||
`;
|
||||
|
||||
exports[`type_params.js 1`] = `
|
||||
<T>(a) => { }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
<T>(a) => {};
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<T>(a) => { }
|
|
@ -0,0 +1,15 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`keyof.ts 1`] = `
|
||||
type A = keyof (T | U);
|
||||
type B = keyof (X & Y);
|
||||
type C = keyof T | U;
|
||||
type D = keyof X & Y;
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
type A = keyof (T | U);
|
||||
type B = keyof (X & Y);
|
||||
type C = keyof T | U;
|
||||
type D = keyof X & Y;
|
||||
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, { parser: "typescript" });
|
|
@ -0,0 +1,5 @@
|
|||
type A = keyof (T | U);
|
||||
type B = keyof (X & Y);
|
||||
type C = keyof T | U;
|
||||
type D = keyof X & Y;
|
||||
|
Loading…
Reference in New Issue