Skip to content

Commit

Permalink
Allow empty export statements (#338)
Browse files Browse the repository at this point in the history
Fixes #335
  • Loading branch information
alangpierce authored Nov 18, 2018
1 parent 9fdabab commit de4c909
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CJSImportProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ get: () => ${primaryImportName}[key]}); });`;
private getNamedImports(index: number): {newIndex: number; namedImports: Array<NamedImport>} {
const namedImports = [];
while (true) {
if (this.tokens.matchesAtIndex(index, [tt.braceR])) {
index++;
break;
}

// Flow type imports should just be ignored.
let isTypeImport = false;
if (
Expand Down
5 changes: 5 additions & 0 deletions src/transformers/CJSImportTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ export default class CJSImportTransformer extends Transformer {

const exportStatements = [];
while (true) {
if (this.tokens.matches1(tt.braceR)) {
this.tokens.removeToken();
break;
}

const localName = this.tokens.identifierName();
let exportedName;
this.tokens.removeToken();
Expand Down
22 changes: 22 additions & 0 deletions test/imports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ describe("transform imports", () => {
);
});

it("allows an empty export statement", () => {
assertResult(
`
export {};
`,
`"use strict";${ESMODULE_PREFIX}
`,
);
});

it("allows trailing commas in exported names", () => {
assertResult(
`
Expand Down Expand Up @@ -314,6 +325,17 @@ return obj && obj.__esModule ? obj : { default: obj }; }
);
});

it("allows an import statement with no import bindings", () => {
assertResult(
`
import {} from 'moduleName';
`,
`"use strict";
`,
);
});

it("handles trailing commas in named imports", () => {
assertResult(
`
Expand Down

0 comments on commit de4c909

Please # to comment.