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

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

Open
Losstie opened this issue Nov 18, 2022 · 0 comments
Open

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

Losstie opened this issue Nov 18, 2022 · 0 comments

Comments

@Losstie
Copy link

Losstie commented Nov 18, 2022

错误信息

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插桩的兼容,对于上述也算常用的三元表达式没有做兼容。能否兼容处理一下?

@Losstie Losstie changed the title babel-plugin-import与babel-plugin-import冲突 babel-plugin-import与babel-plugin-istanbul冲突 Nov 18, 2022
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

1 participant