Fix ASI protection for private fields (#10334)

This commit is contained in:
Georgii Dolzhykov authored and GitHub committed 2021-02-18 12:39:56 +02:00
1 parent 3950ce194d
commit e147c3b1c4
5 files changed
+90 -2

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
#### Fix ASI protection for private fields (#10334 by @thorn0)
<!-- prettier-ignore -->
```jsx
// Input
class C {
#field = 'value';
["method"]() {}
}
// Prettier stable (with --no-semi)
class C {
#field = "value"
["method"]() {}
}
// Prettier main (with --no-semi)
class C {
#field = "value";
["method"]() {}
}
```
+2 -1
View File
@@ -59,7 +59,8 @@ function printStatementSequence(path, options, print, property) {
parts.push(";");
} else if (
node.type === "ClassProperty" ||
node.type === "PropertyDefinition"
node.type === "PropertyDefinition" ||
node.type === "ClassPrivateProperty"
) {
// `ClassBody` don't allow `EmptyStatement`,
// so we can use `statements` to get next node
@@ -1007,3 +1007,64 @@ aReallyLongLine012345678901234567890123456789012345678901234567890123456789 *
================================================================================
`;
exports[`private-field.js [espree] format 1`] = `
"Unexpected character '#' (2:3)
1 | class C {
> 2 | #field = 'value';
| ^
3 | [\\"method\\"]() {}
4 | }
5 |"
`;
exports[`private-field.js - {"semi":false} [espree] format 1`] = `
"Unexpected character '#' (2:3)
1 | class C {
> 2 | #field = 'value';
| ^
3 | [\\"method\\"]() {}
4 | }
5 |"
`;
exports[`private-field.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
class C {
#field = 'value';
["method"]() {}
}
=====================================output=====================================
class C {
#field = "value";
["method"]() {}
}
================================================================================
`;
exports[`private-field.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
class C {
#field = 'value';
["method"]() {}
}
=====================================output=====================================
class C {
#field = "value";
["method"]() {}
}
================================================================================
`;
+1 -1
View File
@@ -1,4 +1,4 @@
const errors = { espree: ["class.js"] };
const errors = { espree: ["class.js", "private-field.js"] };
run_spec(__dirname, ["babel", "flow"], { errors });
run_spec(__dirname, ["babel", "flow"], { semi: false, errors });
+4
View File
@@ -0,0 +1,4 @@
class C {
#field = 'value';
["method"]() {}
}