pkg/csslib: fixed analysis error, more cleanup
R=terry@google.com
Review URL: https://codereview.chromium.org//60983003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/csslib@30480 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/lib/parser.dart b/lib/parser.dart
index 92f1652..840b9f2 100644
--- a/lib/parser.dart
+++ b/lib/parser.dart
@@ -30,7 +30,7 @@
: super(tokenizer);
}
-void _createMessages({List errors, List options}) {
+void _createMessages({List<Message> errors, List<String> options}) {
if (errors == null) errors = [];
if (options == null) {
@@ -45,8 +45,11 @@
// TODO(terry): Remove nested name parameter.
/** Parse and analyze the CSS file. */
-StyleSheet compile(var input, {List errors, List options, bool nested: true,
- bool polyfill: false, List<StyleSheet> includes: null}) {
+StyleSheet compile(var input, {List<Message> errors, List<String> options,
+ bool nested: true,
+ bool polyfill: false,
+ List<StyleSheet> includes: null}) {
+
if (includes == null) {
includes = [];
}
@@ -70,7 +73,9 @@
}
/** Analyze the CSS file. */
-void analyze(List<StyleSheet> styleSheets, {List errors, List options}) {
+void analyze(List<StyleSheet> styleSheets,
+ {List<Message> errors, List<String> options}) {
+
_createMessages(errors: errors, options: options);
new Analyzer(styleSheets, messages).run();
}
@@ -80,7 +85,7 @@
* or [List<int>] of bytes and returns a [StyleSheet] AST. The optional
* [errors] list will contain each error/warning as a [Message].
*/
-StyleSheet parse(var input, {List errors, List options}) {
+StyleSheet parse(var input, {List<Message> errors, List<String> options}) {
var source = _inputAsString(input);
_createMessages(errors: errors, options: options);
@@ -95,7 +100,7 @@
* or [List<int>] of bytes and returns a [StyleSheet] AST. The optional
* [errors] list will contain each error/warning as a [Message].
*/
-StyleSheet selector(var input, {List errors}) {
+StyleSheet selector(var input, {List<Message> errors}) {
var source = _inputAsString(input);
_createMessages(errors: errors);
@@ -150,7 +155,7 @@
/** A simple recursive descent parser for CSS. */
class _Parser {
- Tokenizer tokenizer;
+ final Tokenizer tokenizer;
/** Base url of CSS file. */
final String _baseUrl;
@@ -1184,9 +1189,9 @@
/**
* Return list of selectors
*/
- processSelector() {
- List<SimpleSelectorSequence> simpleSequences = [];
- int start = _peekToken.start;
+ Selector processSelector() {
+ var simpleSequences = <SimpleSelectorSequence>[];
+ var start = _peekToken.start;
while (true) {
// First item is never descendant make sure it's COMBINATOR_NONE.
var selectorItem = simpleSelectorSequence(simpleSequences.length == 0);
@@ -1344,12 +1349,12 @@
*/
simpleSelectorTail() {
// Check for HASH | class | attrib | pseudo | negation
- int start = _peekToken.start;
+ var start = _peekToken.start;
switch (_peek()) {
case TokenKind.HASH:
_eat(TokenKind.HASH);
- bool hasWhiteSpace = false;
+ var hasWhiteSpace = false;
if (_anyWhiteSpaceBeforePeekToken(TokenKind.HASH)) {
_warning("Not a valid ID selector expected #id", _makeSpan(start));
hasWhiteSpace = true;
@@ -1395,7 +1400,7 @@
// :pseudo-class ::pseudo-element
// TODO(terry): '::' should be token.
_eat(TokenKind.COLON);
- bool pseudoElement = _maybeEat(TokenKind.COLON);
+ var pseudoElement = _maybeEat(TokenKind.COLON);
// TODO(terry): If no identifier specified consider optimizing out the
// : or :: and making this a normal selector. For now,
@@ -1456,7 +1461,7 @@
* NUMBER {num}
*/
processSelectorExpression() {
- int start = _peekToken.start;
+ var start = _peekToken.start;
var expression = new SelectorExpression(_makeSpan(start));
@@ -1467,7 +1472,7 @@
// operator not identifier.
tokenizer.selectorExpression = true;
- bool keepParsing = true;
+ var keepParsing = true;
while (keepParsing) {
switch (_peek()) {
case TokenKind.PLUS:
@@ -1539,8 +1544,8 @@
// SUBSTRMATCH: '*='
//
//
- processAttribute() {
- int start = _peekToken.start;
+ AttributeSelector processAttribute() {
+ var start = _peekToken.start;
if (_maybeEat(TokenKind.LBRACK)) {
var attrName = identifier();
@@ -1593,7 +1598,7 @@
// *IDENT - IE7 or below
// _IDENT - IE6 property (automatically a valid ident)
//
- processDeclaration(List dartStyles) {
+ Declaration processDeclaration(List dartStyles) {
Declaration decl;
int start = _peekToken.start;
@@ -1637,7 +1642,7 @@
var include = processInclude(span, eatSemiColon: false);
decl = new IncludeMixinAtDeclaration(include, span);
} else if (_peekToken.kind == TokenKind.DIRECTIVE_EXTEND) {
- List<SimpleSelectorSequence> simpleSequences = [];
+ var simpleSequences = <TreeNode>[];
_next();
var span = _makeSpan(start);
@@ -1730,14 +1735,11 @@
'normal' : FontWeight.normal
};
- static _findStyle(String styleName) {
- if (_stylesToDart.containsKey(styleName)) {
- return _stylesToDart[styleName];
- }
- }
+ static int _findStyle(String styleName) => _stylesToDart[styleName];
- _styleForDart(Identifier property, Expressions exprs, List dartStyles) {
- int styleType = _findStyle(property.name.toLowerCase());
+ DartStyleExpression _styleForDart(Identifier property, Expressions exprs,
+ List dartStyles) {
+ var styleType = _findStyle(property.name.toLowerCase());
if (styleType != null) {
return buildDartStyleNode(styleType, exprs, dartStyles);
}
@@ -1754,7 +1756,9 @@
return fontExpr;
}
- buildDartStyleNode(int styleType, Expressions exprs, List dartStyles) {
+ DartStyleExpression buildDartStyleNode(int styleType, Expressions exprs,
+ List dartStyles) {
+
switch (styleType) {
/*
* Properties in order:
@@ -1897,7 +1901,7 @@
// TODO(terry): Look at handling width of thin, thick, etc. any none numbers
// to convert to a number.
- processOneNumber(Expressions exprs, int part) {
+ DartStyleExpression processOneNumber(Expressions exprs, int part) {
var value = marginValue(exprs.expressions[0]);
if (value != null) {
switch (part) {
@@ -1947,7 +1951,7 @@
*
* The values of the margins can be a unit or unitless or auto.
*/
- processFourNums(Expressions exprs) {
+ BoxEdge processFourNums(Expressions exprs) {
num top;
num right;
num bottom;
@@ -2000,16 +2004,16 @@
// operator: '/' | ','
// term: (see processTerm)
//
- processExpr([bool ieFilter = false]) {
- int start = _peekToken.start;
- Expressions expressions = new Expressions(_makeSpan(start));
+ Expressions processExpr([bool ieFilter = false]) {
+ var start = _peekToken.start;
+ var expressions = new Expressions(_makeSpan(start));
- bool keepGoing = true;
+ var keepGoing = true;
var expr;
while (keepGoing && (expr = processTerm(ieFilter)) != null) {
var op;
- int opStart = _peekToken.start;
+ var opStart = _peekToken.start;
switch (_peek()) {
case TokenKind.SLASH:
@@ -2061,7 +2065,7 @@
return expressions;
}
- static int MAX_UNICODE = int.parse('0x10FFFF');
+ static final int MAX_UNICODE = int.parse('0x10FFFF');
// Term grammar:
//
@@ -2085,7 +2089,7 @@
// function: IDENT '(' expr ')'
//
processTerm([bool ieFilter = false]) {
- int start = _peekToken.start;
+ var start = _peekToken.start;
Token t; // token for term's value
var value; // value of term (numeric values)
@@ -2193,8 +2197,8 @@
}
// Yes, process the color as an RGB value.
- String rgbColor = TokenKind.decimalToHex(
- TokenKind.colorValue(colorEntry), 6);
+ var rgbColor =
+ TokenKind.decimalToHex(TokenKind.colorValue(colorEntry), 6);
return _parseHex(rgbColor, _makeSpan(start));
case TokenKind.UNICODE_RANGE:
var first;
@@ -2248,8 +2252,8 @@
}
/** Process all dimension units. */
- processDimension(Token t, var value, Span span) {
- var term;
+ LiteralTerm processDimension(Token t, var value, Span span) {
+ LiteralTerm term;
var unitType = this._peek();
switch (unitType) {
@@ -2328,11 +2332,11 @@
return term;
}
- processQuotedString([bool urlString = false]) {
- int start = _peekToken.start;
+ String processQuotedString([bool urlString = false]) {
+ var start = _peekToken.start;
// URI term sucks up everything inside of quotes(' or ") or between parens
- int stopToken = urlString ? TokenKind.RPAREN : -1;
+ var stopToken = urlString ? TokenKind.RPAREN : -1;
switch (_peek()) {
case TokenKind.SINGLE_QUOTE:
stopToken = TokenKind.SINGLE_QUOTE;
@@ -2358,13 +2362,13 @@
}
// Gobble up everything until we hit our stop token.
- int runningStart = _peekToken.start;
+ var runningStart = _peekToken.start;
while (_peek() != stopToken && _peek() != TokenKind.END_OF_FILE) {
var tok = _next();
}
// All characters between quotes is the string.
- int end = _peekToken.end;
+ var end = _peekToken.end;
var stringValue = (_peekToken.span as FileSpan).file.getText(start,
end - 1);
@@ -2386,7 +2390,7 @@
* then parse to the right paren ignoring everything in between.
*/
processIEFilter(int startAfterProgidColon) {
- int parens = 0;
+ var parens = 0;
while (_peek() != TokenKind.END_OF_FILE) {
switch (_peek()) {
@@ -2413,14 +2417,14 @@
// function: IDENT '(' expr ')'
//
processFunction(Identifier func) {
- int start = _peekToken.start;
+ var start = _peekToken.start;
- String name = func.name;
+ var name = func.name;
switch (name) {
case 'url':
// URI term sucks up everything inside of quotes(' or ") or between parens
- String urlParam = processQuotedString(true);
+ var urlParam = processQuotedString(true);
// TODO(terry): Better error messge and checking for mismatched quotes.
if (_peek() == TokenKind.END_OF_FILE) {
@@ -2470,7 +2474,7 @@
return null;
}
- identifier() {
+ Identifier identifier() {
var tok = _next();
if (!TokenKind.isIdentifier(tok.kind) &&
@@ -2486,7 +2490,7 @@
// TODO(terry): Move this to base <= 36 and into shared code.
static int _hexDigit(int c) {
- if(c >= 48/*0*/ && c <= 57/*9*/) {
+ if (c >= 48/*0*/ && c <= 57/*9*/) {
return c - 48;
} else if (c >= 97/*a*/ && c <= 102/*f*/) {
return c - 87;
@@ -2498,9 +2502,9 @@
}
HexColorTerm _parseHex(String hexText, Span span) {
- int hexValue = 0;
+ var hexValue = 0;
- for (int i = 0; i < hexText.length; i++) {
+ for (var i = 0; i < hexText.length; i++) {
var digit = _hexDigit(hexText.codeUnitAt(i));
if (digit < 0) {
_warning('Bad hex number', span);
@@ -2535,7 +2539,7 @@
ExpressionsProcessor(this._exprs);
// TODO(terry): Only handles ##px unit.
- processFontSize() {
+ FontExpression processFontSize() {
/* font-size[/line-height]
*
* Possible size values:
@@ -2553,7 +2557,7 @@
*/
LengthTerm size;
LineHeight lineHt;
- bool nextIsLineHeight = false;
+ var nextIsLineHeight = false;
for (; _index < _exprs.expressions.length; _index++) {
var expr = _exprs.expressions[_index];
if (size == null && expr is LengthTerm) {
@@ -2580,14 +2584,14 @@
return new FontExpression(_exprs.span, size: size, lineHeight: lineHt);
}
- processFontFamily() {
- final List<String> family = <String>[];
+ FontExpression processFontFamily() {
+ var family = <String>[];
/* Possible family values:
* font-family: arial, Times new roman ,Lucida Sans Unicode,Courier;
* font-family: "Times New Roman", arial, Lucida Sans Unicode, Courier;
*/
- bool moreFamilies = false;
+ var moreFamilies = false;
for (; _index < _exprs.expressions.length; _index++) {
Expression expr = _exprs.expressions[_index];
@@ -2609,8 +2613,8 @@
return new FontExpression(_exprs.span, family: family);
}
- processFont() {
- var family;
+ FontExpression processFont() {
+ List<String> family;
// Process all parts of the font expression.
FontExpression fontSize;
@@ -2645,8 +2649,8 @@
StringBuffer result = null;
for (int i = 0; i < text.length; i++) {
- int code = text.codeUnitAt(i);
- var replace = null;
+ var code = text.codeUnitAt(i);
+ String replace = null;
switch (code) {
case 34/*'"'*/: if (!single) replace = r'\"'; break;
case 39/*"'"*/: if (single) replace = r"\'"; break;
diff --git a/lib/src/analyzer.dart b/lib/src/analyzer.dart
index cd0c6fb..e0ec078 100644
--- a/lib/src/analyzer.dart
+++ b/lib/src/analyzer.dart
@@ -573,7 +573,7 @@
* parameters.
*/
class CallMixin extends Visitor {
- var mixinDef;
+ final MixinDefinition mixinDef;
List _definedArgs;
Expressions _currExpressions;
int _currIndex = -1;
@@ -595,7 +595,7 @@
* Given a mixin's defined arguments return a cloned mixin defintion that has
* replaced all defined arguments with user's supplied VarUsages.
*/
- transform(List<TreeNode> callArgs) {
+ MixinDefinition transform(List<TreeNode> callArgs) {
// TODO(terry): Handle default arguments and varArgs.
// Transform mixin with callArgs.
var index = 0;
@@ -620,7 +620,6 @@
}
var expressions = varUsages[varDef.definedName];
- var expressionsLength = expressions.length;
expressions.forEach((k, v) {
for (var usagesIndex in v) {
k.expressions.replaceRange(usagesIndex, usagesIndex + 1, callArg);
@@ -724,7 +723,7 @@
bool _allIncludes(rulesets) =>
rulesets.every((rule) => rule is IncludeDirective || rule is NoOp);
- CallMixin _createCallDeclMixin(mixinDef) {
+ CallMixin _createCallDeclMixin(MixinDefinition mixinDef) {
callMap.putIfAbsent(mixinDef.name, () =>
callMap[mixinDef.name] = new CallMixin(mixinDef, varDefs));
return callMap[mixinDef.name];
@@ -968,8 +967,8 @@
* Changes any selector that matches @extend.
*/
class InheritExtends extends Visitor {
- Messages _messages;
- AllExtends _allExtends;
+ final Messages _messages;
+ final AllExtends _allExtends;
InheritExtends(this._messages, this._allExtends);
diff --git a/lib/src/css_printer.dart b/lib/src/css_printer.dart
index 73c2984..9a80ee1 100644
--- a/lib/src/css_printer.dart
+++ b/lib/src/css_printer.dart
@@ -104,7 +104,7 @@
emit(' ');
var declsMargin = node._declsMargin;
- int declsMarginLength = declsMargin.length;
+ var declsMarginLength = declsMargin.length;
for (var i = 0; i < declsMarginLength; i++) {
if (i > 0) emit(_newLine);
emit('{$_newLine');
@@ -161,7 +161,7 @@
}
void visitStyletDirective(StyletDirective node) {
- emit('/* @stylet export as ${node._dartClassName} */\n');
+ emit('/* @stylet export as ${node.dartClassName} */\n');
}
void visitNamespaceDirective(NamespaceDirective node) {
@@ -224,7 +224,7 @@
}
void visitDeclarationGroup(DeclarationGroup node) {
- var declarations = node._declarations;
+ var declarations = node.declarations;
var declarationsLength = declarations.length;
for (var i = 0; i < declarationsLength; i++) {
if (i > 0) emit(_newLine);
@@ -338,7 +338,7 @@
}
void visitSelectorExpression(SelectorExpression node) {
- var expressions = node._expressions;
+ var expressions = node.expressions;
var expressionsLength = expressions.length;
for (var i = 0; i < expressionsLength; i++) {
// Add space seperator between terms without an operator.
diff --git a/lib/src/messages.dart b/lib/src/messages.dart
index 829b419..24964ad 100644
--- a/lib/src/messages.dart
+++ b/lib/src/messages.dart
@@ -68,7 +68,7 @@
}
}
-typedef void PrintHandler(Object obj);
+typedef void PrintHandler(Message obj);
/**
* This class tracks and prints information, warnings, and errors emitted by the
diff --git a/lib/src/tree.dart b/lib/src/tree.dart
index 941eb57..f3c71eb 100644
--- a/lib/src/tree.dart
+++ b/lib/src/tree.dart
@@ -23,19 +23,25 @@
class Wildcard extends TreeNode {
Wildcard(Span span): super(span);
Wildcard clone() => new Wildcard(span);
- visit(VisitorBase visitor) => visitor.visitWildcard(this);
+ void visit(VisitorBase visitor) => visitor.visitWildcard(this);
+
+ String get name => '*';
}
class ThisOperator extends TreeNode {
ThisOperator(Span span): super(span);
ThisOperator clone() => new ThisOperator(span);
- visit(VisitorBase visitor) => visitor.visitThisOperator(this);
+ void visit(VisitorBase visitor) => visitor.visitThisOperator(this);
+
+ String get name => '&';
}
class Negation extends TreeNode {
Negation(Span span): super(span);
Negation clone() => new Negation(span);
- visit(VisitorBase visitor) => visitor.visitNegation(this);
+ void visit(VisitorBase visitor) => visitor.visitNegation(this);
+
+ String get name => 'not';
}
// /* .... */
@@ -44,14 +50,14 @@
CssComment(this.comment, Span span): super(span);
CssComment clone() => new CssComment(comment, span);
- visit(VisitorBase visitor) => visitor.visitCssComment(this);
+ void visit(VisitorBase visitor) => visitor.visitCssComment(this);
}
// CDO/CDC (Comment Definition Open <!-- and Comment Definition Close -->).
class CommentDefinition extends CssComment {
CommentDefinition(String comment, Span span): super(comment, span);
CommentDefinition clone() => new CommentDefinition(comment, span);
- visit(VisitorBase visitor) => visitor.visitCommentDefinition(this);
+ void visit(VisitorBase visitor) => visitor.visitCommentDefinition(this);
}
class SelectorGroup extends TreeNode {
@@ -110,32 +116,33 @@
new SimpleSelectorSequence(simpleSelector, span, combinator);
void visit(VisitorBase visitor) => visitor.visitSimpleSelectorSequence(this);
+
+ String toString() => simpleSelector.name;
}
/* All other selectors (element, #id, .class, attribute, pseudo, negation,
* namespace, *) are derived from this selector.
*/
-class SimpleSelector extends TreeNode {
- final _name; // Wildcard, ThisOperator, Identifier, others?
+abstract class SimpleSelector extends TreeNode {
+ final _name; // Wildcard, ThisOperator, Identifier, Negation, others?
SimpleSelector(this._name, Span span) : super(span);
- // Name can be an Identifier or WildCard we'll return either the name or '*'.
- String get name => isWildcard ? '*' : isThis ? '&' : _name.name;
+ String get name => _name.name;
bool get isWildcard => _name is Wildcard;
bool get isThis => _name is ThisOperator;
- SimpleSelector clone() => new SimpleSelector(_name, span);
-
void visit(VisitorBase visitor) => visitor.visitSimpleSelector(this);
}
// element name
class ElementSelector extends SimpleSelector {
ElementSelector(name, Span span) : super(name, span);
- visit(VisitorBase visitor) => visitor.visitElementSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitElementSelector(this);
+
+ ElementSelector clone() => new ElementSelector(_name, span);
String toString() => name;
}
@@ -155,7 +162,7 @@
NamespaceSelector clone() => new NamespaceSelector(_namespace, "", span);
- visit(VisitorBase visitor) => visitor.visitNamespaceSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitNamespaceSelector(this);
String toString() => "$namespace|${nameAsSimpleSelector.name}";
}
@@ -219,7 +226,7 @@
AttributeSelector clone() => new AttributeSelector(_name, _op, _value, span);
- visit(VisitorBase visitor) => visitor.visitAttributeSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitAttributeSelector(this);
String toString() => "[$name${matchOperator()}${valueToString()}]";
}
@@ -228,7 +235,7 @@
class IdSelector extends SimpleSelector {
IdSelector(Identifier name, Span span) : super(name, span);
IdSelector clone() => new IdSelector(_name, span);
- visit(VisitorBase visitor) => visitor.visitIdSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitIdSelector(this);
String toString() => "#$_name";
}
@@ -237,7 +244,7 @@
class ClassSelector extends SimpleSelector {
ClassSelector(Identifier name, Span span) : super(name, span);
ClassSelector clone() => new ClassSelector(_name, span);
- visit(VisitorBase visitor) => visitor.visitClassSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitClassSelector(this);
String toString() => ".$_name";
}
@@ -245,7 +252,9 @@
// :pseudoClass
class PseudoClassSelector extends SimpleSelector {
PseudoClassSelector(Identifier name, Span span) : super(name, span);
- visit(VisitorBase visitor) => visitor.visitPseudoClassSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitPseudoClassSelector(this);
+
+ PseudoClassSelector clone() => new PseudoClassSelector(_name, span);
String toString() => ":$name";
}
@@ -253,59 +262,64 @@
// ::pseudoElement
class PseudoElementSelector extends SimpleSelector {
PseudoElementSelector(Identifier name, Span span) : super(name, span);
- visit(VisitorBase visitor) => visitor.visitPseudoElementSelector(this);
+ void visit(VisitorBase visitor) => visitor.visitPseudoElementSelector(this);
+
+ PseudoElementSelector clone() => new PseudoElementSelector(_name, span);
String toString() => "::$name";
}
// :pseudoClassFunction(expression)
class PseudoClassFunctionSelector extends PseudoClassSelector {
- SelectorExpression expression;
+ final SelectorExpression expression;
PseudoClassFunctionSelector(Identifier name, this.expression, Span span)
: super(name, span);
+
PseudoClassFunctionSelector clone() =>
new PseudoClassFunctionSelector(_name, expression, span);
- visit(VisitorBase visitor) => visitor.visitPseudoClassFunctionSelector(this);
+
+ void visit(VisitorBase visitor) =>
+ visitor.visitPseudoClassFunctionSelector(this);
}
// ::pseudoElementFunction(expression)
class PseudoElementFunctionSelector extends PseudoElementSelector {
- SelectorExpression expression;
+ final SelectorExpression expression;
PseudoElementFunctionSelector(Identifier name, this.expression, Span span)
: super(name, span);
+
PseudoElementFunctionSelector clone() =>
new PseudoElementFunctionSelector(_name, expression, span);
- visit(VisitorBase visitor) =>
+
+ void visit(VisitorBase visitor) =>
visitor.visitPseudoElementFunctionSelector(this);
}
class SelectorExpression extends TreeNode {
- final List<Expression> _expressions = [];
+ final List<Expression> expressions = [];
SelectorExpression(Span span): super(span);
- add(Expression expression) {
- _expressions.add(expression);
+ void add(Expression expression) {
+ expressions.add(expression);
}
- List<Expression> get expressions => _expressions;
-
SelectorExpression clone() {
var selectorExpr = new SelectorExpression(span);
- for (var expr in _expressions) {
+ for (var expr in expressions) {
selectorExpr.add(expr.clone());
}
return selectorExpr;
}
- visit(VisitorBase visitor) => visitor.visitSelectorExpression(this);
+ void visit(VisitorBase visitor) => visitor.visitSelectorExpression(this);
}
// :NOT(negation_arg)
class NegationSelector extends SimpleSelector {
- SimpleSelector negationArg;
+ final SimpleSelector negationArg;
NegationSelector(this.negationArg, Span span)
: super(new Negation(span), span);
@@ -320,7 +334,7 @@
NoOp clone() => new NoOp();
- visit(VisitorBase visitor) => visitor.visitNoOp(this);
+ void visit(VisitorBase visitor) => visitor.visitNoOp(this);
}
class StyleSheet extends TreeNode {
@@ -349,7 +363,7 @@
class TopLevelProduction extends TreeNode {
TopLevelProduction(Span span) : super(span);
TopLevelProduction clone() => new TopLevelProduction(span);
- visit(VisitorBase visitor) => visitor.visitTopLevelProduction(this);
+ void visit(VisitorBase visitor) => visitor.visitTopLevelProduction(this);
}
class RuleSet extends TopLevelProduction {
@@ -367,7 +381,7 @@
return new RuleSet(cloneSelectorGroup, cloneDeclarationGroup, span);
}
- visit(VisitorBase visitor) => visitor.visitRuleSet(this);
+ void visit(VisitorBase visitor) => visitor.visitRuleSet(this);
}
class Directive extends TreeNode {
@@ -456,7 +470,7 @@
}
return new MediaQuery(_mediaUnary, _mediaType, cloneExpressions, span);
}
- visit(VisitorBase visitor) => visitor.visitMediaQuery(this);
+ void visit(VisitorBase visitor) => visitor.visitMediaQuery(this);
}
class MediaDirective extends Directive {
@@ -585,24 +599,22 @@
}
class StyletDirective extends Directive {
- final String _dartClassName;
- final List<RuleSet> _rulesets;
+ final String dartClassName;
+ final List<RuleSet> rulesets;
- StyletDirective(this._dartClassName, this._rulesets, Span span) : super(span);
+ StyletDirective(this.dartClassName, this.rulesets, Span span) : super(span);
bool get isBuiltIn => false;
bool get isExtension => true;
- String get dartClassName => _dartClassName;
- List<RuleSet> get rulesets => _rulesets;
-
StyletDirective clone() {
var cloneRulesets = [];
- for (var ruleset in _rulesets) {
+ for (var ruleset in rulesets) {
cloneRulesets.add(ruleset.clone());
}
- return new StyletDirective(_dartClassName, cloneRulesets, span);
+ return new StyletDirective(dartClassName, cloneRulesets, span);
}
+
void visit(VisitorBase visitor) => visitor.visitStyletDirective(this);
}
@@ -616,6 +628,7 @@
NamespaceDirective(this._prefix, this._uri, Span span) : super(span);
NamespaceDirective clone() => new NamespaceDirective(_prefix, _uri, span);
+
void visit(VisitorBase visitor) => visitor.visitNamespaceDirective(this);
String get prefix => _prefix.length > 0 ? '$_prefix ' : '';
@@ -629,6 +642,7 @@
VarDefinitionDirective clone() =>
new VarDefinitionDirective(def.clone(), span);
+
void visit(VisitorBase visitor) => visitor.visitVarDefinitionDirective(this);
}
@@ -647,6 +661,7 @@
}
return new MixinDefinition(name, cloneDefinedArgs, varArgs, span);
}
+
void visit(VisitorBase visitor) => visitor.visitMixinDefinition(this);
}
@@ -670,6 +685,7 @@
return new MixinRulesetDirective(name, clonedArgs, varArgs, clonedRulesets,
span);
}
+
void visit(VisitorBase visitor) => visitor.visitMixinRulesetDirective(this);
}
@@ -679,6 +695,7 @@
MixinDeclarationDirective(String name, List<VarDefinitionDirective> args,
bool varArgs, this.declarations, Span span) :
super(name, args, varArgs, span);
+
MixinDeclarationDirective clone() {
var clonedArgs = [];
for (var arg in definedArgs) {
@@ -687,6 +704,7 @@
return new MixinDeclarationDirective(name, clonedArgs, varArgs,
declarations.clone(), span);
}
+
void visit(VisitorBase visitor) => visitor.visitMixinDeclarationDirective(this);
}
@@ -721,7 +739,7 @@
final Identifier _property;
final Expression _expression;
/** Style exposed to Dart. */
- dynamic _dart;
+ dynamic dartStyle;
final bool important;
/**
@@ -734,21 +752,17 @@
*/
final bool isIE7;
- Declaration(this._property, this._expression, this._dart, Span span,
+ Declaration(this._property, this._expression, this.dartStyle, Span span,
{important: false, ie7: false})
: this.important = important, this.isIE7 = ie7, super(span);
String get property => isIE7 ? '*${_property.name}' : _property.name;
Expression get expression => _expression;
- bool get hasDartStyle => _dart != null;
- get dartStyle => _dart;
- set dartStyle(dStyle) {
- _dart = dStyle;
- }
+ bool get hasDartStyle => dartStyle != null;
Declaration clone() =>
- new Declaration(_property.clone(), _expression.clone(), _dart, span,
+ new Declaration(_property.clone(), _expression.clone(), dartStyle, span,
important: important);
void visit(VisitorBase visitor) => visitor.visitDeclaration(this);
@@ -768,11 +782,10 @@
String get definedName => _property.name;
- set dartStyle(dStyle) { }
-
VarDefinition clone() =>
new VarDefinition(_property.clone(),
expression != null ? expression.clone() : null, span);
+
void visit(VisitorBase visitor) => visitor.visitVarDefinition(this);
}
@@ -797,16 +810,13 @@
}
class ExtendDeclaration extends Declaration {
- List<SimpleSelectorSequence> selectors;
+ final List<TreeNode> selectors;
ExtendDeclaration(this.selectors, Span span) :
super(null, null, null, span);
ExtendDeclaration clone() {
- List<SimpleSelectorSequence> newSelector = [];
- for (var selectorSeq in selectors) {
- newSelector.add(selectorSeq.clone());
- }
+ var newSelector = selectors.map((s) => s.clone()).toList();
return new ExtendDeclaration(newSelector, span);
}
@@ -815,17 +825,12 @@
class DeclarationGroup extends TreeNode {
/** Can be either Declaration or RuleSet (if nested selector). */
- final List _declarations;
+ final List declarations;
- DeclarationGroup(this._declarations, Span span) : super(span);
-
- List get declarations => _declarations;
+ DeclarationGroup(this.declarations, Span span) : super(span);
DeclarationGroup clone() {
- var clonedDecls = [];
- for (var decl in _declarations) {
- clonedDecls.add(decl.clone());
- }
+ var clonedDecls = declarations.map((d) => d.clone()).toList();
return new DeclarationGroup(clonedDecls, span);
}
@@ -917,17 +922,15 @@
}
class UnitTerm extends LiteralTerm {
- final int _unit;
+ final int unit;
- UnitTerm(value, String t, Span span, this._unit) : super(value, t, span);
+ UnitTerm(value, String t, Span span, this.unit) : super(value, t, span);
- int get unit => _unit;
-
- UnitTerm clone() => new UnitTerm(value, text, span, _unit);
+ UnitTerm clone() => new UnitTerm(value, text, span, unit);
void visit(VisitorBase visitor) => visitor.visitUnitTerm(this);
- String unitToString() => TokenKind.unitToString(_unit);
+ String unitToString() => TokenKind.unitToString(unit);
String toString() => '$text${unitToString()}';
}
@@ -935,14 +938,14 @@
class LengthTerm extends UnitTerm {
LengthTerm(value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(this._unit == TokenKind.UNIT_LENGTH_PX ||
- this._unit == TokenKind.UNIT_LENGTH_CM ||
- this._unit == TokenKind.UNIT_LENGTH_MM ||
- this._unit == TokenKind.UNIT_LENGTH_IN ||
- this._unit == TokenKind.UNIT_LENGTH_PT ||
- this._unit == TokenKind.UNIT_LENGTH_PC);
+ assert(this.unit == TokenKind.UNIT_LENGTH_PX ||
+ this.unit == TokenKind.UNIT_LENGTH_CM ||
+ this.unit == TokenKind.UNIT_LENGTH_MM ||
+ this.unit == TokenKind.UNIT_LENGTH_IN ||
+ this.unit == TokenKind.UNIT_LENGTH_PT ||
+ this.unit == TokenKind.UNIT_LENGTH_PC);
}
- LengthTerm clone() => new LengthTerm(value, text, span, _unit);
+ LengthTerm clone() => new LengthTerm(value, text, span, unit);
void visit(VisitorBase visitor) => visitor.visitLengthTerm(this);
}
@@ -967,10 +970,10 @@
class AngleTerm extends UnitTerm {
AngleTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(this._unit == TokenKind.UNIT_ANGLE_DEG ||
- this._unit == TokenKind.UNIT_ANGLE_RAD ||
- this._unit == TokenKind.UNIT_ANGLE_GRAD ||
- this._unit == TokenKind.UNIT_ANGLE_TURN);
+ assert(this.unit == TokenKind.UNIT_ANGLE_DEG ||
+ this.unit == TokenKind.UNIT_ANGLE_RAD ||
+ this.unit == TokenKind.UNIT_ANGLE_GRAD ||
+ this.unit == TokenKind.UNIT_ANGLE_TURN);
}
AngleTerm clone() => new AngleTerm(value, text, span, unit);
@@ -980,9 +983,9 @@
class TimeTerm extends UnitTerm {
TimeTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(this._unit == TokenKind.UNIT_ANGLE_DEG ||
- this._unit == TokenKind.UNIT_TIME_MS ||
- this._unit == TokenKind.UNIT_TIME_S);
+ assert(this.unit == TokenKind.UNIT_ANGLE_DEG ||
+ this.unit == TokenKind.UNIT_TIME_MS ||
+ this.unit == TokenKind.UNIT_TIME_S);
}
TimeTerm clone() => new TimeTerm(value, text, span, unit);
@@ -992,7 +995,7 @@
class FreqTerm extends UnitTerm {
FreqTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(_unit == TokenKind.UNIT_FREQ_HZ || _unit == TokenKind.UNIT_FREQ_KHZ);
+ assert(unit == TokenKind.UNIT_FREQ_HZ || unit == TokenKind.UNIT_FREQ_KHZ);
}
FreqTerm clone() => new FreqTerm(value, text, span, unit);
@@ -1016,9 +1019,9 @@
class ResolutionTerm extends UnitTerm {
ResolutionTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(_unit == TokenKind.UNIT_RESOLUTION_DPI ||
- _unit == TokenKind.UNIT_RESOLUTION_DPCM ||
- _unit == TokenKind.UNIT_RESOLUTION_DPPX);
+ assert(unit == TokenKind.UNIT_RESOLUTION_DPI ||
+ unit == TokenKind.UNIT_RESOLUTION_DPCM ||
+ unit == TokenKind.UNIT_RESOLUTION_DPPX);
}
ResolutionTerm clone() => new ResolutionTerm(value, text, span, unit);
@@ -1028,7 +1031,7 @@
class ChTerm extends UnitTerm {
ChTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(_unit == TokenKind.UNIT_CH);
+ assert(unit == TokenKind.UNIT_CH);
}
ChTerm clone() => new ChTerm(value, text, span, unit);
@@ -1038,7 +1041,7 @@
class RemTerm extends UnitTerm {
RemTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(_unit == TokenKind.UNIT_REM);
+ assert(unit == TokenKind.UNIT_REM);
}
RemTerm clone() => new RemTerm(value, text, span, unit);
@@ -1048,10 +1051,10 @@
class ViewportTerm extends UnitTerm {
ViewportTerm(var value, String t, Span span,
[int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
- assert(_unit == TokenKind.UNIT_VIEWPORT_VW ||
- _unit == TokenKind.UNIT_VIEWPORT_VH ||
- _unit == TokenKind.UNIT_VIEWPORT_VMIN ||
- _unit == TokenKind.UNIT_VIEWPORT_VMAX);
+ assert(unit == TokenKind.UNIT_VIEWPORT_VW ||
+ unit == TokenKind.UNIT_VIEWPORT_VH ||
+ unit == TokenKind.UNIT_VIEWPORT_VMIN ||
+ unit == TokenKind.UNIT_VIEWPORT_VMAX);
}
ViewportTerm clone() => new ViewportTerm(value, text, span, unit);
@@ -1094,7 +1097,7 @@
GroupTerm(Span span) : _terms = [], super(span);
- add(LiteralTerm term) {
+ void add(LiteralTerm term) {
_terms.add(term);
}
@@ -1114,7 +1117,7 @@
Expressions(Span span): super(span);
- add(Expression expression) {
+ void add(Expression expression) {
expressions.add(expression);
}
@@ -1151,13 +1154,13 @@
}
abstract class DartStyleExpression extends TreeNode {
- static final int unknownType = 0;
- static final int fontStyle = 1;
- static final int marginStyle = 2;
- static final int borderStyle = 3;
- static final int paddingStyle = 4;
- static final int heightStyle = 5;
- static final int widthStyle = 6;
+ static const int unknownType = 0;
+ static const int fontStyle = 1;
+ static const int marginStyle = 2;
+ static const int borderStyle = 3;
+ static const int paddingStyle = 4;
+ static const int heightStyle = 5;
+ static const int widthStyle = 6;
final int _styleType;
int priority;
@@ -1186,20 +1189,19 @@
}
class FontExpression extends DartStyleExpression {
- Font font;
+ final Font font;
// font-style font-variant font-weight font-size/line-height font-family
- FontExpression(Span span, {dynamic size, List<String>family,
- int weight, String style, String variant, LineHeight lineHeight})
- : super(DartStyleExpression.fontStyle, span) {
- // TODO(terry): Only px/pt for now need to handle all possible units to
- // support calc expressions on units.
- font = new Font(size : size is LengthTerm ? size.value : size,
- family: family, weight: weight, style: style, variant: variant,
- lineHeight: lineHeight);
- }
+ // TODO(terry): Only px/pt for now need to handle all possible units to
+ // support calc expressions on units.
+ FontExpression(Span span, {dynamic size, List<String> family,
+ int weight, String style, String variant, LineHeight lineHeight}) :
+ font = new Font(size : size is LengthTerm ? size.value : size,
+ family: family, weight: weight, style: style, variant: variant,
+ lineHeight: lineHeight),
+ super(DartStyleExpression.fontStyle, span);
- merged(FontExpression newFontExpr) {
+ FontExpression merged(FontExpression newFontExpr) {
if (this.isFont && newFontExpr.isFont) {
return new FontExpression.merge(this, newFontExpr);
}
@@ -1341,7 +1343,7 @@
}
HeightExpression clone() => new HeightExpression(span, height);
- visit(VisitorBase visitor) => visitor.visitHeightExpression(this);
+ void visit(VisitorBase visitor) => visitor.visitHeightExpression(this);
}
class WidthExpression extends DartStyleExpression {
@@ -1359,7 +1361,7 @@
}
WidthExpression clone() => new WidthExpression(span, width);
- visit(VisitorBase visitor) => visitor.visitWidthExpression(this);
+ void visit(VisitorBase visitor) => visitor.visitWidthExpression(this);
}
class PaddingExpression extends BoxExpression {
@@ -1393,5 +1395,5 @@
PaddingExpression clone() =>
new PaddingExpression(span, top: box.top, right: box.right,
bottom: box.bottom, left: box.left);
- visit(VisitorBase visitor) => visitor.visitPaddingExpression(this);
+ void visit(VisitorBase visitor) => visitor.visitPaddingExpression(this);
}
diff --git a/lib/src/tree_base.dart b/lib/src/tree_base.dart
index e61a06c..6dc27b1 100644
--- a/lib/src/tree_base.dart
+++ b/lib/src/tree_base.dart
@@ -77,20 +77,6 @@
writeln('${label}: ${v}');
}
- void writeList(String label, List<TreeNode> list) {
- write('${label}: ');
- if (list == null) {
- buf.write('null');
- buf.write('\n');
- } else {
- for (var item in list) {
- buf.write(item.toString());
- buf.write(', ');
- }
- buf.write('\n');
- }
- }
-
void writeNodeList(String label, List<TreeNode> list) {
writeln('${label} [');
if (list != null) {
diff --git a/lib/src/tree_printer.dart b/lib/src/tree_printer.dart
index 3d381bd..3a8b748 100644
--- a/lib/src/tree_printer.dart
+++ b/lib/src/tree_printer.dart
@@ -129,9 +129,9 @@
void visitStyletDirective(StyletDirective node) {
heading('StyletDirective', node);
- output.writeValue('dartClassName', node._dartClassName);
+ output.writeValue('dartClassName', node.dartClassName);
output.depth++;
- output.writeNodeList('rulesets', node._rulesets);
+ output.writeNodeList('rulesets', node.rulesets);
output.depth--;
}
@@ -200,7 +200,7 @@
void visitDeclarationGroup(DeclarationGroup node) {
heading('DeclarationGroup', node);
output.depth++;
- output.writeNodeList('declarations', node._declarations);
+ output.writeNodeList('declarations', node.declarations);
output.depth--;
}
@@ -208,7 +208,7 @@
heading('MarginGroup', node);
output.depth++;
output.writeValue('@directive', node.margin_sym);
- output.writeNodeList('declarations', node._declarations);
+ output.writeNodeList('declarations', node.declarations);
output.depth--;
}
diff --git a/lib/visitor.dart b/lib/visitor.dart
index 3b20a4e..6c009ff 100644
--- a/lib/visitor.dart
+++ b/lib/visitor.dart
@@ -111,7 +111,7 @@
/** Base vistor class for the style sheet AST. */
class Visitor implements VisitorBase {
/** Helper function to walk a list of nodes. */
- void _visitNodeList(list) {
+ void _visitNodeList(List<TreeNode> list) {
// Don't use iterable otherwise the list can't grow while using Visitor.
// It certainly can't have items deleted before the index being iterated
// but items could be added after the index.
@@ -194,7 +194,7 @@
}
void visitStyletDirective(StyletDirective node) {
- _visitNodeList(node._rulesets);
+ _visitNodeList(node.rulesets);
}
void visitNamespaceDirective(NamespaceDirective node) { }
@@ -230,7 +230,7 @@
}
void visitDeclarationGroup(DeclarationGroup node) {
- _visitNodeList(node._declarations);
+ _visitNodeList(node.declarations);
}
void visitMarginGroup(MarginGroup node) => visitDeclarationGroup(node);
@@ -329,7 +329,7 @@
visitSimpleSelector(node);
void visitSelectorExpression(SelectorExpression node) {
- _visitNodeList(node._expressions);
+ _visitNodeList(node.expressions);
}
void visitUnicodeRangeTerm(UnicodeRangeTerm node) { }
diff --git a/test/testing.dart b/test/testing.dart
index 168a4e5..002c452 100644
--- a/test/testing.dart
+++ b/test/testing.dart
@@ -18,7 +18,8 @@
* CSS will allow any property/value pairs regardless of validity; all of our
* tests (by default) will ensure that the CSS is really valid.
*/
-StyleSheet parseCss(String cssInput, {List errors, List opts}) =>
+StyleSheet parseCss(String cssInput, {List<Message> errors,
+ List<String> opts}) =>
parse(cssInput, errors: errors, options: opts == null ?
['--no-colors', '--checked', '--warnings_as_errors', 'memory'] : opts);
@@ -27,13 +28,14 @@
* CSS will allow any property/value pairs regardless of validity; all of our
* tests (by default) will ensure that the CSS is really valid.
*/
-StyleSheet compileCss(String cssInput, {List errors, List opts,
+StyleSheet compileCss(String cssInput, {List<Message> errors, List<String> opts,
bool polyfill: false, List<StyleSheet> includes: null}) =>
compile(cssInput, errors: errors, options: opts == null ?
['--no-colors', '--checked', '--warnings_as_errors', 'memory'] : opts,
polyfill: polyfill, includes: includes);
-StyleSheet polyFillCompileCss(input, {List errors, List opts}) =>
+StyleSheet polyFillCompileCss(input, {List<Message> errors,
+ List<String> opts}) =>
compileCss(input, errors: errors, polyfill: true, opts: opts);
/** CSS emitter walks the style sheet tree and emits readable CSS. */