Skip to content

Unexpected parse problems in valid JS code when arrow functions are used as values in object surrounded with parentheses #32914

@IllusionMH

Description

@IllusionMH

TypeScript Version: 3.7.0-dev.20190815 (there are same errors in playground even in 2.x)

Search Terms: Identifier expected , arrow function in object

Code

test.js

const value = 1;
const a = {
    b: () => false
}

const test = () => ({
    // "Identifier expected." error on "!" and two "Duplicate identifier '(Missing)'." errors on space.
    prop: !value, // remove ! to see that errors will be gone
    run: () => { //replace arrow function with regular function to see that errors will be gone
        // comment next line or remove "()" to see that errors will be gone
        if(!a.b()) { return 'special'; }

        return 'default';
    }
});

There are no look-alike Unicode characters.
There are no problems if you switch order of prop and run.

Error is reproducible even when I write

const test = ({
    prop: !value
    run: () => {
        if(!a.b()) { return 'special'; }

        return 'default';
    },
});

But works as expected if I remove parentheses around object or replace arrow function with regular one.

Expected behavior: No errors (code is valid and produces expected results in browsers)

Actual behavior: A lot of errors, most notably Identifier expected. on ! character in line prop: !value

UPD. Object properties are actually parsed as arrow function parameters:
image

Playground Link: Example (I disabled noImplicitAny to remove noise)

Related Issues: Not found

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions