From 0ea2e0dbe0751d2a3e49776f4227ef0a1e399c49 Mon Sep 17 00:00:00 2001 From: Howard Date: Wed, 23 Oct 2019 20:07:24 -0400 Subject: [PATCH 1/4] Fix broken links in perf.md (#861) --- perf.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/perf.md b/perf.md index a5506ab21..93b792114 100644 --- a/perf.md +++ b/perf.md @@ -168,5 +168,5 @@ relative slowdown becomes more pronounced as the raw Dart code becomes faster. Solutions for this such as [the embedded protocol][] or [WebAssembly support][] are becoming more and more important. -[embedded Dart Sass]: https://github.com/sass/sass-embedded-protocol -[Dart WebAssembly support]: https://github.com/dart-lang/sdk/issues/32894 +[the embedded protocol]: https://github.com/sass/sass-embedded-protocol +[WebAssembly support]: https://github.com/dart-lang/sdk/issues/32894 \ No newline at end of file From 3392db0074fa8d65903f4b89c9358e744f5ebc86 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 29 Oct 2019 23:48:21 +0000 Subject: [PATCH 2/4] Don't compile .css files in directories to themselves (#862) This also adds support for compiling .css files in directories *at all*, which had previously only worked in --watch mode. Closes #853 --- CHANGELOG.md | 9 +++++++++ lib/src/executable/options.dart | 6 ++++-- lib/src/executable/watch.dart | 12 ++++++++---- pubspec.yaml | 2 +- test/cli/shared/colon_args.dart | 16 ++++++++++++++-- test/cli/shared/update.dart | 10 ++++++++++ test/cli/shared/watch.dart | 23 +++++++++++++++++++++++ 7 files changed, 69 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 581fc7b0c..b05e5a9e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.23.2 + +### Command-Line Interface + +* Fix a bug when compiling all Sass files in a directory where a CSS file could + be compiled to its own location, creating an infinite loop in `--watch` mode. + +* Properly compile CSS entrypoints in directories outside of `--watch` mode. + ## 1.23.1 * Fix a bug preventing built-in modules from being loaded within a configured diff --git a/lib/src/executable/options.dart b/lib/src/executable/options.dart index 9f76ee761..ed657ebf6 100644 --- a/lib/src/executable/options.dart +++ b/lib/src/executable/options.dart @@ -373,7 +373,9 @@ class ExecutableOptions { Map _listSourceDirectory(String source, String destination) { return { for (var path in listDir(source, recursive: true)) - if (_isEntrypoint(path)) + if (_isEntrypoint(path) && + // Don't compile a CSS file to its own location. + !(source == destination && p.extension(path) == '.css')) path: p.join(destination, p.setExtension(p.relative(path, from: source), '.css')) }; @@ -383,7 +385,7 @@ class ExecutableOptions { bool _isEntrypoint(String path) { if (p.basename(path).startsWith("_")) return false; var extension = p.extension(path); - return extension == ".scss" || extension == ".sass"; + return extension == ".scss" || extension == ".sass" || extension == ".css"; } /// Whether to emit a source map file. diff --git a/lib/src/executable/watch.dart b/lib/src/executable/watch.dart index 9b3a957a1..1b6941e31 100644 --- a/lib/src/executable/watch.dart +++ b/lib/src/executable/watch.dart @@ -267,10 +267,14 @@ class _Watcher { if (p.basename(source).startsWith('_')) return null; for (var sourceDir in _options.sourceDirectoriesToDestinations.keys) { - if (p.isWithin(sourceDir, source)) { - return p.join(_options.sourceDirectoriesToDestinations[sourceDir], - p.setExtension(p.relative(source, from: sourceDir), '.css')); - } + if (!p.isWithin(sourceDir, source)) continue; + + var destination = p.join( + _options.sourceDirectoriesToDestinations[sourceDir], + p.setExtension(p.relative(source, from: sourceDir), '.css')); + + // Don't compile ".css" files to their own locations. + if (destination != source) return destination; } return null; diff --git a/pubspec.yaml b/pubspec.yaml index 7c42fff0b..b2012e52c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.23.1 +version: 1.23.2 description: A Sass implementation in Dart. author: Sass Team homepage: https://github.com/sass/dart-sass diff --git a/test/cli/shared/colon_args.dart b/test/cli/shared/colon_args.dart index f1296ee77..34075f8a1 100644 --- a/test/cli/shared/colon_args.dart +++ b/test/cli/shared/colon_args.dart @@ -106,7 +106,8 @@ void sharedTests(Future runSass(Iterable arguments)) { test("compiles all the stylesheets in the directory", () async { await d.dir("in", [ d.file("test1.scss", "a {b: c}"), - d.file("test2.sass", "x\n y: z") + d.file("test2.sass", "x\n y: z"), + d.file("test3.css", "q {r: s}") ]).create(); var sass = await runSass(["--no-source-map", "in:out"]); @@ -115,7 +116,8 @@ void sharedTests(Future runSass(Iterable arguments)) { await d.dir("out", [ d.file("test1.css", equalsIgnoringWhitespace("a { b: c; }")), - d.file("test2.css", equalsIgnoringWhitespace("x { y: z; }")) + d.file("test2.css", equalsIgnoringWhitespace("x { y: z; }")), + d.file("test3.css", equalsIgnoringWhitespace("q { r: s; }")) ]).validate(); }); @@ -183,6 +185,16 @@ void sharedTests(Future runSass(Iterable arguments)) { d.nothing("fake.css") ]).validate(); }); + + test("ignores a CSS file that would compile to itself", () async { + await d.dir("dir", [d.file("test.css", "a {b: c}")]).create(); + + var sass = await runSass(["dir:dir"]); + expect(sass.stdout, emitsDone); + await sass.shouldExit(0); + + await d.file("dir/test.css", "a {b: c}").validate(); + }); }); group("reports all", () { diff --git a/test/cli/shared/update.dart b/test/cli/shared/update.dart index d7b439191..d41cea1be 100644 --- a/test/cli/shared/update.dart +++ b/test/cli/shared/update.dart @@ -175,6 +175,16 @@ void sharedTests(Future runSass(Iterable arguments)) { await d.file("out.css", contains(message)).validate(); }); + + test("from itself", () async { + await d.dir("dir", [d.file("test.css", "a {b: c}")]).create(); + + var sass = await update(["dir:dir"]); + expect(sass.stdout, emitsDone); + await sass.shouldExit(0); + + await d.file("dir/test.css", "a {b: c}").validate(); + }); }); group("updates a CSS file", () { diff --git a/test/cli/shared/watch.dart b/test/cli/shared/watch.dart index 1b601e03c..b901b8c79 100644 --- a/test/cli/shared/watch.dart +++ b/test/cli/shared/watch.dart @@ -639,6 +639,29 @@ void sharedTests(Future runSass(Iterable arguments)) { await d.nothing("out/test.scss").validate(); }); + // Regression test for #853. + test("doesn't try to compile a CSS file to itself", () async { + await d.dir("dir").create(); + + var sass = await watch(["dir:dir"]); + await expectLater(sass.stdout, _watchingForChanges); + await tickIfPoll(); + + await d.file("dir/test.css", "a {b: c}").create(); + await tick; + + // Create a new file that *will* be compiled so that if the first change + // did incorrectly trigger a compilation, it would emit a message + // before the message for this change. + await d.file("dir/test2.scss", "x {y: z}").create(); + await expectLater( + sass.stdout, emits(_compiled('dir/test2.scss', 'dir/test2.css'))); + + await sass.kill(); + + await d.file("dir/test.css", "a {b: c}").validate(); + }); + group("doesn't allow", () { test("--stdin", () async { var sass = await watch(["--stdin", "test.scss"]); From df5f3af4e90403d5c5591b2a4e2d25f776cec36d Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 30 Oct 2019 14:23:55 -0700 Subject: [PATCH 3/4] Remove some unused specificity calculations --- lib/src/extend/extender.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/src/extend/extender.dart b/lib/src/extend/extender.dart index 7c5a80370..bada20916 100644 --- a/lib/src/extend/extender.dart +++ b/lib/src/extend/extender.dart @@ -669,11 +669,9 @@ class Extender { } var lineBreak = false; - var specificity = _sourceSpecificityFor(compound); for (var state in path) { state.assertCompatibleMediaContext(mediaQueryContext); lineBreak = lineBreak || state.extender.lineBreak; - specificity = math.max(specificity, state.specificity); } return complexes From be4ca600450b9fa8df1866f57afcedcbfa99687e Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 30 Oct 2019 15:11:25 -0700 Subject: [PATCH 4/4] Propagate selector source specificity between modules Closes #866 --- CHANGELOG.md | 5 +++++ lib/src/extend/extender.dart | 1 + pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b05e5a9e4..427e722e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.23.3 + +* Fix a bug where selectors were being trimmed over-eagerly when `@extend` + crossed module boundaries. + ## 1.23.2 ### Command-Line Interface diff --git a/lib/src/extend/extender.dart b/lib/src/extend/extender.dart index bada20916..4fb97b821 100644 --- a/lib/src/extend/extender.dart +++ b/lib/src/extend/extender.dart @@ -400,6 +400,7 @@ class Extender { for (var extender in extenders) { if (extender.isEmpty) continue; + _sourceSpecificity.addAll(extender._sourceSpecificity); extender._extensions.forEach((target, newSources) { // Private selectors can't be extended across module boundaries. if (target is PlaceholderSelector && target.isPrivate) return; diff --git a/pubspec.yaml b/pubspec.yaml index b2012e52c..dc073ee86 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.23.2 +version: 1.23.3 description: A Sass implementation in Dart. author: Sass Team homepage: https://github.com/sass/dart-sass