Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes bug rendering backslashes when present as last character in doc comment line #3881

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/fix-get-doc-2024-6-17-16-36-18.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 5 additions & 2 deletions packages/compiler/src/core/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion packages/compiler/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
);
Expand Down
Loading