| 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 part of csslib.parser; | 5 part of csslib.parser; |
| 6 | 6 |
| 7 // TODO(terry): Add optimizing phase to remove duplicated selectors in the same | 7 // TODO(terry): Add optimizing phase to remove duplicated selectors in the same |
| 8 // selector group (e.g., .btn, .btn { color: red; }). Also, look | 8 // selector group (e.g., .btn, .btn { color: red; }). Also, look |
| 9 // at simplifying selectors expressions too (much harder). | 9 // at simplifying selectors expressions too (much harder). |
| 10 // TODO(terry): Detect invalid directive usage. All @imports must occur before | 10 // TODO(terry): Detect invalid directive usage. All @imports must occur before |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 // Remove nested rules; they're all flatten and in the _expandedRuleSets. | 216 // Remove nested rules; they're all flatten and in the _expandedRuleSets. |
| 217 node.declarationGroup.declarations | 217 node.declarationGroup.declarations |
| 218 .removeWhere((declaration) => declaration is RuleSet); | 218 .removeWhere((declaration) => declaration is RuleSet); |
| 219 | 219 |
| 220 _nestedSelectorGroup = oldNestedSelectorGroups; | 220 _nestedSelectorGroup = oldNestedSelectorGroups; |
| 221 | 221 |
| 222 // If any expandedRuleSets and we're back at the top-level rule set then | 222 // If any expandedRuleSets and we're back at the top-level rule set then |
| 223 // there were nested rule set(s). | 223 // there were nested rule set(s). |
| 224 if (_parentRuleSet == null) { | 224 if (_parentRuleSet == null) { |
| 225 if (!_expandedRuleSets.isEmpty) { | 225 if (_expandedRuleSets.isNotEmpty) { |
| 226 // Remember ruleset to replace with these flattened rulesets. | 226 // Remember ruleset to replace with these flattened rulesets. |
| 227 _expansions[node] = _expandedRuleSets; | 227 _expansions[node] = _expandedRuleSets; |
| 228 _expandedRuleSets = []; | 228 _expandedRuleSets = []; |
| 229 } | 229 } |
| 230 assert(_flatDeclarationGroup == null); | 230 assert(_flatDeclarationGroup == null); |
| 231 assert(_nestedSelectorGroup == null); | 231 assert(_nestedSelectorGroup == null); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 /** | 235 /** |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 if (!hasThis) { | 271 if (!hasThis) { |
| 272 // If no & in the sector group then prefix with the parent selector. | 272 // If no & in the sector group then prefix with the parent selector. |
| 273 newSequence.addAll(parent); | 273 newSequence.addAll(parent); |
| 274 newSequence.addAll(_convertToDescendentSequence(current)); | 274 newSequence.addAll(_convertToDescendentSequence(current)); |
| 275 } else { | 275 } else { |
| 276 for (var sequence in current) { | 276 for (var sequence in current) { |
| 277 if (sequence.simpleSelector.isThis) { | 277 if (sequence.simpleSelector.isThis) { |
| 278 // Substitue the & with the parent selector and only use a combinator | 278 // Substitue the & with the parent selector and only use a combinator |
| 279 // descendant if & is prefix by a sequence with an empty name e.g., | 279 // descendant if & is prefix by a sequence with an empty name e.g., |
| 280 // "... + &", "&", "... ~ &", etc. | 280 // "... + &", "&", "... ~ &", etc. |
| 281 var hasPrefix = !newSequence.isEmpty && | 281 var hasPrefix = newSequence.isNotEmpty && |
| 282 !newSequence.last.simpleSelector.name.isEmpty; | 282 newSequence.last.simpleSelector.name.isNotEmpty; |
| 283 newSequence.addAll( | 283 newSequence.addAll( |
| 284 hasPrefix ? _convertToDescendentSequence(parent) : parent); | 284 hasPrefix ? _convertToDescendentSequence(parent) : parent); |
| 285 } else { | 285 } else { |
| 286 newSequence.add(sequence); | 286 newSequence.add(sequence); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 | 290 |
| 291 return newSequence; | 291 return newSequence; |
| 292 } | 292 } |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 899 } |
| 900 } | 900 } |
| 901 | 901 |
| 902 /** Find all @extend to create inheritance. */ | 902 /** Find all @extend to create inheritance. */ |
| 903 class AllExtends extends Visitor { | 903 class AllExtends extends Visitor { |
| 904 final Map<String, List<SelectorGroup>> inherits = | 904 final Map<String, List<SelectorGroup>> inherits = |
| 905 new Map<String, List<SelectorGroup>>(); | 905 new Map<String, List<SelectorGroup>>(); |
| 906 | 906 |
| 907 SelectorGroup _currSelectorGroup; | 907 SelectorGroup _currSelectorGroup; |
| 908 int _currDeclIndex; | 908 int _currDeclIndex; |
| 909 List<int> _extendsToRemove = []; | 909 final List<int> _extendsToRemove = []; |
| 910 | 910 |
| 911 void visitRuleSet(RuleSet node) { | 911 void visitRuleSet(RuleSet node) { |
| 912 var oldSelectorGroup = _currSelectorGroup; | 912 var oldSelectorGroup = _currSelectorGroup; |
| 913 _currSelectorGroup = node.selectorGroup; | 913 _currSelectorGroup = node.selectorGroup; |
| 914 | 914 |
| 915 super.visitRuleSet(node); | 915 super.visitRuleSet(node); |
| 916 | 916 |
| 917 _currSelectorGroup = oldSelectorGroup; | 917 _currSelectorGroup = oldSelectorGroup; |
| 918 } | 918 } |
| 919 | 919 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 isLastNone = false; | 1004 isLastNone = false; |
| 1005 } | 1005 } |
| 1006 } else { | 1006 } else { |
| 1007 isLastNone = simpleSeq.isCombinatorNone; | 1007 isLastNone = simpleSeq.isCombinatorNone; |
| 1008 } | 1008 } |
| 1009 } | 1009 } |
| 1010 } | 1010 } |
| 1011 super.visitSelectorGroup(node); | 1011 super.visitSelectorGroup(node); |
| 1012 } | 1012 } |
| 1013 } | 1013 } |
| OLD | NEW |