fix formatting for typescript Enum with computed members (#12930)
* fix formatting for typescript Enum with computed members * add change log * remove extra examples in change log
This commit is contained in:
1 parent
3147244f55
commit
a089819223
5 files changed
+91
-2
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### fix formatting for typescript Enum with computed members (#12930 by @HosokawaR)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```tsx
|
||||
// Input
|
||||
enum A {
|
||||
[i++],
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
enum A {
|
||||
i++,
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
enum A {
|
||||
[i++],
|
||||
}
|
||||
```
|
||||
@@ -414,7 +414,12 @@ function printTypescript(path, options, print) {
|
||||
|
||||
return parts;
|
||||
case "TSEnumMember":
|
||||
parts.push(print("id"));
|
||||
if (node.computed) {
|
||||
parts.push("[", print("id"), "]");
|
||||
} else {
|
||||
parts.push(print("id"));
|
||||
}
|
||||
|
||||
if (node.initializer) {
|
||||
parts.push(" = ", print("initializer"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,53 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`computed-members.ts [babel-ts] format 1`] = `
|
||||
"Unexpected token (2:3)
|
||||
1 | enum A {
|
||||
> 2 | [i++],
|
||||
| ^
|
||||
3 | }
|
||||
4 |
|
||||
5 | const bar = "bar""
|
||||
`;
|
||||
|
||||
exports[`computed-members.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
enum A {
|
||||
[i++],
|
||||
}
|
||||
|
||||
const bar = "bar"
|
||||
enum B {
|
||||
[bar] = 2,
|
||||
}
|
||||
|
||||
const foo = () => "foo";
|
||||
enum C {
|
||||
[foo()] = 2,
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
enum A {
|
||||
[i++],
|
||||
}
|
||||
|
||||
const bar = "bar";
|
||||
enum B {
|
||||
[bar] = 2,
|
||||
}
|
||||
|
||||
const foo = () => "foo";
|
||||
enum C {
|
||||
[foo()] = 2,
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`enum.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
enum A {
|
||||
[i++],
|
||||
}
|
||||
|
||||
const bar = "bar"
|
||||
enum B {
|
||||
[bar] = 2,
|
||||
}
|
||||
|
||||
const foo = () => "foo";
|
||||
enum C {
|
||||
[foo()] = 2,
|
||||
}
|
||||
@@ -1 +1,5 @@
|
||||
run_spec(__dirname, ["typescript"]);
|
||||
run_spec(__dirname, ["typescript"], {
|
||||
errors: {
|
||||
"babel-ts": ["computed-members.ts"],
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user