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

Commit

Permalink
fix(code-generation): Imports with no specifiers are generated correc…
Browse files Browse the repository at this point in the history
…tly (#264)
  • Loading branch information
buehler authored Aug 10, 2017
1 parent 0ea7816 commit abaa2dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function extendGenerator(generator: TypescriptCodeGenerator): void {
GENERATORS[RegexImportGroup.name] = simpleGenerator;
GENERATORS[RemainImportGroup.name] = simpleGenerator;
GENERATORS[ImportProxy.name] = (proxy: ImportProxy) => {
if (proxy.specifiers.length <= 0) {
if (proxy.specifiers.length <= 0 && (proxy.defaultAlias || proxy.defaultPurposal)) {
return generator.generate(
new DefaultImport(
proxy.libraryName, (proxy.defaultAlias || proxy.defaultPurposal)!, proxy.start, proxy.end,
Expand Down
6 changes: 5 additions & 1 deletion test/extension/proxy-objects/ImportProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('ImportProxy', () => {

before(() => {
GENERATORS[ImportProxy.name] = (proxy: ImportProxy) => {
if (proxy.specifiers.length <= 0) {
if (proxy.specifiers.length <= 0 && (proxy.defaultAlias || proxy.defaultPurposal)) {
return generator.generate(
new DefaultImport(
proxy.libraryName, (proxy.defaultAlias || proxy.defaultPurposal)!, proxy.start, proxy.end,
Expand Down Expand Up @@ -238,6 +238,10 @@ describe('ImportProxy', () => {
generator.generate(proxy).should.equal(`import ALIAS from 'foo'`);
});

it('should generate an empty named import if no specifiers and no default is set', () => {
generator.generate(proxy).should.equal(`import { } from 'foo';`);
});

});

});

0 comments on commit abaa2dd

Please sign in to comment.