-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[Bug]: super()
in class methods is not reported by @babel/eslint-parser
#13903
Comments
super()
in class methods is not reported by @babel/eslint-parser
Babel with estree plugin already throws: https://astexplorer.net/#/gist/03f767f5dbe210bd68f53a0e841b7d35/453f531ef48973e6054e8ca3860479762c2b626b and we don't have "contructor" in the codebase anyway, I guess there is nothing can be done on Babel's side? |
hmm, then why does the test case pass for me in eslint-plugin-react? it fails properly in eslint 8. |
In AST Explorer, when i select the babel eslint parser, as opposed to the babel parser, it does not throw. |
I don't know why, but it looks like this is intentional:
However, EDIT: It was introduced in babel/babel-eslint#215 |
We should probably just align with the current ESLint 7 and 8 behavior, since that PR was to align with the old ESLint/espree version. Or maybe @hzoo you remember more context, even if it was 6 years ago? |
Other context for a similar behavior: babel/babel-eslint#327. Since it was enabled on purpose, making it opt-in is a breaking change. |
oof, ok - so how can i opt out of this behavior? |
In your eslint config: parserOpts: {
babelOptions: {
allowReturnOutsideFunction: false,
allowSuperOutsideMethod: false,
}
} |
Actually, babel/babel-eslint#327 is opt-in and not by default, so it's different (I can't convince myself if this should be a patch release or a breaking change). |
Currently ESLint accepts this code (our return 2; |
|
💻
How are you using Babel?
@babel/eslint-parser
Input code
Configuration file name
No response
Configuration
n/a
Current and expected behavior
I would expect a parse error, because
super()
is not valid except inconstructor() {}
and this iscontructor() {}
.Environment
v7.16.0 of
@babel/eslint-parser
, eslint v8.1.10, node v17.0.1Possible solution
Don't allow
super()
outside of a classconstructor() {}
Additional context
Confusion over this led me to file eslint/eslint#15234, but eslint 8 is actually handling this correctly because of the typo.
related: typescript-eslint/typescript-eslint#4072
The text was updated successfully, but these errors were encountered: