Skip to content

[Bug]: TypeScript import alias can cause import to be incorrectly removed #14912

@youngderekm

Description

@youngderekm

💻

  • Would you like to work on a fix?

How are you using Babel?

@babel/cli

Input code

import * as babel from '@babel/core';
import {MyNamespace} from 'myimport';

import b = babel;
import x = MyNamespace.x;

Configuration file name

No response

Configuration

module.exports = {
  plugins: [
    "@babel/plugin-transform-typescript"
  ]
};

Current and expected behavior

Both imports should be retained, however the second import is incorrectly removed.

Output:

import * as babel from '@babel/core';
var b = babel;
var x = MyNamespace.x;

expected output:

import * as babel from '@babel/core';
import {MyNamespace} from 'myimport'
var b = babel;
var x = MyNamespace.x;

The code is incorrect and fails at runtime with MyNamespace being undefined.

The unit test test case for the import alias feature tests the first style of import but not the second.

Environment

  • @babel/core: 7.19.0
  • @babel/cli: 7.18.10
  • @babel/plugin-transform-typescript: 7.19.0

Possible solution

retain the import in the generated code.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: typescriptoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions