Preserve quotes for TSMethodSignature nodes named new (#19621)
This commit is contained in:
1 parent
c03ab4e71c
commit
dd5e24eabe
4 files changed
+122
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Preserve quotes for methods named `new` (#19621 by @kovsu)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
interface Container {
|
||||
new(id: string): number;
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
}
|
||||
```
|
||||
@@ -99,6 +99,10 @@ function isKeySafeToUnquote(node, options) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node.type === "TSMethodSignature" && value === "new") {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Safe to unquote as identifier
|
||||
if (
|
||||
// With `--strictPropertyInitialization`, TS treats properties with quoted names differently than unquoted ones.
|
||||
|
||||
@@ -240,6 +240,96 @@ interface I2 {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-19618.ts - {"quoteProps":"as-needed"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
quoteProps: "as-needed"
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
'new'(id: string): number;
|
||||
'method'(): void;
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
method(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
"new"(id: string): number;
|
||||
method(): void;
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-19618.ts - {"quoteProps":"consistent"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
quoteProps: "consistent"
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
'new'(id: string): number;
|
||||
'method'(): void;
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`issue-19618.ts - {"quoteProps":"preserve"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
quoteProps: "preserve"
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
'new'(id: string): number;
|
||||
'method'(): void;
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`type-literal.ts - {"quoteProps":"as-needed"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
interface Container {
|
||||
"new"(id: string): number;
|
||||
"method"(): void;
|
||||
}
|
||||
|
||||
type ContainerType = {
|
||||
'new'(id: string): number;
|
||||
'method'(): void;
|
||||
};
|
||||
Reference in new issue
Block a user