| OLD | NEW |
| 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 // 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 library csslib.src.validate; | 5 library csslib.src.validate; |
| 6 | 6 |
| 7 import 'package:csslib/visitor.dart'; | 7 import 'package:csslib/visitor.dart'; |
| 8 import 'package:source_span/source_span.dart'; | 8 import 'package:source_span/source_span.dart'; |
| 9 | 9 |
| 10 /** Can be thrown on any Css runtime problem includes source location. */ | 10 /** Can be thrown on any Css runtime problem includes source location. */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } else { | 46 } else { |
| 47 String error = selector.simpleSelector.toString(); | 47 String error = selector.simpleSelector.toString(); |
| 48 throw new CssSelectorException( | 48 throw new CssSelectorException( |
| 49 'Selectors can not have combinators (>, +, or ~) before $error'); | 49 'Selectors can not have combinators (>, +, or ~) before $error'); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Validate the @{css expression} only .class and #elementId are valid inside | 53 // Validate the @{css expression} only .class and #elementId are valid inside |
| 54 // of @{...}. | 54 // of @{...}. |
| 55 static template(List<Selector> selectors) { | 55 static template(List<Selector> selectors) { |
| 56 var errorSelector; // signal which selector didn't match. | |
| 57 bool found = false; // signal if a selector is matched. | 56 bool found = false; // signal if a selector is matched. |
| 58 int matches = 0; // < 0 IdSelectors, > 0 ClassSelector | 57 int matches = 0; // < 0 IdSelectors, > 0 ClassSelector |
| 59 | 58 |
| 60 // At most one selector group (any number of simple selector sequences). | 59 // At most one selector group (any number of simple selector sequences). |
| 61 assert(selectors.length <= 1); | 60 assert(selectors.length <= 1); |
| 62 | 61 |
| 63 for (final sels in selectors) { | 62 for (final sels in selectors) { |
| 64 for (final selector in sels.simpleSelectorSequences) { | 63 for (final selector in sels.simpleSelectorSequences) { |
| 65 found = false; | 64 found = false; |
| 66 var simpleSelector = selector.simpleSelector; | 65 var simpleSelector = selector.simpleSelector; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 115 } |
| 117 } | 116 } |
| 118 } | 117 } |
| 119 | 118 |
| 120 // Every selector must match. | 119 // Every selector must match. |
| 121 Selector selector = selectors[0]; | 120 Selector selector = selectors[0]; |
| 122 assert((matches >= 0 ? matches : -matches) == | 121 assert((matches >= 0 ? matches : -matches) == |
| 123 selector.simpleSelectorSequences.length); | 122 selector.simpleSelectorSequences.length); |
| 124 } | 123 } |
| 125 } | 124 } |
| OLD | NEW |