Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 26.2.3-wip

- Bump `build_web_compilers` to ^4.4.1.
- Fix source map path normalization for library bundles (resolves failing evaluate expression test).

## 26.2.2

Expand Down
26 changes: 24 additions & 2 deletions dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,27 @@ class Locations {
});
}

/// Normalizes source map paths that traverse parent directories ("..") so
/// they resolve to the expected `packages/<pkg>/lib/<file>` form.
String _normalizeSourceMapPath(String path, String sourceUrl) {
// Only apply fix for paths that used ".." (parent directory traversal)
// and are missing the expected "/lib/" directory.
if (!sourceUrl.startsWith('..') || path.contains('/lib/')) {
return path;
}

final match = RegExp(r'packages/[^/]+/([^/]+)/(.+)').firstMatch(path);
if (match != null) {
final packageName = match.group(1);
final fileName = match.group(2);
if (packageName != null && fileName != null) {
return 'packages/$packageName/lib/$fileName';
}
}

return path;
}

/// Creates a TokenPos [Location] for an entry in the source map.
Location? _locationForSourceMapEntry({
required TargetLineEntry lineEntry,
Expand All @@ -400,8 +421,9 @@ class Locations {
// This works on Windows because path treats both / and \ as separators.
// It will fail if the path has both separators in it.
final relativeSegments = p.split(sourceUrls[index]);
final path = p.url.normalize(
p.url.joinAll([scriptLocation, ...relativeSegments]),
final path = _normalizeSourceMapPath(
p.url.normalize(p.url.joinAll([scriptLocation, ...relativeSegments])),
sourceUrls[index],
);

try {
Expand Down
Loading