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

Compatibility with [email protected]: Don't break the default exported statement #1292

Closed
qiqiboy opened this issue Jul 7, 2019 · 2 comments

Comments

@qiqiboy
Copy link

qiqiboy commented Jul 7, 2019

Description

RHL makes the 'export default' statement omitted while using @babel/[email protected].

Expected behavior

Keep the 'export default' statement.

Environment

{
  "react-ho-loader": "^4.12.3",
  "@babel/core": "^7.5.0",
  "@babel/cli": "^7.5.0",
  "@babel/plugin-transform-typescript": "^7.5.1"
}

Reproducible Demo

Input:

export default 'foo';

Output:

(function () {
  var enterModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')).enterModule;
  enterModule && enterModule(module);
})();

var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
  return a;
};

const _default = 'Foo';
; // 'export default _defualt'' was Omitted <<<<<<<<<<<<<<<

(function () {
  var reactHotLoader = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')).default;

  if (!reactHotLoader) {
    return;
  }

  reactHotLoader.register(_default, "default", "/Users/qiqiboy/develop/tigerNewTest/babel-debug/test.tsx");
})();

;

(function () {
  var leaveModule = (typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal : require('react-hot-loader')).leaveModule;
  leaveModule && leaveModule(module);
})();

The related issue

babel/babel#10162 (comment)

https://github.com/gaearon/react-hot-loader/blob/master/src/babel.dev.js#L118
insertBefore returns an array of ast paths, and that plugin should call path.scope.registerDeclaration(resultOfInsertBefore[0])

Maybe I should open a PR, but I don't know how to do it.

@theKashey
Copy link
Collaborator

Hooray! Break the web again!
PS: PR drafted

theKashey added a commit that referenced this issue Jul 7, 2019
@theKashey
Copy link
Collaborator

Released in 4.12.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants