kentcdodds/babel-plugin-macros

Namespace import crashes the plugin

Open

#111 geöffnet am 16. Mai 2019

Auf GitHub ansehen
 (9 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (138 Forks)github user discovery
enhancementhelp wanted

Repository-Metriken

Stars
 (2.635 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

  • 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: https://github.com/kentcdodds/babel-plugin-macros/blob/e0ebca780856be76cbe1c5841d09a922fdde533b/src/index.js#L78-L80

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,

Contributor Guide