Conversation
99f61c2 to
a4cac51
Compare
76ad1db to
8b82801
Compare
8b82801 to
a3e2139
Compare
8fe2160 to
44acc05
Compare
c8be35d to
4564d85
Compare
4564d85 to
331db67
Compare
331db67 to
7b78a30
Compare
d39b1dc to
7f1e685
Compare
7f1e685 to
6555562
Compare
4ff78a6 to
be48ba7
Compare
nex3
left a comment
There was a problem hiding this comment.
Just a preliminary review so far.
|
|
||
| import '../source_map_include_sources.dart'; | ||
|
|
||
| Map<String, dynamic> sourceMapToJson(SingleMapping sourceMap, |
|
|
||
| @Deprecated('Use always instead.') | ||
| true_, | ||
|
|
||
| @Deprecated('Use never instead.') | ||
| false_, |
There was a problem hiding this comment.
There's no need to include these in the Dart enum. It's not actually providing any more backwards-compatibility.
There was a problem hiding this comment.
I added these to throw deprecation warnings… It turns out the logger for throwing deprecation warnings isn’t accessible at JS interop code so I had to pass these value into Dart code and throw it there.
| /// | ||
| /// {@category Compile} | ||
| enum SourceMapIncludeSources { | ||
| /// Let compiler decide whether to include each source content. |
There was a problem hiding this comment.
We can be more specific about this: source contents are included only for sources for which ImporterResult.sourceMapUrl isn't set.
| sourceMapIncludeSources == SourceMapIncludeSources.always || | ||
| (sourceMapIncludeSources == SourceMapIncludeSources.auto && | ||
| sourceMap.files.any((file) => file != null))); |
There was a problem hiding this comment.
I don't think this logic is right, for several reasons. First, Sass only deals in FileSpans—every span will have a SourceFile, because we know the whole file it was parsed from. None of these should be null, even if they don't have a defined source map URL. Second, this flag is all-or-nothing: it'll either include the sourcesContent for every file in the map, or for none of them. I think we'll need to submit an upstream change to make it possible to select whether to include the contents on a file-by-file basis.
There was a problem hiding this comment.
This flag is to change whether the output source map will have sourceContent key or not. E.g. For never we can omit the whole sourceContent key. For autowe can omit the key if every sourceContent is null.
There was a problem hiding this comment.
Right, but checking whether files are null isn't the right way to do that... every SourceLocation we pass in will be a FileLocation, and so have a non-null file. In addition, we need to filter out the contents of files whose URLs we know in auto mode.
There was a problem hiding this comment.
every SourceLocation we pass in will be a FileLocation
That's exactly what I was saying, that the Dart API's default was "always".
For "auto" and "never" to actually work for Dart API, they are conditionally set to null here in post processing: https://github.com/ntkme/dart-sass/blob/0cceb8aa1de82c58123dd93a11106cff62c13dbd/lib/src/async_compile.dart#L242-L251
From Dart's source_maps lib:
https://pub.dev/documentation/source_maps/latest/source_maps.parser/SingleMapping/files.html
Files whose contents aren't available are null.
| Uri get sourceMapUrl => | ||
| _sourceMapUrl ?? Uri.dataFromString(contents, encoding: utf8); | ||
| final Uri? _sourceMapUrl; | ||
| /// An absolute URL indicating the resolved location of the imported stylesheet. |
There was a problem hiding this comment.
It's probably worth also describing how this interacts with the sourceMapIncludeSources option.
| SourceMapIncludeSources sourceMapIncludeSources = | ||
| SourceMapIncludeSources.always, |
There was a problem hiding this comment.
Shouldn't this default to auto?
Also, in Dart it's generally a good practice to avoid default parameters for anything other than booleans, because it breaks the ability for callers to pass in null for "do the default behavior". Better to make this nullable and handle the fallback in the method body.
There was a problem hiding this comment.
The previous behavior of Dart API without this option is effectively “always”, the previous “auto” behavior is done via post processing in Dart-JS code only.
There was a problem hiding this comment.
I'm okay with changing the default here for Dart Sass callers, since the previous default didn't make a lot of sense anyway. Either way, this should by nullable and handle the default in the body.
| logger?.warnForDeprecation( | ||
| Deprecation.sourceMapIncludeSourcesBoolean, | ||
| 'Passing boolean value for Options.sourceMapIncludeSources is ' | ||
| 'deprecated and will be removed in Dart Sass 2.0.0.\n\n' | ||
| 'More info: https://sass-lang.com/d/source-map-include-sources-boolean', | ||
| ); |
There was a problem hiding this comment.
This should be handled at the JS level.
There was a problem hiding this comment.
The logger object isn’t available at JS level. Also throwing it here allow us to only need to throw in a single code path, instead of need to duplicate it in multiple code paths.
There was a problem hiding this comment.
In fact, if you just look at a few lines above, the legacy JS API warning is done here, instead of in the JS API code, I think for exactly same reason...
There was a problem hiding this comment.
I think that's probably something we'll need to fix sooner or later anyway as APIs evolve over time. The DeprecationProcessingLogger initialization isn't that complex; we should be able to copy it into the JS code and then check if the logger that's passed in to compile*Async is already deprecation-processing and avoid rewrapping if so.
Either way, we shouldn't expose immediately-deprecated enum fields in a new Dart API. If we had to handle that, we should either make this parameter Object or have two separate enums.
be48ba7 to
c4a7a9a
Compare
sourceMapUrlfallback inImporterResultcreates bloated source map output with source contents as source urls #2712sass/sass#4170
sass/sass-spec#2097
sass/embedded-host-node#411