Skip to content

Commit

Permalink
fix: #410 - sourceFile.getExportedDeclarations() throws exception i…
Browse files Browse the repository at this point in the history
…f file is empty
  • Loading branch information
dsherret committed Aug 27, 2018
1 parent 888cdc2 commit 8d563ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/file/SourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ export class SourceFile extends SourceFileBase<ts.SourceFile> {
* Gets the export symbols of the source file.
*/
getExportSymbols(): Symbol[] {
return this.context.typeChecker.getExportsOfModule(this.getSymbolOrThrow());
const symbol = this.getSymbol();
return symbol == null ? [] : this.context.typeChecker.getExportsOfModule(symbol);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/tests/compiler/file/sourceFileTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,12 @@ describe(nameof(SourceFile), () => {
expect(mainSourceFile.getExportedDeclarations().map(d => (d as any).getName()).sort())
.to.deep.equal(["MainFileClass"].sort());
});

it("should not error for an empty file", () => {
const project = new Project({ useVirtualFileSystem: true });
const mainSourceFile = project.createSourceFile("main.ts", "");
expect(mainSourceFile.getExportedDeclarations().length).to.equal(0);
});
});

describe(nameof<SourceFile>(n => n.insertExportAssignments), () => {
Expand Down

0 comments on commit 8d563ac

Please sign in to comment.