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

Ban old-style type assertions as arrow function bodies under erasableSyntaxOnly #61244

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Feb 21, 2025

Code like ()=><any>{} is not erasable, since ()=> {} is a different tree, and there's nowhere to add parens to the body without shifting its contents backwards one character. If there were extra spaces after the {}, maybe it'd work, but that's atypical.

This PR bans this specific case, though, I personally feel like banning the old-style assertions would be a good idea too.

@ajafff
Copy link
Contributor

ajafff commented Feb 24, 2025

you probably want to ban it in more places:

// return and yield ASI
function *foo() {
    yield <any>
        1;
    return <any>
        1;
}

// at the start of an ExpressionStatement if followed by an object literal; though I'm not sure why one would use it there
<unknown>{foo() {}}.foo();

// at the start of an ExpressionStatement if followed by function keyword
<unknown>function() {}();
<unknown>function() {};

// at the start of an ExpressionStatement if followed by an anonymous class expression
// note that this exact syntax currently emits invalid JS (no parenthesis added like for function above)
<unknown>class {}

there's probably more parsing ambiguity I cannot remember right now.

@jakebailey
Copy link
Member Author

Yeah, so that furthers my feeling that this syntax should be wholly banned in this mode. I tried to carve something out, but it sure doesn't seem like that's tractable if we want to ban something here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

2 participants