From 71d1a3f051c0990c07a510dc811dfc4be4b3b6d7 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Jan 2017 11:38:50 -0800 Subject: [PATCH] property handle misspelled namepath in @typedef tag (#13702) --- src/compiler/parser.ts | 9 ++++++-- .../misspelledJsDocTypedefTags.symbols | 8 +++++++ .../misspelledJsDocTypedefTags.types | 22 +++++++++++++++++++ .../compiler/misspelledJsDocTypedefTags.ts | 9 ++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/misspelledJsDocTypedefTags.symbols create mode 100644 tests/baselines/reference/misspelledJsDocTypedefTags.types create mode 100644 tests/cases/compiler/misspelledJsDocTypedefTags.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c795cab14a3..c5439aa051b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6693,10 +6693,15 @@ namespace ts { typedefTag.fullName = parseJSDocTypeNameWithNamespace(/*flags*/ 0); if (typedefTag.fullName) { let rightNode = typedefTag.fullName; - while (rightNode.kind !== SyntaxKind.Identifier) { + while (true) { + if (rightNode.kind === SyntaxKind.Identifier || !rightNode.body) { + // if node is identifier - use it as name + // otherwise use name of the rightmost part that we were able to parse + typedefTag.name = rightNode.kind === SyntaxKind.Identifier ? rightNode : rightNode.name; + break; + } rightNode = rightNode.body; } - typedefTag.name = rightNode; } typedefTag.typeExpression = typeExpression; skipWhitespace(); diff --git a/tests/baselines/reference/misspelledJsDocTypedefTags.symbols b/tests/baselines/reference/misspelledJsDocTypedefTags.symbols new file mode 100644 index 00000000000..bf3f6e7fab0 --- /dev/null +++ b/tests/baselines/reference/misspelledJsDocTypedefTags.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/a.js === + +No type information for this code./** @typedef {{ endTime: number, screenshots: number}} A.*/ +No type information for this code.Animation.AnimationModel.ScreenshotCapture.Request; +No type information for this code. +No type information for this code./** @typedef {{ endTime: number, screenshots: !B.}} */ +No type information for this code.Animation.AnimationModel.ScreenshotCapture.Request; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/misspelledJsDocTypedefTags.types b/tests/baselines/reference/misspelledJsDocTypedefTags.types new file mode 100644 index 00000000000..70cc011ea69 --- /dev/null +++ b/tests/baselines/reference/misspelledJsDocTypedefTags.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/a.js === + +/** @typedef {{ endTime: number, screenshots: number}} A.*/ +Animation.AnimationModel.ScreenshotCapture.Request; +>Animation.AnimationModel.ScreenshotCapture.Request : any +>Animation.AnimationModel.ScreenshotCapture : any +>Animation.AnimationModel : any +>Animation : any +>AnimationModel : any +>ScreenshotCapture : any +>Request : any + +/** @typedef {{ endTime: number, screenshots: !B.}} */ +Animation.AnimationModel.ScreenshotCapture.Request; +>Animation.AnimationModel.ScreenshotCapture.Request : any +>Animation.AnimationModel.ScreenshotCapture : any +>Animation.AnimationModel : any +>Animation : any +>AnimationModel : any +>ScreenshotCapture : any +>Request : any + diff --git a/tests/cases/compiler/misspelledJsDocTypedefTags.ts b/tests/cases/compiler/misspelledJsDocTypedefTags.ts new file mode 100644 index 00000000000..3f3221020bd --- /dev/null +++ b/tests/cases/compiler/misspelledJsDocTypedefTags.ts @@ -0,0 +1,9 @@ +// @allowJs: true +// @noEmit: true + +// @filename: a.js +/** @typedef {{ endTime: number, screenshots: number}} A.*/ +Animation.AnimationModel.ScreenshotCapture.Request; + +/** @typedef {{ endTime: number, screenshots: !B.}} */ +Animation.AnimationModel.ScreenshotCapture.Request; \ No newline at end of file