Update typescript-eslint (#1787)

It improves a few things.
master
Christopher Chedeau 2017-05-28 13:18:29 -07:00 committed by GitHub
parent f0683b8e1a
commit 882b712c5f
8 changed files with 102 additions and 22 deletions

View File

@ -219,7 +219,7 @@ function handleError(filename, e) {
// If validation fails for one file, it will fail for all of them.
process.exit(1);
} else {
console.error(filename + ":", e);
console.error(filename + ":", e.stack);
}
// Don't exit the process if one file failed

View File

@ -41,7 +41,7 @@
"rollup-plugin-node-globals": "1.1.0",
"rollup-plugin-node-resolve": "2.0.0",
"typescript": "2.3.2",
"typescript-eslint-parser": "git://github.com/eslint/typescript-eslint-parser.git#992f1fa940c5679c8a509059665146f717da58cb"
"typescript-eslint-parser": "git://github.com/eslint/typescript-eslint-parser.git#2d09fb183e36a3b4089509c67cd256cd5f8871b0"
},
"scripts": {
"test": "jest",

View File

@ -435,6 +435,8 @@ FastPath.prototype.needsParens = function() {
return false;
} else if (parent.type === "ExpressionStatement") {
return node.left.type === "ObjectPattern";
} else if (parent.type === "TSPropertySignature" && parent.key === node) {
return false;
} else if (parent.type === "AssignmentExpression") {
return false;
} else if (

View File

@ -2220,21 +2220,30 @@ function genericPrintNoParens(path, options, print, args) {
case "TSArrayType":
return concat([path.call(print, "elementType"), "[]"]);
case "TSPropertySignature": {
const computed = n.name.type !== "Identifier" && !isLiteral(n.name);
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.export) {
parts.push("export ");
}
if (n.static) {
parts.push("static ");
}
if (n.readonly) {
parts.push("readonly ");
}
parts.push(printTypeScriptModifiers(path, options, print));
if (computed) {
if (n.computed) {
parts.push("[");
}
parts.push(path.call(print, "name"));
parts.push(path.call(print, "key"));
if (computed) {
if (n.computed) {
parts.push("]");
}
if (n.questionToken && !n.name.optional) {
if (n.optional) {
parts.push("?");
}
@ -2254,6 +2263,12 @@ function genericPrintNoParens(path, options, print, args) {
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
if (n.export) {
parts.push("export ");
}
if (n.static) {
parts.push("static ");
}
if (n.isReadonly) {
parts.push("readonly ");
}
@ -2270,16 +2285,29 @@ function genericPrintNoParens(path, options, print, args) {
return concat(["typeof ", path.call(print, "exprName")]);
case "TSParenthesizedType":
return concat(["(", path.call(print, "typeAnnotation"), ")"]);
case "TSIndexSignature":
case "TSIndexSignature": {
let printedParams = [];
if (n.params) {
printedParams = path.map(print, "params");
}
if (n.parameters) {
printedParams = path.map(print, "parameters");
}
return concat([
printTypeScriptModifiers(path, options, print),
n.accessibility ? concat([n.accessibility, " "]) : "",
n.export ? "export " : "",
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(", ", path.map(print, "parameters")),
join(", ", printedParams),
"]: ",
path.call(print, "typeAnnotation")
]);
}
case "TSTypePredicate":
return concat([
path.call(print, "parameterName"),
@ -2311,7 +2339,10 @@ function genericPrintNoParens(path, options, print, args) {
parts.push(printTypeParameters(path, options, print, "typeParameters"));
}
parts.push("(", join(", ", path.map(print, "parameters")), ")");
const params = n.params
? path.map(print, "params")
: path.map(print, "parameters");
parts.push("(", join(", ", params), ")");
if (n.typeAnnotation) {
parts.push(isType ? " => " : ": ", path.call(print, "typeAnnotation"));
}
@ -2353,8 +2384,8 @@ function genericPrintNoParens(path, options, print, args) {
return concat(parts);
case "TSMethodSignature":
parts.push(
path.call(print, "name"),
n.questionToken && !n.name.optional ? "?" : "",
path.call(print, "key"),
n.optional ? "?" : "",
printFunctionTypeParameters(path, options, print),
printFunctionParams(path, print, options)
);
@ -3059,12 +3090,12 @@ function printFunctionTypeParameters(path, options, print) {
function printFunctionParams(path, print, options, expandArg) {
const fun = path.getValue();
const paramsField = fun.type === "TSFunctionType" ||
fun.type === "TSMethodSignature"
? "parameters"
: "params";
const paramsField = fun.parameters ? "parameters" : "params";
const printed = path.map(print, paramsField);
let printed = [];
if (fun[paramsField]) {
printed = path.map(print, paramsField);
}
if (fun.defaults) {
path.each(defExprPath => {

View File

@ -1,5 +1,24 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`constructor.ts 1`] = `
class foo {
constructor(static a: number) {}
}
class foo {
constructor(export a: number) {}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class foo {
constructor(static a: number) {}
}
class foo {
constructor(export a: number) {}
}
`;
exports[`dunder.ts 1`] = `
// eslint/typescript-eslint-parser#296
class F<__T> {}
@ -34,3 +53,14 @@ class X {
}
`;
exports[`optional.ts 1`] = `
class X {
private foo? = undefined;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class X {
private foo? = undefined;
}
`;

View File

@ -0,0 +1,7 @@
class foo {
constructor(static a: number) {}
}
class foo {
constructor(export a: number) {}
}

View File

@ -0,0 +1,3 @@
class X {
private foo? = undefined;
}

View File

@ -2808,9 +2808,16 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
"typescript-eslint-parser@git://github.com/eslint/typescript-eslint-parser.git#992f1fa940c5679c8a509059665146f717da58cb":
"typescript-eslint-parser@git://github.com/eslint/typescript-eslint-parser.git#2d09fb183e36a3b4089509c67cd256cd5f8871b0":
version "3.0.0"
resolved "git://github.com/eslint/typescript-eslint-parser.git#992f1fa940c5679c8a509059665146f717da58cb"
resolved "git://github.com/eslint/typescript-eslint-parser.git#2d09fb183e36a3b4089509c67cd256cd5f8871b0"
dependencies:
lodash.unescape "4.0.1"
semver "5.3.0"
"typescript-eslint-parser@git://github.com/eslint/typescript-eslint-parser.git#a3610632a8bd1ee9ad4179ed01a01b7739143bf5":
version "3.0.0"
resolved "git://github.com/eslint/typescript-eslint-parser.git#a3610632a8bd1ee9ad4179ed01a01b7739143bf5"
dependencies:
lodash.unescape "4.0.1"
semver "5.3.0"