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

Side by Side Diff: lib/src/transformer/asset_universe.dart

Issue 1788973002: Remove code that requires whole-program compile (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: merged Created 4 years, 9 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 | « lib/src/transformer/asset_source.dart ('k') | lib/src/transformer/error_listener.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
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.
4
5 library dev_compiler.src.transformer.asset_universe;
6
7 import 'dart:async';
8
9 import 'package:analyzer/analyzer.dart' show UriBasedDirective, parseDirectives;
10 import 'package:barback/barback.dart' show Asset, AssetId;
11
12 import 'asset_source.dart';
13 import 'uri_resolver.dart' show assetIdToUri, resolveAssetId;
14
15 /// Set of assets sources available for analysis / compilation.
16 class AssetUniverse {
17 final _assetCache = <AssetId, AssetSource>{};
18
19 Iterable<AssetId> get assetIds => _assetCache.keys;
20
21 AssetSource getAssetSource(AssetId id) {
22 var source = _assetCache[id];
23 if (source == null) {
24 throw new ArgumentError(id.toString());
25 }
26 return source;
27 }
28
29 /// Recursively loads the asset with [id] and all its transitive dependencies.
30 Future scanSources(AssetId id, Future<Asset> getInput(AssetId id)) async {
31 if (_assetCache.containsKey(id)) return;
32
33 var asset = await getInput(id);
34 var contents = await asset.readAsString();
35 _assetCache[id] =
36 new AssetSource(Uri.parse(assetIdToUri(id)), asset, contents);
37
38 var deps = _getDependentAssetIds(id, contents);
39 await Future.wait(deps.map((depId) => scanSources(depId, getInput)));
40 }
41
42 Iterable<AssetId> _getDependentAssetIds(AssetId id, String contents) sync* {
43 var directives = parseDirectives(contents, suppressErrors: true).directives;
44 for (var directive in directives) {
45 if (directive is UriBasedDirective) {
46 var uri = directive.uri.stringValue;
47 var assetId = resolveAssetId(Uri.parse(uri), fromAssetId: id);
48 if (assetId != null) yield assetId;
49 }
50 }
51 }
52 }
OLDNEW
« no previous file with comments | « lib/src/transformer/asset_source.dart ('k') | lib/src/transformer/error_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698