Ban old-style type assertions under erasableSyntaxOnly#61244
Conversation
|
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. |
|
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. |
|
When I was first creating |
|
Updated the PR to just straight up ban the syntax. |
|
@typescript-bot cherry-pick this to release-5.8 |
|
Hey, @jakebailey! I've created #61320 for you. |
…e-5.8 (#61320) Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
| const start = node.type.pos - "<".length; | ||
| const end = skipTrivia(file.text, node.type.end) + ">".length; |
There was a problem hiding this comment.
Mentioned a different way of doing this in the pick PR, but this is probably not the right way to do this for non-syntactically correct code like
let x = <foo;
or
let y = <foo 123
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.Updated the PR to just ban them. There are too may edge cases IMO.