Skip to content

Commit

Permalink
Allow exported generator functions (#290)
Browse files Browse the repository at this point in the history
Fixes #289
  • Loading branch information
alangpierce authored Jul 2, 2018
1 parent d31351a commit a1685b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/transformers/CJSImportTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export default class CJSImportTransformer extends Transformer {
return true;
} else if (
this.tokens.matches2(tt._export, tt._function) ||
// export async function
this.tokens.matches3(tt._export, tt.name, tt._function)
) {
this.processExportFunction();
Expand Down Expand Up @@ -357,6 +358,9 @@ export default class CJSImportTransformer extends Transformer {
this.tokens.copyToken();
this.tokens.copyToken();
}
if (this.tokens.matches1(tt.star)) {
this.tokens.copyToken();
}
if (!this.tokens.matches1(tt.name)) {
throw new Error("Expected identifier for exported function name.");
}
Expand Down
17 changes: 17 additions & 0 deletions test/imports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,21 @@ module.exports = exports.default;
`,
);
});

it("allows exported generator functions", () => {
assertResult(
`
export function* foo() {}
export async function* bar() {}
export default function* baz() {}
export default async function* qux() {}
`,
`"use strict";${ESMODULE_PREFIX}
function* foo() {} exports.foo = foo;
async function* bar() {} exports.bar = bar;
exports. default = function* baz() {}
exports. default = async function* qux() {}
`,
);
});
});

0 comments on commit a1685b2

Please sign in to comment.