From c66ea3f9a53e00c8a81e9781c2e62c5940dbe6fe Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Thu, 17 Feb 2022 13:25:21 -0800 Subject: [PATCH] Fix CSS import bug (#1633) --- CHANGELOG.md | 2 ++ lib/src/node/compile.dart | 18 ++++++++++++------ lib/src/visitor/async_evaluate.dart | 11 ++++++----- lib/src/visitor/evaluate.dart | 13 +++++++------ pkg/sass_api/CHANGELOG.md | 4 ++++ pkg/sass_api/pubspec.yaml | 4 ++-- pubspec.yaml | 2 +- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3547042de..a7bd5f485 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/lib/src/node/compile.dart b/lib/src/node/compile.dart index c66dd813f..237a97c3b 100644 --- a/lib/src/node/compile.dart +++ b/lib/src/node/compile.dart @@ -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); } @@ -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); } @@ -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); } @@ -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 && !sourceMap.containsKey('sources')) { // Dart's source map library can omit the sources key, but JS's type // declaration doesn't allow that. diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index 1dd378235..3becc09fd 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -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; }); @@ -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 diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 2627a58ee..7450cc750 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -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 @@ -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; }); @@ -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 diff --git a/pkg/sass_api/CHANGELOG.md b/pkg/sass_api/CHANGELOG.md index d0e23aa21..95b1fa865 100644 --- a/pkg/sass_api/CHANGELOG.md +++ b/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. diff --git a/pkg/sass_api/pubspec.yaml b/pkg/sass_api/pubspec.yaml index 8458cf549..3e1d12174 100644 --- a/pkg/sass_api/pubspec.yaml +++ b/pkg/sass_api/pubspec.yaml @@ -2,7 +2,7 @@ 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 @@ -10,7 +10,7 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - sass: 1.49.7 + sass: 1.49.8 dependency_overrides: sass: {path: ../..} diff --git a/pubspec.yaml b/pubspec.yaml index dae4087a5..4d79d774d 100644 --- a/pubspec.yaml +++ b/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