Skip to content

Commit e5b4473

Browse files
committed
Fix token splitting
1 parent f065138 commit e5b4473

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

.changeset/hip-swans-listen.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@code-hike/lighter": patch
3+
---
4+
5+
Fix token splitting

lib/dist/index.cjs.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dist/index.esm.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,7 @@ function reannotateLine(annotatedLine, annotation) {
26492649
return newAnnotatedLine;
26502650
}
26512651
const lastGroup = annotatedLine[i];
2652-
if (lastGroup.toColumn > toColumn) {
2652+
if (lastGroup.fromColumn <= toColumn) {
26532653
// we need to split the last group in two
26542654
const [firstHalf, secondHalf] = splitGroup$1(lastGroup, toColumn + 1);
26552655
newGroup.tokens.push(firstHalf);
@@ -2757,7 +2757,7 @@ function reannotateLines(annotatedLines, annotation) {
27572757
return newAnnotatedLines;
27582758
}
27592759
const lastGroup = annotatedLines[i];
2760-
if (lastGroup.toLineNumber > toLineNumber) {
2760+
if (lastGroup.fromLineNumber <= toLineNumber) {
27612761
const [firstHalf, secondHalf] = splitGroup(lastGroup, toLineNumber + 1);
27622762
newGroup.lines.push(firstHalf);
27632763
newAnnotatedLines.push(secondHalf);

lib/src/annotations.inline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function reannotateLine(
9898
}
9999

100100
const lastGroup = annotatedLine[i];
101-
if (lastGroup.toColumn > toColumn) {
101+
if (lastGroup.fromColumn <= toColumn) {
102102
// we need to split the last group in two
103103

104104
const [firstHalf, secondHalf] = splitGroup(lastGroup, toColumn + 1);

lib/src/annotations.multiline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function reannotateLines(
104104
}
105105

106106
const lastGroup = annotatedLines[i];
107-
if (lastGroup.toLineNumber > toLineNumber) {
107+
if (lastGroup.fromLineNumber <= toLineNumber) {
108108
const [firstHalf, secondHalf] = splitGroup(lastGroup, toLineNumber + 1);
109109
newGroup.lines.push(firstHalf);
110110
newAnnotatedLines.push(secondHalf);

test/test.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ const test1 = `
88
const x = 1; /* bar x */ more /* notannotated */ code`;
99

1010
const code = `
11-
// mark(2:3) first
12-
// mark(1:2) second
13-
foo1
14-
foo2
15-
foo3
11+
// mark[4:7]
12+
console.log(1)
1613
`.trim();
1714
// const code = `// foo `;
1815
const alias = "js";

0 commit comments

Comments
 (0)