fix(typescript): handle undefined variable declarations (#1645)
parent
8f00393a56
commit
5c6fd80d50
|
@ -1129,8 +1129,7 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
parts = [
|
parts = [
|
||||||
isNodeStartingWithDeclare(n, options) ? "declare " : "",
|
isNodeStartingWithDeclare(n, options) ? "declare " : "",
|
||||||
n.kind,
|
n.kind,
|
||||||
" ",
|
printed.length ? concat([" ", printed[0]]) : "",
|
||||||
printed[0],
|
|
||||||
indent(concat(printed.slice(1).map(p => concat([",", line, p]))))
|
indent(concat(printed.slice(1).map(p => concat([",", line, p]))))
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -2207,7 +2206,11 @@ function genericPrintNoParens(path, options, print, args) {
|
||||||
path.call(print, "typeAnnotation")
|
path.call(print, "typeAnnotation")
|
||||||
]);
|
]);
|
||||||
case "TSFirstTypeNode":
|
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":
|
case "TSNonNullExpression":
|
||||||
return concat([path.call(print, "expression"), "!"]);
|
return concat([path.call(print, "expression"), "!"]);
|
||||||
case "TSThisType":
|
case "TSThisType":
|
||||||
|
|
|
@ -194,6 +194,12 @@ interface i2 {
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`downlevelLetConst1.ts 1`] = `
|
||||||
|
const~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
const;
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`errorOnInitializerInInterfaceProperty.ts 1`] = `
|
exports[`errorOnInitializerInInterfaceProperty.ts 1`] = `
|
||||||
interface Foo {
|
interface Foo {
|
||||||
bar: number = 5;
|
bar: number = 5;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
const
|
|
@ -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 {}
|
||||||
|
|
||||||
|
`;
|
|
@ -0,0 +1,11 @@
|
||||||
|
// @declaration: true
|
||||||
|
// @module: commonjs
|
||||||
|
|
||||||
|
export class C {
|
||||||
|
m(): this is D {
|
||||||
|
return this instanceof D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D extends C {
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname, { parser: "typescript" });
|
|
@ -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) {
|
||||||
|
}
|
||||||
|
|
||||||
|
`;
|
|
@ -0,0 +1 @@
|
||||||
|
run_spec(__dirname, { parser: "typescript" });
|
|
@ -0,0 +1,3 @@
|
||||||
|
//@target: ES5
|
||||||
|
for (var of X) {
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
//@target: ES5
|
||||||
|
for (var of of) { }
|
|
@ -0,0 +1,2 @@
|
||||||
|
for (var in X) {
|
||||||
|
}
|
Loading…
Reference in New Issue