Skip to content

Commit ad1ce09

Browse files
authored
Improve scope filtering heuristic (#1077)
* Improve scope filtering heuristic * fix tests
1 parent caba0d7 commit ad1ce09

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
module information to `Dwds`.
1010
- Hide JavaScript type errors when hovering over text in the debugger.
1111
- Fix an issue where reusing a connection could cause a null error.
12+
- Improve the heuristic which filters JS scopes for debugging needs.
1213

1314
**Breaking Changes:**
1415
- Require access to the `.ddc_merged_metadata` file.

dwds/lib/src/debugging/dart_scope.dart

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,12 @@ Future<List<Property>> visibleProperties({
6464
/// Filters the provided frame scopes to those that are pertinent for Dart
6565
/// debugging.
6666
List<WipScope> filterScopes(WipCallFrame frame) {
67-
// For RequireJS modules, the last three scopes are generally
68-
// `[unnamed closure] [script] [global]` in that order. We never want the
69-
// global and script scopes. We don't want the last closure scope - that's the
70-
// Dart SDK scope, and contains hundreds or thousands of properties (as does
71-
// the global scope).
72-
73-
// For AMD modules, the last two scopes are generally
74-
// `[named closure] [global]` in that order. The named closure is the Dart SDK
75-
// scope.
76-
77-
// Below, we filter out the last (global) scope, the optional script scope,
78-
// and the first (named or unnamed) closure scope. In the future, we'll likey
79-
// have more rigourous ways to identify the SDK scope.
80-
8167
var scopes = frame.getScopeChain().toList();
82-
83-
if (scopes.isNotEmpty && scopes.last.scope == 'global') {
68+
// Remove outer scopes up to and including the Dart SDK.
69+
while (
70+
scopes.isNotEmpty && !(scopes.last.name?.startsWith('load__') ?? false)) {
8471
scopes.removeLast();
8572
}
86-
87-
if (scopes.isNotEmpty && scopes.last.scope == 'script') {
88-
scopes.removeLast();
89-
}
90-
91-
if (scopes.isNotEmpty && scopes.last.scope == 'closure') {
92-
scopes.removeLast();
93-
}
94-
73+
if (scopes.isNotEmpty) scopes.removeLast();
9574
return scopes;
9675
}

dwds/test/fixtures/debugger_data.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ List<Map<String, dynamic>> frames1Json = [
6060
},
6161
{
6262
"type": "closure",
63+
"name": "load__some_module",
6364
"object": {
6465
"type": "object",
6566
"className": "Object",

0 commit comments

Comments
 (0)