Skip to content

Fix assert in getjsdochost #23575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,7 @@ namespace ts {
}

export interface JSDocTag extends Node {
parent: JSDoc;
parent: JSDoc | JSDocTypeLiteral;
atToken: AtToken;
tagName: Identifier;
comment: string | undefined;
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,9 @@ namespace ts {
}

export function getJSDocHost(node: JSDocTag): HasJSDoc {
while (node.parent.kind === SyntaxKind.JSDocTypeLiteral) {
node = node.parent.parent.parent as JSDocParameterTag;
}
Debug.assert(node.parent!.kind === SyntaxKind.JSDocComment);
return node.parent!.parent!;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ declare namespace ts {
comment: string | undefined;
}
interface JSDocTag extends Node {
parent: JSDoc;
parent: JSDoc | JSDocTypeLiteral;
atToken: AtToken;
tagName: Identifier;
comment: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ declare namespace ts {
comment: string | undefined;
}
interface JSDocTag extends Node {
parent: JSDoc;
parent: JSDoc | JSDocTypeLiteral;
atToken: AtToken;
tagName: Identifier;
comment: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js(21,1): error TS2322: Type 'false' is not assignable to type 'number'.


==== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js (1 errors) ====
/**
* @template {T}
* @param {T} t
*/
function Zet(t) {
/** @type {T} */
this.u
this.t = t
}
/**
* @param {T} v
* @param {object} o
* @param {T} o.nested
*/
Zet.prototype.add = function(v, o) {
this.u = v || o.nested
return this.u
}
var z = new Zet(1)
z.t = 2
z.u = false
~~~
!!! error TS2322: Type 'false' is not assignable to type 'number'.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
=== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js ===
/**
* @template {T}
* @param {T} t
*/
function Zet(t) {
>Zet : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0))
>t : Symbol(t, Decl(templateTagWithNestedTypeLiteral.js, 4, 13))

/** @type {T} */
this.u
this.t = t
>t : Symbol(Zet.t, Decl(templateTagWithNestedTypeLiteral.js, 6, 10))
>t : Symbol(t, Decl(templateTagWithNestedTypeLiteral.js, 4, 13))
}
/**
* @param {T} v
* @param {object} o
* @param {T} o.nested
*/
Zet.prototype.add = function(v, o) {
>Zet.prototype : Symbol(Zet.add, Decl(templateTagWithNestedTypeLiteral.js, 8, 1))
>Zet : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0))
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --))
>add : Symbol(Zet.add, Decl(templateTagWithNestedTypeLiteral.js, 8, 1))
>v : Symbol(v, Decl(templateTagWithNestedTypeLiteral.js, 14, 29))
>o : Symbol(o, Decl(templateTagWithNestedTypeLiteral.js, 14, 31))

this.u = v || o.nested
>this.u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))
>this : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0))
>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))
>v : Symbol(v, Decl(templateTagWithNestedTypeLiteral.js, 14, 29))
>o.nested : Symbol(nested, Decl(templateTagWithNestedTypeLiteral.js, 12, 3))
>o : Symbol(o, Decl(templateTagWithNestedTypeLiteral.js, 14, 31))
>nested : Symbol(nested, Decl(templateTagWithNestedTypeLiteral.js, 12, 3))

return this.u
>this.u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))
>this : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0))
>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))
}
var z = new Zet(1)
>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3))
>Zet : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0))

z.t = 2
>z.t : Symbol(Zet.t, Decl(templateTagWithNestedTypeLiteral.js, 6, 10))
>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3))
>t : Symbol(Zet.t, Decl(templateTagWithNestedTypeLiteral.js, 6, 10))

z.u = false
>z.u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))
>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3))
>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36))

74 changes: 74 additions & 0 deletions tests/baselines/reference/jsdocTemplateConstructorFunction2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
=== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js ===
/**
* @template {T}
* @param {T} t
*/
function Zet(t) {
>Zet : typeof Zet
>t : T

/** @type {T} */
this.u
>this.u : any
>this : any
>u : any

this.t = t
>this.t = t : T
>this.t : any
>this : any
>t : any
>t : T
}
/**
* @param {T} v
* @param {object} o
* @param {T} o.nested
*/
Zet.prototype.add = function(v, o) {
>Zet.prototype.add = function(v, o) { this.u = v || o.nested return this.u} : (v: T, o: { nested: T; }) => T
>Zet.prototype.add : any
>Zet.prototype : any
>Zet : typeof Zet
>prototype : any
>add : any
>function(v, o) { this.u = v || o.nested return this.u} : (v: T, o: { nested: T; }) => T
>v : T
>o : { nested: T; }

this.u = v || o.nested
>this.u = v || o.nested : T
>this.u : T
>this : Zet
>u : T
>v || o.nested : T
>v : T
>o.nested : T
>o : { nested: T; }
>nested : T

return this.u
>this.u : T
>this : Zet
>u : T
}
var z = new Zet(1)
>z : typeof Zet
>new Zet(1) : typeof Zet
>Zet : typeof Zet
>1 : 1

z.t = 2
>z.t = 2 : 2
>z.t : number
>z : typeof Zet
>t : number
>2 : 2

z.u = false
>z.u = false : false
>z.u : number
>z : typeof Zet
>u : number
>false : false

26 changes: 26 additions & 0 deletions tests/cases/conformance/jsdoc/jsdocTemplateConstructorFunction2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: templateTagWithNestedTypeLiteral.js

/**
* @template {T}
* @param {T} t
*/
function Zet(t) {
/** @type {T} */
this.u
this.t = t
}
/**
* @param {T} v
* @param {object} o
* @param {T} o.nested
*/
Zet.prototype.add = function(v, o) {
this.u = v || o.nested
return this.u
}
var z = new Zet(1)
z.t = 2
z.u = false