File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1
1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
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
+
3
29
exports[`compiler: codeframe > line in middle 1`] = `
4
30
"2 | <template key = " one" ></template >
5
31
3 | <ul >
Original file line number Diff line number Diff line change 44
44
expect ( generateCodeFrame ( source , attrStart , attrEnd ) ) . toMatchSnapshot ( )
45
45
} )
46
46
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
+
47
53
{
48
54
const source = `
49
55
<template>
Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ export function generateCodeFrame(
5
5
start = 0 ,
6
6
end = source . length ,
7
7
) : 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
+
8
14
// Split the content into individual lines but capture the newline sequence
9
15
// that separated each line. This is important because the actual sequence is
10
16
// needed to properly take into account the full line length for offset
You can’t perform that action at this time.
0 commit comments