-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
[@typescript-eslint/camelcase] There is a bug When I destructure and assign default values #1686
Comments
Hi there, Please make sure you use the issue templates when filing a bug. Hmmm, this looks like a bug in the base rule due to how espree parses. Doing a parse in both our parser, and in espree will produce the same json output. cc @kaicataldo who has more context on espree - this looks like a bug in espree? Or is this intentional? Sharing the node in multiple places in the AST seems really fragile, as mutating the node causes both instances to be mutated, which means the tree is not consistent. |
I don't think happens at the parser level. We add the |
sorry to clarify - the problem isn't the parent references, it's that an AST node has been shared in two places in the AST. const {foo=1} = {}; is parsed into the following AST by both parsers:
The problem is that when parsed with espree, Identifier (1) and (2) are referentially equal (as per the above screenshot). |
Thanks for clarifying. I checked this in Acorn (Espree's underlying parser) and it displays the same behavior. const acorn = require('acorn');
const ast = acorn.parse("const {foo=1} = {};");
/*
{
"type": "Property",
"start": 7,
"end": 12,
"method": false,
"shorthand": true,
"computed": false,
"key": {
"type": "Identifier",
"start": 7,
"end": 10,
"name": "foo"
},
"kind": "init",
"value": {
"type": "AssignmentPattern",
"start": 7,
"end": 12,
"left": {
"type": "Identifier",
"start": 7,
"end": 10,
"name": "foo"
},
"right": {
"type": "Literal",
"start": 11,
"end": 12,
"value": 1,
"raw": "1"
}
}
}
*/
const node = ast.body[0].declarations[0].id.properties[0];
console.log(node.key === node.value.left) // true It's probably worth making an issue an Acorn to discuss - I'm honestly not sure what the correct behavior should be here. |
Thanks for your troubleshooting, so is there a solution now |
no. this looks like a bug in acorn. |
thank you!I try it |
our |
What were you trying to do?
There is a bug When I destructure and assign default values
What did you expect to happen?
There is no error
What actually happened?
Error Identifier 'a_b' is not in camel case
Versions
2.22.0
@typescript-eslint/eslint-plugin
^2.22.0
@typescript-eslint/parser
^2.22.0
TypeScript
^3.5.3
node
v10.15.0
npm
6.4.1
The text was updated successfully, but these errors were encountered: