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

_interopRequireWildcard breaks on nodejs cases #10577

Closed
theKashey opened this issue Oct 19, 2019 · 4 comments
Closed

_interopRequireWildcard breaks on nodejs cases #10577

theKashey opened this issue Oct 19, 2019 · 4 comments
Labels
i: bug i: duplicate outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@theKashey
Copy link

Bug Report

The bug was introduced by #10161, v7.5.5 is confirmed to work

Current Behavior

  • Given a code import * as isNode from 'detect-node'; (TypeScript syntax)
  • Compiles to es5 code const isNode = require('detect-node') (again TypeScript)
  • Parcel bundler then compiles es2015 code to the following
const isNode = _interopRequireWildcard(require('detect-node'));

The result would be correct, however, internally it uses WeakMap based cache, and by some reason, expects any module to be resolved to an object.

https://github.com/babel/babel/blob/master/packages/babel-helpers/src/helpers.js#L623-L626

var cache = _getRequireWildcardCache();
    if (cache && cache.has(obj)) {
      return cache.get(obj);
    }

require('detect-node') resolves to true or false

A clear and concise description of the behavior.

Input Code

_interopRequireWildcard(false); // throws

Expected behavior/code

_interopRequireWildcard(false) === false
_interopRequireWildcard(42) === 42
_interopRequireWildcard(function) === function (!!)

import * as cx from 'classnames'; is also not working, even at 7.5.5

Possible Solution
Many "object like" structures are not "WeakMapable", however - typeof value === 'object' would be more than enought.

@babel-bot
Copy link
Collaborator

Hey @theKashey! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@jridgewell
Copy link
Member

Closing as a dupe of #10561, PR at #10574.

@jridgewell
Copy link
Member

Sorry for being brief. This was an excellent bug report, and thank you for filling it!

@theKashey
Copy link
Author

No worries.
But I've added a comment to PR for the case module.exports = function

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 18, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: duplicate outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants