Skip to content

Commit d9abe7b

Browse files
committed
Fix one char tokens
1 parent 9ec6aa1 commit d9abe7b

File tree

6 files changed

+26
-95
lines changed

6 files changed

+26
-95
lines changed

.changeset/perfect-rings-hang.md

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

lib/dist/index.cjs.js

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

lib/dist/index.esm.mjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2649,7 +2649,10 @@ function reannotateLine(annotatedLine, annotation) {
26492649
}
26502650
i++;
26512651
}
2652-
while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) {
2652+
else {
2653+
newAnnotatedLine.push(newGroup);
2654+
}
2655+
while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) {
26532656
newGroup.tokens.push(annotatedLine[i]);
26542657
i++;
26552658
}
@@ -2763,6 +2766,9 @@ function reannotateLines(annotatedLines, annotation) {
27632766
}
27642767
i++;
27652768
}
2769+
else {
2770+
newAnnotatedLines.push(newGroup);
2771+
}
27662772
while (i < annotatedLines.length &&
27672773
annotatedLines[i].toLineNumber <= toLineNumber) {
27682774
newGroup.lines.push(annotatedLines[i]);

lib/src/annotations.inline.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ function reannotateLine(
9797
newGroup.tokens.push(secondHalf);
9898
}
9999
i++;
100+
} else {
101+
newAnnotatedLine.push(newGroup);
100102
}
101103

102-
while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) {
104+
while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) {
103105
newGroup.tokens.push(annotatedLine[i]);
104106
i++;
105107
}

lib/src/annotations.multiline.ts

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ function reannotateLines(
9898
newGroup.lines.push(secondHalf);
9999
}
100100
i++;
101+
} else {
102+
newAnnotatedLines.push(newGroup);
101103
}
102104

103105
while (

test/test.js

+2-92
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import { annotatedHighlight, extractAnnotations } from "@code-hike/lighter";
44
// console.log("default", JSON.stringify(tokens));
55
// });
66

7-
const test1 = `
8-
const x = 1; /* bar x */ more /* notannotated */ code`;
9-
107
const code = `
11-
// mark[4:7]
12-
consolessssssssss
8+
// foo[9:11]
9+
const x = 20
1310
`.trim();
1411
// const code = `// foo `;
1512
const alias = "js";
@@ -28,90 +25,3 @@ async function run() {
2825
}
2926

3027
run();
31-
32-
const x = [
33-
{
34-
lineNumber: 1,
35-
tokens: [
36-
{
37-
content: "console.",
38-
style: {
39-
color: "#F8F8F2",
40-
},
41-
},
42-
{
43-
content: "log",
44-
style: {
45-
color: "#50FA7B",
46-
},
47-
},
48-
{
49-
content: "(",
50-
style: {
51-
color: "#F8F8F2",
52-
},
53-
},
54-
{
55-
content: "1",
56-
style: {
57-
color: "#BD93F9",
58-
},
59-
},
60-
{
61-
content: ")",
62-
style: {
63-
color: "#F8F8F2",
64-
},
65-
},
66-
],
67-
},
68-
{
69-
lineNumber: 2,
70-
tokens: [
71-
{
72-
annotationName: "mark",
73-
annotationQuery: "",
74-
fromColumn: 4,
75-
toColumn: 7,
76-
tokens: [
77-
{
78-
content: "console.",
79-
style: {
80-
color: "#F8F8F2",
81-
},
82-
},
83-
{
84-
content: "console.",
85-
style: {
86-
color: "#F8F8F2",
87-
},
88-
},
89-
{
90-
content: "log",
91-
style: {
92-
color: "#50FA7B",
93-
},
94-
},
95-
{
96-
content: "(",
97-
style: {
98-
color: "#F8F8F2",
99-
},
100-
},
101-
{
102-
content: "2",
103-
style: {
104-
color: "#BD93F9",
105-
},
106-
},
107-
{
108-
content: ")",
109-
style: {
110-
color: "#F8F8F2",
111-
},
112-
},
113-
],
114-
},
115-
],
116-
},
117-
];

0 commit comments

Comments
 (0)