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

Unified Diff: lib/build/import_crawler.dart

Issue 978453003: add option to ImportCrawler to start from an already parsed document (Closed) Base URL: git@github.com:dart-lang/web-components.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/build/import_crawler.dart
diff --git a/lib/build/import_crawler.dart b/lib/build/import_crawler.dart
index 5566efbd3da4639afb6cc5395651f22e4bbe9ebf..c655efc7aece41ee5fa0c9a46c2f402d50caa8b6 100644
--- a/lib/build/import_crawler.dart
+++ b/lib/build/import_crawler.dart
@@ -30,7 +30,12 @@ class ImportCrawler {
final BuildLogger _logger;
final AssetId _primaryInputId;
- ImportCrawler(this._transform, this._primaryInputId, this._logger);
+ // Optional parsed document for the primary id if available.
+ final Document _primaryDocument;
+
+ ImportCrawler(this._transform, this._primaryInputId, this._logger,
+ {Document primaryDocument})
+ : _primaryDocument = primaryDocument;
/// Returns a post-ordered map of [AssetId]'s to [ImportData]. The [AssetId]'s
/// represent an asset which was discovered via an html import, and the
@@ -40,13 +45,11 @@ class ImportCrawler {
var documents = new LinkedHashMap<AssetId, ImportData>();
var seen = new Set<AssetId>();
- Future doCrawl(AssetId assetId, [Element import]) {
+ Future doCrawl(AssetId assetId, [Element import, Document document]) {
if (seen.contains(assetId)) return null;
seen.add(assetId);
- return _transform.readInputAsString(assetId).then((html) {
- var document = parseHtml(html, assetId.path);
-
+ Future crawlImports(Document document) {
var imports = document.querySelectorAll('link[rel="import"]');
var done =
Future.forEach(imports, (i) => doCrawl(_importId(assetId, i), i));
@@ -55,14 +58,23 @@ class ImportCrawler {
return done.then((_) {
documents[assetId] = new ImportData(document, import);
});
- }).catchError((error) {
- var span;
- if (import != null) span = import.sourceSpan;
- _logger.error(inlineImportFail.create({'error': error}), span: span);
- });
+ }
+
+ if (document != null) {
+ return crawlImports(document);
+ } else {
+ return _transform.readInputAsString(assetId).then((html) {
+ return crawlImports(parseHtml(html, assetId.path));
+ }).catchError((error) {
+ var span;
+ if (import != null) span = import.sourceSpan;
+ _logger.error(inlineImportFail.create({'error': error}), span: span);
+ });
+ }
}
- return doCrawl(_primaryInputId).then((_) => documents);
+ return
+ doCrawl(_primaryInputId, null, _primaryDocument).then((_) => documents);
}
AssetId _importId(AssetId source, Element import) {
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698