This repository was archived by the owner on Jul 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 11// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22
3+ exports [` compiler: codeframe > invalid start and end 1` ] = `
4+ "1 | <div >
5+ | ^
6+ 2 | <template key = " one" ></template >
7+ 3 | <ul >"
8+ `;
9+
10+ exports[`compiler: codeframe > invalid start and end 2`] = `
11+ "1 | <div >
12+ | ^^^^^
13+ 2 | <template key = " one" ></template >
14+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+ 3 | <ul >
16+ | ^^^^^^
17+ 4 | <li v-for = " foobar" >hi</li >
18+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+ 5 | </ul >
20+ | ^^^^^^^
21+ 6 | <template key = " two" ></template >
22+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+ 7 | </div >
24+ | ^^^^^^"
25+ `;
26+
27+ exports[`compiler: codeframe > invalid start and end 3`] = `""`;
28+
329exports[`compiler: codeframe > line in middle 1`] = `
430"2 | <template key = " one" ></template >
5313 | <ul >
Original file line number Diff line number Diff line change 4444 expect ( generateCodeFrame ( source , attrStart , attrEnd ) ) . toMatchSnapshot ( )
4545 } )
4646
47+ test ( 'invalid start and end' , ( ) => {
48+ expect ( generateCodeFrame ( source , - Infinity , 0 ) ) . toMatchSnapshot ( )
49+ expect ( generateCodeFrame ( source , 0 , Infinity ) ) . toMatchSnapshot ( )
50+ expect ( generateCodeFrame ( source , Infinity , 0 ) ) . toMatchSnapshot ( )
51+ } )
52+
4753 {
4854 const source = `
4955<template>
Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ export function generateCodeFrame(
55 start = 0 ,
66 end = source . length ,
77) : string {
8+ // Ensure start and end are within the source length
9+ start = Math . max ( 0 , Math . min ( start , source . length ) )
10+ end = Math . max ( 0 , Math . min ( end , source . length ) )
11+
12+ if ( start > end ) return ''
13+
814 // Split the content into individual lines but capture the newline sequence
915 // that separated each line. This is important because the actual sequence is
1016 // needed to properly take into account the full line length for offset
You can’t perform that action at this time.
0 commit comments