Skip to content

Commit cdc5cc3

Browse files
authored
Pass script uri for javascript expression compilation (#2682)
Pass the script uri for expression compilation; add test for expression compilation in parts.
1 parent 29ba1b1 commit cdc5cc3

25 files changed

+862
-354
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## 25.1.1-wip
1+
## 26.0.0-wip
22

33
- Bump SDK constraint to ^3.10.0
4+
- Added 'scriptUri' parameter to compileExpressionToJs
45

56
## 25.1.0
67

dwds/lib/src/debugging/modules.dart

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class Modules {
2222

2323
// The Dart server path to library import uri
2424
final _sourceToLibrary = <String, Uri>{};
25+
26+
// The Dart server path to library/part import uri
27+
final _sourceToLibraryOrPart = <String, Uri>{};
28+
29+
// Library import uri to list of script (parts) dart server path for the
30+
// library.
31+
final _scriptsForLibrary = <Uri, List<String>>{};
32+
2533
var _moduleMemoizer = AsyncMemoizer<void>();
2634

2735
final Map<String, String> _libraryToModule = {};
@@ -45,7 +53,18 @@ class Modules {
4553
assert(_entrypoint == entrypoint);
4654
for (final library in modifiedModuleReport.modifiedLibraries) {
4755
final libraryServerPath = _getLibraryServerPath(library);
48-
_sourceToLibrary.remove(libraryServerPath);
56+
final libraryUri = _sourceToLibrary.remove(libraryServerPath);
57+
_sourceToLibraryOrPart.remove(libraryServerPath);
58+
if (libraryUri != null) {
59+
final scriptServerPaths = _scriptsForLibrary[libraryUri];
60+
if (scriptServerPaths != null) {
61+
for (final scriptServerPath in scriptServerPaths) {
62+
_sourceToLibraryOrPart.remove(scriptServerPath);
63+
_sourceToLibrary.remove(scriptServerPath);
64+
}
65+
_scriptsForLibrary.remove(libraryUri);
66+
}
67+
}
4968
_sourceToModule.remove(libraryServerPath);
5069
_libraryToModule.remove(library);
5170
}
@@ -57,6 +76,8 @@ class Modules {
5776
}
5877
_entrypoint = entrypoint;
5978
_sourceToLibrary.clear();
79+
_sourceToLibraryOrPart.clear();
80+
_scriptsForLibrary.clear();
6081
_sourceToModule.clear();
6182
_libraryToModule.clear();
6283
_moduleToSources.clear();
@@ -81,6 +102,13 @@ class Modules {
81102
return _sourceToLibrary[serverPath];
82103
}
83104

105+
/// Returns the importUri of the library or part for the provided Dart server
106+
/// path.
107+
Future<Uri?> libraryOrPartForSource(String serverPath) async {
108+
await _moduleMemoizer.runOnce(_initializeMapping);
109+
return _sourceToLibraryOrPart[serverPath];
110+
}
111+
84112
Future<String?> moduleForLibrary(String libraryUri) async {
85113
await _moduleMemoizer.runOnce(_initializeMapping);
86114
return _libraryToModule[libraryUri];
@@ -105,7 +133,8 @@ class Modules {
105133
? library
106134
: DartUri(library, _root).serverPath;
107135

108-
/// Initializes [_sourceToModule], [_moduleToSources], and [_sourceToLibrary].
136+
/// Initializes [_sourceToModule], [_moduleToSources], [_sourceToLibrary] and
137+
/// [_sourceToLibraryOrPart].
109138
///
110139
/// If [modifiedModuleReport] is not null, only updates the maps for the
111140
/// modified libraries in the report.
@@ -125,6 +154,7 @@ class Modules {
125154
// it, so it's okay to only process the modified libraries.
126155
continue;
127156
}
157+
final libraryUri = Uri.parse(library);
128158
final scripts = libraryToScripts[library]!;
129159
final libraryServerPath = _getLibraryServerPath(library);
130160

@@ -133,15 +163,17 @@ class Modules {
133163

134164
_sourceToModule[libraryServerPath] = module;
135165
_moduleToSources.putIfAbsent(module, () => {}).add(libraryServerPath);
136-
_sourceToLibrary[libraryServerPath] = Uri.parse(library);
166+
_sourceToLibrary[libraryServerPath] = libraryUri;
167+
_sourceToLibraryOrPart[libraryServerPath] = libraryUri;
137168
_libraryToModule[library] = module;
138169

139170
for (final script in scripts) {
140171
final scriptServerPath = _getLibraryServerPath(script);
141-
142172
_sourceToModule[scriptServerPath] = module;
143173
_moduleToSources[module]!.add(scriptServerPath);
144-
_sourceToLibrary[scriptServerPath] = Uri.parse(library);
174+
_sourceToLibrary[scriptServerPath] = libraryUri;
175+
_sourceToLibraryOrPart[scriptServerPath] = Uri.parse(script);
176+
(_scriptsForLibrary[libraryUri] ??= []).add(scriptServerPath);
145177
}
146178
} else {
147179
_logger.warning('No module found for library $library');

0 commit comments

Comments
 (0)