Skip to content

Exporting declaration after function invocation misses semi #824

@erikmueller

Description

@erikmueller

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions