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
babel-parser(ts): Raise recoverable error for abstract interface #12771
Conversation
sosukesuzuki
commented
Feb 6, 2021
Q | A |
---|---|
Fixed Issues? | Fixes #12768 |
Patch: Bug Fix? | Y |
Tests Added + Pass? | Yes |
License | MIT |
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 da8ce69:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/39972/ |
Could you rebase? CI should be fixed now. |
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.
LGTM with some edge cases and code nits.
node: any, | ||
): N.ClassDeclaration | N.TsInterfaceDeclaration { | ||
const isClass = this.match(tt._class); | ||
if (!isClass && !this.isContextual("interface")) { |
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.
nit: I prefer to move this branch to the else
branch of isClass
:
if (isClass) {
parseClass(...)
} else if (this.isContextual("interface")) {
throw on abstract interface;
} else {
throw on unexpected token;
}
TSErrors.NonClassMethodPropertyHasAbstractModifer, | ||
); | ||
this.next(); | ||
return this.tsParseInterfaceDeclaration( |
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.
interface
should not have a proceeding line break:
interface
Foo {}
is invalid. So it does not suffice to conclude that it is an interface declaration when we see a contextual interface
name.
Address reviews Address reviews
39a1c7e
to
7d1e3d8
Compare
// To avoid | ||
// abstract interface | ||
// Foo {} | ||
if (!this.hasPrecedingLineBreak(this.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.
Is there a way to avoid this 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.
Maybe with a combination of lineBreak.test
and this.nextTokenStart
.
If it works, it would be useful to extract it to a hasFollowingLineBreak()
method.
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 seems to work fine! da8ce69