Do not expand empty catch (#783)
I originally wanted to expand it but I think that it may not be a good decision because it's very common for them to be empty and you want it to take as little space as possible. I tried to remove all those conditions but I think that there are valid places where we always want to expand like empty if/for/while loops. Fixes #778master
parent
c84027745b
commit
694816517a
|
@ -555,6 +555,7 @@ function genericPrintNoParens(path, options, print) {
|
||||||
const hasDirectives = n.directives && n.directives.length > 0;
|
const hasDirectives = n.directives && n.directives.length > 0;
|
||||||
|
|
||||||
var parent = path.getParentNode();
|
var parent = path.getParentNode();
|
||||||
|
const parentParent = path.getParentNode(1);
|
||||||
if (
|
if (
|
||||||
!hasContent &&
|
!hasContent &&
|
||||||
!hasDirectives &&
|
!hasDirectives &&
|
||||||
|
@ -563,7 +564,8 @@ function genericPrintNoParens(path, options, print) {
|
||||||
parent.type === "FunctionExpression" ||
|
parent.type === "FunctionExpression" ||
|
||||||
parent.type === "FunctionDeclaration" ||
|
parent.type === "FunctionDeclaration" ||
|
||||||
parent.type === "ObjectMethod" ||
|
parent.type === "ObjectMethod" ||
|
||||||
parent.type === "ClassMethod")
|
parent.type === "ClassMethod" ||
|
||||||
|
(parent.type === "CatchClause" && !parentParent.finalizer))
|
||||||
) {
|
) {
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,8 +205,7 @@ function f() {
|
||||||
try {
|
try {
|
||||||
var x: number = 0;
|
var x: number = 0;
|
||||||
var y: number = x;
|
var y: number = x;
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// and within catch
|
// and within catch
|
||||||
|
@ -311,16 +310,14 @@ function f() {
|
||||||
var y: number = x; // error
|
var y: number = x; // error
|
||||||
try {
|
try {
|
||||||
var x: number = 0;
|
var x: number = 0;
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// another non-dominated post
|
// another non-dominated post
|
||||||
function f() {
|
function f() {
|
||||||
try {
|
try {
|
||||||
var x: number = 0;
|
var x: number = 0;
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
var y: number = x; // error
|
var y: number = x; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,8 +338,7 @@ function f(b) {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
x = 0;
|
x = 0;
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
var y: number = x; // error
|
var y: number = x; // error
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@ -448,8 +444,7 @@ function baz(): string {
|
||||||
function qux(): string {
|
function qux(): string {
|
||||||
try {
|
try {
|
||||||
throw new Error(\\"foo\\");
|
throw new Error(\\"foo\\");
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
console.log();
|
console.log();
|
||||||
return \\"bar\\";
|
return \\"bar\\";
|
||||||
}
|
}
|
||||||
|
@ -457,8 +452,7 @@ function qux(): string {
|
||||||
function quux(): string {
|
function quux(): string {
|
||||||
try {
|
try {
|
||||||
return qux();
|
return qux();
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
return \\"bar\\";
|
return \\"bar\\";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,7 +280,6 @@ try {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
throw \\"foo\\";
|
throw \\"foo\\";
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -1,5 +1,26 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`empty.js 1`] = `
|
||||||
|
"try {
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (e) {}
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`try.js 1`] = `
|
exports[`try.js 1`] = `
|
||||||
"try
|
"try
|
||||||
/* missing comment */
|
/* missing comment */
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
}
|
Loading…
Reference in New Issue