Skip to content

Commit

Permalink
Fix CSS import bug (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed Feb 17, 2022
1 parent 4181d0d commit c66ea3f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
## 1.49.8

* Fixed a bug where some plain CSS imports would not be emitted.

### JS API

* Fix a bug where inspecting the Sass module in the Node.js console crashed on
Expand Down
18 changes: 12 additions & 6 deletions lib/src/node/compile.dart
Expand Up @@ -47,7 +47,8 @@ NodeCompileResult compile(String path, [CompileOptions? options]) {
ascii: ascii),
importers: options?.importers?.map(_parseImporter),
functions: _parseFunctions(options?.functions).cast());
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
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 +77,8 @@ NodeCompileResult compileString(String text, [CompileStringOptions? options]) {
importer: options?.importer.andThen(_parseImporter) ??
(options?.url == null ? NoOpImporter() : null),
functions: _parseFunctions(options?.functions).cast());
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
return _convertResult(result,
includeSourceContents: options?.sourceMapIncludeSources ?? false);
} on SassException catch (error, stackTrace) {
throwNodeException(error, color: color, ascii: ascii, trace: stackTrace);
}
Expand All @@ -102,7 +104,8 @@ Promise compileAsync(String path, [CompileOptions? options]) {
importers: options?.importers
?.map((importer) => _parseAsyncImporter(importer)),
functions: _parseFunctions(options?.functions, asynch: true));
return _convertResult(result, includeSourceContents: options?.sourceMapIncludeSources ?? false);
return _convertResult(result,
includeSourceContents: options?.sourceMapIncludeSources ?? false);
}()), color: color, ascii: ascii);
}

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

/// Converts a Dart [CompileResult] into a JS API [NodeCompileResult].
NodeCompileResult _convertResult(CompileResult result, {required bool includeSourceContents}) {
var sourceMap = result.sourceMap?.toJson(includeSourceContents: includeSourceContents);
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
11 changes: 6 additions & 5 deletions lib/src/visitor/async_evaluate.dart
Expand Up @@ -1526,10 +1526,12 @@ class _EvaluateVisitor

_importer = oldImporter;
_stylesheet = oldStylesheet;
_root = oldRoot;
_parent = oldParent;
_endOfImports = oldEndOfImports;
_outOfOrderImports = oldOutOfOrderImports;
if (loadsUserDefinedModules) {
_root = oldRoot;
_parent = oldParent;
_endOfImports = oldEndOfImports;
_outOfOrderImports = oldOutOfOrderImports;
}
_configuration = oldConfiguration;
_inDependency = oldInDependency;
});
Expand All @@ -1539,7 +1541,6 @@ class _EvaluateVisitor
// CSS from modules used by [stylesheet].
var module = environment.toDummyModule();
_environment.importForwards(module);

if (loadsUserDefinedModules) {
if (module.transitivelyContainsCss) {
// If any transitively used module contains extensions, we need to
Expand Down
13 changes: 7 additions & 6 deletions lib/src/visitor/evaluate.dart
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: c1d303225e5cac5e32dd32a4eed30a71a35b390c
// Checksum: d0af88db460da6528bdfeef34eb85baac00f9435
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -1526,10 +1526,12 @@ class _EvaluateVisitor

_importer = oldImporter;
_stylesheet = oldStylesheet;
_root = oldRoot;
_parent = oldParent;
_endOfImports = oldEndOfImports;
_outOfOrderImports = oldOutOfOrderImports;
if (loadsUserDefinedModules) {
_root = oldRoot;
_parent = oldParent;
_endOfImports = oldEndOfImports;
_outOfOrderImports = oldOutOfOrderImports;
}
_configuration = oldConfiguration;
_inDependency = oldInDependency;
});
Expand All @@ -1539,7 +1541,6 @@ class _EvaluateVisitor
// CSS from modules used by [stylesheet].
var module = environment.toDummyModule();
_environment.importForwards(module);

if (loadsUserDefinedModules) {
if (module.transitivelyContainsCss) {
// If any transitively used module contains extensions, we need to
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
@@ -1,3 +1,7 @@
## 1.0.0-beta.37

* No user-visible changes.

## 1.0.0-beta.36

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 1.0.0-beta.36
version: 1.0.0-beta.37
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
sass: 1.49.7
sass: 1.49.8

dependency_overrides:
sass: {path: ../..}
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: sass
version: 1.49.8-dev
version: 1.49.8
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit c66ea3f

Please sign in to comment.