some analysis fixes

This commit is contained in:
Natalie Weizenbaum 2016-08-04 17:25:57 -07:00
parent d5b029de9b
commit 1ea3619d93
8 changed files with 45 additions and 26 deletions

View File

@ -5,6 +5,7 @@
import 'package:source_span/source_span.dart';
import '../../visitor/sass/statement.dart';
import 'expression.dart';
import 'statement.dart';
class ExtendRule implements Statement {

View File

@ -11,7 +11,7 @@ export 'selector/list.dart';
export 'selector/namespaced_identifier.dart';
export 'selector/placeholder.dart';
export 'selector/pseudo.dart';
export 'selector/simple.dart' hide baseSpecificity;
export 'selector/simple.dart';
export 'selector/type.dart';
export 'selector/universal.dart';

View File

@ -37,7 +37,7 @@ class PseudoSelector extends SimpleSelector {
var result = <SimpleSelector>[];
var addedThis = false;
for (var simple in compound) {
if (simple is Pseudo && simple.type == PseudoType.element) {
if (simple is PseudoSelector && simple.type == PseudoType.element) {
// A given compound selector may only contain one pseudo element. If
// [compound] has a different one than [this], unification fails.
if (this.type == PseudoType.element) return null;
@ -69,7 +69,7 @@ class PseudoSelector extends SimpleSelector {
if (name == 'not') {
_minSpecificity = 0;
_maxSpecificity = 0;
for (var complex in selector.members) {
for (var complex in selector.components) {
_minSpecificity = math.max(_minSpecificity, complex.minSpecificity);
_maxSpecificity = math.max(_maxSpecificity, complex.maxSpecificity);
}
@ -77,7 +77,7 @@ class PseudoSelector extends SimpleSelector {
// This is higher than any selector's specificity can actually be.
_minSpecificity = math.pow(super.minSpecificity, 3);
_maxSpecificity = 0;
for (var complex in selector.members) {
for (var complex in selector.components) {
_minSpecificity = math.min(_minSpecificity, complex.minSpecificity);
_maxSpecificity = math.max(_maxSpecificity, complex.maxSpecificity);
}

View File

@ -2,6 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import '../../extend/functions.dart';
import '../selector.dart';
class TypeSelector extends SimpleSelector {
@ -16,7 +17,7 @@ class TypeSelector extends SimpleSelector {
var unified = unifyUniversalAndElement(this, compound.first);
return [unified]..addAll(compound.skip(1));
} else {
return [this].addAll(compound);
return [this]..addAll(compound);
}
}

View File

@ -2,6 +2,7 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import '../../extend/functions.dart';
import '../../utils.dart';
import '../selector.dart';
@ -18,7 +19,9 @@ class UniversalSelector extends SimpleSelector {
return [unified]..addAll(compound.skip(1));
}
if (namespace != null && namespace != "*") return [this].addAll(compound);
if (namespace != null && namespace != "*") {
return <SimpleSelector>[this]..addAll(compound);
}
if (compound.isNotEmpty) return compound;
return [this];
}

View File

@ -2,6 +2,11 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'dart:collection';
import 'package:source_span/source_span.dart';
import '../ast/css/node.dart';
import '../ast/sass/expression.dart';
import '../ast/selector.dart';
import '../utils.dart';
@ -18,19 +23,22 @@ class Extender {
final _sources = new Expando<ComplexSelector>();
CssStyleRule addSelector(SelectorList selector, {FileSpan span}) {
CssStyleRule addSelector(SelectorList selector, {FileSpan selectorSpan,
FileSpan ruleSpan}) {
for (var complex in selector.components) {
for (var component in complex.components) {
if (component is CompoundSelector) {
for (var simple in component.components) {
_sources[simple] = selector;
_sources[simple] = complex;
}
}
}
}
if (_extensions.isNotEmpty) selector = _extendList(selector, _extensions);
var rule = new CssStyleRule(selector, span: span);
var rule = new CssStyleRule(
new CssValue(selector, span: selectorSpan),
span: ruleSpan);
for (var complex in selector.components) {
for (var component in complex.components) {
@ -51,10 +59,10 @@ class Extender {
var rules = _selectors[target];
if (rules == null) return;
var extensions = {target: new Set([extender])};
var extensions = {target: new Set.from([extender])};
for (var rule in rules) {
var list = rule.selector.value;
rule.selector = _extendList(list, extensions);
rule.selector.value = _extendList(list, extensions);
}
}
@ -132,15 +140,15 @@ class Extender {
compound.components.toList()..removeAt(i);
for (var list in extenders) {
for (var complex in list.components) {
var extenderBase = complex.members.last as CompoundSelector;
var extenderBase = complex.components.last as CompoundSelector;
var unified = _unifyCompound(
extenderBase.components, componentsWithoutSimple);
extenderBase.components, compoundWithoutSimple);
if (unified == null) continue;
if (!changed) extended = [[compound]];
changed = true;
extended.add(extenderBase.members
.take(extenderBase.members.length - 1)
extended.add(complex.components
.take(complex.components.length - 1)
.toList()
..add(unified));
}
@ -312,7 +320,8 @@ class Extender {
]
];
var unified = _unifyCompound(compound1.members, compound2.members);
var unified = _unifyCompound(
compound1.components, compound2.components);
if (unified != null) {
choices.add([unified, Combinator.followingSibling]);
}
@ -339,7 +348,8 @@ class Extender {
]
];
var unified = _unifyCompound(compound1.members, compound2.members);
var unified = _unifyCompound(
compound1.components, compound2.components);
if (unified != null) choices.add([unified, Combinator.nextSibling]);
result.addFirst(choices);
}
@ -354,7 +364,8 @@ class Extender {
result.addFirst([[compound2, combinator2]]);
components1..add(compound1)..add(Combinator.child);
} else if (combinator1 == combinator2) {
var unified = _unifyCompound(compound1.members, compound2.members);
var unified = _unifyCompound(
compound1.components, compound2.components);
if (unified == null) return null;
result.addFirst([[merged, combinator1]]);
} else {
@ -469,8 +480,8 @@ class Extender {
List<List<ComplexSelectorComponent> _unifyComplex(
List<SimpleSelector> complex1, List<SimpleSelector> complex2) {
var base1 = complex1.members.last;
var base2 = complex2.members.last;
var base1 = complex1.components.last;
var base2 = complex2.components.last;
if (base1 is CompoundSelector && base2 is CompoundSelector) {
var unified = _unifyCompound(base2.components, base1.components);
if (unified == null) return null;

View File

@ -2,6 +2,8 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import '../ast/selector.dart';
final _subselectorPseudos =
new Set.from(['matches', 'any', 'nth-child', 'nth-last-child']);
@ -44,11 +46,11 @@ SimpleSelector unifyUniversalAndElement(SimpleSelector selector1,
return null;
}
String namespace;
String name;
if (name1 == name2 || name2 == null) {
namespace = name1;
name = name1;
} else if (name1 == null || name1 == '*') {
namespace = name2;
name = name2;
} else {
return null;
}
@ -140,7 +142,7 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
i1 += 2;
i2 = afterSuperselector + 1;
} else if (combinator2 is Combinator) {
if (combinator2 != Combinator2.child) return false;
if (combinator2 != Combinator.child) return false;
i1++;
i2 = afterSuperselector + 1;
} else {
@ -155,7 +157,7 @@ bool compoundIsSuperselector(CompoundSelector compound1,
// Every selector in [compound1.components] must have a matching selector in
// [compound2.components].
for (var simple1 in compound1.components) {
if (simple1 is PseudoSelector && simple2.selector != null) {
if (simple1 is PseudoSelector && simple1.selector != null) {
if (!_selectorPseudoIsSuperselector(
simple1, compound2, parents: parents)) {
return false;
@ -184,7 +186,7 @@ bool _simpleIsSuperselectorOfCompound(SimpleSelector simple,
if (simple == theirSimple) return true;
// Some selector pseudoclasses can match normal selectors.
if (theirSimple is Pseudo && theirSimple.selector != null &&
if (theirSimple is PseudoSelector && theirSimple.selector != null &&
_subselectorPseudos.contains(theirSimple.name)) {
return theirSimple.selector.components.any((complex) {
if (complex.components.length != 1) return false;

View File

@ -3,6 +3,7 @@
// https://opensource.org/licenses/MIT.
import 'dart:collection';
import 'dart:math' as math;
import 'package:charcode/charcode.dart';
import 'package:source_span/source_span.dart';