Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

<!-- ## Unreleased -->
## Unreleased
* Better support for resolving `export {foo as bar}` statements.
<!-- Add new, unreleased changes here. -->

## [3.0.1] - 2018-05-11
Expand Down
12 changes: 12 additions & 0 deletions packages/analyzer/src/model/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ function resolveScopedAt<K extends keyof FeatureKindMap>(
const exportedIdentifier = getExportedIdentifier(path.node, identifier);
return resolveThroughImport(path, exportedIdentifier, document, kind);
}

if (babel.isExportNamedDeclaration(path.node) && !path.node.source) {
for (const specifier of path.node.specifiers) {
if (specifier.exported.name !== specifier.local.name &&
specifier.exported.name === identifier) {
// In cases like `export {foo as bar}`, we need to look for a feature
// called `foo` instead of `bar`.
return resolveScopedAt(path, specifier.local.name, document, kind);
}
}
}

const statement = esutil.getCanonicalStatement(path);
if (statement === undefined) {
return {successful: false, error: undefined};
Expand Down
3 changes: 2 additions & 1 deletion packages/analyzer/src/test/model/reference_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ suite('ScannedReference', () => {
analyzer = (await createForDirectory(fixtureDir)).analyzer;
});

test.skip('resolves exports', async () => {
test('resolves exports', async () => {
const filename = 'javascript/exported-class.js';

const analysis = await analyzer.analyze([filename]);
Expand Down Expand Up @@ -63,6 +63,7 @@ suite('ScannedReference', () => {
assert.deepEqual(actual, [
['Foo', 'Foo'],
['FooAlias', 'Foo'],
['Bar', 'Bar'],
]);
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export class Foo {}

export {Foo as FooAlias};

class Bar {}

export {Bar};