Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow empty export statements #338

Merged
merged 1 commit into from
Nov 18, 2018
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
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