From 418f997d31831aba65de374154f680d2d5735de7 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Tue, 28 Nov 2017 20:39:56 +0300 Subject: [PATCH] Add Object special --- src/globals.js | 13 ++++++++++++- tests/samples/objects.js | 11 +++++++++++ tests/samples/objects.json | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/samples/objects.js create mode 100644 tests/samples/objects.json diff --git a/src/globals.js b/src/globals.js index eaa3e4e..c001790 100644 --- a/src/globals.js +++ b/src/globals.js @@ -2,7 +2,18 @@ import {invariant} from './utils'; import type {Type} from './types'; export default { - Buffer() { + Object(params: (?Type)[]): ?Type { + invariant(params.length === 0); + + return { + kind: 'map', + keys: {kind: 'mixed'}, + values: {kind: 'mixed'}, + }; + }, + Buffer(params: (?Type)[]): ?Type { + invariant(params.length === 0); + return { kind: 'reference', to: ['Buffer'], diff --git a/tests/samples/objects.js b/tests/samples/objects.js new file mode 100644 index 0000000..7253380 --- /dev/null +++ b/tests/samples/objects.js @@ -0,0 +1,11 @@ +type X = Object; + +interface Y { + y: Object; +} + +class Z { + z: Object; +} + +export {X, Y, Z}; diff --git a/tests/samples/objects.json b/tests/samples/objects.json new file mode 100644 index 0000000..beb87ce --- /dev/null +++ b/tests/samples/objects.json @@ -0,0 +1,36 @@ +{ + "types": [ + { + "id": ["objects", "X"], + "kind": "map", + "keys": {"kind": "mixed"}, + "values": {"kind": "mixed"} + }, + { + "id": ["objects", "Y"], + "kind": "record", + "fields": [{ + "name": "y", + "value": { + "kind": "map", + "keys": {"kind": "mixed"}, + "values": {"kind": "mixed"} + }, + "required": true + }] + }, + { + "id": ["objects", "Z"], + "kind": "record", + "fields": [{ + "name": "z", + "value": { + "kind": "map", + "keys": {"kind": "mixed"}, + "values": {"kind": "mixed"} + }, + "required": true + }] + } + ] +}