Correct identification of in/instanceof identifiers (#20019)

Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
Cole Ellisonandfisker Cheung authored and GitHub committed 2026-09-13 03:06:14 +08:00
1 parent 2529b92818
commit c41be0bf9c
4 files changed
+59 -2

No files matched your search

+22
View File
@@ -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 = {}
}
```
+2 -2
View File
@@ -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 = {};
}
================================================================================
`;
+7
View File
@@ -2,3 +2,10 @@ class C {
#field = 'value';
["method"]() {}
}
class PrivateKeywordFields {
a = {};
#in = {};
b = {};
#instanceof = {};
}