alangpierce/sucrase

Exporting declaration after function invocation misses semi

erikmueller opened this issue · 0 comments

I am using sucrase to transpile some jest tests and came across a (typescript) file containing a function invocation followed by an export declaration.

Since the export declaration is wrapped into parens during transpilation, it seems the resulting code created a higher order function as it tries to call the result of the invocation with the wrapped export (as there are no semicolons).

const fn = () => ({ key: { nested: 1 } })

const data = fn()
export const { nested } = data.key

results in

"use strict";Object.defineProperty(exports, "__esModule", {value: true});const fn = () => ({ key: { nested: 1 } })

const data = fn()
( { nested: exports.nested } = data.key)

which would lead to const data = fn()(({ nested: exports.nested } = data.key)) and fail for a couple of reasons.