diff --git a/.chronus/changes/fix-get-doc-2024-6-17-16-36-18.md b/.chronus/changes/fix-get-doc-2024-6-17-16-36-18.md new file mode 100644 index 0000000000..d9dd756e6b --- /dev/null +++ b/.chronus/changes/fix-get-doc-2024-6-17-16-36-18.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/compiler" +--- + +Fixes a bug where ending a non-terminal line in a multi-line comment with a backslash caused the next star to show up in the parsed doc string. \ No newline at end of file diff --git a/packages/compiler/src/core/scanner.ts b/packages/compiler/src/core/scanner.ts index e327ec5980..1b0bed8c32 100644 --- a/packages/compiler/src/core/scanner.ts +++ b/packages/compiler/src/core/scanner.ts @@ -661,8 +661,11 @@ export function createScanner( return next(Token.NewLine); case CharCode.Backslash: - tokenFlags |= TokenFlags.Escaped; - return position === endPosition - 1 ? next(Token.DocText) : next(Token.DocText, 2); + if (lookAhead(1) === CharCode.At) { + tokenFlags |= TokenFlags.Escaped; + return next(Token.DocText, 2); + } + return next(Token.DocText); case CharCode.Space: case CharCode.Tab: diff --git a/packages/compiler/test/parser.test.ts b/packages/compiler/test/parser.test.ts index e70bd01501..72136e299d 100644 --- a/packages/compiler/test/parser.test.ts +++ b/packages/compiler/test/parser.test.ts @@ -1037,7 +1037,7 @@ describe("compiler: parser", () => { *\`\`\` * * \`This is not a @tag either because we're in a code span\`. - * + * * This is not a \\@tag because it is escaped. * * @param x the param @@ -1105,6 +1105,24 @@ describe("compiler: parser", () => { strictEqual(pretend.content[0].text, "this an unknown tag"); }, ], + [ + ` + /** + * Lines that end with \\ + * don't create an extra star. + */ + model M {} + `, + (script) => { + const docs = script.statements[0].docs; + strictEqual(docs?.length, 1); + strictEqual(docs[0].content.length, 1); + strictEqual( + docs[0].content[0].text, + "Lines that end with \\\ndon't create an extra star." + ); + }, + ], ], { docs: true } );