Improve coverage and remove some dead code (#2504)

* Improve test coverage

* Clean up some un-used code

* Lower patch requirements on codecov
master
Lucas Azzola 2017-07-17 23:31:42 +10:00 committed by GitHub
parent d62d1c5c56
commit 02639da9a9
6 changed files with 74 additions and 133 deletions

View File

@ -1 +1,10 @@
comment: off comment: off
coverage:
status:
patch:
default:
target: 80%
project:
default:
target: auto

View File

@ -575,49 +575,24 @@ function genericPrintNoParens(path, options, print, args) {
return concat(parts); return concat(parts);
case "AwaitExpression": case "AwaitExpression":
parts.push("await"); return concat(["await ", path.call(print, "argument")]);
if (n.all) {
parts.push("*");
}
if (n.argument) {
parts.push(" ", path.call(print, "argument"));
}
return concat(parts);
case "ImportSpecifier": case "ImportSpecifier":
if (n.imported) { if (n.importKind) {
if (n.importKind) { parts.push(path.call(print, "importKind"), " ");
parts.push(path.call(print, "importKind"), " "); }
}
parts.push(path.call(print, "imported")); parts.push(path.call(print, "imported"));
if (n.local && n.local.name !== n.imported.name) { if (n.local && n.local.name !== n.imported.name) {
parts.push(" as ", path.call(print, "local")); 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); return concat(parts);
case "ExportSpecifier": case "ExportSpecifier":
if (n.local) { parts.push(path.call(print, "local"));
parts.push(path.call(print, "local"));
if (n.exported && n.exported.name !== n.local.name) { if (n.exported && n.exported.name !== n.local.name) {
parts.push(" as ", path.call(print, "exported")); 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); return concat(parts);
@ -637,22 +612,13 @@ function genericPrintNoParens(path, options, print, args) {
} }
return path.call(print, "id"); return path.call(print, "id");
case "TSExportAssigment": { case "TSExportAssigment":
return concat(["export = ", path.call(print, "expression"), semi]); return concat(["export = ", path.call(print, "expression"), semi]);
}
case "ExportDefaultDeclaration": case "ExportDefaultDeclaration":
case "ExportNamedDeclaration": case "ExportNamedDeclaration":
return printExportDeclaration(path, options, print); return printExportDeclaration(path, options, print);
case "ExportAllDeclaration": case "ExportAllDeclaration":
parts.push("export *"); return concat(["export * from ", path.call(print, "source"), semi]);
if (n.exported) {
parts.push(" as ", path.call(print, "exported"));
}
parts.push(" from ", path.call(print, "source"), semi);
return concat(parts);
case "ExportNamespaceSpecifier": case "ExportNamespaceSpecifier":
case "ExportDefaultSpecifier": case "ExportDefaultSpecifier":
return path.call(print, "exported"); return path.call(print, "exported");
@ -720,7 +686,7 @@ function genericPrintNoParens(path, options, print, args) {
); );
} }
parts.push(" ", "from "); parts.push(" from ");
} else if ( } else if (
(n.importKind && n.importKind === "type") || (n.importKind && n.importKind === "type") ||
// import {} from 'x' // import {} from 'x'
@ -1569,32 +1535,19 @@ function genericPrintNoParens(path, options, print, args) {
path.call(print, "body") path.call(print, "body")
]); ]);
case "TryStatement": case "TryStatement":
parts.push("try ", path.call(print, "block")); return concat([
"try ",
if (n.handler) { path.call(print, "block"),
parts.push(" ", path.call(print, "handler")); n.handler ? concat([" ", path.call(print, "handler")]) : "",
} else if (n.handlers) { n.finalizer ? concat([" finally ", path.call(print, "finalizer")]) : ""
path.each(handlerPath => { ]);
parts.push(" ", print(handlerPath));
}, "handlers");
}
if (n.finalizer) {
parts.push(" finally ", path.call(print, "finalizer"));
}
return concat(parts);
case "CatchClause": case "CatchClause":
parts.push("catch (", path.call(print, "param")); return concat([
"catch (",
if (n.guard) { path.call(print, "param"),
// Note: esprima does not recognize conditional catch clauses. ") ",
parts.push(" if ", path.call(print, "guard")); path.call(print, "body")
} ]);
parts.push(") ", path.call(print, "body"));
return concat(parts);
case "ThrowStatement": case "ThrowStatement":
return concat(["throw ", path.call(print, "argument"), semi]); return concat(["throw ", path.call(print, "argument"), semi]);
// Note: ignoring n.lexical because it has no printing consequences. // 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"); return path.call(print, "typeAnnotation");
} }
/* istanbul ignore next */
return ""; return "";
case "TSTupleType": case "TSTupleType":
case "TupleTypeAnnotation": { case "TupleTypeAnnotation": {
@ -2374,20 +2328,18 @@ function genericPrintNoParens(path, options, print, args) {
case "TSArrayType": case "TSArrayType":
return concat([path.call(print, "elementType"), "[]"]); return concat([path.call(print, "elementType"), "[]"]);
case "TSPropertySignature": { case "TSPropertySignature": {
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.export) { if (n.export) {
parts.push("export "); parts.push("export ");
} }
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.static) { if (n.static) {
parts.push("static "); parts.push("static ");
} }
if (n.readonly) { if (n.readonly) {
parts.push("readonly "); parts.push("readonly ");
} }
if (n.computed) { if (n.computed) {
parts.push("["); parts.push("[");
} }
@ -2397,11 +2349,9 @@ function genericPrintNoParens(path, options, print, args) {
if (n.computed) { if (n.computed) {
parts.push("]"); parts.push("]");
} }
if (n.optional) { if (n.optional) {
parts.push("?"); parts.push("?");
} }
if (n.typeAnnotation) { if (n.typeAnnotation) {
parts.push(": "); parts.push(": ");
parts.push(path.call(print, "typeAnnotation")); parts.push(path.call(print, "typeAnnotation"));
@ -2443,24 +2393,14 @@ function genericPrintNoParens(path, options, print, args) {
} }
case "TSIndexSignature": { case "TSIndexSignature": {
const parent = path.getParentNode(); const parent = path.getParentNode();
let printedParams = [];
if (n.params) {
printedParams = path.map(print, "params");
}
if (n.parameters) {
printedParams = path.map(print, "parameters");
}
return concat([ return concat([
n.accessibility ? concat([n.accessibility, " "]) : "",
n.export ? "export " : "", n.export ? "export " : "",
n.accessibility ? concat([n.accessibility, " "]) : "",
n.static ? "static " : "", n.static ? "static " : "",
n.readonly ? "readonly " : "", n.readonly ? "readonly " : "",
"[", "[",
path.call(print, "index"), 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"), path.call(print, "typeAnnotation"),
parent.type === "ClassBody" ? semi : "" parent.type === "ClassBody" ? semi : ""
@ -2568,18 +2508,10 @@ function genericPrintNoParens(path, options, print, args) {
} }
return group(concat(parts)); return group(concat(parts));
case "TSNamespaceExportDeclaration": case "TSNamespaceExportDeclaration":
if (n.declaration) { parts.push("export as namespace ", path.call(print, "name"));
parts.push(
"export ",
n.default ? "default " : "",
path.call(print, "declaration")
);
} else {
parts.push("export as namespace ", path.call(print, "name"));
if (options.semi) { if (options.semi) {
parts.push(";"); parts.push(";");
}
} }
return group(concat(parts)); return group(concat(parts));
@ -2724,6 +2656,7 @@ function printStatementSequence(path, options, print) {
// Just in case the AST has been modified to contain falsy // Just in case the AST has been modified to contain falsy
// "statements," it's safer simply to skip them. // "statements," it's safer simply to skip them.
/* istanbul ignore if */
if (!stmt) { if (!stmt) {
return; return;
} }
@ -2979,14 +2912,7 @@ function printArgumentsList(path, options, print) {
function printFunctionTypeParameters(path, options, print) { function printFunctionTypeParameters(path, options, print) {
const fun = path.getValue(); const fun = path.getValue();
const paramsFieldIsArray = Array.isArray(fun["typeParameters"]);
if (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 path.call(print, "typeParameters");
} }
return ""; return "";
@ -3005,17 +2931,6 @@ function printFunctionParams(path, print, options, expandArg, printTypeParams) {
printed = path.map(print, paramsField); 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) { if (fun.rest) {
printed.push(concat(["...", path.call(print, "rest")])); printed.push(concat(["...", path.call(print, "rest")]));
} }
@ -3339,11 +3254,10 @@ function getFlowVariance(path) {
switch (variance) { switch (variance) {
case "plus": case "plus":
return "+"; return "+";
case "minus": case "minus":
return "-"; return "-";
default: default:
/* istanbul ignore next */
return variance; return variance;
} }
} }
@ -3403,9 +3317,6 @@ function printClass(path, options, print) {
const n = path.getValue(); const n = path.getValue();
const parts = []; const parts = [];
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.type === "TSAbstractClassDeclaration") { if (n.type === "TSAbstractClassDeclaration") {
parts.push("abstract "); parts.push("abstract ");
} }
@ -4558,9 +4469,6 @@ function exprNeedsASIProtection(node) {
} }
function stmtNeedsASIProtection(path) { function stmtNeedsASIProtection(path) {
if (!path) {
return false;
}
const node = path.getNode(); const node = path.getNode();
if (node.type !== "ExpressionStatement") { if (node.type !== "ExpressionStatement") {
@ -4578,9 +4486,6 @@ function classPropMayCauseASIProblems(path) {
} }
const name = node.key && node.key.name; const name = node.key && node.key.name;
if (!name) {
return false;
}
// this isn't actually possible yet with most parsers available today // this isn't actually possible yet with most parsers available today
// so isn't properly tested yet. // so isn't properly tested yet.
@ -4628,6 +4533,7 @@ function classChildNeedsASIProtection(node) {
} }
default: default:
/* istanbul ignore next */
return false; return false;
} }
} }

View File

@ -9,7 +9,11 @@ module Y3 {
} }
// Apparently this parses :P // 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 { module Y4 {
@ -46,7 +50,11 @@ namespace Y3 {
} }
// Apparently this parses :P // 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 { namespace Y4 {

View File

@ -6,7 +6,11 @@ module Y3 {
} }
// Apparently this parses :P // 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 { module Y4 {

View File

@ -27,3 +27,14 @@ declare global {
} }
`; `;
exports[`namespace_function.ts 1`] = `
namespace X {
declare function f();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
namespace X {
declare function f();
}
`;

View File

@ -0,0 +1,3 @@
namespace X {
declare function f();
}