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
Support TypeScript 4.3 get/set type members #13089
Support TypeScript 4.3 get/set type members #13089
Conversation
sosukesuzuki
commented
Apr 2, 2021
Q | A |
---|---|
Fixed Issues? | Fixes #13071 |
Minor: New Feature? | Y |
Tests Added + Pass? | Yes |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/45139/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 64e389b:
|
@@ -609,6 +656,7 @@ export default (superClass: Class<Parser>): Class<Parser> => | |||
return idx; | |||
} | |||
|
|||
this.tsParseMethodSignatureKind(node); | |||
this.parsePropertyName(node, /* isPrivateNameAllowed */ false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using lookahead
(which is expensive) in tsParseMethodSignatureKind
, can we:
- Call
this.parsePropertyName
- If not computed, not private, does not have type parameters, and the identifier name is
get
orset
:- If
tsNextTokenCanFollowModifier
, then we are parsing an accessor and we callthis.parsePropertyName
again - Otherwise, it's a method/property named
get
orset
- If
- Otherwise, it's a method/property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we parse class accessors using the same strategy mentioned above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the AST babel should return for below code?
interface Foo {
set foo;
}
In current behaviour, two properties named set
and foo
are returned (with recoverable error Missing semicolon
). If we should keep it, we should detect if the property is a method signature after first this.parsePropertyName
call. But then the token is the name of the property, so I don't know how to do that without lookahead...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to throw "Expected (":
- It's what we already do for
class Foo { set foo }
- It's more likely that someone didn't finish writing a setter, than putting two properties on the same line without
;
and that the name of the first one was exactlyset
.
Could you rebase this on top of #13098, to avoid the merge conflicts? 🙏 |
28e17fe
to
3e0369f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the following test cases?
// 'get' and 'set' accessors cannot declare 'this' parameters.
interface Foo {
get bar(this: Foo);
set bar(this: Foo);
}
// A 'set' accessor cannot have an optional parameter.
interface Foo {
set bar(v?);
}
// A 'set' accessor cannot have rest parameter.
interface Foo {
set bar(...v);
}
9571427
to
13d1014
Compare
I rebased |
1d86ce2
to
446432f
Compare
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
3d6f728
to
64e389b
Compare
Thanks! |
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>