Skip to content

@babel/helper-module-transforms rewrites type annotations containing named imports incorrectly #13094

@jaked

Description

@jaked

Bug Report

Current behavior

Type annotations containing named imports are incorrectly transformed to MemberExpressions and cause a validation error: Property typeName of TSTypeReference expected node to be of a type ["TSEntityName"] but instead got "MemberExpression". See Babel repl.

This seems to be due to this line in helper-module-transforms, which rewrites any ReferencedIdentifier to a MemberExpression; but type annotations may contain Identifiers and be matched by ReferencedIdentifier.

Input Code

import { Foo } from './foo'

function bar(foo: Foo) { }

Expected behavior

Type annotations are transformed correctly, or (if this module is not intended to be used with type annotations) flagged with a clear error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA 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