Skip to content

Commit

Permalink
test: compatible targets shouldn't insert regeneratorRuntime
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Sep 20, 2020
1 parent 814c83b commit 794e5ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/babelPluginTsdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
name: 'babel-plugin-polyfill-regenerator',
// don't pollute global env as this is being used in a library
method: 'usage-pure',
targets: customOptions.targets,
},
{
name: '@babel/plugin-proposal-class-properties',
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/tsdx-build-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ describe('tsdx build :: zero-config defaults', () => {
expect(matched).toBeTruthy();
});

it('should not bundle regeneratorRuntime when targeting Node', () => {
const output = execWithCache('node ../dist/index.js build --target node');
expect(output.code).toBe(0);

const matched = grep(/regeneratorRuntime = r/, ['dist/build-default.*.js']);
expect(matched).toBeFalsy();
});

it('should clean the dist directory before rebuilding', () => {
let output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
Expand Down

1 comment on commit 794e5ad

@vercel
Copy link

@vercel vercel bot commented on 794e5ad Sep 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.