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
Add more parser test cases #11923
Add more parser test cases #11923
Conversation
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 cb65cb3:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/27354/ |
5b8da03
to
4af8b29
Compare
@@ -1784,19 +1765,9 @@ export default class StatementParser extends ExpressionParser { | |||
|
|||
maybeParseExportDeclaration(node: N.Node): boolean { | |||
if (this.shouldParseExportDeclaration()) { | |||
if (this.isContextual("async")) { |
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.
These checks are redundant because shouldParseExportDeclaration
will check isAsyncFunction
babel/packages/babel-parser/src/parser/statement.js
Lines 1918 to 1938 in a827ca4
shouldParseExportDeclaration(): boolean { | |
if (this.match(tt.at)) { | |
this.expectOnePlugin(["decorators", "decorators-legacy"]); | |
if (this.hasPlugin("decorators")) { | |
if (this.getPluginOption("decorators", "decoratorsBeforeExport")) { | |
this.unexpected(this.state.start, Errors.DecoratorBeforeExport); | |
} else { | |
return true; | |
} | |
} | |
} | |
return ( | |
this.state.type.keyword === "var" || | |
this.state.type.keyword === "const" || | |
this.state.type.keyword === "function" || | |
this.state.type.keyword === "class" || | |
this.isLet() || | |
this.isAsyncFunction() | |
); | |
} |
When
this.isContextual("async")
is true, isAsyncFunction()
must be true and async
must be followed by a function
token, therefore this.unexpected(next, tt._function);
is never reached.
142bdcb
to
8311e20
Compare
packages/babel-parser/test/expressions/experimental/top-level-await/script/input.js
Show resolved
Hide resolved
Co-authored-by: Brian Ng <bng412@gmail.com>
24a4f69
to
cb65cb3
Compare
This PR aims for improving
@babel/parser
's test coverage. Ideally the only uncovered lines should bethrow new Error("unreachable")
.