Support for Flow's Indexed Access type (#10594)
This commit is contained in:
1 parent
a49942c1ba
commit
99ac66b73a
7 files changed
+44
-1
No files matched your search
@@ -0,0 +1,15 @@
|
||||
#### Support for Flow's indexed access type (#10594 by @gkz)
|
||||
|
||||
Support for Flow's indexed access type.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
const x: Obj['foo'] = 1;
|
||||
|
||||
// Prettier stable
|
||||
// Error: unsupported node type "IndexedAccessType"
|
||||
|
||||
// Prettier main
|
||||
const x: Obj["foo"] = 1;
|
||||
```
|
||||
@@ -10,6 +10,7 @@ const {
|
||||
printUnionType,
|
||||
printFunctionType,
|
||||
printTupleType,
|
||||
printIndexedAccessType,
|
||||
} = require("./type-annotation");
|
||||
const { printInterface } = require("./interface");
|
||||
const { printTypeParameters } = require("./type-parameters");
|
||||
@@ -81,6 +82,8 @@ function printFlow(path, options, print) {
|
||||
print("id"),
|
||||
printTypeParameters(path, options, print, "typeParameters"),
|
||||
];
|
||||
case "IndexedAccessType":
|
||||
return printIndexedAccessType(path, options, print);
|
||||
// Type Annotations for Facebook Flow, typically stripped out or
|
||||
// transformed away before printing.
|
||||
case "TypeAnnotation":
|
||||
|
||||
@@ -297,6 +297,11 @@ function printTupleType(path, options, print) {
|
||||
]);
|
||||
}
|
||||
|
||||
// `TSIndexedAccessType` and `IndexedAccessType`
|
||||
function printIndexedAccessType(path, options, print) {
|
||||
return [print("objectType"), "[", print("indexType"), "]"];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
printOpaqueType,
|
||||
printTypeAlias,
|
||||
@@ -304,5 +309,6 @@ module.exports = {
|
||||
printUnionType,
|
||||
printFunctionType,
|
||||
printTupleType,
|
||||
printIndexedAccessType,
|
||||
shouldHugType,
|
||||
};
|
||||
@@ -47,6 +47,7 @@ const {
|
||||
printUnionType,
|
||||
printFunctionType,
|
||||
printTupleType,
|
||||
printIndexedAccessType,
|
||||
} = require("./type-annotation");
|
||||
|
||||
function printTypescript(path, options, print) {
|
||||
@@ -280,7 +281,7 @@ function printTypescript(path, options, print) {
|
||||
case "TSLiteralType":
|
||||
return print("literal");
|
||||
case "TSIndexedAccessType":
|
||||
return [print("objectType"), "[", print("indexType"), "]"];
|
||||
return printIndexedAccessType(path, options, print);
|
||||
case "TSConstructSignatureDeclaration":
|
||||
case "TSCallSignatureDeclaration":
|
||||
case "TSConstructorType": {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`indexed-access.js - {"trailingComma":"all"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
const x: Obj['bar'] = 1;
|
||||
|
||||
=====================================output=====================================
|
||||
const x: Obj["bar"] = 1;
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1 @@
|
||||
const x: Obj['bar'] = 1;
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, ["flow"], { trailingComma: "all" });
|
||||
Reference in new issue
Block a user