File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -162,6 +162,40 @@ test(`should keep ESQuery highlights aligned while typing before a matching lite
162162 await expect ( highlight ) . toHaveText ( [ "42" ] ) ;
163163} ) ;
164164
165+ test ( `should not crash when an ESQuery selector matches a node with an empty range` , async ( {
166+ page,
167+ } ) => {
168+ const consoleErrors : string [ ] = [ ] ;
169+ page . on ( "console" , message => {
170+ if ( message . type ( ) === "error" ) {
171+ consoleErrors . push ( message . text ( ) ) ;
172+ }
173+ } ) ;
174+
175+ await page . goto ( "/" ) ;
176+
177+ const codeEditor = page . getByRole ( "textbox" , {
178+ name : "Code Editor" ,
179+ exact : true ,
180+ } ) ;
181+ const highlight = codeEditor . locator ( ".bg-editorHighlightedRangeColor" ) ;
182+
183+ await codeEditor . fill ( "" ) ;
184+
185+ await expect (
186+ page . getByRole ( "listitem" ) . filter ( { hasText : "bodyArray[]" } ) ,
187+ ) . toBeVisible ( ) ;
188+
189+ await page
190+ . getByRole ( "textbox" , { name : "ESQuery Selector" } )
191+ . fill ( "Program" ) ;
192+
193+ await codeEditor . fill ( "42;" ) ;
194+
195+ await expect ( highlight ) . toHaveText ( [ "42;" ] ) ;
196+ expect ( consoleErrors ) . toStrictEqual ( [ ] ) ;
197+ } ) ;
198+
165199test . describe ( "AST node expansion" , ( ) => {
166200 test . beforeEach ( async ( { page } ) => {
167201 await page . goto ( "/" ) ;
Original file line number Diff line number Diff line change @@ -7,9 +7,11 @@ const highlightRangeDecoration = Decoration.mark({
77
88function createHighlightedRangeDecorations ( ranges : SourceRange [ ] ) {
99 return Decoration . set (
10- ranges . map ( ( [ rangeFrom , rangeTo ] ) =>
11- highlightRangeDecoration . range ( rangeFrom , rangeTo ) ,
12- ) ,
10+ ranges
11+ . filter ( ( [ rangeFrom , rangeTo ] ) => rangeFrom < rangeTo )
12+ . map ( ( [ rangeFrom , rangeTo ] ) =>
13+ highlightRangeDecoration . range ( rangeFrom , rangeTo ) ,
14+ ) ,
1315 true ,
1416 ) ;
1517}
You can’t perform that action at this time.
0 commit comments