Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: local scope bug #355

Merged
merged 1 commit into from
Sep 23, 2019
Merged

fix: local scope bug #355

merged 1 commit into from
Sep 23, 2019

Conversation

zquancai
Copy link
Contributor

@zquancai zquancai commented Sep 21, 2019

I have some code just like follow:

import React from 'react';
import { Button, message } from 'antd';
import './App.css';

const onAlert = () => {
  message.success(genMsg({ c: 'fffff' }));
};

const genMsg = message => `this is ${message.c}`;

function App() {
  return (
    <div className="App">
      <Button onClick={onAlert}>antd</Button>
    </div>
  );
}

export default App;

when I use babel-plugin-import to convert my code, it generate some unexpected code:

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var antd_es_button_style_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! antd/es/button/style/css */ "./node_modules/antd/es/button/style/css.js");
/* harmony import */ var antd_es_button__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/es/button */ "./node_modules/antd/es/button/index.js");
/* harmony import */ var antd_es_message_style_css__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! antd/es/message/style/css */ "./node_modules/antd/es/message/style/css.js");
/* harmony import */ var antd_es_message__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! antd/es/message */ "./node_modules/antd/es/message/index.js");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! react */ "./node_modules/react/index.js");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _App_css__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./App.css */ "./src/App.css");
/* harmony import */ var _App_css__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_App_css__WEBPACK_IMPORTED_MODULE_5__);




var _jsxFileName = "/Users/zhengqc/project/github/my-app/src/App.js";



const onAlert = () => {
  antd_es_message__WEBPACK_IMPORTED_MODULE_3__["default"].success(genMsg({
    c: 'fffff'
  }));
};

const genMsg = message => "this is ".concat(antd_es_message__WEBPACK_IMPORTED_MODULE_3__["default"].c);

function App() {
  return react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement("div", {
    className: "App",
    __source: {
      fileName: _jsxFileName,
      lineNumber: 13
    },
    __self: this
  }, react__WEBPACK_IMPORTED_MODULE_4___default.a.createElement(antd_es_button__WEBPACK_IMPORTED_MODULE_1__["default"], {
    onClick: onAlert,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 14
    },
    __self: this
  }, "antd"));
}

/* harmony default export */ __webpack_exports__["default"] = (App);

as u see, the follow codes is unexpected:

const genMsg = message => "this is ".concat(antd_es_message__WEBPACK_IMPORTED_MODULE_3__["default"].c);

the right result is:

const genMsg = message => "this is ".concat(message.c);

because the message is a local scope variable, it shouldn't to be convert. This case occured in my online project that is very hoary after I added babel-plugin-import to optimize it. I try to fix it and add some test cases that is passed after I debug the source codes, . Pls check.

How to reproduce it? Pls click the follow link to download demo for it.
my-app.zip

@zquancai zquancai marked this pull request as ready for review September 21, 2019 06:20
@sorrycc
Copy link
Member

sorrycc commented Sep 23, 2019

  • babel-plugin-import@1.12.2

@zquancai zquancai deleted the fix/variable-scope branch September 23, 2019 07:14
zhanguangao pushed a commit to zhanguangao/babel-plugin-module-federation-import that referenced this pull request Sep 1, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants