Skip to content

Commit 637d574

Browse files
core-dumplingcore-dumplingRyanCavanaugh
authored
Fix infinite loop (#63581)
Co-authored-by: core-dumpling <warble-88seesaws@icloud.com> Co-authored-by: Ryan Cavanaugh <RyanCavanaugh@users.noreply.github.com>
1 parent 7816ae6 commit 637d574

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/compiler/scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,7 @@ export function createScanner(
39153915

39163916
if (isIdentifierStart(ch, languageVersion)) {
39173917
let char = ch;
3918-
while (pos < end && isIdentifierPart(char = codePointUnchecked(pos), languageVersion) || char === CharacterCodes.minus) pos += charSize(char);
3918+
while (pos < end && (isIdentifierPart(char = codePointUnchecked(pos), languageVersion) || char === CharacterCodes.minus)) pos += charSize(char);
39193919
tokenValue = text.substring(tokenStart, pos);
39203920
if (char === CharacterCodes.backslash) {
39213921
tokenValue += scanIdentifierParts();

src/testRunner/unittests/comments.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe("comment parsing", () => {
1111
const withTrailing = `;/* comment */
1212
// another one
1313
`;
14+
const endingInHyphen = "/**comment-*/";
1415
it("skips shebang", () => {
1516
const result = ts.getLeadingCommentRanges(withShebang, 0);
1617
assert.isDefined(result);
@@ -29,4 +30,16 @@ describe("comment parsing", () => {
2930
assert.strictEqual(result.length, 1);
3031
assert.strictEqual(result[0].kind, ts.SyntaxKind.SingleLineCommentTrivia);
3132
});
33+
34+
it("parses /** block comments ending in hyphen", () => {
35+
const sourceFile = ts.createSourceFile(
36+
"file.ts",
37+
`${endingInHyphen}\nconst x = 1;`,
38+
ts.ScriptTarget.ESNext,
39+
/*setParentNodes*/ true,
40+
);
41+
42+
assert.strictEqual(sourceFile.parseDiagnostics.length, 0);
43+
assert.strictEqual(sourceFile.statements.length, 1);
44+
});
3245
});

0 commit comments

Comments
 (0)