[Bug]: `super()` in class methods is not reported by `@babel/eslint-parser`
See original GitHub issue💻
- Would you like to work on a fix?
How are you using Babel?
Input code
class Foo extends React.Component {
contructor(props) {
super(props);
this.initialValues = {
test: '',
};
}
render = () => {
return (
<Component
initialValues={this.props.initialValues || this.initialValues}
>
{formikProps => (
<Input {...formikProps} />
)}
</Component>
);
}
}
Configuration file name
No response
Configuration
n/a
Current and expected behavior
I would expect a parse error, because super()
is not valid except in constructor() {}
and this is contructor() {}
.
Environment
v7.16.0 of @babel/eslint-parser
, eslint v8.1.10, node v17.0.1
Possible solution
Don’t allow super()
outside of a class constructor() {}
Additional context
Confusion over this led me to file https://github.com/eslint/eslint/issues/15234, but eslint 8 is actually handling this correctly because of the typo.
related: https://github.com/typescript-eslint/typescript-eslint/issues/4072
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Bug: parse error on valid code in eslint 8 · Issue #15234 - GitHub
Parser correctly reports an error on use of super() call in a method. When the typo is fixed and the method becomes the...
Read more >@babel/eslint-parser | Yarn - Package Manager
ESLint parser that allows for linting of experimental syntax transformed by Babel. readme. babel. The compiler for writing next generation JavaScript.
Read more >Why does ESLint not recognize my class arrow functions?
I think you are getting that linting error because you are not using ECMA version 2022 (aka ECMA latest). Please check this link...
Read more >eslint/eslint - Gitter
Guys I use eslint API with babel-parser. When I make a syntax error I get. Parsing error: Unexpected token, ...
Read more >Changelog - JavaScript Standard Style
This pre-release exists to test out the ESLint 8 related changes and discover possible backwards incompatible changes that comes with it and mitigate...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In your eslint config:
In AST Explorer, when i select the babel eslint parser, as opposed to the babel parser, it does not throw.