Skip to content

Commit

Permalink
Implement the sourceMapIncludeSources JS option
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Dec 27, 2021
1 parent a32000e commit 75534fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.46.0

* Add the `sourceMapIncludeSources` option in the new JS API.

## 1.45.1

* **Potentially breaking bug fix:** Properly parse custom properties in
Expand Down
12 changes: 6 additions & 6 deletions lib/src/node/compile.dart
Expand Up @@ -47,7 +47,7 @@ NodeCompileResult compile(String path, [CompileOptions? options]) {
ascii: ascii),
importers: options?.importers?.map(_parseImporter),
functions: _parseFunctions(options?.functions).cast());
return _convertResult(result);
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
} on SassException catch (error, stackTrace) {
throwNodeException(error, color: color, ascii: ascii, trace: stackTrace);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ NodeCompileResult compileString(String text, [CompileStringOptions? options]) {
importer: options?.importer.andThen(_parseImporter) ??
(options?.url == null ? NoOpImporter() : null),
functions: _parseFunctions(options?.functions).cast());
return _convertResult(result);
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
} on SassException catch (error, stackTrace) {
throwNodeException(error, color: color, ascii: ascii, trace: stackTrace);
}
Expand All @@ -102,7 +102,7 @@ Promise compileAsync(String path, [CompileOptions? options]) {
importers: options?.importers
?.map((importer) => _parseAsyncImporter(importer)),
functions: _parseFunctions(options?.functions, asynch: true));
return _convertResult(result);
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
}()), color: color, ascii: ascii);
}

Expand Down Expand Up @@ -131,13 +131,13 @@ Promise compileStringAsync(String text, [CompileStringOptions? options]) {
.andThen((importer) => _parseAsyncImporter(importer)) ??
(options?.url == null ? NoOpImporter() : null),
functions: _parseFunctions(options?.functions, asynch: true));
return _convertResult(result);
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
}()), color: color, ascii: ascii);
}

/// Converts a Dart [CompileResult] into a JS API [NodeCompileResult].
NodeCompileResult _convertResult(CompileResult result) {
var sourceMap = result.sourceMap?.toJson();
NodeCompileResult _convertResult(CompileResult result, {required bool includeSourceContents}) {
var sourceMap = result.sourceMap?.toJson(includeSourceContents: includeSourceContents);
if (sourceMap is Map<String, dynamic> && !sourceMap.containsKey('sources')) {
// Dart's source map library can omit the sources key, but JS's type
// declaration doesn't allow that.
Expand Down
1 change: 1 addition & 0 deletions lib/src/node/compile_options.dart
Expand Up @@ -18,6 +18,7 @@ class CompileOptions {
external String? get style;
external bool? get verbose;
external bool? get sourceMap;
external bool? get sourceMapIncludeSources;
external NodeLogger? get logger;
external List<Object?>? get importers;
external Object? get functions;
Expand Down

0 comments on commit 75534fd

Please sign in to comment.