From cf63bce7afa3e92d4b77d64ea2c28cec7bc37370 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 5 Aug 2020 16:17:56 -0700 Subject: [PATCH] Fix scanner offset and make it easier to read --- src/compiler/scanner.ts | 6 +-- .../reference/tripleSlashJsdoc.symbols | 40 +++++++++++++++++ .../reference/tripleSlashJsdoc.types | 45 +++++++++++++++++++ .../cases/fourslash/commentsCommentParsing.ts | 2 +- 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/tripleSlashJsdoc.symbols create mode 100644 tests/baselines/reference/tripleSlashJsdoc.types diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index e198102f5eb..2cd3ca63454 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -1745,10 +1745,10 @@ namespace ts { case CharacterCodes.slash: // Single-line comment if (text.charCodeAt(pos + 1) === CharacterCodes.slash) { - pos += 2; if (text.charCodeAt(pos + 2) === CharacterCodes.slash) { tokenFlags |= TokenFlags.PrecedingJSDocComment; } + pos += 2; while (pos < end) { if (isLineBreak(text.charCodeAt(pos))) { @@ -1773,10 +1773,10 @@ namespace ts { } // Multi-line comment if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) { - pos += 2; - if (text.charCodeAt(pos) === CharacterCodes.asterisk && text.charCodeAt(pos + 1) !== CharacterCodes.slash) { + if (text.charCodeAt(pos + 2) === CharacterCodes.asterisk && text.charCodeAt(pos + 3) !== CharacterCodes.slash) { tokenFlags |= TokenFlags.PrecedingJSDocComment; } + pos += 2; let commentClosed = false; let lastLineStart = tokenPos; diff --git a/tests/baselines/reference/tripleSlashJsdoc.symbols b/tests/baselines/reference/tripleSlashJsdoc.symbols new file mode 100644 index 00000000000..8f5dca5a63b --- /dev/null +++ b/tests/baselines/reference/tripleSlashJsdoc.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/jsdoc/tripleSlash.js === +/// @type {number} - TODO this is still skipped for some reason +var x; +>x : Symbol(x, Decl(tripleSlash.js, 1, 3)) + +/// Adds one +/// @param {number} n - this is a long, +/// multiline comment +/// +/// @return {number} +function add1(n) { +>add1 : Symbol(add1, Decl(tripleSlash.js, 1, 6)) +>n : Symbol(n, Decl(tripleSlash.js, 8, 14)) + + return n + 1 +>n : Symbol(n, Decl(tripleSlash.js, 8, 14)) +} + +// Should be the same + +/** Adds one + * @param {number} n - this is a long, + * multiline comment + * + * @return {number} +*/ +function add2(n) { +>add2 : Symbol(add2, Decl(tripleSlash.js, 10, 1)) +>n : Symbol(n, Decl(tripleSlash.js, 20, 14)) + + return n + 1 +>n : Symbol(n, Decl(tripleSlash.js, 20, 14)) +} + +/// I documented this const +const documented = "" +>documented : Symbol(documented, Decl(tripleSlash.js, 25, 5)) + + + diff --git a/tests/baselines/reference/tripleSlashJsdoc.types b/tests/baselines/reference/tripleSlashJsdoc.types new file mode 100644 index 00000000000..8a58c317010 --- /dev/null +++ b/tests/baselines/reference/tripleSlashJsdoc.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/jsdoc/tripleSlash.js === +/// @type {number} - TODO this is still skipped for some reason +var x; +>x : number + +/// Adds one +/// @param {number} n - this is a long, +/// multiline comment +/// +/// @return {number} +function add1(n) { +>add1 : (n: number) => number +>n : number + + return n + 1 +>n + 1 : number +>n : number +>1 : 1 +} + +// Should be the same + +/** Adds one + * @param {number} n - this is a long, + * multiline comment + * + * @return {number} +*/ +function add2(n) { +>add2 : (n: number) => number +>n : number + + return n + 1 +>n + 1 : number +>n : number +>1 : 1 +} + +/// I documented this const +const documented = "" +>documented : "" +>"" : "" + + + diff --git a/tests/cases/fourslash/commentsCommentParsing.ts b/tests/cases/fourslash/commentsCommentParsing.ts index 4731194ba69..755a1d1cc63 100644 --- a/tests/cases/fourslash/commentsCommentParsing.ts +++ b/tests/cases/fourslash/commentsCommentParsing.ts @@ -202,7 +202,7 @@ ////class NoQuic/*50*/kInfoClass { ////} -verify.signatureHelp({ marker: "1", docComment: "" }); +verify.signatureHelp({ marker: "1", docComment: " This is simple /// comments" }); verify.quickInfoAt("1q", "function simple(): void"); verify.signatureHelp({ marker: "2", docComment: "" });