Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Side by Side Diff: packages/csslib/lib/src/css_printer.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/csslib/lib/src/analyzer.dart ('k') | packages/csslib/lib/src/messages.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of csslib.visitor; 5 part of csslib.visitor;
6 6
7 /** 7 /**
8 * Visitor that produces a formatted string representation of the CSS tree. 8 * Visitor that produces a formatted string representation of the CSS tree.
9 */ 9 */
10 class CssPrinter extends Visitor { 10 class CssPrinter extends Visitor {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 void visitCssComment(CssComment node) { 47 void visitCssComment(CssComment node) {
48 emit('/* ${node.comment} */'); 48 emit('/* ${node.comment} */');
49 } 49 }
50 50
51 void visitCommentDefinition(CommentDefinition node) { 51 void visitCommentDefinition(CommentDefinition node) {
52 emit('<!-- ${node.comment} -->'); 52 emit('<!-- ${node.comment} -->');
53 } 53 }
54 54
55 void visitMediaExpression(MediaExpression node) { 55 void visitMediaExpression(MediaExpression node) {
56 emit(node.andOperator ? ' AND ' : ' '); 56 emit(node.andOperator ? ' AND ' : ' ');
57 emit('(${node.mediaFeature}:'); 57 emit('(${node.mediaFeature}');
58 visitExpressions(node.exprs); 58 if (node.exprs.expressions.isNotEmpty) {
59 emit(':');
60 visitExpressions(node.exprs);
61 }
59 emit(')'); 62 emit(')');
60 } 63 }
61 64
62 void visitMediaQuery(MediaQuery query) { 65 void visitMediaQuery(MediaQuery query) {
63 var unary = query.hasUnary ? ' ${query.unary}' : ''; 66 var unary = query.hasUnary ? ' ${query.unary}' : '';
64 var mediaType = query.hasMediaType ? ' ${query.mediaType}' : ''; 67 var mediaType = query.hasMediaType ? ' ${query.mediaType}' : '';
65 emit('$unary$mediaType'); 68 emit('$unary$mediaType');
66 for (var expression in query.expressions) { 69 for (var expression in query.expressions) {
67 visitMediaExpression(expression); 70 visitMediaExpression(expression);
68 } 71 }
69 } 72 }
70 73
71 void emitMediaQueries(queries) { 74 void emitMediaQueries(List<MediaQuery> queries) {
72 var queriesLen = queries.length; 75 var queriesLen = queries.length;
73 for (var i = 0; i < queriesLen; i++) { 76 for (var i = 0; i < queriesLen; i++) {
74 var query = queries[i]; 77 var query = queries[i];
75 if (query.hasMediaType && i > 0) emit(','); 78 if (i > 0) emit(',');
76 visitMediaQuery(query); 79 visitMediaQuery(query);
77 } 80 }
78 } 81 }
79 82
83 void visitDocumentDirective(DocumentDirective node) {
84 emit('$_newLine@-moz-document ');
85 node.functions.first.visit(this);
86 for (var function in node.functions.skip(1)) {
87 emit(',$_sp');
88 function.visit(this);
89 }
90 emit('$_sp{');
91 for (var ruleSet in node.groupRuleBody) {
92 ruleSet.visit(this);
93 }
94 emit('$_newLine}');
95 }
96
97 void visitSupportsDirective(SupportsDirective node) {
98 emit('$_newLine@supports ');
99 node.condition.visit(this);
100 emit('$_sp{');
101 for (var rule in node.groupRuleBody) {
102 rule.visit(this);
103 }
104 emit('$_newLine}');
105 }
106
107 void visitSupportsConditionInParens(SupportsConditionInParens node) {
108 emit('(');
109 node.condition.visit(this);
110 emit(')');
111 }
112
113 void visitSupportsNegation(SupportsNegation node) {
114 emit('not$_sp');
115 node.condition.visit(this);
116 }
117
118 void visitSupportsConjunction(SupportsConjunction node) {
119 node.conditions.first.visit(this);
120 for (var condition in node.conditions.skip(1)) {
121 emit('${_sp}and$_sp');
122 condition.visit(this);
123 }
124 }
125
126 void visitSupportsDisjunction(SupportsDisjunction node) {
127 node.conditions.first.visit(this);
128 for (var condition in node.conditions.skip(1)) {
129 emit('${_sp}or$_sp');
130 condition.visit(this);
131 }
132 }
133
134 void visitViewportDirective(ViewportDirective node) {
135 emit('@${node.name}$_sp{$_newLine');
136 node.declarations.visit(this);
137 emit('}');
138 }
139
80 void visitMediaDirective(MediaDirective node) { 140 void visitMediaDirective(MediaDirective node) {
81 emit(' @media'); 141 emit('$_newLine@media');
82 emitMediaQueries(node.mediaQueries); 142 emitMediaQueries(node.mediaQueries);
83 emit(' {'); 143 emit('$_sp{');
84 for (var ruleset in node.rulesets) { 144 for (var ruleset in node.rulesets) {
85 ruleset.visit(this); 145 ruleset.visit(this);
86 } 146 }
87 emit('$_newLine\}'); 147 emit('$_newLine}');
88 } 148 }
89 149
90 void visitHostDirective(HostDirective node) { 150 void visitHostDirective(HostDirective node) {
91 emit('\n@host {'); 151 emit('$_newLine@host$_sp{');
92 for (var ruleset in node.rulesets) { 152 for (var ruleset in node.rulesets) {
93 ruleset.visit(this); 153 ruleset.visit(this);
94 } 154 }
95 emit('$_newLine\}'); 155 emit('$_newLine}');
96 } 156 }
97 157
98 /** 158 /**
99 * @page : pseudoPage { 159 * @page : pseudoPage {
100 * decls 160 * decls
101 * } 161 * }
102 */ 162 */
103 void visitPageDirective(PageDirective node) { 163 void visitPageDirective(PageDirective node) {
104 emit('$_newLine@page'); 164 emit('$_newLine@page');
105 if (node.hasIdent || node.hasPseudoPage) { 165 if (node.hasIdent || node.hasPseudoPage) {
106 if (node.hasIdent) emit(' '); 166 if (node.hasIdent) emit(' ');
107 emit(node._ident); 167 emit(node._ident);
108 emit(node.hasPseudoPage ? ':${node._pseudoPage}' : ''); 168 emit(node.hasPseudoPage ? ':${node._pseudoPage}' : '');
109 } 169 }
110 emit(' ');
111 170
112 var declsMargin = node._declsMargin; 171 var declsMargin = node._declsMargin;
113 var declsMarginLength = declsMargin.length; 172 var declsMarginLength = declsMargin.length;
173 emit(' {$_newLine');
114 for (var i = 0; i < declsMarginLength; i++) { 174 for (var i = 0; i < declsMarginLength; i++) {
115 if (i > 0) emit(_newLine);
116 emit('{$_newLine');
117 declsMargin[i].visit(this); 175 declsMargin[i].visit(this);
118 emit('}');
119 } 176 }
177 emit('}');
120 } 178 }
121 179
122 /** @charset "charset encoding" */ 180 /** @charset "charset encoding" */
123 void visitCharsetDirective(CharsetDirective node) { 181 void visitCharsetDirective(CharsetDirective node) {
124 emit('$_newLine@charset "${node.charEncoding}";'); 182 emit('$_newLine@charset "${node.charEncoding}";');
125 } 183 }
126 184
127 void visitImportDirective(ImportDirective node) { 185 void visitImportDirective(ImportDirective node) {
128 bool isStartingQuote(String ch) => ('\'"'.indexOf(ch[0]) >= 0); 186 bool isStartingQuote(String ch) => ('\'"'.indexOf(ch[0]) >= 0);
129 187
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 TokenKind.idToValue(TokenKind.MARGIN_DIRECTIVES, node.margin_sym); 304 TokenKind.idToValue(TokenKind.MARGIN_DIRECTIVES, node.margin_sym);
247 305
248 emit("@$margin_sym_name {$_newLine"); 306 emit("@$margin_sym_name {$_newLine");
249 307
250 visitDeclarationGroup(node); 308 visitDeclarationGroup(node);
251 309
252 emit("}$_newLine"); 310 emit("}$_newLine");
253 } 311 }
254 312
255 void visitDeclaration(Declaration node) { 313 void visitDeclaration(Declaration node) {
256 String importantAsString() => node.important ? '$_sp!important' : ''; 314 emit('${node.property}:$_sp');
257
258 emit("${node.property}: ");
259 node._expression.visit(this); 315 node._expression.visit(this);
260 316 if (node.important) {
261 emit("${importantAsString()}"); 317 emit('$_sp!important');
318 }
262 } 319 }
263 320
264 void visitVarDefinition(VarDefinition node) { 321 void visitVarDefinition(VarDefinition node) {
265 emit("var-${node.definedName}: "); 322 emit("var-${node.definedName}: ");
266 node._expression.visit(this); 323 node._expression.visit(this);
267 } 324 }
268 325
269 void visitIncludeMixinAtDeclaration(IncludeMixinAtDeclaration node) { 326 void visitIncludeMixinAtDeclaration(IncludeMixinAtDeclaration node) {
270 // Don't emit a new line we're inside of a declaration group. 327 // Don't emit a new line we're inside of a declaration group.
271 visitIncludeDirective(node.include, false); 328 visitIncludeDirective(node.include, false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 void visitPseudoClassSelector(PseudoClassSelector node) { 376 void visitPseudoClassSelector(PseudoClassSelector node) {
320 emit(node.toString()); 377 emit(node.toString());
321 } 378 }
322 379
323 void visitPseudoElementSelector(PseudoElementSelector node) { 380 void visitPseudoElementSelector(PseudoElementSelector node) {
324 emit(node.toString()); 381 emit(node.toString());
325 } 382 }
326 383
327 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node) { 384 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node) {
328 emit(":${node.name}("); 385 emit(":${node.name}(");
329 node.expression.visit(this); 386 node.argument.visit(this);
330 emit(')'); 387 emit(')');
331 } 388 }
332 389
333 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node) { 390 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node) {
334 emit("::${node.name}("); 391 emit("::${node.name}(");
335 node.expression.visit(this); 392 node.expression.visit(this);
336 emit(')'); 393 emit(')');
337 } 394 }
338 395
339 void visitNegationSelector(NegationSelector node) { 396 void visitNegationSelector(NegationSelector node) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 570
514 void visitWildcard(Wildcard node) { 571 void visitWildcard(Wildcard node) {
515 emit('*'); 572 emit('*');
516 } 573 }
517 574
518 void visitDartStyleExpression(DartStyleExpression node) { 575 void visitDartStyleExpression(DartStyleExpression node) {
519 // TODO(terry): TBD 576 // TODO(terry): TBD
520 throw UnimplementedError; 577 throw UnimplementedError;
521 } 578 }
522 } 579 }
OLDNEW
« no previous file with comments | « packages/csslib/lib/src/analyzer.dart ('k') | packages/csslib/lib/src/messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698