Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 /** Portion of the analyzer dealing with CSS sources. */ | 5 /** Portion of the analyzer dealing with CSS sources. */ |
| 6 library polymer.src.css_analyzer; | 6 library polymer.src.css_analyzer; |
| 7 | 7 |
| 8 import 'package:csslib/parser.dart' as css; | 8 import 'package:csslib/parser.dart' as css; |
| 9 import 'package:csslib/visitor.dart'; | 9 import 'package:csslib/visitor.dart'; |
| 10 import 'package:html5lib/dom.dart'; | 10 import 'package:html5lib/dom.dart'; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 _AnalyzerCss(this.info, this._pseudoElements, | 40 _AnalyzerCss(this.info, this._pseudoElements, |
| 41 this._messages, this._warningsAsErrors); | 41 this._messages, this._warningsAsErrors); |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Run the analyzer on every file that is a style sheet or any component that | 44 * Run the analyzer on every file that is a style sheet or any component that |
| 45 * has a style tag. | 45 * has a style tag. |
| 46 */ | 46 */ |
| 47 void process(SourceFile file) { | 47 void process(SourceFile file) { |
| 48 var fileInfo = info[file.path]; | 48 var fileInfo = info[file.path]; |
| 49 if (file.isStyleSheet || fileInfo.styleSheets.length > 0) { | 49 if (file.isStyleSheet || fileInfo.styleSheets.length > 0) { |
| 50 var styleSheets = processVars(fileInfo); | 50 var styleSheets = processVars(fileInfo.inputUrl, fileInfo); |
| 51 | 51 |
| 52 // Add to list of all style sheets analyzed. | 52 // Add to list of all style sheets analyzed. |
| 53 allStyleSheets.addAll(styleSheets); | 53 allStyleSheets.addAll(styleSheets); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Process any components. | 56 // Process any components. |
| 57 for (var component in fileInfo.declaredComponents) { | 57 for (var component in fileInfo.declaredComponents) { |
| 58 var all = processVars(component); | 58 var all = processVars(fileInfo.inputUrl, component); |
| 59 | 59 |
| 60 // Add to list of all style sheets analyzed. | 60 // Add to list of all style sheets analyzed. |
| 61 allStyleSheets.addAll(all); | 61 allStyleSheets.addAll(all); |
| 62 } | 62 } |
| 63 | 63 |
| 64 processCustomPseudoElements(); | 64 processCustomPseudoElements(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void normalize() { | 67 void normalize() { |
| 68 // Remove all var definitions for all style sheets analyzed. | 68 // Remove all var definitions for all style sheets analyzed. |
| 69 for (var tree in allStyleSheets) new _RemoveVarDefinitions().visitTree(tree) ; | 69 for (var tree in allStyleSheets) new _RemoveVarDefinitions().visitTree(tree) ; |
| 70 } | 70 } |
| 71 | 71 |
| 72 List<StyleSheet> processVars(var libraryInfo) { | 72 List<StyleSheet> processVars(var inputUrl, var libraryInfo) { |
| 73 // Get list of all stylesheet(s) dependencies referenced from this file. | 73 // Get list of all stylesheet(s) dependencies referenced from this file. |
| 74 var styleSheets = _dependencies(libraryInfo).toList(); | 74 var styleSheets = _dependencies(inputUrl, libraryInfo).toList(); |
| 75 | 75 |
| 76 var errors = []; | 76 var errors = []; |
| 77 css.analyze(styleSheets, errors: errors, options: | 77 css.analyze(styleSheets, errors: errors, options: |
| 78 [_warningsAsErrors ? '--warnings_as_errors' : '', 'memory']); | 78 [_warningsAsErrors ? '--warnings_as_errors' : '', 'memory']); |
| 79 | 79 |
| 80 // Print errors as warnings. | 80 // Print errors as warnings. |
| 81 for (var e in errors) { | 81 for (var e in errors) { |
| 82 _messages.warning(e.message, e.span); | 82 _messages.warning(e.message, e.span); |
| 83 } | 83 } |
| 84 | 84 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 110 for (var tree in allStyleSheets) { | 110 for (var tree in allStyleSheets) { |
| 111 polyFiller.visitTree(tree); | 111 polyFiller.visitTree(tree); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * Given a component or file check if any stylesheets referenced. If so then | 116 * Given a component or file check if any stylesheets referenced. If so then |
| 117 * return a list of all referenced stylesheet dependencies (@imports or <link | 117 * return a list of all referenced stylesheet dependencies (@imports or <link |
| 118 * rel="stylesheet" ..>). | 118 * rel="stylesheet" ..>). |
| 119 */ | 119 */ |
| 120 Set<StyleSheet> _dependencies(var libraryInfo, {Set<StyleSheet> seen}) { | 120 Set<StyleSheet> _dependencies(var inputUrl, var libraryInfo, {Set<StyleSheet> seen}) { |
|
terry
2013/08/28 21:41:52
line length > 80?
Jennifer Messerly
2013/08/28 22:10:25
also no need for "var" on these parameters.
Signe
Siggi Cherem (dart-lang)
2013/08/29 00:34:15
funny, I was just copying the old code structure a
| |
| 121 if (seen == null) seen = new Set(); | 121 if (seen == null) seen = new Set(); |
| 122 | 122 |
| 123 // Used to resolve all pathing information. | |
| 124 var inputUrl = libraryInfo is FileInfo | |
| 125 ? libraryInfo.inputUrl | |
| 126 : (libraryInfo as ComponentInfo).declaringFile.inputUrl; | |
| 127 | |
| 128 for (var styleSheet in libraryInfo.styleSheets) { | 123 for (var styleSheet in libraryInfo.styleSheets) { |
| 129 if (!seen.contains(styleSheet)) { | 124 if (!seen.contains(styleSheet)) { |
| 130 // TODO(terry): VM uses expandos to implement hashes. Currently, it's a | 125 // TODO(terry): VM uses expandos to implement hashes. Currently, it's a |
| 131 // linear (not constant) time cost (see dartbug.com/5746). | 126 // linear (not constant) time cost (see dartbug.com/5746). |
| 132 // If this bug isn't fixed and performance show's this a | 127 // If this bug isn't fixed and performance show's this a |
| 133 // a problem we'll need to implement our own hashCode or | 128 // a problem we'll need to implement our own hashCode or |
| 134 // use a different key for better perf. | 129 // use a different key for better perf. |
| 135 // Add the stylesheet. | 130 // Add the stylesheet. |
| 136 seen.add(styleSheet); | 131 seen.add(styleSheet); |
| 137 | 132 |
| 138 // Any other imports in this stylesheet? | 133 // Any other imports in this stylesheet? |
| 139 var urlInfos = findImportsInStyleSheet(styleSheet, inputUrl, _messages); | 134 var urlInfos = findImportsInStyleSheet(styleSheet, inputUrl, _messages); |
| 140 | 135 |
| 141 // Process other imports in this stylesheets. | 136 // Process other imports in this stylesheets. |
| 142 for (var importSS in urlInfos) { | 137 for (var importSS in urlInfos) { |
| 143 var importInfo = info[importSS.resolvedPath]; | 138 var importInfo = info[importSS.resolvedPath]; |
| 144 if (importInfo != null) { | 139 if (importInfo != null) { |
| 145 // Add all known stylesheets processed. | 140 // Add all known stylesheets processed. |
| 146 seen.addAll(importInfo.styleSheets); | 141 seen.addAll(importInfo.styleSheets); |
| 147 // Find dependencies for stylesheet referenced with a | 142 // Find dependencies for stylesheet referenced with a |
| 148 // @import | 143 // @import |
| 149 for (var ss in importInfo.styleSheets) { | 144 for (var ss in importInfo.styleSheets) { |
| 150 var urls = findImportsInStyleSheet(ss, inputUrl, _messages); | 145 var urls = findImportsInStyleSheet(ss, inputUrl, _messages); |
| 151 for (var url in urls) { | 146 for (var url in urls) { |
| 152 _dependencies(info[url.resolvedPath], seen: seen); | 147 var fileInfo = info[url.resolvedPath]; |
| 148 _dependencies(fileInfo.inputUrl, fileInfo, seen: seen); | |
| 153 } | 149 } |
| 154 } | 150 } |
| 155 } | 151 } |
| 156 } | 152 } |
| 157 } | 153 } |
| 158 } | 154 } |
| 159 | 155 |
| 160 return seen; | 156 return seen; |
| 161 } | 157 } |
| 162 } | 158 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 | 487 |
| 492 // Find all imports return list of @imports in this style tag. | 488 // Find all imports return list of @imports in this style tag. |
| 493 var urlInfos = findImportsInStyleSheet(styleSheet, | 489 var urlInfos = findImportsInStyleSheet(styleSheet, |
| 494 _inputUrl, _messages); | 490 _inputUrl, _messages); |
| 495 imports.addAll(urlInfos); | 491 imports.addAll(urlInfos); |
| 496 } | 492 } |
| 497 } | 493 } |
| 498 super.visitElement(node); | 494 super.visitElement(node); |
| 499 } | 495 } |
| 500 } | 496 } |
| OLD | NEW |