Skip to content

Commit 794e5ad

Browse files
committed
test: compatible targets shouldn't insert regeneratorRuntime
- specifically, this checks that `--target node`, which targets Node 10 right now, does not output regeneratorRuntime as generators have native support there (as does async/await) - remove `targets` from `polyfill-regenerator` config because it's actually not necessary for this specific polyfill - it only inserts regenerator if a `regeneratorRuntime` global is detected, which is only inserted by `@babel/plugin-transform-generator` if the `targets` require it - meaning that for this particular polyfill, `preset-env`'s `targets` are sufficient
1 parent 814c83b commit 794e5ad

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/babelPluginTsdx.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
7878
name: 'babel-plugin-polyfill-regenerator',
7979
// don't pollute global env as this is being used in a library
8080
method: 'usage-pure',
81-
targets: customOptions.targets,
8281
},
8382
{
8483
name: '@babel/plugin-proposal-class-properties',

test/e2e/tsdx-build-default.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ describe('tsdx build :: zero-config defaults', () => {
5959
expect(matched).toBeTruthy();
6060
});
6161

62+
it('should not bundle regeneratorRuntime when targeting Node', () => {
63+
const output = execWithCache('node ../dist/index.js build --target node');
64+
expect(output.code).toBe(0);
65+
66+
const matched = grep(/regeneratorRuntime = r/, ['dist/build-default.*.js']);
67+
expect(matched).toBeFalsy();
68+
});
69+
6270
it('should clean the dist directory before rebuilding', () => {
6371
let output = execWithCache('node ../dist/index.js build');
6472
expect(output.code).toBe(0);

0 commit comments

Comments
 (0)