Handle definite variable declarations (#4025)

* Handle definite variable declarations

* printDefinite -> isDefinite
master
Lucas Azzola 2018-02-22 13:03:35 +11:00 committed by GitHub
parent e1491d0f95
commit b7f0794ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -3204,6 +3204,12 @@ function printTypeAnnotation(path, options, print) {
}
const parentNode = path.getParentNode();
const isDefinite =
node.definite ||
(parentNode &&
parentNode.type === "VariableDeclarator" &&
parentNode.definite);
const isFunctionDeclarationIdentifier =
parentNode.type === "DeclareFunction" && parentNode.id === node;
@ -3214,7 +3220,7 @@ function printTypeAnnotation(path, options, print) {
}
return concat([
isFunctionDeclarationIdentifier ? "" : node.definite ? "!: " : ": ",
isFunctionDeclarationIdentifier ? "" : isDefinite ? "!: " : ": ",
path.call(print, "typeAnnotation")
]);
}

View File

@ -4,9 +4,17 @@ exports[`definite.ts 1`] = `
class MyComponent {
ngModel!: ng.INgModelController;
}
const x!: string
var y!: MyComponent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class MyComponent {
ngModel!: ng.INgModelController;
}
const x!: string;
var y!: MyComponent;
`;

View File

@ -1,3 +1,7 @@
class MyComponent {
ngModel!: ng.INgModelController;
}
const x!: string
var y!: MyComponent