speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
843 stars 90 forks source link

Add support for object spread #200

Closed malthejorgensen closed 5 years ago

malthejorgensen commented 6 years ago

Currently invalid syntax is output when transforming object rest properties (TC39 proposal). The rewiring seems to work as expected if we simply skip rewiring rest properties.

A small example triggering the error would be a module like this:

const newUser = { id: 123, name: 'John', createdAt: 10000229393, updatedAt: 10000782231 }
export const { id, name, ...metadata } = newUser // <- This line makes babel not transform/compile

export const userCreatedAt = () => {
  return metadata.createdAt;
}

The code above is also provided in a test in the first of the two commits.

roneyrao commented 6 years ago

how about this one: ({ pathname } = parsedUrl) v 1.1.0 fails.

usersaurus commented 6 years ago

Merge this, please.

speedskater commented 6 years ago

@malthejorgensen Thank your for your PR and sorry for my very late reply. I finally managed to tmerged it into the 1.2.0 branch and puglished 1.2.0-rc.1 on npm as a prerelease. I also added you as a contributor to the README. I hope this is okay with you? Could you please test this release in your code bases. If I won't get any negativ feedback till next monday I will convert it to the final 1.2.0 and will then merge it onto master.

malthejorgensen commented 6 years ago

All good with me!