From a4e3635f790ebccdbacb3f432064891c7cee9b60 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Sat, 7 May 2022 21:06:25 -0700 Subject: [PATCH] fix: issue parsing expressions with unenclosed newlines in windows --- .changeset/afraid-comics-whisper.md | 5 +++++ src/__tests__/main.test.ts | 2 ++ src/states/EXPRESSION.ts | 7 +++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/afraid-comics-whisper.md diff --git a/.changeset/afraid-comics-whisper.md b/.changeset/afraid-comics-whisper.md new file mode 100644 index 00000000..4872dbe9 --- /dev/null +++ b/.changeset/afraid-comics-whisper.md @@ -0,0 +1,5 @@ +--- +"htmljs-parser": patch +--- + +Fixes issue where expressions could consume an extra character when windows line endings used. diff --git a/src/__tests__/main.test.ts b/src/__tests__/main.test.ts index 2768c963..e60646dd 100644 --- a/src/__tests__/main.test.ts +++ b/src/__tests__/main.test.ts @@ -16,6 +16,8 @@ for (const entry of fs.readdirSync(FIXTURES)) { const dir = path.join(FIXTURES, entry); const filename = path.join(dir, "input.marko"); const src = await fs.promises.readFile(filename, "utf-8"); + // Use this if you want to psuedo test on windows locally. + // const src = (await fs.promises.readFile(filename, "utf-8")).replace(/\n/g, "\r\n"); const lines = getLines(src); const partsByLine: { range: Range; diff --git a/src/states/EXPRESSION.ts b/src/states/EXPRESSION.ts index a6273f2e..d8819e17 100644 --- a/src/states/EXPRESSION.ts +++ b/src/states/EXPRESSION.ts @@ -258,11 +258,14 @@ function checkForOperators(parser: Parser, expression: ExpressionMeta) { if (match.length === 0) { // We matched a look behind. parser.consumeWhitespace(); - parser.pos--; } else { // We matched a look ahead. - parser.pos += match.length - 1; + parser.pos += match.length; } + + // After this point we should be on the character we want to process next + // so we don't want to move forward and miss that character. + parser.forward = 0; } else { return false; }