From be95e9198cbd52b90dd2417e82a613a8f6f575fc Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 5 Apr 2023 14:03:37 +0200 Subject: [PATCH] Improve block comment tokenizers FIX: Fix a bug where tokenizing of block comments got confused when nested comment start/end markers appeared directly next to each other. See https://discuss.codemirror.net/t/block-comments-not-closed-correctly/6182 --- src/tokens.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/tokens.ts b/src/tokens.ts index 4c7527d..9430699 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -194,18 +194,17 @@ export function tokensFor(d: Dialect) { input.acceptToken(LineComment) } else if (next == Ch.Slash && input.next == Ch.Star) { input.advance() - for (let prev = -1, depth = 1;;) { + for (let depth = 1;;) { + let cur: number = input.next if (input.next < 0) break input.advance() - if (prev == Ch.Star && (input as any).next == Ch.Slash) { + if (cur == Ch.Star && (input as any).next == Ch.Slash) { depth-- - if (!depth) { input.advance(); break } - prev = -1 - } else if (prev == Ch.Slash && input.next == Ch.Star) { + input.advance() + if (!depth) break + } else if (cur == Ch.Slash && input.next == Ch.Star) { depth++ - prev = -1 - } else { - prev = input.next + input.advance() } } input.acceptToken(BlockComment)