Fix TypeScript regression by moving non-null assertion to the end of the line instead of the beginning#4052
Conversation
|
This needs to go in 1.11. Without it, non-null declarations on identifiers get split on lines, causing tslint to not be able to parse the line. |
|
Thanks for contributing! :) |
|
I'm curious, is the fact that tslint doesn't parse it the only issue with this? Let me preface it with the fact that I've never seen or written any code with it but the way it was originally printed looked clearer to me. It feels weird to have the |
|
It seemed typescript didn't mind it. I thought this was important because it was a regression. I also think the ! must go with the preceding thing as thats what it modifies. |
|
In JavaScript, SyntaxError: Unexpected token (1:5)
> 1 | a ? . b
| ^Can you give what was the error message for tslint? We should definitely raise an issue to the project at least. |
It’s not just TSLint, it’s invalid TypeScript. TS parses it as: foo;
!(<identifier with name === "">.bar()) |
|
That sounds like a bug! Could any of you two report it to the typescript repo? |
|
This is the fix |
|
@vjeux I don't think they should behave the same in this case.. I think
(I think that's it, I don't really use TS or |
|
My understanding is that |
|
|
Makes sense, thanks for the explanation @duailibe! I would still like to see an issue reported. a!
.band a
!.bshould likely parse the same way. |
|
I'm perfectly fine with the second form being an error. |
|
Ohhh, okay I re-read @j-f1 explanation and this is because of automatic semi-colon insertion. Because it's a post-fix operator and not an infix one with the dot, then it changes the parsing tree. I doubt that they'll want to change the ASI rules to have @ericanderson thanks for doing this! I just wanted to make sure that we were doing the right thing. |
Fixes #4051
Tests are failing but its the same tests that are failing on master (see #4053), in typescript conditional code; unrelated to chaining.