umijs / babel-plugin-import

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

babel-plugin-import 对 ts语法 ( Com as any ) 和 带装饰器的 class extends Com 支持有问题 #623

Open yunqiangwu opened 2 years ago

yunqiangwu commented 2 years ago

babel config:

{
  "plugins": [
    ["@babel/plugin-transform-typescript", { "legacy": true }],
    [
      "babel-plugin-import",
      {
        "libraryName": "antd",
        "libraryDirectory": "lib",
        "style": true
      },
      "c7n-pro"
    ],
    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]
}

source js:

import { observer } from 'mobx-react';
import { Button } from 'antd';

@observer
export default class TestAaa extends RichText {
  hello() {
    console.log({
      Button: (Button as any)
    });
    console.log({
      Button,
    });
    const MyButton = { ...Button };
  }
}

babel transpiled:

import "antd/lib/button/style";
import _Button from "antd/lib/button";

var _class;

import { observer } from 'mobx-react';

let TestAaa = observer(_class = class TestAaa extends RichText {
  hello() {
    console.log({
      Button: Button
    });
    console.log({
      Button: _Button
    });
    const MyButton = { ...Button };
  }

}) || _class;

export { TestAaa as default };

第 11 行代码应该是 _Button 才对, 这里却变成了 Button

相关依赖版本:

image

bug online demo (重现的在线链接): bug online demo

image

zzuhit commented 1 year ago

[ "babel-plugin-import", { "libraryName": "antd", "libraryDirectory": "lib", "style": true }, "c7n-pro" ]

中 "c7n-pro" 这个参数值 代表什么意思的呢?