From 064c595fe624d387f646cd7bcec2760c93e44f94 Mon Sep 17 00:00:00 2001 From: Stephen Hicks Date: Sun, 18 Aug 2024 03:43:10 -0400 Subject: [PATCH] Fix line accounting for `alternateCommentMode` When `alternateCommentMode` is enabled, the tokenizer treats a block of multiple end-of-line (`//`) comments as a single line when keeping track of line numbers, making error messages very difficult to understand, since they refer to the wrong line number. This change increments the line number in the inner loop, so that each line is accounted correctly. --- src/tokenize.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tokenize.js b/src/tokenize.js index f107bea8a..c814d1170 100644 --- a/src/tokenize.js +++ b/src/tokenize.js @@ -274,6 +274,7 @@ function tokenize(source, alternateCommentMode) { break; } offset++; + line++; if (!isLeadingComment) { // Trailing comment cannot not be multi-line break; @@ -281,12 +282,12 @@ function tokenize(source, alternateCommentMode) { } while (isDoubleSlashCommentLine(offset)); } else { offset = Math.min(length, findEndOfLine(offset) + 1); + line++; } if (isDoc) { setComment(start, offset, isLeadingComment); isLeadingComment = true; } - line++; repeat = true; } } else if ((curr = charAt(offset)) === "*") { /* Block */