umijs / babel-plugin-import

Modularly import plugin for babel.
3.16k stars 404 forks source link

逗号表达式编译异常 #568

Closed eightHundreds closed 3 years ago

eightHundreds commented 3 years ago

输入

import { Layout } from 'antd';
const ref = (1, Layout);
console.log(ref.Content);

输出

const ref = (1, Layout);
console.log(ref.Content);

期望

import "antd/lib/layout/style/css";
import _Layout from "antd/lib/layout";
const ref = (1, Layout);
console.log(ref.Content);
eightHundreds commented 3 years ago

背景: https://github.com/istanbuljs/babel-plugin-istanbul/issues/161

使用babel-plugin-istanbul 编译下面代码

import { Layout } from 'antd';
const { Content } Layout;
console.log(Content)

结果:

function cov_2fztfe5rtr() {
 // ...
}

cov_2fztfe5rtr();
import { Layout } from 'antd';

const _ref = (cov_2fztfe5rtr().s[0]++, Layout),  // 逗号表达式
  Content = _ref.Content;

cov_2fztfe5rtr().s[1]++;
console.log(Content);

再经过babel-plugin-import编译,最后出现import消失但没有生成对应require

eightHundreds commented 3 years ago

升级包后解决