Skip to content

Commit 43a7210

Browse files
committed
Pass the script uri for expression compilation; add test for expression compilation in parts.
1 parent 769a056 commit 43a7210

20 files changed

+540
-28
lines changed

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];
@@ -106,7 +134,8 @@ class Modules {
106134
? library
107135
: DartUri(library, _root).serverPath;
108136

109-
/// Initializes [_sourceToModule], [_moduleToSources], and [_sourceToLibrary].
137+
/// Initializes [_sourceToModule], [_moduleToSources], [_sourceToLibrary] and
138+
/// [_sourceToLibraryOrPart].
110139
///
111140
/// If [modifiedModuleReport] is not null, only updates the maps for the
112141
/// modified libraries in the report.
@@ -126,6 +155,7 @@ class Modules {
126155
// it, so it's okay to only process the modified libraries.
127156
continue;
128157
}
158+
final libraryUri = Uri.parse(library);
129159
final scripts = libraryToScripts[library]!;
130160
final libraryServerPath = _getLibraryServerPath(library);
131161

@@ -134,15 +164,17 @@ class Modules {
134164

135165
_sourceToModule[libraryServerPath] = module;
136166
_moduleToSources.putIfAbsent(module, () => {}).add(libraryServerPath);
137-
_sourceToLibrary[libraryServerPath] = Uri.parse(library);
167+
_sourceToLibrary[libraryServerPath] = libraryUri;
168+
_sourceToLibraryOrPart[libraryServerPath] = libraryUri;
138169
_libraryToModule[library] = module;
139170

140171
for (final script in scripts) {
141172
final scriptServerPath = _getLibraryServerPath(script);
142-
143173
_sourceToModule[scriptServerPath] = module;
144174
_moduleToSources[module]!.add(scriptServerPath);
145-
_sourceToLibrary[scriptServerPath] = Uri.parse(library);
175+
_sourceToLibrary[scriptServerPath] = libraryUri;
176+
_sourceToLibraryOrPart[scriptServerPath] = Uri.parse(script);
177+
(_scriptsForLibrary[libraryUri] ??= []).add(scriptServerPath);
146178
}
147179
} else {
148180
_logger.warning('No module found for library $library');

dwds/lib/src/services/expression_compiler.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ abstract class ExpressionCompiler {
6363
Future<ExpressionCompilationResult> compileExpressionToJs(
6464
String isolateId,
6565
String libraryUri,
66+
String scriptUri,
6667
int line,
6768
int column,
6869
Map<String, String> jsModules,

dwds/lib/src/services/expression_compiler_service.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class _Compiler {
144144

145145
Future<ExpressionCompilationResult> compileExpressionToJs(
146146
String libraryUri,
147+
String scriptUri,
147148
int line,
148149
int column,
149150
Map<String, String> jsModules,
@@ -171,6 +172,7 @@ class _Compiler {
171172
'jsModules': jsModules,
172173
'jsScope': jsFrameValues,
173174
'libraryUri': libraryUri,
175+
'scriptUri': scriptUri,
174176
'moduleName': moduleName,
175177
});
176178

@@ -241,6 +243,7 @@ class ExpressionCompilerService implements ExpressionCompiler {
241243
Future<ExpressionCompilationResult> compileExpressionToJs(
242244
String isolateId,
243245
String libraryUri,
246+
String scriptUri,
244247
int line,
245248
int column,
246249
Map<String, String> jsModules,
@@ -249,6 +252,7 @@ class ExpressionCompilerService implements ExpressionCompiler {
249252
String expression,
250253
) async => (await _compiler.future).compileExpressionToJs(
251254
libraryUri,
255+
scriptUri,
252256
line,
253257
column,
254258
jsModules,

dwds/lib/src/services/expression_evaluator.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ class ExpressionEvaluator {
125125
final compilationResult = await _compiler.compileExpressionToJs(
126126
isolateId,
127127
libraryUri.toString(),
128+
// Evaluating at "the library level" (and passing line 0 column 0) we'll
129+
// also just pass the library uri as the script uri.
130+
libraryUri.toString(),
128131
0,
129132
0,
130133
{},
@@ -280,6 +283,7 @@ class ExpressionEvaluator {
280283
final dartLocation = locationMap.dartLocation;
281284
final dartSourcePath = dartLocation.uri.serverPath;
282285
final libraryUri = await _modules.libraryForSource(dartSourcePath);
286+
final scriptUri = await _modules.libraryOrPartForSource(dartSourcePath);
283287
if (libraryUri == null) {
284288
return createError(
285289
EvaluationErrorKind.internal,
@@ -298,6 +302,7 @@ class ExpressionEvaluator {
298302
_logger.finest(
299303
'Evaluating "$expression" at $module, '
300304
'$libraryUri:${dartLocation.line}:${dartLocation.column} '
305+
'or rather $scriptUri:${dartLocation.line}:${dartLocation.column} '
301306
'with scope: $scope',
302307
);
303308

@@ -317,6 +322,7 @@ class ExpressionEvaluator {
317322
final compilationResult = await _compiler.compileExpressionToJs(
318323
isolateId,
319324
libraryUri.toString(),
325+
scriptUri.toString(),
320326
dartLocation.line,
321327
dartLocation.column,
322328
{},
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@TestOn('vm')
6+
@Timeout(Duration(minutes: 2))
7+
library;
8+
9+
import 'package:test/test.dart';
10+
import 'package:test_common/test_sdk_configuration.dart';
11+
12+
import 'evaluate_parts_common.dart';
13+
import 'fixtures/context.dart';
14+
15+
void main() async {
16+
// Enable verbose logging for debugging.
17+
const debug = false;
18+
19+
final provider = TestSdkConfigurationProvider(verbose: debug);
20+
tearDownAll(provider.dispose);
21+
22+
testAll(
23+
provider: provider,
24+
compilationMode: CompilationMode.buildDaemon,
25+
debug: debug,
26+
);
27+
}

0 commit comments

Comments
 (0)