Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #39 from dart-lang/shared-sources-fix
Browse files Browse the repository at this point in the history
dont remove unreachable sources if using a shared sources cache
  • Loading branch information
jakemac53 committed Mar 29, 2016
2 parents cde6c50 + 7ee7c39 commit 30a4dcc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,12 @@
## 0.4.2+1

* Contains a fix for the `useSharedSources` option that could result in null
library elements when running on multiple entry points.

## 0.4.2

* Use Strong Mode, fixes
[#38](https://github.com/dart-lang/code_transformers/issues/38).
[#38](https://github.com/dart-lang/code_transformers/issues/38).

## 0.4.1

Expand Down
23 changes: 16 additions & 7 deletions lib/src/resolver_impl.dart
Expand Up @@ -49,11 +49,15 @@ class ResolverImpl implements Resolver {
/// Completer for wrapping up the current phase.
Completer _currentPhaseComplete;

/// Whether or not we are using a shared sources cache.
final bool _usingSharedSources;

/// Creates a resolver with a given [sdk] implementation for resolving
/// `dart:*` imports.
ResolverImpl(DartSdk sdk, DartUriResolver dartUriResolver,
{AnalysisOptions options, Map<AssetId, AssetBasedSource> sources})
: sources = sources ?? <AssetId, AssetBasedSource>{} {
: _usingSharedSources = sources != null,
sources = sources ?? <AssetId, AssetBasedSource>{} {
if (options == null) {
options = new AnalysisOptionsImpl()
..cacheSize = 256 // # of sources to cache ASTs for.
Expand Down Expand Up @@ -144,12 +148,17 @@ class ResolverImpl implements Resolver {
return visiting.future.then((_) {
var changeSet = new ChangeSet();
toUpdate.forEach((pending) => pending.apply(changeSet));
var unreachableAssets =
sources.keys.toSet().difference(visited).map((id) => sources[id]);
for (var unreachable in unreachableAssets) {
changeSet.removedSource(unreachable);
unreachable.updateContents(null);
sources.remove(unreachable.assetId);

// If we aren't using shared sources, then remove from the cache any
// sources which are no longer reachable.
if (!_usingSharedSources) {
var unreachableAssets =
sources.keys.toSet().difference(visited).map((id) => sources[id]);
for (var unreachable in unreachableAssets) {
changeSet.removedSource(unreachable);
unreachable.updateContents(null);
sources.remove(unreachable.assetId);
}
}

// Update the analyzer context with the latest sources
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: code_transformers
version: 0.4.2
version: 0.4.2+1
author: Dart Team <misc@dartlang.org>
description: Collection of utilities related to creating barback transformers.
homepage: https://github.com/dart-lang/code-transformers
Expand Down

0 comments on commit 30a4dcc

Please sign in to comment.