sucrase icon indicating copy to clipboard operation
sucrase copied to clipboard

Exporting declaration after function invocation misses semi

Open erikmueller opened this issue 5 months ago • 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.

erikmueller avatar Jan 29 '24 09:01 erikmueller