diff --git a/.changeset/perfect-rings-hang.md b/.changeset/perfect-rings-hang.md new file mode 100644 index 0000000..178eb4f --- /dev/null +++ b/.changeset/perfect-rings-hang.md @@ -0,0 +1,5 @@ +--- +"@code-hike/lighter": patch +--- + +Fix one char tokens diff --git a/lib/dist/index.cjs.js b/lib/dist/index.cjs.js index 38eeac2..dc37b00 100644 --- a/lib/dist/index.cjs.js +++ b/lib/dist/index.cjs.js @@ -2671,7 +2671,10 @@ function reannotateLine(annotatedLine, annotation) { } i++; } - while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) { + else { + newAnnotatedLine.push(newGroup); + } + while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) { newGroup.tokens.push(annotatedLine[i]); i++; } @@ -2785,6 +2788,9 @@ function reannotateLines(annotatedLines, annotation) { } i++; } + else { + newAnnotatedLines.push(newGroup); + } while (i < annotatedLines.length && annotatedLines[i].toLineNumber <= toLineNumber) { newGroup.lines.push(annotatedLines[i]); diff --git a/lib/dist/index.esm.mjs b/lib/dist/index.esm.mjs index 330321b..c1fa366 100644 --- a/lib/dist/index.esm.mjs +++ b/lib/dist/index.esm.mjs @@ -2649,7 +2649,10 @@ function reannotateLine(annotatedLine, annotation) { } i++; } - while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) { + else { + newAnnotatedLine.push(newGroup); + } + while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) { newGroup.tokens.push(annotatedLine[i]); i++; } @@ -2763,6 +2766,9 @@ function reannotateLines(annotatedLines, annotation) { } i++; } + else { + newAnnotatedLines.push(newGroup); + } while (i < annotatedLines.length && annotatedLines[i].toLineNumber <= toLineNumber) { newGroup.lines.push(annotatedLines[i]); diff --git a/lib/src/annotations.inline.ts b/lib/src/annotations.inline.ts index 37b6b1d..004e078 100644 --- a/lib/src/annotations.inline.ts +++ b/lib/src/annotations.inline.ts @@ -97,9 +97,11 @@ function reannotateLine( newGroup.tokens.push(secondHalf); } i++; + } else { + newAnnotatedLine.push(newGroup); } - while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) { + while (i < annotatedLine.length && annotatedLine[i].toColumn <= toColumn) { newGroup.tokens.push(annotatedLine[i]); i++; } diff --git a/lib/src/annotations.multiline.ts b/lib/src/annotations.multiline.ts index 69af4ca..15397da 100644 --- a/lib/src/annotations.multiline.ts +++ b/lib/src/annotations.multiline.ts @@ -98,6 +98,8 @@ function reannotateLines( newGroup.lines.push(secondHalf); } i++; + } else { + newAnnotatedLines.push(newGroup); } while ( diff --git a/test/test.js b/test/test.js index d96e0be..92c7c99 100644 --- a/test/test.js +++ b/test/test.js @@ -4,12 +4,9 @@ import { annotatedHighlight, extractAnnotations } from "@code-hike/lighter"; // console.log("default", JSON.stringify(tokens)); // }); -const test1 = ` -const x = 1; /* bar x */ more /* notannotated */ code`; - const code = ` -// mark[4:7] -consolessssssssss +// foo[9:11] +const x = 20 `.trim(); // const code = `// foo `; const alias = "js"; @@ -28,90 +25,3 @@ async function run() { } run(); - -const x = [ - { - lineNumber: 1, - tokens: [ - { - content: "console.", - style: { - color: "#F8F8F2", - }, - }, - { - content: "log", - style: { - color: "#50FA7B", - }, - }, - { - content: "(", - style: { - color: "#F8F8F2", - }, - }, - { - content: "1", - style: { - color: "#BD93F9", - }, - }, - { - content: ")", - style: { - color: "#F8F8F2", - }, - }, - ], - }, - { - lineNumber: 2, - tokens: [ - { - annotationName: "mark", - annotationQuery: "", - fromColumn: 4, - toColumn: 7, - tokens: [ - { - content: "console.", - style: { - color: "#F8F8F2", - }, - }, - { - content: "console.", - style: { - color: "#F8F8F2", - }, - }, - { - content: "log", - style: { - color: "#50FA7B", - }, - }, - { - content: "(", - style: { - color: "#F8F8F2", - }, - }, - { - content: "2", - style: { - color: "#BD93F9", - }, - }, - { - content: ")", - style: { - color: "#F8F8F2", - }, - }, - ], - }, - ], - }, -];