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

Side by Side Diff: example/call_parser.dart

Issue 1832993003: Fix all strong mode errors and warnings. (Closed) Base URL: https://github.com/dart-lang/csslib.git@master
Patch Set: Move type. Created 4 years, 8 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 | « CHANGELOG.md ('k') | lib/parser.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 3
4 import 'package:csslib/parser.dart' as css; 4 import 'package:csslib/parser.dart' as css;
5 import 'package:csslib/src/messages.dart';
5 import 'package:csslib/visitor.dart'; 6 import 'package:csslib/visitor.dart';
6 7
7 const _default = const css.PreprocessorOptions( 8 const _default = const css.PreprocessorOptions(
8 useColors: false, 9 useColors: false,
9 checked: true, 10 checked: true,
10 warningsAsErrors: true, 11 warningsAsErrors: true,
11 inputFile: 'memory'); 12 inputFile: 'memory');
12 13
13 /** 14 /**
14 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally, 15 * Spin-up CSS parser in checked mode to detect any problematic CSS. Normally,
15 * CSS will allow any property/value pairs regardless of validity; all of our 16 * CSS will allow any property/value pairs regardless of validity; all of our
16 * tests (by default) will ensure that the CSS is really valid. 17 * tests (by default) will ensure that the CSS is really valid.
17 */ 18 */
18 StyleSheet parseCss(String cssInput, 19 StyleSheet parseCss(String cssInput,
19 {List errors, css.PreprocessorOptions opts}) { 20 {List<Message> errors, css.PreprocessorOptions opts}) {
20 return css.parse(cssInput, 21 return css.parse(cssInput,
21 errors: errors, options: opts == null ? _default : opts); 22 errors: errors, options: opts == null ? _default : opts);
22 } 23 }
23 24
24 // Pretty printer for CSS. 25 // Pretty printer for CSS.
25 var emitCss = new CssPrinter(); 26 var emitCss = new CssPrinter();
26 String prettyPrint(StyleSheet ss) => 27 String prettyPrint(StyleSheet ss) =>
27 (emitCss..visitTree(ss, pretty: true)).toString(); 28 (emitCss..visitTree(ss, pretty: true)).toString();
28 29
29 main() { 30 main() {
30 var errors = []; 31 var errors = <Message>[];
31 32
32 // Parse a simple stylesheet. 33 // Parse a simple stylesheet.
33 print('1. Good CSS, parsed CSS emitted:'); 34 print('1. Good CSS, parsed CSS emitted:');
34 print(' ============================='); 35 print(' =============================');
35 var stylesheet = parseCss( 36 var stylesheet = parseCss(
36 '@import "support/at-charset-019.css"; div { color: red; }' 37 '@import "support/at-charset-019.css"; div { color: red; }'
37 'button[type] { background-color: red; }' 38 'button[type] { background-color: red; }'
38 '.foo { ' 39 '.foo { '
39 'color: red; left: 20px; top: 20px; width: 100px; height:200px' 40 'color: red; left: 20px; top: 20px; width: 100px; height:200px'
40 '}' 41 '}'
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 var selectorAst = css.selector('#div .foo', errors: errors); 88 var selectorAst = css.selector('#div .foo', errors: errors);
88 if (!errors.isEmpty) { 89 if (!errors.isEmpty) {
89 print("Got ${errors.length} errors.\n"); 90 print("Got ${errors.length} errors.\n");
90 for (var error in errors) { 91 for (var error in errors) {
91 print(error); 92 print(error);
92 } 93 }
93 } else { 94 } else {
94 print(prettyPrint(selectorAst)); 95 print(prettyPrint(selectorAst));
95 } 96 }
96 } 97 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698