From b8e3c41ee1fc228717c9ed672b5c838cb74dc3cb Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Thu, 25 Apr 2019 16:53:06 -0500 Subject: [PATCH] fix jsdoc iterator on expression of export assignment (#30558) --- src/compiler/utilities.ts | 1 + .../reference/exportDefaultWithJSDoc1.symbols | 15 +++++++++++++++ .../reference/exportDefaultWithJSDoc1.types | 19 +++++++++++++++++++ .../reference/exportDefaultWithJSDoc2.symbols | 15 +++++++++++++++ .../reference/exportDefaultWithJSDoc2.types | 19 +++++++++++++++++++ .../cases/compiler/exportDefaultWithJSDoc1.ts | 16 ++++++++++++++++ .../cases/compiler/exportDefaultWithJSDoc2.ts | 16 ++++++++++++++++ 7 files changed, 101 insertions(+) create mode 100644 tests/baselines/reference/exportDefaultWithJSDoc1.symbols create mode 100644 tests/baselines/reference/exportDefaultWithJSDoc1.types create mode 100644 tests/baselines/reference/exportDefaultWithJSDoc2.symbols create mode 100644 tests/baselines/reference/exportDefaultWithJSDoc2.types create mode 100644 tests/cases/compiler/exportDefaultWithJSDoc1.ts create mode 100644 tests/cases/compiler/exportDefaultWithJSDoc2.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 76fb001de0dd9..e7cf9a6a62a13 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2221,6 +2221,7 @@ namespace ts { function getNextJSDocCommentLocation(node: Node) { const parent = node.parent; if (parent.kind === SyntaxKind.PropertyAssignment || + parent.kind === SyntaxKind.ExportAssignment || parent.kind === SyntaxKind.PropertyDeclaration || parent.kind === SyntaxKind.ExpressionStatement && node.kind === SyntaxKind.PropertyAccessExpression || getNestedModuleDeclaration(parent) || diff --git a/tests/baselines/reference/exportDefaultWithJSDoc1.symbols b/tests/baselines/reference/exportDefaultWithJSDoc1.symbols new file mode 100644 index 0000000000000..bad38b845bb09 --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc1.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/a.js === +/** +No type information for this code. * A number, or a string containing a number. +No type information for this code. * @typedef {(number|string)} NumberLike +No type information for this code. */ +No type information for this code. +No type information for this code./** @type {NumberLike[]} */export default ([ ]); +No type information for this code. +No type information for this code.=== tests/cases/compiler/b.ts === +import A from './a' +>A : Symbol(A, Decl(b.ts, 0, 6)) + +A[0] +>A : Symbol(A, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc1.types b/tests/baselines/reference/exportDefaultWithJSDoc1.types new file mode 100644 index 0000000000000..5e82e37b33b2a --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc1.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/a.js === +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +/** @type {NumberLike[]} */export default ([ ]); +>([ ]) : (string | number)[] +>[ ] : undefined[] + +=== tests/cases/compiler/b.ts === +import A from './a' +>A : (string | number)[] + +A[0] +>A[0] : string | number +>A : (string | number)[] +>0 : 0 + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc2.symbols b/tests/baselines/reference/exportDefaultWithJSDoc2.symbols new file mode 100644 index 0000000000000..ff3e74a3fbe94 --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc2.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/a.js === +/** +No type information for this code. * A number, or a string containing a number. +No type information for this code. * @typedef {(number|string)} NumberLike +No type information for this code. */ +No type information for this code. +No type information for this code.export default /** @type {NumberLike[]} */([ ]); +No type information for this code. +No type information for this code.=== tests/cases/compiler/b.ts === +import A from './a' +>A : Symbol(A, Decl(b.ts, 0, 6)) + +A[0] +>A : Symbol(A, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/exportDefaultWithJSDoc2.types b/tests/baselines/reference/exportDefaultWithJSDoc2.types new file mode 100644 index 0000000000000..0fd9f022a7321 --- /dev/null +++ b/tests/baselines/reference/exportDefaultWithJSDoc2.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/a.js === +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +export default /** @type {NumberLike[]} */([ ]); +>([ ]) : (string | number)[] +>[ ] : undefined[] + +=== tests/cases/compiler/b.ts === +import A from './a' +>A : (string | number)[] + +A[0] +>A[0] : string | number +>A : (string | number)[] +>0 : 0 + diff --git a/tests/cases/compiler/exportDefaultWithJSDoc1.ts b/tests/cases/compiler/exportDefaultWithJSDoc1.ts new file mode 100644 index 0000000000000..2140ccc8aa164 --- /dev/null +++ b/tests/cases/compiler/exportDefaultWithJSDoc1.ts @@ -0,0 +1,16 @@ + +// @allowJs: true +// @checkJs: true +// @noEmit: true + +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +// @Filename: a.js +/** @type {NumberLike[]} */export default ([ ]); + +// @Filename: b.ts +import A from './a' +A[0] \ No newline at end of file diff --git a/tests/cases/compiler/exportDefaultWithJSDoc2.ts b/tests/cases/compiler/exportDefaultWithJSDoc2.ts new file mode 100644 index 0000000000000..1b14248bfa668 --- /dev/null +++ b/tests/cases/compiler/exportDefaultWithJSDoc2.ts @@ -0,0 +1,16 @@ + +// @allowJs: true +// @checkJs: true +// @noEmit: true + +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ + +// @Filename: a.js +export default /** @type {NumberLike[]} */([ ]); + +// @Filename: b.ts +import A from './a' +A[0] \ No newline at end of file