From 17f10c032ed41a79f2711e63c8df6d3eaef9450e Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 25 Sep 2017 09:58:46 -0700 Subject: [PATCH] Fix crash when @augments tag has no type (#18739) --- src/compiler/checker.ts | 2 +- .../jsdocAugmentsMissingType.errors.txt | 14 +++++++++++ .../jsdocAugmentsMissingType.symbols | 22 +++++++++++++++++ .../reference/jsdocAugmentsMissingType.types | 24 +++++++++++++++++++ .../compiler/jsdocAugmentsMissingType.ts | 12 ++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsdocAugmentsMissingType.errors.txt create mode 100644 tests/baselines/reference/jsdocAugmentsMissingType.symbols create mode 100644 tests/baselines/reference/jsdocAugmentsMissingType.types create mode 100644 tests/cases/compiler/jsdocAugmentsMissingType.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 604357511c..bc4180f831 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4990,7 +4990,7 @@ namespace ts { const valueDecl = type.symbol.valueDeclaration; if (valueDecl && isInJavaScriptFile(valueDecl)) { const augTag = getJSDocAugmentsTag(type.symbol.valueDeclaration); - if (augTag) { + if (augTag && augTag.typeExpression && augTag.typeExpression.type) { baseType = getTypeFromTypeNode(augTag.typeExpression.type); } } diff --git a/tests/baselines/reference/jsdocAugmentsMissingType.errors.txt b/tests/baselines/reference/jsdocAugmentsMissingType.errors.txt new file mode 100644 index 0000000000..b5ac97db31 --- /dev/null +++ b/tests/baselines/reference/jsdocAugmentsMissingType.errors.txt @@ -0,0 +1,14 @@ +/a.js(2,14): error TS1005: '{' expected. + + +==== /a.js (1 errors) ==== + class A { constructor() { this.x = 0; } } + /** @augments */ + ~ +!!! error TS1005: '{' expected. + class B extends A { + m() { + this.x + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocAugmentsMissingType.symbols b/tests/baselines/reference/jsdocAugmentsMissingType.symbols new file mode 100644 index 0000000000..0ef9debf11 --- /dev/null +++ b/tests/baselines/reference/jsdocAugmentsMissingType.symbols @@ -0,0 +1,22 @@ +=== /a.js === +class A { constructor() { this.x = 0; } } +>A : Symbol(A, Decl(a.js, 0, 0)) +>this.x : Symbol(A.x, Decl(a.js, 0, 25)) +>this : Symbol(A, Decl(a.js, 0, 0)) +>x : Symbol(A.x, Decl(a.js, 0, 25)) + +/** @augments */ +class B extends A { +>B : Symbol(B, Decl(a.js, 0, 41)) +>A : Symbol(A, Decl(a.js, 0, 0)) + + m() { +>m : Symbol(B.m, Decl(a.js, 2, 19)) + + this.x +>this.x : Symbol(A.x, Decl(a.js, 0, 25)) +>this : Symbol(B, Decl(a.js, 0, 41)) +>x : Symbol(A.x, Decl(a.js, 0, 25)) + } +} + diff --git a/tests/baselines/reference/jsdocAugmentsMissingType.types b/tests/baselines/reference/jsdocAugmentsMissingType.types new file mode 100644 index 0000000000..6d687d81d1 --- /dev/null +++ b/tests/baselines/reference/jsdocAugmentsMissingType.types @@ -0,0 +1,24 @@ +=== /a.js === +class A { constructor() { this.x = 0; } } +>A : A +>this.x = 0 : 0 +>this.x : number +>this : this +>x : number +>0 : 0 + +/** @augments */ +class B extends A { +>B : B +>A : A + + m() { +>m : () => void + + this.x +>this.x : number +>this : this +>x : number + } +} + diff --git a/tests/cases/compiler/jsdocAugmentsMissingType.ts b/tests/cases/compiler/jsdocAugmentsMissingType.ts new file mode 100644 index 0000000000..f8669eb92b --- /dev/null +++ b/tests/cases/compiler/jsdocAugmentsMissingType.ts @@ -0,0 +1,12 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @Filename: /a.js +class A { constructor() { this.x = 0; } } +/** @augments */ +class B extends A { + m() { + this.x + } +}