Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: search for browserslist if esmodules is falsy #11124

Merged
merged 4 commits into from Feb 24, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/babel-helper-compilation-targets/src/index.js
Expand Up @@ -184,6 +184,9 @@ export default function getTargets(
targets.browsers = Object.keys(supportsESModules)
.map(browser => `${browser} ${supportsESModules[browser]}`)
.join(", ");
} else {
// remove falsy esmodules to fix `hasTargets` below
delete targets.esmodules;
Copy link
Member

Choose a reason for hiding this comment

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

Should we also delete it if it is truthy, since at this point we have already handled it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User may invoke this method twice or more, keep the truthy value is safer for this case

const getTargets = require( '@babel/helper-compilation-targets' ).default
const targets = { esmodules: true }
const result1 = getTargets( targets )
const result2 = getTargets( targets )
// result1 should be equal to result2 here

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't they still be the same?

After the first call, targets has a browsers property which makes its behaviour identical to esmodules: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, sorry I didn't realize targets.browsers have already been assigned to targets. Updated

}

// Parse browsers target via browserslist
Expand Down