From 28fc441b0e04b7fa273fe0f2241107e21c37a215 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 30 Aug 2018 10:21:42 -0600 Subject: [PATCH] Ignore newline and asterisk when parsing JSDoc typedef --- src/compiler/parser.ts | 2 +- .../reference/typedefTagWrapping.symbols | 23 ++++++++++++++++++ .../reference/typedefTagWrapping.types | 24 +++++++++++++++++++ .../conformance/jsdoc/typedefTagWrapping.ts | 20 ++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typedefTagWrapping.symbols create mode 100644 tests/baselines/reference/typedefTagWrapping.types create mode 100644 tests/cases/conformance/jsdoc/typedefTagWrapping.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e9eb953d22ab5..b40648033de37 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6856,7 +6856,7 @@ namespace ts { function parseTypedefTag(atToken: AtToken, tagName: Identifier, indent: number): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); - skipWhitespace(); + skipWhitespaceOrAsterisk(); const typedefTag = createNode(SyntaxKind.JSDocTypedefTag, atToken.pos); typedefTag.atToken = atToken; diff --git a/tests/baselines/reference/typedefTagWrapping.symbols b/tests/baselines/reference/typedefTagWrapping.symbols new file mode 100644 index 0000000000000..ec93da5a45b4c --- /dev/null +++ b/tests/baselines/reference/typedefTagWrapping.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/jsdoc/mod1.js === +/** + * @typedef {function(string): boolean} + * MyType + */ + +/** + * Tries to use a type whose name is on a different + * line than the typedef tag. + * @param {MyType} func The function to call. + * @param {string} arg The argument to call it with. + * @returns {boolean} The return. + */ +function callIt(func, arg) { +>callIt : Symbol(callIt, Decl(mod1.js, 0, 0)) +>func : Symbol(func, Decl(mod1.js, 12, 16)) +>arg : Symbol(arg, Decl(mod1.js, 12, 21)) + + return func(arg); +>func : Symbol(func, Decl(mod1.js, 12, 16)) +>arg : Symbol(arg, Decl(mod1.js, 12, 21)) +} + diff --git a/tests/baselines/reference/typedefTagWrapping.types b/tests/baselines/reference/typedefTagWrapping.types new file mode 100644 index 0000000000000..8c92717d1a1ab --- /dev/null +++ b/tests/baselines/reference/typedefTagWrapping.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/jsdoc/mod1.js === +/** + * @typedef {function(string): boolean} + * MyType + */ + +/** + * Tries to use a type whose name is on a different + * line than the typedef tag. + * @param {MyType} func The function to call. + * @param {string} arg The argument to call it with. + * @returns {boolean} The return. + */ +function callIt(func, arg) { +>callIt : (func: (arg0: string) => boolean, arg: string) => boolean +>func : (arg0: string) => boolean +>arg : string + + return func(arg); +>func(arg) : boolean +>func : (arg0: string) => boolean +>arg : string +} + diff --git a/tests/cases/conformance/jsdoc/typedefTagWrapping.ts b/tests/cases/conformance/jsdoc/typedefTagWrapping.ts new file mode 100644 index 0000000000000..53cff6d02c0ae --- /dev/null +++ b/tests/cases/conformance/jsdoc/typedefTagWrapping.ts @@ -0,0 +1,20 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: mod1.js + +/** + * @typedef {function(string): boolean} + * MyType + */ + +/** + * Tries to use a type whose name is on a different + * line than the typedef tag. + * @param {MyType} func The function to call. + * @param {string} arg The argument to call it with. + * @returns {boolean} The return. + */ +function callIt(func, arg) { + return func(arg); +}