Correct identification of in/instanceof identifiers (#20019)
Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
1 parent
2529b92818
commit
c41be0bf9c
4 files changed
+59
-2
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#### Avoid unnecessary semicolons before private members named `#in` or `#instanceof` (#20019 by @cellison-figma)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
class Graph {
|
||||
#nodes = {};
|
||||
#in = {};
|
||||
}
|
||||
|
||||
// Prettier stable (--parser oxc --no-semi)
|
||||
class Graph {
|
||||
#nodes = {};
|
||||
#in = {}
|
||||
}
|
||||
|
||||
// Prettier main (--parser oxc --no-semi)
|
||||
class Graph {
|
||||
#nodes = {}
|
||||
#in = {}
|
||||
}
|
||||
```
|
||||
@@ -256,8 +256,8 @@ function shouldPrintSemicolonAfterClassProperty(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!nextNode.computed) {
|
||||
const name = nextNode.key?.name;
|
||||
if (!nextNode.computed && nextNode.key?.type === "Identifier") {
|
||||
const { name } = nextNode.key;
|
||||
if (name === "in" || name === "instanceof") {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2104,12 +2104,26 @@ class C {
|
||||
["method"]() {}
|
||||
}
|
||||
|
||||
class PrivateKeywordFields {
|
||||
a = {};
|
||||
#in = {};
|
||||
b = {};
|
||||
#instanceof = {};
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class C {
|
||||
#field = "value";
|
||||
["method"]() {}
|
||||
}
|
||||
|
||||
class PrivateKeywordFields {
|
||||
a = {}
|
||||
#in = {}
|
||||
b = {}
|
||||
#instanceof = {}
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -2123,12 +2137,26 @@ class C {
|
||||
["method"]() {}
|
||||
}
|
||||
|
||||
class PrivateKeywordFields {
|
||||
a = {};
|
||||
#in = {};
|
||||
b = {};
|
||||
#instanceof = {};
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class C {
|
||||
#field = "value";
|
||||
["method"]() {}
|
||||
}
|
||||
|
||||
class PrivateKeywordFields {
|
||||
a = {};
|
||||
#in = {};
|
||||
b = {};
|
||||
#instanceof = {};
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
|
||||
@@ -2,3 +2,10 @@ class C {
|
||||
#field = 'value';
|
||||
["method"]() {}
|
||||
}
|
||||
|
||||
class PrivateKeywordFields {
|
||||
a = {};
|
||||
#in = {};
|
||||
b = {};
|
||||
#instanceof = {};
|
||||
}
|
||||
Reference in new issue
Block a user