From a6e288ed9d3859432c2d6faf4a822bed625fc715 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 11 Jul 2025 21:46:46 -0400 Subject: [PATCH 1/4] Character offset repro --- test/node/parse.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/node/parse.test.js b/test/node/parse.test.js index 6998b1b..96576ca 100644 --- a/test/node/parse.test.js +++ b/test/node/parse.test.js @@ -165,4 +165,35 @@ describe(`parse`, function () { }, ]); }); + + it('has correct character ranges', function () { + let file = [ + 'const one = ;' + + '' + + 'const two = ;' + ].join('\n') + + let output = p.parse(file); + + let one = output[0]; + let two = output[1]; + + { + let { range, startRange, endRange, contentRange } = one; + + expect(file.slice(range.startChar, range.endChar)).to.eql(``); + expect(file.slice(startRange.startChar, startRange.endChar)).to.eql(``); + expect(file.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩💩💩💩💩💩💩`); + } + + { + let { range, startRange, endRange, contentRange } = two; + + expect(file.slice(range.startChar, range.endChar)).to.eql(``); + expect(file.slice(startRange.startChar, startRange.endChar)).to.eql(``); + expect(file.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`); + } + }); }); From cdc70f64135b271ce4abc31175d98c1e5338050e Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 15 Jul 2025 10:38:44 -0400 Subject: [PATCH 2/4] Use Array.from --- test/node/parse.test.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/node/parse.test.js b/test/node/parse.test.js index 96576ca..28d34bd 100644 --- a/test/node/parse.test.js +++ b/test/node/parse.test.js @@ -177,23 +177,24 @@ describe(`parse`, function () { let one = output[0]; let two = output[1]; + let arr = Array.from(file); { let { range, startRange, endRange, contentRange } = one; - expect(file.slice(range.startChar, range.endChar)).to.eql(``); - expect(file.slice(startRange.startChar, startRange.endChar)).to.eql(``); - expect(file.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩💩💩💩💩💩💩`); + expect(arr.slice(range.startChar, range.endChar)).to.eql(``); + expect(arr.slice(startRange.startChar, startRange.endChar)).to.eql(``); + expect(arr.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩💩💩💩💩💩💩`); } { let { range, startRange, endRange, contentRange } = two; - expect(file.slice(range.startChar, range.endChar)).to.eql(``); - expect(file.slice(startRange.startChar, startRange.endChar)).to.eql(``); - expect(file.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`); + expect(arr.slice(range.startChar, range.endChar)).to.eql(``); + expect(arr.slice(startRange.startChar, startRange.endChar)).to.eql(``); + expect(arr.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`); } }); }); From 305af686363ec6c8c3ba039347f1d760ee53777e Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 15 Jul 2025 10:40:48 -0400 Subject: [PATCH 3/4] ope --- test/node/parse.test.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/test/node/parse.test.js b/test/node/parse.test.js index 28d34bd..adf27ee 100644 --- a/test/node/parse.test.js +++ b/test/node/parse.test.js @@ -8,8 +8,8 @@ const { expect } = chai; const p = new Preprocessor(); -describe(`parse`, function () { - it("basic example", function () { +describe(`parse`, function() { + it("basic example", function() { let output = p.parse(""); expect(output).to.eql([ @@ -30,7 +30,7 @@ describe(`parse`, function () { ]); }); - it("expression position", function () { + it("expression position", function() { let output = p.parse("const tpl = "); expect(output).to.eql([ @@ -51,7 +51,7 @@ describe(`parse`, function () { ]); }); - it("inside class body", function () { + it("inside class body", function() { let output = p.parse(` class A { @@ -76,7 +76,7 @@ describe(`parse`, function () { ]); }); - it("preceded by a slash character", function () { + it("preceded by a slash character", function() { // What is this testing? // Would a better test be: // `const divide = 1 / ;` @@ -103,7 +103,7 @@ describe(`parse`, function () { ]); }); - it("/