Skip to content

Commit 9ada46f

Browse files
authored
Hide more temporary variables when debugging (#2445)
Some variables created by DDC that are not present in the original source code were being shown by the debugger in the local scope. Update the regular expression used to detect temporary variable names. It has been simplified to: if the variable starts with 't$' or contains '$35' then it should be hidden. DDC names it's temporary variables to start with the characters `t$`. Hiding all of these does hide some valid variable names that could appear in the original source, but that is the status quo and not being changed here. In addition some names that are created by the CFE and added to the program contain an illegal character '#' which DDC replaces as '$35'. Variables with this sequence in the name can't appear in the original source so we hide them as well. This should hide variables synthetically added to support late local variables.
1 parent a97c2a1 commit 9ada46f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- Respect the value of `pause_isolates_on_start` during page-refreshes. - [#2431](https://github.com/dart-lang/webdev/pull/2431)
55
- Fix issue where DAP clients wouldn't resume after a restart. - [#2441](https://github.com/dart-lang/webdev/pull/2441)
66
- Add implementation for the VM Service's `getFlagList` API. - [#2438](https://github.com/dart-lang/webdev/pull/2438)
7+
- Hide more variables from the local scope when debugging. These variables were synthetically added by the compiler to
8+
support late local variables and don't appear in the original source code. - [#2445](https://github.com/dart-lang/webdev/pull/2445)
79

810
## 24.0.0
911

dwds/lib/src/debugging/dart_scope.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1212
/// TODO(annagrin) - use an alternative way to identify
1313
/// synthetic variables.
1414
/// Issue: https://github.com/dart-lang/sdk/issues/44262
15-
final ddcTemporaryVariableRegExp = RegExp(r'^t(\$[0-9]*)+\w*$');
15+
final ddcTemporaryVariableRegExp = RegExp(
16+
// Starts with t$
17+
r'^t\$'
18+
// followed by anything
19+
r'.*'
20+
// or,
21+
r'|'
22+
// anything that contains the sequence '$35'.
23+
r'.*\$35.*');
1624
final ddcTemporaryTypeVariableRegExp = RegExp(r'^__t[\$\w*]+$');
1725

1826
/// Temporary variable regex before SDK changes for patterns.

dwds/test/variable_scope_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ void main() {
7171
ddcTemporaryVariableRegExp.hasMatch(r't$36$350$354$35isSet'),
7272
isTrue,
7373
);
74+
expect(
75+
ddcTemporaryVariableRegExp.hasMatch(r't$36$35variable$35isSet'),
76+
isTrue,
77+
);
78+
expect(
79+
ddcTemporaryVariableRegExp.hasMatch(r'synthetic$35variable'),
80+
isTrue,
81+
);
7482
expect(ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$TL'), isTrue);
7583
expect(ddcTemporaryTypeVariableRegExp.hasMatch(r'__t$StringN'), isTrue);
7684
expect(
@@ -84,6 +92,7 @@ void main() {
8492
expect(ddcTemporaryVariableRegExp.hasMatch(r't10'), isFalse);
8593
expect(ddcTemporaryVariableRegExp.hasMatch(r't10foo'), isFalse);
8694
expect(ddcTemporaryVariableRegExp.hasMatch(r'ten'), isFalse);
95+
expect(ddcTemporaryVariableRegExp.hasMatch(r'my$3635variable'), isFalse);
8796
});
8897
});
8998

0 commit comments

Comments
 (0)