ElementUI / babel-plugin-component

Modular element-ui build plugin for babel.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upgrade Babel dependency

andrew-humu opened this issue · comments

It would be nice to unlock the version of @babel/* dependencies required by this module.

Related to: #44

Updating the babel deps breaks the snapshot tests in the project, most of them are similar to:

  1) index
       should work with array:

      Error: Expected '"use strict";\n\nrequire("element-ui/lib/button/style.css");\n\nvar _button = _interopRequireDefault(require("element-ui/lib/button"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }\n\nnew Vue({\n  components: [_button["default"]]\n});' to equal 'require("element-ui/lib/button/style.css");\n\nvar _Button = _interopRequireDefault(require("element-ui/lib/button")).default;\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nnew Vue({\n  components: [_Button]\n});'
      + expected - actual

      -"use strict";
      -
       require("element-ui/lib/button/style.css");
       
      -var _button = _interopRequireDefault(require("element-ui/lib/button"));
      +var _Button = _interopRequireDefault(require("element-ui/lib/button")).default;
       
      -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
      +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
       
       new Vue({
      -  components: [_button["default"]]
      +  components: [_Button]
       });
      
      at assert (node_modules/expect/lib/assert.js:29:9)
      at Expectation.toEqual (node_modules/expect/lib/Expectation.js:81:30)
      at Context.toEqual (test/index-test.js:147:29)

Most of them look mostly cosmetic. The "use strict"; part is hard for me to judge in the context of this package. Anyone with more in-depth knowledge able to assess?

Babel 7 now assumes that files it processes are ES modules, by default. I believe there's a babel configuration to disable that if desired, but I don't see any reason to do so.

babel/babel#8394

Yeah I thought the same, but the commonjs'ness of element-ui gave me pause.
Going through the new output files, this one looks suspicious to me (unexpected _Select var):

// test/fixtures/conditions/expected.js
"use strict";

require("element-ui/lib/select/style.css");

var _select = _interopRequireDefault(require("element-ui/lib/select"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

if (a === _select["default"]) { }

if (_Select) { }

_Select ? 'a' : 'b';
a ? _Select : 2;
_Select || 'a';
a || _Select;

Another mystery guest: (_Element)

// test/fixtures/import-all-css/expected.js
"use strict";

require("element-ui/lib/style.css");

var _lib = _interopRequireDefault(require("element-ui/lib"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

console.log(_lib["default"].Button);
console.log(_Element);

And one more: (same as above)

// test/fixtures/import-module/expected.js
"use strict";

require("element-ui/lib/abc/style.css");

var _abc = _interopRequireDefault(require("element-ui/lib/abc"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

console.log(_abc["default"].Button);
console.log(_Element);

I would expect something like var _Element = bind({})(_abc["default"]);?