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

Commit

Permalink
Avoid LibraryElement instances for part files (#53)
Browse files Browse the repository at this point in the history
If we pass a Source representing a 'part of' file to the analysis
context it will create a LibraryElement which is not sensible. We should
only create a LibraryElement when the Source represents a library.

Fixes dart-lang/source_gen#115
  • Loading branch information
natebosch authored Jan 10, 2017
1 parent 1b4fce9 commit e7583dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.5.0+2

* Resolver no longer returns a partial LibraryElement for assets which are not
libraries

## 0.5.0+1

* Stop using deprecated analyzer apis.
Expand Down
7 changes: 6 additions & 1 deletion lib/src/resolver_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class ResolverImpl implements Resolver {

LibraryElement getLibrary(AssetId assetId) {
var source = sources[assetId];
return source == null ? null : _context.computeLibraryElement(source);
if (source == null) return null;
var kind = _context.computeKindOf(source);
if (kind != SourceKind.LIBRARY) return null;
return _context.computeLibraryElement(source);
}

Future<Resolver> resolve(Transform transform,
Expand Down Expand Up @@ -150,6 +153,8 @@ class ResolverImpl implements Resolver {
_entryLibraries = entryPoints.map((id) {
var source = sources[id];
if (source == null) return null;
var kind = _context.computeKindOf(source);
if (kind != SourceKind.LIBRARY) return null;
return _context.computeLibraryElement(source);
}).toList();

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: code_transformers
version: 0.5.0+1
version: 0.5.0+2
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 e7583dc

Please sign in to comment.