Only clone CSS if it actually uses @extends

This commit is contained in:
Natalie Weizenbaum 2019-03-30 17:47:24 -07:00
parent d6f319f5b4
commit 2d1047bb36
6 changed files with 33 additions and 7 deletions

View File

@ -632,6 +632,7 @@ class _EnvironmentModule implements AsyncModule {
final Extender extender;
final CssStylesheet css;
final bool transitivelyContainsCss;
final bool transitivelyContainsExtensions;
/// The environment that defines this module's members.
final AsyncEnvironment _environment;
@ -648,7 +649,10 @@ class _EnvironmentModule implements AsyncModule {
mixins = PublicMemberMap(_environment._mixins.first),
transitivelyContainsCss = css.children.isNotEmpty ||
_environment._allModules
.any((module) => module.transitivelyContainsCss);
.any((module) => module.transitivelyContainsCss),
transitivelyContainsExtensions = !extender.isEmpty ||
_environment._allModules
.any((module) => module.transitivelyContainsExtensions);
void setVariable(String name, Value value, AstNode nodeWithSpan) {
if (!_environment._variables.first.containsKey(name)) {

View File

@ -58,6 +58,10 @@ abstract class AsyncModule {
/// Whether this module *or* any modules in [upstream] contain any CSS.
bool get transitivelyContainsCss;
/// Whether this module *or* any modules in [upstream] contain `@extend`
/// rules..
bool get transitivelyContainsExtensions;
/// Sets the variable named [name] to [value], associated with
/// [nodeWithSpan]'s source span.
///

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_environment.dart.
// See tool/synchronize.dart for details.
//
// Checksum: 097eb94cd15103bf4bef739a61e61414db4b55b1
// Checksum: 3210a5c0528eac456ae8ca7827b65f3976f6b29d
//
// ignore_for_file: unused_import
@ -634,6 +634,7 @@ class _EnvironmentModule implements Module {
final Extender extender;
final CssStylesheet css;
final bool transitivelyContainsCss;
final bool transitivelyContainsExtensions;
/// The environment that defines this module's members.
final Environment _environment;
@ -650,7 +651,10 @@ class _EnvironmentModule implements Module {
mixins = PublicMemberMap(_environment._mixins.first),
transitivelyContainsCss = css.children.isNotEmpty ||
_environment._allModules
.any((module) => module.transitivelyContainsCss);
.any((module) => module.transitivelyContainsCss),
transitivelyContainsExtensions = !extender.isEmpty ||
_environment._allModules
.any((module) => module.transitivelyContainsExtensions);
void setVariable(String name, Value value, AstNode nodeWithSpan) {
if (!_environment._variables.first.containsKey(name)) {

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_module.dart.
// See tool/synchronize.dart for details.
//
// Checksum: 895440529b78f1ef2830cf105af00dba0755e947
// Checksum: d996840504b080c2c4e6b34136562b8152bb2e97
//
// ignore_for_file: unused_import
@ -65,6 +65,10 @@ abstract class Module {
/// Whether this module *or* any modules in [upstream] contain any CSS.
bool get transitivelyContainsCss;
/// Whether this module *or* any modules in [upstream] contain `@extend`
/// rules..
bool get transitivelyContainsExtensions;
/// Sets the variable named [name] to [value], associated with
/// [nodeWithSpan]'s source span.
///

View File

@ -1033,7 +1033,12 @@ class _EvaluateVisitor
var module = environment.toModule(
CssStylesheet(const [], stylesheet.span), Extender.empty);
if (module.transitivelyContainsCss) {
await _combineCss(module, clone: true).accept(this);
// If any transitively used module contains extensions, we need to clone
// all modules' CSS. Otherwise, it's possible that they'll be used or
// imported from another location that shouldn't have the same extensions
// applied.
await _combineCss(module, clone: module.transitivelyContainsExtensions)
.accept(this);
}
var visitor = _ImportedCssVisitor(this);

View File

@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/synchronize.dart for details.
//
// Checksum: 0f4f00db38a7f2a60771d3d50652cbfdeb322e52
// Checksum: 4de442e73c75611a675e2fd0d8962219f1ceffd7
//
// ignore_for_file: unused_import
@ -1036,7 +1036,12 @@ class _EvaluateVisitor
var module = environment.toModule(
CssStylesheet(const [], stylesheet.span), Extender.empty);
if (module.transitivelyContainsCss) {
_combineCss(module, clone: true).accept(this);
// If any transitively used module contains extensions, we need to clone
// all modules' CSS. Otherwise, it's possible that they'll be used or
// imported from another location that shouldn't have the same extensions
// applied.
_combineCss(module, clone: module.transitivelyContainsExtensions)
.accept(this);
}
var visitor = _ImportedCssVisitor(this);