Remove dead code (#10869)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-05-16 12:35:55 +08:00
1 parent 0b3fabd5b9
commit a9c3960f2f
5 files changed
+35 -61

No files matched your search

-1
View File
@@ -413,7 +413,6 @@ function needsParens(path, options) {
return false;
}
case "TSJSDocFunctionType":
case "TSConditionalType":
if (name === "extendsType" && parent.type === "TSConditionalType") {
return true;
+8 -1
View File
@@ -13,7 +13,10 @@ const {
printIndexedAccessType,
} = require("./type-annotation");
const { printInterface } = require("./interface");
const { printTypeParameters } = require("./type-parameters");
const {
printTypeParameter,
printTypeParameters,
} = require("./type-parameters");
const {
printExportDeclaration,
printExportAllDeclaration,
@@ -89,6 +92,10 @@ function printFlow(path, options, print) {
// transformed away before printing.
case "TypeAnnotation":
return print("typeAnnotation");
case "TypeParameter":
return printTypeParameter(path, options, print);
case "TypeofTypeAnnotation":
return ["typeof ", print("argument")];
}
}
+9
View File
@@ -698,6 +698,12 @@ function printJsxSpreadAttribute(path, options, print) {
function printJsx(path, options, print) {
const node = path.getValue();
// JSX nodes always starts with `JSX`
if (!node.type.startsWith("JSX")) {
return;
}
switch (node.type) {
case "JSXAttribute":
return printJsxAttribute(path, options, print);
@@ -731,6 +737,9 @@ function printJsx(path, options, print) {
case "JSXText":
/* istanbul ignore next */
throw new Error("JSXTest should be handled by JSXElement");
default:
/* istanbul ignore next */
throw new Error(`Unknown JSX node type: ${JSON.stringify(node.type)}.`);
}
}
+18 -48
View File
@@ -52,9 +52,22 @@ const {
function printTypescript(path, options, print) {
const node = path.getValue();
// TypeScript nodes always starts with `TS`
if (!node.type.startsWith("TS")) {
return;
}
if (node.type.endsWith("Keyword")) {
return node.type.slice(2, -7).toLowerCase();
}
const semi = options.semi ? ";" : "";
const parts = [];
switch (node.type) {
case "TSThisType":
return "this";
case "TSTypeAssertion": {
const shouldBreakAfterCast = !(
node.expression.type === "ArrayExpression" ||
@@ -131,40 +144,8 @@ function printTypescript(path, options, print) {
case "TSTypeParameterDeclaration":
case "TSTypeParameterInstantiation":
return printTypeParameters(path, options, print, "params");
case "TSTypeParameter":
case "TypeParameter":
return printTypeParameter(path, options, print);
case "TypeofTypeAnnotation":
return ["typeof ", print("argument")];
case "TSAbstractKeyword":
return "abstract";
case "TSAsyncKeyword":
return "async";
case "TSDeclareKeyword":
return "declare";
case "TSExportKeyword":
return "export";
case "TSNeverKeyword":
return "never";
case "TSObjectKeyword":
return "object";
case "TSProtectedKeyword":
return "protected";
case "TSPrivateKeyword":
return "private";
case "TSPublicKeyword":
return "public";
case "TSReadonlyKeyword":
return "readonly";
case "TSStaticKeyword":
return "static";
case "TSUndefinedKeyword":
return "undefined";
case "TSUnknownKeyword":
return "unknown";
case "TSIntrinsicKeyword":
return "intrinsic";
case "TSAsExpression": {
parts.push(print("expression"), " as ", print("typeAnnotation"));
const parent = path.getParentNode();
@@ -179,15 +160,6 @@ function printTypescript(path, options, print) {
case "TSArrayType":
return [print("elementType"), "[]"];
case "TSPropertySignature": {
if (node.export) {
parts.push("export ");
}
if (node.accessibility) {
parts.push(node.accessibility + " ");
}
if (node.static) {
parts.push("static ");
}
if (node.readonly) {
parts.push("readonly ");
}
@@ -547,13 +519,11 @@ function printTypescript(path, options, print) {
return ["?", print("typeAnnotation")];
case "TSJSDocNonNullableType":
return ["!", print("typeAnnotation")];
case "TSJSDocFunctionType":
return [
"function(",
// The parameters could be here, but typescript-estree doesn't convert them anyway (throws an error).
"): ",
print("typeAnnotation"),
];
default:
/* istanbul ignore next */
throw new Error(
`Unknown TypeScript node type: ${JSON.stringify(node.type)}.`
);
}
}
-11
View File
@@ -967,33 +967,22 @@ function printPathNoParens(path, options, print, args) {
case "DeclaredPredicate":
return ["%checks(", print("value"), ")"];
case "AnyTypeAnnotation":
case "TSAnyKeyword":
return "any";
case "BooleanTypeAnnotation":
case "TSBooleanKeyword":
return "boolean";
case "BigIntTypeAnnotation":
case "TSBigIntKeyword":
return "bigint";
case "TSConstKeyword":
return "const";
case "NullLiteralTypeAnnotation":
case "TSNullKeyword":
return "null";
case "NumberTypeAnnotation":
case "TSNumberKeyword":
return "number";
case "SymbolTypeAnnotation":
case "TSSymbolKeyword":
return "symbol";
case "StringTypeAnnotation":
case "TSStringKeyword":
return "string";
case "VoidTypeAnnotation":
case "TSVoidKeyword":
return "void";
case "ThisTypeAnnotation":
case "TSThisType":
return "this";
case "PrivateIdentifier":