Skip to content

Commit 3bd0258

Browse files
author
Chris K
committed
Fix for DFL-3333, JS source tooltips throw with Syntax errors on nested arrays.
1 parent 53f82ed commit 3bd0258

File tree

1 file changed

+53
-5
lines changed

1 file changed

+53
-5
lines changed

src/ecma-debugger/jssourcetooltip.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ cls.JSSourceTooltip = function(view)
147147
box, shift_key)
148148
{
149149
var sel = _get_identifier(script, line_number, char_offset, shift_key);
150-
if (sel)
150+
if (sel && sel.bracket_balance == 0)
151151
{
152152
var start = script.line_arr[sel.start_line - 1] + sel.start_offset;
153153
var end = script.line_arr[sel.end_line - 1] + sel.end_offset;
@@ -322,7 +322,8 @@ cls.JSSourceTooltip = function(view)
322322
return {start_line: start.start_line,
323323
start_offset: start.start_offset,
324324
end_line: end.end_line,
325-
end_offset: end.end_offset};
325+
end_offset: end.end_offset,
326+
bracket_balance: start.bracket_stack_count + end.bracket_stack_count};
326327
}
327328
}
328329
else
@@ -334,10 +335,12 @@ cls.JSSourceTooltip = function(view)
334335
var start = _get_line_and_offset(range.startContainer, range.startOffset);
335336
var end = _get_line_and_offset(range.endContainer, range.endOffset);
336337
if (start && end)
338+
{
337339
return {start_line: start.line_number,
338340
start_offset: start.offset,
339341
end_line: end.line_number,
340342
end_offset: end.offset - 1};
343+
}
341344
}
342345
}
343346

@@ -384,6 +387,25 @@ cls.JSSourceTooltip = function(view)
384387
continue;
385388
}
386389

390+
if (shift_key && bracket_stack.length)
391+
{
392+
if (token[TYPE] == PUNCTUATOR)
393+
{
394+
if (token[VALUE] == "]")
395+
{
396+
bracket_stack.push(token[VALUE])
397+
previous_token = token;
398+
}
399+
if (token[VALUE] == "[")
400+
{
401+
bracket_stack.pop();
402+
previous_token = token;
403+
}
404+
}
405+
index = i - 1;
406+
continue;
407+
}
408+
387409
switch (previous_token[TYPE])
388410
{
389411
case IDENTIFIER:
@@ -547,7 +569,9 @@ cls.JSSourceTooltip = function(view)
547569
break
548570
}
549571

550-
return {start_line: start_line, start_offset: _get_sum(tokens, index)};
572+
return {start_line: start_line,
573+
start_offset: _get_sum(tokens, index),
574+
bracket_stack_count: bracket_stack.length};
551575
};
552576

553577
var _get_identifier_chain_end = function(script, line_number, tokens,
@@ -568,7 +592,9 @@ cls.JSSourceTooltip = function(view)
568592

569593
while (bracket_stack.length || (shift_key && parens_stack.length))
570594
{
571-
for (var i = match_index + 1, token = null; token = tokens[i]; i++)
595+
for (var i = match_index + 1, token = null, break_loop = false;
596+
!break_loop && (token = tokens[i]);
597+
i++)
572598
{
573599
// consume everything between parentheses if shiftKey is pressed
574600
if (shift_key && parens_stack.length)
@@ -590,6 +616,25 @@ cls.JSSourceTooltip = function(view)
590616
continue;
591617
}
592618

619+
if (shift_key && bracket_stack.length)
620+
{
621+
if (token[TYPE] == PUNCTUATOR)
622+
{
623+
if (token[VALUE] == "[")
624+
{
625+
bracket_stack.push(token[VALUE])
626+
previous_token = token;
627+
}
628+
if (token[VALUE] == "]")
629+
{
630+
bracket_stack.pop();
631+
previous_token = token;
632+
}
633+
}
634+
index = i;
635+
continue;
636+
}
637+
593638
if (!bracket_stack.length)
594639
break;
595640

@@ -723,6 +768,7 @@ cls.JSSourceTooltip = function(view)
723768
}
724769
}
725770
}
771+
break_loop = true;
726772
break;
727773
}
728774
}
@@ -754,7 +800,9 @@ cls.JSSourceTooltip = function(view)
754800
break
755801
}
756802

757-
return {end_line: start_line, end_offset: _get_sum(tokens, index) - 1};
803+
return {end_line: start_line,
804+
end_offset: _get_sum(tokens, index) - 1,
805+
bracket_stack_count: bracket_stack.length};
758806
};
759807

760808
var _get_line_and_offset = function(node, offset)

0 commit comments

Comments
 (0)