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(endRange.startChar, endRange.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(endRange.startChar, endRange.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(endRange.startChar, endRange.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(endRange.startChar, endRange.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(endRange.startChar, endRange.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(endRange.startChar, endRange.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("Hello!");
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 = Hello!");
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 {
Hello!
@@ -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 / Hello!;`
@@ -103,7 +103,7 @@ describe(`parse`, function () {
]);
});
- it("// inside a regexp", function () {
+ it("// inside a regexp", function() {
let output = p.parse(`
const myregex = //;
Hello!
@@ -127,14 +127,14 @@ describe(`parse`, function () {
]);
});
- it("no match", function () {
+ it("no match", function() {
let output = p.parse("console.log('Hello world');");
expect(output).to.eql([]);
});
- it("Emits parse errors", function () {
- expect(function () {
+ it("Emits parse errors", function() {
+ expect(function() {
p.process(
`const thing = "face";
Hi`,
@@ -143,7 +143,7 @@ describe(`parse`, function () {
}).to.throw(`Parse Error at path/to/my/component.gjs:2:15: 2:15`);
});
- it("handles multibyte characters", function () {
+ it("handles multibyte characters", function() {
let output = p.parse(
"const prefix = '熊';\nconst tpl = Hello!"
);
@@ -166,7 +166,7 @@ describe(`parse`, function () {
]);
});
- it('has correct character ranges', function () {
+ it('has correct character ranges', function() {
let file = [
'const one = 💩💩💩💩💩💩💩;' +
'' +
@@ -179,22 +179,24 @@ describe(`parse`, function () {
let two = output[1];
let arr = Array.from(file);
+ const slice = (start, end) => arr.slice(start, end).join('');
+
{
let { range, startRange, endRange, contentRange } = one;
- expect(arr.slice(range.startChar, range.endChar)).to.eql(`💩💩💩💩💩💩💩`);
- expect(arr.slice(startRange.startChar, startRange.endChar)).to.eql(``);
- expect(arr.slice(endRange.startChar, endRange.endChar)).to.eql(``);
- expect(arr.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩💩💩💩💩💩💩`);
+ expect(slice(range.startChar, range.endChar)).to.eql(`💩💩💩💩💩💩💩`);
+ expect(slice(startRange.startChar, startRange.endChar)).to.eql(``);
+ expect(slice(endRange.startChar, endRange.endChar)).to.eql(``);
+ expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩💩💩💩💩💩💩`);
}
{
let { range, startRange, endRange, contentRange } = two;
- expect(arr.slice(range.startChar, range.endChar)).to.eql(`💩`);
- expect(arr.slice(startRange.startChar, startRange.endChar)).to.eql(``);
- expect(arr.slice(endRange.startChar, endRange.endChar)).to.eql(``);
- expect(arr.slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`);
+ expect(slice(range.startChar, range.endChar)).to.eql(`💩`);
+ expect(slice(startRange.startChar, startRange.endChar)).to.eql(``);
+ expect(slice(endRange.startChar, endRange.endChar)).to.eql(``);
+ expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`);
}
});
});
From f72707c1200237bdf427f63ec0ba4b798d1cf0b0 Mon Sep 17 00:00:00 2001
From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com>
Date: Tue, 15 Jul 2025 10:44:13 -0400
Subject: [PATCH 4/4] Grr prettier tooling
---
test/node/parse.test.js | 56 ++++++++++++++++++++++++-----------------
1 file changed, 33 insertions(+), 23 deletions(-)
diff --git a/test/node/parse.test.js b/test/node/parse.test.js
index adf27ee..9dfb439 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("Hello!");
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 = Hello!");
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 {
Hello!
@@ -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 / Hello!;`
@@ -103,7 +103,7 @@ describe(`parse`, function() {
]);
});
- it("// inside a regexp", function() {
+ it("// inside a regexp", function () {
let output = p.parse(`
const myregex = //;
Hello!
@@ -127,25 +127,25 @@ describe(`parse`, function() {
]);
});
- it("no match", function() {
+ it("no match", function () {
let output = p.parse("console.log('Hello world');");
expect(output).to.eql([]);
});
- it("Emits parse errors", function() {
- expect(function() {
+ it("Emits parse errors", function () {
+ expect(function () {
p.process(
`const thing = "face";
Hi`,
- { filename: "path/to/my/component.gjs" }
+ { filename: "path/to/my/component.gjs" },
);
}).to.throw(`Parse Error at path/to/my/component.gjs:2:15: 2:15`);
});
- it("handles multibyte characters", function() {
+ it("handles multibyte characters", function () {
let output = p.parse(
- "const prefix = '熊';\nconst tpl = Hello!"
+ "const prefix = '熊';\nconst tpl = Hello!",
);
expect(output).to.eql([
@@ -166,12 +166,12 @@ describe(`parse`, function() {
]);
});
- it('has correct character ranges', function() {
+ it("has correct character ranges", function () {
let file = [
- 'const one = 💩💩💩💩💩💩💩;' +
- '' +
- 'const two = 💩;'
- ].join('\n')
+ "const one = 💩💩💩💩💩💩💩;" +
+ "" +
+ "const two = 💩;",
+ ].join("\n");
let output = p.parse(file);
@@ -179,22 +179,32 @@ describe(`parse`, function() {
let two = output[1];
let arr = Array.from(file);
- const slice = (start, end) => arr.slice(start, end).join('');
+ const slice = (start, end) => arr.slice(start, end).join("");
{
let { range, startRange, endRange, contentRange } = one;
- expect(slice(range.startChar, range.endChar)).to.eql(`💩💩💩💩💩💩💩`);
- expect(slice(startRange.startChar, startRange.endChar)).to.eql(``);
+ expect(slice(range.startChar, range.endChar)).to.eql(
+ `💩💩💩💩💩💩💩`,
+ );
+ expect(slice(startRange.startChar, startRange.endChar)).to.eql(
+ ``,
+ );
expect(slice(endRange.startChar, endRange.endChar)).to.eql(``);
- expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩💩💩💩💩💩💩`);
+ expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(
+ `💩💩💩💩💩💩💩`,
+ );
}
{
let { range, startRange, endRange, contentRange } = two;
- expect(slice(range.startChar, range.endChar)).to.eql(`💩`);
- expect(slice(startRange.startChar, startRange.endChar)).to.eql(``);
+ expect(slice(range.startChar, range.endChar)).to.eql(
+ `💩`,
+ );
+ expect(slice(startRange.startChar, startRange.endChar)).to.eql(
+ ``,
+ );
expect(slice(endRange.startChar, endRange.endChar)).to.eql(``);
expect(slice(contentRange.startChar, contentRange.endChar)).to.eql(`💩`);
}