bernard-lin / babel-plugin-glamorous-displayname

A babel plugin for Glamorous displayNames 💄
http://npm.im/babel-plugin-glamorous-displayname
MIT License
32 stars 2 forks source link

Destructuring glamorous doesn't work #13

Closed aaronjensen closed 6 years ago

aaronjensen commented 6 years ago

Something like this:

import glamorous from 'glamorous'

const {Div} = glamorous

causes this plugin to fail with:

TypeError: e.js: Property value expected type of string but got null
    at Object.validate (my-app/node_modules/babel-types/lib/definitions/index.js:161:13)
    at validate (my-app/node_modules/babel-types/lib/index.js:505:9)
    at Object.builder (my-app/node_modules/babel-types/lib/index.js:466:7)
    at my-app/node_modules/babel-plugin-glamorous-displayname/dist/index.js:86:21
    at Array.forEach (native)
    at PluginPass.exit (my-app/node_modules/babel-plugin-glamorous-displayname/dist/index.js:61:45)
    at newFn (my-app/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (my-app/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (my-app/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (my-app/node_modules/babel-traverse/lib/path/context.js:117:8)
kentcdodds commented 6 years ago

We should definitely address this. One thing you can do is:

import glamorous, {Div} from 'glamorous'

We do export all the built-in components explicitly (see the end of glamorous.es.js).

Would you like to fix it? Here's a start to try things out: https://astexplorer.net/#/gist/c2209ae08bfb5b1de4eb8a7a71129bc0/aa1bba48fa492e629a4101a3068b0c1ed1880763

Once you've got that, it should be pretty easy to copy your changes to this project and add a test case :+1:

aaronjensen commented 6 years ago

I can't do that in typescript because the definitions don't support it (another thing to fix).

Yes, I can probably fix this today.

kentcdodds commented 6 years ago

Wonderful, thank you!