Improve coverage and remove some dead code (#2504)
* Improve test coverage * Clean up some un-used code * Lower patch requirements on codecovmaster
parent
d62d1c5c56
commit
02639da9a9
|
@ -1 +1,10 @@
|
|||
comment: off
|
||||
|
||||
coverage:
|
||||
status:
|
||||
patch:
|
||||
default:
|
||||
target: 80%
|
||||
project:
|
||||
default:
|
||||
target: auto
|
||||
|
|
142
src/printer.js
142
src/printer.js
|
@ -575,18 +575,8 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
|
||||
return concat(parts);
|
||||
case "AwaitExpression":
|
||||
parts.push("await");
|
||||
|
||||
if (n.all) {
|
||||
parts.push("*");
|
||||
}
|
||||
if (n.argument) {
|
||||
parts.push(" ", path.call(print, "argument"));
|
||||
}
|
||||
|
||||
return concat(parts);
|
||||
return concat(["await ", path.call(print, "argument")]);
|
||||
case "ImportSpecifier":
|
||||
if (n.imported) {
|
||||
if (n.importKind) {
|
||||
parts.push(path.call(print, "importKind"), " ");
|
||||
}
|
||||
|
@ -596,29 +586,14 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
if (n.local && n.local.name !== n.imported.name) {
|
||||
parts.push(" as ", path.call(print, "local"));
|
||||
}
|
||||
} else if (n.id) {
|
||||
parts.push(path.call(print, "id"));
|
||||
|
||||
if (n.name) {
|
||||
parts.push(" as ", path.call(print, "name"));
|
||||
}
|
||||
}
|
||||
|
||||
return concat(parts);
|
||||
case "ExportSpecifier":
|
||||
if (n.local) {
|
||||
parts.push(path.call(print, "local"));
|
||||
|
||||
if (n.exported && n.exported.name !== n.local.name) {
|
||||
parts.push(" as ", path.call(print, "exported"));
|
||||
}
|
||||
} else if (n.id) {
|
||||
parts.push(path.call(print, "id"));
|
||||
|
||||
if (n.name) {
|
||||
parts.push(" as ", path.call(print, "name"));
|
||||
}
|
||||
}
|
||||
|
||||
return concat(parts);
|
||||
case "ImportNamespaceSpecifier":
|
||||
|
@ -637,22 +612,13 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
}
|
||||
|
||||
return path.call(print, "id");
|
||||
case "TSExportAssigment": {
|
||||
case "TSExportAssigment":
|
||||
return concat(["export = ", path.call(print, "expression"), semi]);
|
||||
}
|
||||
case "ExportDefaultDeclaration":
|
||||
case "ExportNamedDeclaration":
|
||||
return printExportDeclaration(path, options, print);
|
||||
case "ExportAllDeclaration":
|
||||
parts.push("export *");
|
||||
|
||||
if (n.exported) {
|
||||
parts.push(" as ", path.call(print, "exported"));
|
||||
}
|
||||
|
||||
parts.push(" from ", path.call(print, "source"), semi);
|
||||
|
||||
return concat(parts);
|
||||
return concat(["export * from ", path.call(print, "source"), semi]);
|
||||
case "ExportNamespaceSpecifier":
|
||||
case "ExportDefaultSpecifier":
|
||||
return path.call(print, "exported");
|
||||
|
@ -720,7 +686,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
);
|
||||
}
|
||||
|
||||
parts.push(" ", "from ");
|
||||
parts.push(" from ");
|
||||
} else if (
|
||||
(n.importKind && n.importKind === "type") ||
|
||||
// import {} from 'x'
|
||||
|
@ -1569,32 +1535,19 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
path.call(print, "body")
|
||||
]);
|
||||
case "TryStatement":
|
||||
parts.push("try ", path.call(print, "block"));
|
||||
|
||||
if (n.handler) {
|
||||
parts.push(" ", path.call(print, "handler"));
|
||||
} else if (n.handlers) {
|
||||
path.each(handlerPath => {
|
||||
parts.push(" ", print(handlerPath));
|
||||
}, "handlers");
|
||||
}
|
||||
|
||||
if (n.finalizer) {
|
||||
parts.push(" finally ", path.call(print, "finalizer"));
|
||||
}
|
||||
|
||||
return concat(parts);
|
||||
return concat([
|
||||
"try ",
|
||||
path.call(print, "block"),
|
||||
n.handler ? concat([" ", path.call(print, "handler")]) : "",
|
||||
n.finalizer ? concat([" finally ", path.call(print, "finalizer")]) : ""
|
||||
]);
|
||||
case "CatchClause":
|
||||
parts.push("catch (", path.call(print, "param"));
|
||||
|
||||
if (n.guard) {
|
||||
// Note: esprima does not recognize conditional catch clauses.
|
||||
parts.push(" if ", path.call(print, "guard"));
|
||||
}
|
||||
|
||||
parts.push(") ", path.call(print, "body"));
|
||||
|
||||
return concat(parts);
|
||||
return concat([
|
||||
"catch (",
|
||||
path.call(print, "param"),
|
||||
") ",
|
||||
path.call(print, "body")
|
||||
]);
|
||||
case "ThrowStatement":
|
||||
return concat(["throw ", path.call(print, "argument"), semi]);
|
||||
// Note: ignoring n.lexical because it has no printing consequences.
|
||||
|
@ -1935,6 +1888,7 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
return path.call(print, "typeAnnotation");
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
return "";
|
||||
case "TSTupleType":
|
||||
case "TupleTypeAnnotation": {
|
||||
|
@ -2374,20 +2328,18 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
case "TSArrayType":
|
||||
return concat([path.call(print, "elementType"), "[]"]);
|
||||
case "TSPropertySignature": {
|
||||
if (n.accessibility) {
|
||||
parts.push(n.accessibility + " ");
|
||||
}
|
||||
if (n.export) {
|
||||
parts.push("export ");
|
||||
}
|
||||
if (n.accessibility) {
|
||||
parts.push(n.accessibility + " ");
|
||||
}
|
||||
if (n.static) {
|
||||
parts.push("static ");
|
||||
}
|
||||
|
||||
if (n.readonly) {
|
||||
parts.push("readonly ");
|
||||
}
|
||||
|
||||
if (n.computed) {
|
||||
parts.push("[");
|
||||
}
|
||||
|
@ -2397,11 +2349,9 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
if (n.computed) {
|
||||
parts.push("]");
|
||||
}
|
||||
|
||||
if (n.optional) {
|
||||
parts.push("?");
|
||||
}
|
||||
|
||||
if (n.typeAnnotation) {
|
||||
parts.push(": ");
|
||||
parts.push(path.call(print, "typeAnnotation"));
|
||||
|
@ -2443,24 +2393,14 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
}
|
||||
case "TSIndexSignature": {
|
||||
const parent = path.getParentNode();
|
||||
let printedParams = [];
|
||||
if (n.params) {
|
||||
printedParams = path.map(print, "params");
|
||||
}
|
||||
if (n.parameters) {
|
||||
printedParams = path.map(print, "parameters");
|
||||
}
|
||||
|
||||
return concat([
|
||||
n.accessibility ? concat([n.accessibility, " "]) : "",
|
||||
n.export ? "export " : "",
|
||||
n.accessibility ? concat([n.accessibility, " "]) : "",
|
||||
n.static ? "static " : "",
|
||||
n.readonly ? "readonly " : "",
|
||||
"[",
|
||||
path.call(print, "index"),
|
||||
// This should only contain a single element, however TypeScript parses
|
||||
// it using parseDelimitedList that uses commas as delimiter.
|
||||
join(", ", printedParams),
|
||||
"]: ",
|
||||
path.call(print, "typeAnnotation"),
|
||||
parent.type === "ClassBody" ? semi : ""
|
||||
|
@ -2568,19 +2508,11 @@ function genericPrintNoParens(path, options, print, args) {
|
|||
}
|
||||
return group(concat(parts));
|
||||
case "TSNamespaceExportDeclaration":
|
||||
if (n.declaration) {
|
||||
parts.push(
|
||||
"export ",
|
||||
n.default ? "default " : "",
|
||||
path.call(print, "declaration")
|
||||
);
|
||||
} else {
|
||||
parts.push("export as namespace ", path.call(print, "name"));
|
||||
|
||||
if (options.semi) {
|
||||
parts.push(";");
|
||||
}
|
||||
}
|
||||
|
||||
return group(concat(parts));
|
||||
case "TSEnumDeclaration":
|
||||
|
@ -2724,6 +2656,7 @@ function printStatementSequence(path, options, print) {
|
|||
|
||||
// Just in case the AST has been modified to contain falsy
|
||||
// "statements," it's safer simply to skip them.
|
||||
/* istanbul ignore if */
|
||||
if (!stmt) {
|
||||
return;
|
||||
}
|
||||
|
@ -2979,14 +2912,7 @@ function printArgumentsList(path, options, print) {
|
|||
|
||||
function printFunctionTypeParameters(path, options, print) {
|
||||
const fun = path.getValue();
|
||||
const paramsFieldIsArray = Array.isArray(fun["typeParameters"]);
|
||||
|
||||
if (fun.typeParameters) {
|
||||
// for TSFunctionType typeParameters is an array
|
||||
// for FunctionTypeAnnotation it's a single node
|
||||
if (paramsFieldIsArray) {
|
||||
return concat("<", join(", ", path.map(print, "typeParameters")), ">");
|
||||
}
|
||||
return path.call(print, "typeParameters");
|
||||
}
|
||||
return "";
|
||||
|
@ -3005,17 +2931,6 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) {
|
|||
printed = path.map(print, paramsField);
|
||||
}
|
||||
|
||||
if (fun.defaults) {
|
||||
path.each(defExprPath => {
|
||||
const i = defExprPath.getName();
|
||||
const p = printed[i];
|
||||
|
||||
if (p && defExprPath.getValue()) {
|
||||
printed[i] = concat([p, " = ", print(defExprPath)]);
|
||||
}
|
||||
}, "defaults");
|
||||
}
|
||||
|
||||
if (fun.rest) {
|
||||
printed.push(concat(["...", path.call(print, "rest")]));
|
||||
}
|
||||
|
@ -3339,11 +3254,10 @@ function getFlowVariance(path) {
|
|||
switch (variance) {
|
||||
case "plus":
|
||||
return "+";
|
||||
|
||||
case "minus":
|
||||
return "-";
|
||||
|
||||
default:
|
||||
/* istanbul ignore next */
|
||||
return variance;
|
||||
}
|
||||
}
|
||||
|
@ -3403,9 +3317,6 @@ function printClass(path, options, print) {
|
|||
const n = path.getValue();
|
||||
const parts = [];
|
||||
|
||||
if (n.accessibility) {
|
||||
parts.push(n.accessibility + " ");
|
||||
}
|
||||
if (n.type === "TSAbstractClassDeclaration") {
|
||||
parts.push("abstract ");
|
||||
}
|
||||
|
@ -4558,9 +4469,6 @@ function exprNeedsASIProtection(node) {
|
|||
}
|
||||
|
||||
function stmtNeedsASIProtection(path) {
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
const node = path.getNode();
|
||||
|
||||
if (node.type !== "ExpressionStatement") {
|
||||
|
@ -4578,9 +4486,6 @@ function classPropMayCauseASIProblems(path) {
|
|||
}
|
||||
|
||||
const name = node.key && node.key.name;
|
||||
if (!name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// this isn't actually possible yet with most parsers available today
|
||||
// so isn't properly tested yet.
|
||||
|
@ -4628,6 +4533,7 @@ function classChildNeedsASIProtection(node) {
|
|||
}
|
||||
|
||||
default:
|
||||
/* istanbul ignore next */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,11 @@ module Y3 {
|
|||
}
|
||||
|
||||
// Apparently this parses :P
|
||||
export private public protected static readonly async enum X { }
|
||||
export private public protected static readonly abstract async enum X { }
|
||||
|
||||
interface x {
|
||||
export private static readonly [x: any]: any;
|
||||
}
|
||||
}
|
||||
|
||||
module Y4 {
|
||||
|
@ -46,7 +50,11 @@ namespace Y3 {
|
|||
}
|
||||
|
||||
// Apparently this parses :P
|
||||
export private public protected static readonly async enum X {}
|
||||
export private public protected static readonly abstract async enum X {}
|
||||
|
||||
interface x {
|
||||
export private static readonly [x: any]: any;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Y4 {
|
||||
|
|
|
@ -6,7 +6,11 @@ module Y3 {
|
|||
}
|
||||
|
||||
// Apparently this parses :P
|
||||
export private public protected static readonly async enum X { }
|
||||
export private public protected static readonly abstract async enum X { }
|
||||
|
||||
interface x {
|
||||
export private static readonly [x: any]: any;
|
||||
}
|
||||
}
|
||||
|
||||
module Y4 {
|
||||
|
|
|
@ -27,3 +27,14 @@ declare global {
|
|||
}
|
||||
|
||||
`;
|
||||
|
||||
exports[`namespace_function.ts 1`] = `
|
||||
namespace X {
|
||||
declare function f();
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
namespace X {
|
||||
declare function f();
|
||||
}
|
||||
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
namespace X {
|
||||
declare function f();
|
||||
}
|
Loading…
Reference in New Issue