-
Notifications
You must be signed in to change notification settings - Fork 373
Description
- Proposal (Enhance sourceMapIncludeSources option sass#4170)
- Deprecation
- Specification
- Tests (Enhance sourceMapIncludeSources option sass-spec#2097)
- Dart Sass (Enhance sourceMapIncludeSources option #2713)
- Embedded host (Enhance sourceMapIncludeSources option embedded-host-node#411)
- Breaking change
- Specification
- Tests
- Dart Sass
- Embedded Host
dart-sass/lib/src/async_import_cache.dart
Lines 371 to 375 in 62ec662
| /// Returns the URL to use in the source map to refer to [canonicalUrl]. | |
| /// | |
| /// Returns [canonicalUrl] as-is if it hasn't been loaded by this cache. | |
| Uri sourceMapUrl(Uri canonicalUrl) => | |
| _resultsCache[canonicalUrl]?.sourceMapUrl ?? canonicalUrl; |
In ImportCache, the sourceMapUrl always fallback to canonicalUrl for null.
dart-sass/lib/src/importer/result.dart
Lines 20 to 28 in 62ec662
| /// An absolute, browser-accessible URL indicating the resolved location of | |
| /// the imported stylesheet. | |
| /// | |
| /// This should be a `file:` URL if one is available, but an `http:` URL is | |
| /// acceptable as well. If no URL is supplied, a `data:` URL is generated | |
| /// automatically from [contents]. | |
| Uri get sourceMapUrl => | |
| _sourceMapUrl ?? Uri.dataFromString(contents, encoding: utf8); | |
| final Uri? _sourceMapUrl; |
However, in ImporterResult it already fallbacks to a data url for null, so in the ImportCache it will never actually fallback to the canonicalUrl.
This causes undesired bloats with sourceMapIncludeSources: true, where the source contents are included and the sourceMapUrl are encoded version of the exact same source contents. On the other hand, with sourceMapIncludeSources: false, the source map can still contain the source contents via data uri, despite being explicitly told to not expose contents.
The comments around the original code makes be believe the intention was to provide source map for source map url that's not file: protocol. However, modern browser can handle non-file: url in source map just fine, especially when source contents are present.