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

test: add invalid-lone-import test #10950

Merged
merged 2 commits into from Jan 3, 2020

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 1, 2020

Q                       A
License MIT

This PR removes an unreachable unexpected check, so it is not covered in any unit test:
https://codecov.io/gh/babel/babel/src/b91720c1ccbfc066cbc6af7e3db6114acefac17a/packages/babel-parser/src/parser/expression.js#L929

If the next token is neither tt.dot nor tt.parenL, it will be parsed in parseStatementContent

case tt._import: {
const nextTokenCharCode = this.lookaheadCharCode();
if (
nextTokenCharCode === charCodes.leftParenthesis ||
nextTokenCharCode === charCodes.dot
) {
break;
}

Add a new lone-import test for coverage.

@JLHwung JLHwung added PR: Internal 🏠 A type of pull request used for our changelog categories pkg: parser labels Jan 1, 2020
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JLHwung JLHwung changed the title refactor: remove unreachable unexpected check test: add invalid-lone-import test Jan 2, 2020
@nicolo-ribaudo
Copy link
Member

While looking at this error, I realized that we can use this.raise to provide a better error message: "import" can only be used as part of dynamic import() or import.meta.
Also, since the most common error would probably be thinking of import() as a function call and thus of import as a norma identifier that you can pass around, recovering from this error by using it as a norma expression makes sense.

@nicolo-ribaudo nicolo-ribaudo merged commit 455d782 into babel:master Jan 3, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the remove-unreachable-code branch January 3, 2020 22:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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

3 participants