diff --git a/packages/typescript/src/ast/scanner.ts b/packages/typescript/src/ast/scanner.ts index 8e956bb967f54..df3a7415cec5d 100644 --- a/packages/typescript/src/ast/scanner.ts +++ b/packages/typescript/src/ast/scanner.ts @@ -2434,7 +2434,7 @@ export function createScanner( if (isIdentifierStart(ch)) { let char = ch; - while (pos < end && isIdentifierPart(char = codePointUnchecked(pos)) || char === CharacterCodes.minus) pos += charSize(char); + while (pos < end && (isIdentifierPart(char = codePointUnchecked(pos)) || char === CharacterCodes.minus)) pos += charSize(char); tokenValue = text.substring(tokenStart, pos); if (char === CharacterCodes.backslash) { tokenValue += scanIdentifierParts(); diff --git a/packages/typescript/test/scanner.test.ts b/packages/typescript/test/scanner.test.ts new file mode 100644 index 0000000000000..0f52a34040628 --- /dev/null +++ b/packages/typescript/test/scanner.test.ts @@ -0,0 +1,23 @@ +import { + createScanner, + SyntaxKind, +} from "@typescript/typescript/unstable/ast"; +import assert from "node:assert"; +import { test } from "node:test"; + +test("scanJsDocToken respects a range ending in a hyphen", () => { + const text = "/** x-yy"; + const scanner = createScanner(/*skipTrivia*/ true); + scanner.setText(text); + + scanner.scanRange(3, text.length - 5, () => { + const tokens = []; + while (scanner.scanJsDocToken() !== SyntaxKind.EndOfFile) { + tokens.push([scanner.getToken(), scanner.getTokenText()]); + } + assert.deepStrictEqual(tokens, [ + [SyntaxKind.WhitespaceTrivia, " "], + [SyntaxKind.Identifier, "x-"], + ]); + }); +});