Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintuitive behavior for isIdentifier #15008

Closed
ghost opened this issue Apr 4, 2017 · 3 comments
Closed

Unintuitive behavior for isIdentifier #15008

ghost opened this issue Apr 4, 2017 · 3 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@ghost
Copy link

ghost commented Apr 4, 2017

TypeScript Version: nightly (2.3.0-dev.20170404)

Code

function f() {
    interface I {
        [yield: string]: boolean;
    }
}

function* g() {
    interface I {
        [yield: string]: boolean;
    }
}

Expected behavior:

No errors.

Actual behavior:

src/a.ts(9,15): error TS1005: ']' expected.
src/a.ts(9,23): error TS1005: ';' expected.
src/a.ts(9,24): error TS1131: Property or signature expected.

We use isIdentifier in a few places where it doesn't really make sense to care whether we're in a yield context or not.

@RyanCavanaugh
Copy link
Member

Isn't this just about the parser calling parseIdentifier when it should call parseIdentifierName ?

@ghost
Copy link
Author

ghost commented Apr 5, 2017

Turns out we do allow yield in all these other cases:

function* f() {
    interface I {
        (yield: number): void;
        new (yield: number): void;
        f(yield: number): void;
    }
}

The reason is that those use fillSignature, which sets yield/await context.
parseIndexSignatureDeclaration doesn't, presumably because the parameters are delimited by [] instead of ().
So we could simply modify the parseIndexSignatureDeclaration code to set yield/await context too.

Or, pass the open/close token as parameters to parseParameterList instead of hardcoding parens there, then call that instead of parseBracketedList.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 5, 2017
@mhegazy mhegazy added this to the Future milestone Jul 20, 2018
@RyanCavanaugh
Copy link
Member

Doesn't seem like anyone else has noticed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants