fix(typescript): handle undefined variable declarations (#1645)

master
Lucas Azzola 2017-05-22 01:03:38 +10:00 committed by Christopher Chedeau
parent 8f00393a56
commit 5c6fd80d50
11 changed files with 97 additions and 10 deletions

View File

@ -770,7 +770,7 @@ function genericPrintNoParens(path, options, print, args) {
n.typeParameters ? path.call(print, "typeParameters") : "",
" "
);
if (n.heritage.length) {
parts.push(
"extends ",
@ -778,9 +778,9 @@ function genericPrintNoParens(path, options, print, args) {
" "
);
}
parts.push(path.call(print, "body"));
return concat(parts);
case "ObjectExpression":
case "ObjectPattern":
@ -805,7 +805,7 @@ function genericPrintNoParens(path, options, print, args) {
const parent = path.getParentNode(0);
const parentIsUnionTypeAnnotation = parent.type === "UnionTypeAnnotation";
let propertiesField;
if (n.type === 'TSTypeLiteral') {
propertiesField = "members";
} else if (n.type === "TSInterfaceBody") {
@ -1129,8 +1129,7 @@ function genericPrintNoParens(path, options, print, args) {
parts = [
isNodeStartingWithDeclare(n, options) ? "declare " : "",
n.kind,
" ",
printed[0],
printed.length ? concat([" ", printed[0]]) : "",
indent(concat(printed.slice(1).map(p => concat([",", line, p]))))
];
@ -1629,11 +1628,11 @@ function genericPrintNoParens(path, options, print, args) {
return concat(parts);
case "TSInterfaceHeritage":
parts.push(path.call(print, "id"));
if (n.typeParameters) {
parts.push(path.call(print, "typeParameters"));
}
return concat(parts);
case "TSHeritageClause":
return join(", ", path.map(print, "types"));
@ -2207,7 +2206,11 @@ function genericPrintNoParens(path, options, print, args) {
path.call(print, "typeAnnotation")
]);
case "TSFirstTypeNode":
return concat([n.parameterName.name, " is ", path.call(print, "typeAnnotation")])
return concat([
path.call(print, "parameterName"),
" is ",
path.call(print, "typeAnnotation")
]);
case "TSNonNullExpression":
return concat([path.call(print, "expression"), "!"]);
case "TSThisType":
@ -2748,7 +2751,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

View File

@ -194,6 +194,12 @@ interface i2 {
`;
exports[`downlevelLetConst1.ts 1`] = `
const~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const;
`;
exports[`errorOnInitializerInInterfaceProperty.ts 1`] = `
interface Foo {
bar: number = 5;

View File

@ -0,0 +1 @@
const

View File

@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`declarationEmitThisPredicatesWithPrivateName01.ts 1`] = `
// @declaration: true
// @module: commonjs
export class C {
m(): this is D {
return this instanceof D;
}
}
class D extends C {
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// @declaration: true
// @module: commonjs
export class C {
m(): this is D {
return this instanceof D;
}
}
class D extends C {}
`;

View File

@ -0,0 +1,11 @@
// @declaration: true
// @module: commonjs
export class C {
m(): this is D {
return this instanceof D;
}
}
class D extends C {
}

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });

View File

@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`parserES5ForOfStatement2.ts 1`] = `
//@target: ES5
for (var of X) {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@target: ES5
for (var of X) {
}
`;
exports[`parserES5ForOfStatement21.ts 1`] = `
//@target: ES5
for (var of of) { }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//@target: ES5
for (var of of) {
}
`;
exports[`parserForInStatement2.ts 1`] = `
for (var in X) {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (var in X) {
}
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });

View File

@ -0,0 +1,3 @@
//@target: ES5
for (var of X) {
}

View File

@ -0,0 +1,2 @@
//@target: ES5
for (var of of) { }

View File

@ -0,0 +1,2 @@
for (var in X) {
}