You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Describe the bug
Thanks for the project! I'm running into an undefined access bug preventing highlighting of the final index when using the decorations API. Looks like normalizePosition adds an invalid decoration (line is lines.length) and therefore const lineEl = lines[line]; in applyLineSection is undefined. I can submit a test and PR within the next couple days if it's still open.
Basic Reproduction
import{createHighlighter}from'shiki';consthighlighterCore=awaitcreateHighlighter({langs: ['ts'],themes: ['nord']});functionhighlight(str: string,start: number,end: number){returnhighlighterCore.codeToHtml(str,{lang: 'ts',theme: 'nord',decorations: [{ start, end,properties: {['data-wrap']: ''}}],})}// ✅ Add `data-wrap` to `.line` around `a`:highlight(`a\nbcd`,0,1);// ✅ Add a `data-wrap` span after `a` in first `.line`:highlight(`a\nbcd`,1,1);// ✅ Add `data-wrap` around `bc` in second `.line`:highlight(`a\nbcd`,2,4);// ❌ Expect to add `data-wrap` to `.line` around `bcd`, but throws TypeErrorhighlight(`a\nbcd`,2,5);// ❌ Expect to add `data-wrap` after `bcd` in second `.line`, but throws TypeErrorhighlight(`a\nbcd`,5,5);
Error Log
file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:1022
const children = lineEl.children.slice(startIndex, endIndex);
^
TypeError: Cannot read properties of undefined (reading 'children')
at applyLineSection (file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:1022:41)
at Object.code (file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:1066:21)
at tokensToHast (file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:1215:43)
at codeToHast (file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:1113:12)
at codeToHtml (file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:4685:25)
at Object.codeToHtml (file:///Users/~/shiki-error/node_modules/.pnpm/@shikijs+core@1.11.0/node_modules/@shikijs/core/dist/index.mjs:5605:40)
at highlight (/Users/~/shiki-error/src/index.ts:9:4)
at <anonymous> (/Users/~/shiki-error/src/index.ts:22:13)
Node.js v20.14.0
Validations
Describe the bug
Thanks for the project! I'm running into an
undefined
access bug preventing highlighting of the final index when using the decorations API. Looks like normalizePosition adds an invalid decoration (line is lines.length) and thereforeconst lineEl = lines[line];
in applyLineSection isundefined
. I can submit a test and PR within the next couple days if it's still open.Basic Reproduction
Error Log
Reproduction
https://stackblitz.com/edit/stackblitz-starters-w5wlgw
Contributes
The text was updated successfully, but these errors were encountered: