vacuumlabs / babel-plugin-extensible-destructuring

Plugin for extensible destructuring in Babel
BSD 2-Clause "Simplified" License
116 stars 11 forks source link

Cannot destructure function properties #19

Closed cooperka closed 7 years ago

cooperka commented 7 years ago

Take the following example:

import { fromJS } from 'immutable'

// Works as expected:
let { a, b: { c } } = fromJS({ a: 1, b: { c: 2 } })
console.log(a, c)

let barFn = () => {}
barFn.bar = 'baz'

// Works with plain JS, but fails with extensible-destructuring:
let { foo: { bar } } = { foo: barFn }
console.log(bar)

Destructuring a and c works fine, but trying to destructure bar throws Error: cannot resolve property bar in object of type function (function barFn() {}). Seems to be an easy fix by just changing the logic here: https://github.com/vacuumlabs/babel-plugin-extensible-destructuring/blob/master/runtime/src/runtime.js#L32-L34

I'll try to make a PR soon.

hleumas commented 7 years ago

Thanks! I will be grateful for PR.