griffel icon indicating copy to clipboard operation
griffel copied to clipboard

babel-preset: multiple modules produce the same import

Open layershifter opened this issue 3 years ago • 0 comments

#103 fixed handling of multiple exports of the same module, but there is an edge case with multiple modules:

import { makeStyles as makeStylesA } from 'module-a'
import { makeStyles as makeStylesB } from 'module-b'

// ⬇️⬇️⬇️

import { __styles } from 'module-a'
import { __styles } from 'module-b' // 💥 duplicate import for "__styles"

This will explode as __styles is duplicated identifier. We should use local imports for this case, i.e. result should be:

import { __styles } from 'module-a'
import { __styles as __stylesB } from 'module-b'

References

  • https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md#scope
  • https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md#generating-a-uid

layershifter avatar Apr 25 '22 09:04 layershifter