-
Notifications
You must be signed in to change notification settings - Fork 381
Enhance sourceMapIncludeSources option #2713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,6 @@ | |
| // MIT-style license that can be found in the LICENSE file or at | ||
| // https://opensource.org/licenses/MIT. | ||
|
|
||
| import 'dart:convert'; | ||
|
|
||
| import 'package:cli_pkg/js.dart'; | ||
| import 'package:path/path.dart' as p; | ||
|
|
||
|
|
@@ -18,8 +16,8 @@ import 'importer/no_op.dart'; | |
| import 'io.dart'; | ||
| import 'logger.dart'; | ||
| import 'logger/deprecation_processing.dart'; | ||
| import 'source_map_include_sources.dart'; | ||
| import 'syntax.dart'; | ||
| import 'utils.dart'; | ||
| import 'visitor/async_evaluate.dart'; | ||
| import 'visitor/serialize.dart'; | ||
|
|
||
|
|
@@ -42,6 +40,8 @@ Future<CompileResult> compileAsync( | |
| bool quietDeps = false, | ||
| bool verbose = false, | ||
| bool sourceMap = false, | ||
| SourceMapIncludeSources sourceMapIncludeSources = | ||
| SourceMapIncludeSources.always, | ||
| bool charset = true, | ||
| Iterable<Deprecation>? silenceDeprecations, | ||
| Iterable<Deprecation>? fatalDeprecations, | ||
|
|
@@ -88,6 +88,7 @@ Future<CompileResult> compileAsync( | |
| lineFeed, | ||
| quietDeps, | ||
| sourceMap, | ||
| sourceMapIncludeSources, | ||
| charset, | ||
| ); | ||
|
|
||
|
|
@@ -117,6 +118,8 @@ Future<CompileResult> compileStringAsync( | |
| bool quietDeps = false, | ||
| bool verbose = false, | ||
| bool sourceMap = false, | ||
| SourceMapIncludeSources sourceMapIncludeSources = | ||
| SourceMapIncludeSources.always, | ||
| bool charset = true, | ||
| Iterable<Deprecation>? silenceDeprecations, | ||
| Iterable<Deprecation>? fatalDeprecations, | ||
|
|
@@ -156,6 +159,7 @@ Future<CompileResult> compileStringAsync( | |
| lineFeed, | ||
| quietDeps, | ||
| sourceMap, | ||
| sourceMapIncludeSources, | ||
| charset, | ||
| ); | ||
|
|
||
|
|
@@ -179,6 +183,7 @@ Future<CompileResult> _compileStylesheet( | |
| LineFeed? lineFeed, | ||
| bool quietDeps, | ||
| bool sourceMap, | ||
| SourceMapIncludeSources sourceMapIncludeSources, | ||
| bool charset, | ||
| ) async { | ||
| if (nodeImporter != null) { | ||
|
|
@@ -188,6 +193,23 @@ Future<CompileResult> _compileStylesheet( | |
| 'Dart Sass 2.0.0.\n\n' | ||
| 'More info: https://sass-lang.com/d/legacy-js-api', | ||
| ); | ||
| } else { | ||
| if (sourceMapIncludeSources == SourceMapIncludeSources.true_ || | ||
| sourceMapIncludeSources == SourceMapIncludeSources.false_) { | ||
| var boolean = sourceMapIncludeSources == SourceMapIncludeSources.true_; | ||
| var suggestion = boolean ? 'always' : 'never'; | ||
| logger?.warnForDeprecation( | ||
| Deprecation.sourceMapIncludeSourcesBoolean, | ||
| 'Passing a boolean value for Options.sourceMapIncludeSources is ' | ||
| 'deprecated and will be removed in Dart Sass 2.0.0.\n' | ||
| "Please use '$suggestion' instead of $boolean.\n\n" | ||
| 'More info: https://sass-lang.com/d/source-map-include-sources-boolean', | ||
| ); | ||
|
Comment on lines
+201
to
+207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be handled at the JS level.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, if you just look at a few lines above, the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's probably something we'll need to fix sooner or later anyway as APIs evolve over time. The 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 |
||
| sourceMapIncludeSources = | ||
| sourceMapIncludeSources == SourceMapIncludeSources.true_ | ||
| ? SourceMapIncludeSources.always | ||
| : SourceMapIncludeSources.never; | ||
| } | ||
| } | ||
| var evaluateResult = await evaluateAsync( | ||
| stylesheet, | ||
|
|
@@ -212,16 +234,22 @@ Future<CompileResult> _compileStylesheet( | |
| ); | ||
|
|
||
| var resultSourceMap = serializeResult.sourceMap; | ||
| if (resultSourceMap != null && importCache != null) { | ||
| mapInPlace( | ||
| resultSourceMap.urls, | ||
| (url) => url == '' | ||
| ? Uri.dataFromString( | ||
| stylesheet.span.file.getText(0), | ||
| encoding: utf8, | ||
| ).toString() | ||
| : importCache.sourceMapUrl(Uri.parse(url)).toString(), | ||
| ); | ||
| if (resultSourceMap != null) { | ||
| if (importCache != null) { | ||
| for (var i = 0, length = resultSourceMap.urls.length; i < length; i++) { | ||
| var canonicalUrl = Uri.parse(resultSourceMap.urls[i]); | ||
| var sourceMapUrl = importCache.sourceMapUrlOrNull(canonicalUrl); | ||
| if (sourceMapUrl != null) { | ||
| resultSourceMap.urls[i] = sourceMapUrl.toString(); | ||
| if (sourceMapIncludeSources == SourceMapIncludeSources.auto) { | ||
| resultSourceMap.files[i] = null; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (sourceMapIncludeSources == SourceMapIncludeSources.never) { | ||
| resultSourceMap.files.fillRange(0, resultSourceMap.files.length, null); | ||
| } | ||
| } | ||
|
|
||
| return CompileResult(evaluateResult, serializeResult); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
nullfor "do the default behavior". Better to make this nullable and handle the fallback in the method body.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.