Skip to content

Namespace import crashes the plugin #111

@InvictusMB

Description

@InvictusMB
  • babel-plugin-macros version: 2.5.1

Relevant code or config

import * as foo from 'foo.macro'

What happened:
Compiler fails with the following message

./src/App.jsx
TypeError: Cannot read property 'name' of undefined
    at Array.map (<anonymous>)

Problem description:
ImportNamespaceSpecifier node is not handled properly here and the error message is not helpful. Offending code:

s.type === 'ImportDefaultSpecifier'
? 'default'
: s.imported.name,

Suggested solution:
ImportNamespaceSpecifier should either be handled as default case or as a separate namespace case. Or maybe both variants are valid and there should be a config option akin to allowSyntheticDefaultImports in TypeScript

Quick fix:

(s.type === 'ImportDefaultSpecifier' || s.type === 'ImportNamespaceSpecifier')
  ? 'default'
  : s.imported.name,

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions