From 11ecd4f7f6f401d177ec8cb5076955512ccc3fc2 Mon Sep 17 00:00:00 2001 From: wenqi73 <1264578441@qq.com> Date: Tue, 5 May 2020 21:33:16 +0800 Subject: [PATCH] report error for duplicate @type declaration --- src/compiler/diagnosticMessages.json | 8 ++++++++ src/compiler/parser.ts | 8 ++++++++ .../typedefDuplicateTypeDeclaration.errors.txt | 13 +++++++++++++ .../typedefDuplicateTypeDeclaration.symbols | 7 +++++++ .../reference/typedefDuplicateTypeDeclaration.types | 7 +++++++ .../jsdoc/typedefDuplicateTypeDeclaration.ts | 9 +++++++++ 6 files changed, 52 insertions(+) create mode 100644 tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt create mode 100644 tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols create mode 100644 tests/baselines/reference/typedefDuplicateTypeDeclaration.types create mode 100644 tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 03f426084545b..5b1b52c281ccb 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4907,6 +4907,14 @@ "category": "Error", "code": 8032 }, + "A JSDoc '@typedef' comment may not contain multiple '@type' tags.": { + "category": "Error", + "code": 8033 + }, + "The tag was first specified here.": { + "category": "Error", + "code": 8034 + }, "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": { "category": "Error", "code": 9002 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ae13b11389779..fdc1e8246ac0d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -7483,6 +7483,14 @@ namespace ts { } if (child.kind === SyntaxKind.JSDocTypeTag) { if (childTypeTag) { + parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags); + const lastError = lastOrUndefined(parseDiagnostics); + if (lastError) { + addRelatedInfo( + lastError, + createDiagnosticForNode(sourceFile, Diagnostics.The_tag_was_first_specified_here) + ); + } break; } else { diff --git a/tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt b/tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt new file mode 100644 index 0000000000000..70e0f941b9770 --- /dev/null +++ b/tests/baselines/reference/typedefDuplicateTypeDeclaration.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js(4,16): error TS8033: A JSDoc '@typedef' comment may not contain multiple '@type' tags. + + +==== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js (1 errors) ==== + /** + * @typedef Name + * @type {string} + * @type {Oops} + + */ + +!!! error TS8033: A JSDoc '@typedef' comment may not contain multiple '@type' tags. +!!! related TS8034 tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js:1:1: The tag was first specified here. \ No newline at end of file diff --git a/tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols b/tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols new file mode 100644 index 0000000000000..eeafce6655c55 --- /dev/null +++ b/tests/baselines/reference/typedefDuplicateTypeDeclaration.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js === +/** +No type information for this code. * @typedef Name +No type information for this code. * @type {string} +No type information for this code. * @type {Oops} +No type information for this code. */ +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/typedefDuplicateTypeDeclaration.types b/tests/baselines/reference/typedefDuplicateTypeDeclaration.types new file mode 100644 index 0000000000000..eeafce6655c55 --- /dev/null +++ b/tests/baselines/reference/typedefDuplicateTypeDeclaration.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js === +/** +No type information for this code. * @typedef Name +No type information for this code. * @type {string} +No type information for this code. * @type {Oops} +No type information for this code. */ +No type information for this code. \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts b/tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts new file mode 100644 index 0000000000000..75ec41f78e35f --- /dev/null +++ b/tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.ts @@ -0,0 +1,9 @@ +// @allowJS: true +// @checkJS: true +// @noEmit: true +// @Filename: typedefDuplicateTypeDeclaration.js +/** + * @typedef Name + * @type {string} + * @type {Oops} + */ \ No newline at end of file