Skip to content
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

Merged
merged 7 commits into from Aug 14, 2020
Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Aug 5, 2020

Q                       A
License MIT

This PR aims for improving @babel/parser's test coverage. Ideally the only uncovered lines should be throw new Error("unreachable").

@JLHwung JLHwung added area: tests PR: Internal 🏠 A type of pull request used for our changelog categories pkg: parser labels Aug 5, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 5, 2020

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 5, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/27354/

@JLHwung JLHwung force-pushed the add-more-parser-test-cases branch 2 times, most recently from 5b8da03 to 4af8b29 Compare August 6, 2020 20:44
@@ -1784,19 +1765,9 @@ export default class StatementParser extends ExpressionParser {

maybeParseExportDeclaration(node: N.Node): boolean {
if (this.shouldParseExportDeclaration()) {
if (this.isContextual("async")) {
Copy link
Contributor Author

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

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.

@JLHwung JLHwung force-pushed the add-more-parser-test-cases branch 2 times, most recently from 142bdcb to 8311e20 Compare August 6, 2020 21:45
@JLHwung JLHwung marked this pull request as ready for review August 6, 2020 21:48
@JLHwung JLHwung merged commit 66c6b3b into babel:main Aug 14, 2020
@JLHwung JLHwung deleted the add-more-parser-test-cases branch August 14, 2020 15:53
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: tests outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants