ExpandNestedSelectors class
Traverse all rulesets looking for nested ones. If a ruleset is in a declaration group (implies nested selector) then generate new ruleset(s) at level 0 of CSS using selector inheritance syntax (flattens the nesting).
How the AST works for a rule RuleSet and nested rules. First of all a CSS rule RuleSet consist of a selector and a declaration e.g.,
selector {
declaration
}
AST structure of a RuleSet is:
RuleSet
SelectorGroup
List<Selector>
List<SimpleSelectorSequence>
Combinator // +, >, ~, DESCENDENT, or NONE
SimpleSelector // class, id, element, namespace, attribute
DeclarationGroup
List // Declaration or RuleSet
For the simple rule:
div + span { color: red; }
the AST RuleSet is:
RuleSet
SelectorGroup
List<Selector>
[0]
List<SimpleSelectorSequence>
[0] Combinator = COMBINATOR_NONE
ElementSelector (name = div)
[1] Combinator = COMBINATOR_PLUS
ElementSelector (name = span)
DeclarationGroup
List // Declarations or RuleSets
[0]
Declaration (property = color, expression = red)
Usually a SelectorGroup contains 1 Selector. Consider the selectors:
div { color: red; }
a { color: red; }
are equivalent to
div, a { color : red; }
In the above the RuleSet would have a SelectorGroup with 2 selectors e.g.,
RuleSet
SelectorGroup
List<Selector>
[0]
List<SimpleSelectorSequence>
[0] Combinator = COMBINATOR_NONE
ElementSelector (name = div)
[1]
List<SimpleSelectorSequence>
[0] Combinator = COMBINATOR_NONE
ElementSelector (name = a)
DeclarationGroup
List // Declarations or RuleSets
[0]
Declaration (property = color, expression = red)
For a nested rule e.g.,
div {
color : blue;
a { color : red; }
}
Would map to the follow CSS rules:
div { color: blue; }
div a { color: red; }
The AST for the former nested rule is:
RuleSet
SelectorGroup
List<Selector>
[0]
List<SimpleSelectorSequence>
[0] Combinator = COMBINATOR_NONE
ElementSelector (name = div)
DeclarationGroup
List // Declarations or RuleSets
[0]
Declaration (property = color, expression = blue)
[1]
RuleSet
SelectorGroup
List<Selector>
[0]
List<SimpleSelectorSequence>
[0] Combinator = COMBINATOR_NONE
ElementSelector (name = a)
DeclarationGroup
List // Declarations or RuleSets
[0]
Declaration (property = color, expression = red)
Nested rules is a terse mechanism to describe CSS inheritance. The analyzer
will flatten and expand the nested rules to it's flatten strucure. Using
the all parent RuleSets
(selector expressions) and applying each nested
RuleSet to the list of Selectors
in a SelectorGroup.
Then result is a style sheet where all nested rules have been flatten and expanded.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
flatten(
StyleSheet styleSheet) → void - Replace the rule set that contains nested rules with the flatten rule sets.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
visitAngleTerm(
AngleTerm node) → dynamic -
inherited
-
visitAttributeSelector(
AttributeSelector node) → dynamic -
inherited
-
visitBinaryExpression(
BinaryExpression node) → dynamic -
inherited
-
visitBorderExpression(
BorderExpression node) → dynamic -
inherited
-
visitBoxExpression(
BoxExpression node) → dynamic -
inherited
-
visitCalcTerm(
CalcTerm node) → dynamic -
inherited
-
visitCharsetDirective(
CharsetDirective node) → dynamic -
inherited
-
visitChTerm(
ChTerm node) → dynamic -
inherited
-
visitClassSelector(
ClassSelector node) → dynamic -
inherited
-
visitCommentDefinition(
CommentDefinition node) → dynamic -
inherited
-
visitContentDirective(
ContentDirective node) → dynamic -
inherited
-
visitCssComment(
CssComment node) → dynamic -
inherited
-
visitDartStyleExpression(
DartStyleExpression node) → dynamic -
inherited
-
visitDeclaration(
Declaration node) → void -
override
-
visitDeclarationGroup(
DeclarationGroup node) → void -
override
-
visitDirective(
Directive node) → dynamic -
inherited
-
visitDocumentDirective(
DocumentDirective node) → dynamic -
inherited
-
visitElementSelector(
ElementSelector node) → dynamic -
inherited
-
visitEmTerm(
EmTerm node) → dynamic -
inherited
-
visitExpressions(
Expressions node) → dynamic -
inherited
-
visitExtendDeclaration(
ExtendDeclaration node) → void -
override
-
visitExTerm(
ExTerm node) → dynamic -
inherited
-
visitFontExpression(
FontExpression node) → dynamic -
inherited
-
visitFontFaceDirective(
FontFaceDirective node) → dynamic -
inherited
-
visitFractionTerm(
FractionTerm node) → dynamic -
inherited
-
visitFreqTerm(
FreqTerm node) → dynamic -
inherited
-
visitFunctionTerm(
FunctionTerm node) → dynamic -
inherited
-
visitGroupTerm(
GroupTerm node) → dynamic -
inherited
-
visitHeightExpression(
HeightExpression node) → dynamic -
inherited
-
visitHexColorTerm(
HexColorTerm node) → dynamic -
inherited
-
visitHostDirective(
HostDirective node) → dynamic -
inherited
-
visitIdentifier(
Identifier node) → dynamic -
inherited
-
visitIdSelector(
IdSelector node) → dynamic -
inherited
-
visitIE8Term(
IE8Term node) → dynamic -
inherited
-
visitImportDirective(
ImportDirective node) → dynamic -
inherited
-
visitIncludeDirective(
IncludeDirective node) → dynamic -
inherited
-
visitIncludeMixinAtDeclaration(
IncludeMixinAtDeclaration node) → dynamic -
inherited
-
visitItemTerm(
ItemTerm node) → dynamic -
inherited
-
visitKeyFrameBlock(
KeyFrameBlock node) → dynamic -
inherited
-
visitKeyFrameDirective(
KeyFrameDirective node) → dynamic -
inherited
-
visitLengthTerm(
LengthTerm node) → dynamic -
inherited
-
visitLiteralTerm(
LiteralTerm node) → dynamic -
inherited
-
visitMarginExpression(
MarginExpression node) → dynamic -
inherited
-
visitMarginGroup(
MarginGroup node) → void -
override
-
visitMediaDirective(
MediaDirective node) → dynamic -
inherited
-
visitMediaExpression(
MediaExpression node) → dynamic -
inherited
-
visitMediaQuery(
MediaQuery node) → dynamic -
inherited
-
visitMixinDeclarationDirective(
MixinDeclarationDirective node) → dynamic -
inherited
-
visitMixinDefinition(
MixinDefinition node) → dynamic -
inherited
-
visitMixinRulesetDirective(
MixinRulesetDirective node) → dynamic -
inherited
-
visitNamespaceDirective(
NamespaceDirective node) → dynamic -
inherited
-
visitNamespaceSelector(
NamespaceSelector node) → dynamic -
inherited
-
visitNegation(
Negation node) → dynamic -
inherited
-
visitNegationSelector(
NegationSelector node) → dynamic -
inherited
-
visitNoOp(
NoOp node) → dynamic -
inherited
-
visitNumberTerm(
NumberTerm node) → dynamic -
inherited
-
visitOperatorComma(
OperatorComma node) → dynamic -
inherited
-
visitOperatorMinus(
OperatorMinus node) → dynamic -
inherited
-
visitOperatorPlus(
OperatorPlus node) → dynamic -
inherited
-
visitOperatorSlash(
OperatorSlash node) → dynamic -
inherited
-
visitPaddingExpression(
PaddingExpression node) → dynamic -
inherited
-
visitPageDirective(
PageDirective node) → dynamic -
inherited
-
visitPercentageTerm(
PercentageTerm node) → dynamic -
inherited
-
visitPseudoClassFunctionSelector(
PseudoClassFunctionSelector node) → dynamic -
inherited
-
visitPseudoClassSelector(
PseudoClassSelector node) → dynamic -
inherited
-
visitPseudoElementFunctionSelector(
PseudoElementFunctionSelector node) → dynamic -
inherited
-
visitPseudoElementSelector(
PseudoElementSelector node) → dynamic -
inherited
-
visitRemTerm(
RemTerm node) → dynamic -
inherited
-
visitResolutionTerm(
ResolutionTerm node) → dynamic -
inherited
-
visitRuleSet(
RuleSet node) → void -
override
-
visitSelector(
Selector node) → dynamic -
inherited
-
visitSelectorExpression(
SelectorExpression node) → dynamic -
inherited
-
visitSelectorGroup(
SelectorGroup node) → dynamic -
inherited
-
visitSimpleSelector(
SimpleSelector node) → dynamic -
inherited
-
visitSimpleSelectorSequence(
SimpleSelectorSequence node) → dynamic -
inherited
-
visitStyleSheet(
StyleSheet ss) → dynamic -
inherited
-
visitStyletDirective(
StyletDirective node) → dynamic -
inherited
-
visitSupportsConditionInParens(
SupportsConditionInParens node) → dynamic -
inherited
-
visitSupportsConjunction(
SupportsConjunction node) → dynamic -
inherited
-
visitSupportsDirective(
SupportsDirective node) → dynamic -
inherited
-
visitSupportsDisjunction(
SupportsDisjunction node) → dynamic -
inherited
-
visitSupportsNegation(
SupportsNegation node) → dynamic -
inherited
-
visitThisOperator(
ThisOperator node) → dynamic -
inherited
-
visitTimeTerm(
TimeTerm node) → dynamic -
inherited
-
visitTopLevelProduction(
TopLevelProduction node) → dynamic -
inherited
-
visitTree(
StyleSheet tree) → dynamic -
inherited
-
visitUnaryExpression(
UnaryExpression node) → dynamic -
inherited
-
visitUnicodeRangeTerm(
UnicodeRangeTerm node) → dynamic -
inherited
-
visitUnitTerm(
UnitTerm node) → dynamic -
inherited
-
visitUriTerm(
UriTerm node) → dynamic -
inherited
-
visitVarDefinition(
VarDefinition node) → void -
override
-
visitVarDefinitionDirective(
VarDefinitionDirective node) → dynamic -
inherited
-
visitVarUsage(
VarUsage node) → dynamic -
inherited
-
visitViewportDirective(
ViewportDirective node) → dynamic -
inherited
-
visitViewportTerm(
ViewportTerm node) → dynamic -
inherited
-
visitWidthExpression(
WidthExpression node) → dynamic -
inherited
-
visitWildcard(
Wildcard node) → dynamic -
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited