bryanrsmith / eslint-plugin-sort-class-members

An ESLint rule for enforcing consistent ES6 class member order
119 stars 21 forks source link

How to find `PrivateName`? #78

Closed AkatQuas closed 2 years ago

AkatQuas commented 2 years ago

https://github.com/bryanrsmith/eslint-plugin-sort-class-members/blob/aa1c1f3e896fe39dc730311c5da3a6c551e82935/src/rules/sort-class-members.js#L171

I have a class statement like

class {
  private _a = () => {}
}

However, the AST show _a has a field accessibility: 'private' other than PrivateName in its key.type.

So what's the difference ?

Is there any issue with the parser ? I'm using @typescript-eslint/parser now.


I have a small test project for JavaScript files.

It turns out the type for private property #b is PrivateIdentifier.

image

So, where does PrivateName come from?

AkatQuas commented 2 years ago

Never mind.

I realize the issue with the parser . So I use the @babel/eslint-parser to check the type.

image

Maybe the RFC has update.

AkatQuas commented 2 years ago

https://github.com/babel/babel/blob/2e2d202694df8ec485ac2bae79e5258b9e552fd9/packages/babel-parser/src/plugins/estree.js#L194-L203

babel parser has convert PrivateName to PrivateIdentifier .