umijs / babel-plugin-import

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

babel-plugin-import与babel-plugin-istanbul冲突 #624

Open Losstie opened 1 year ago

Losstie commented 1 year ago

错误信息

Input is not defined

对应代码:

import {Input, InputNumber } from 'antd';
const FinalInput = ComponentType === 'number' ? InputNumber: Input;

istanbul插桩结果

var FinalInput = (cov_16x0fs0ihf.s[13]++, (cov_16x0fs0ihf.b[5][0]++, componentType === \'number\') ||(cov_16x0fs0ihf.b[5][1]++, componentType === \'year\') ? 
(cov_16x0fs0ihf.b[4][0]++, _antd.InputNumber) : (cov_16x0fs0ihf.b[4][1]++,_antd.Input))

babelConfig.js

const  path = require('path');
   module.exports = {
   presets: [
    '@babel/preset-react',
    [
      '@babel/preset-env',
      {
        "modules": "commonjs",
        "targets": {
          "browsers": ["last 4 versions", "ie >= 9", "safari >= 10"] // "last 2 Chrome versions",
        },
        "useBuiltIns": "entry",
        "corejs": 2,
        exclude: ['proposal-dynamic-import'],
      }
    ],
    '@babel/preset-typescript',
  ],
  plugins: [
    ['babel-plugin-istanbul'],
    ['@babel/plugin-syntax-dynamic-import'],
    ['@babel/plugin-transform-async-to-generator'],
    ['@babel/plugin-proposal-object-rest-spread'],
    ['@babel/plugin-transform-runtime'],
    ['@babel/plugin-proposal-decorators', { legacy: true }],
    ['@babel/plugin-proposal-class-properties', { loose: true }],
    ['@babel/plugin-proposal-private-methods', { loose: true }],
    ['@babel/plugin-proposal-private-property-in-object', { loose: true }],
    [['import', { libraryName: 'antd', libraryDirectory: 'lib', style: false }, 'antd']],
  ],
};

原因

babel-plugin-import目前貌似只针对Property及VariableDeclarator两种节点做了istanbul插桩的兼容,对于上述也算常用的三元表达式没有做兼容。能否兼容处理一下?