From c9b24ee574f7998a0809f5a5a31bad825e12ec14 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Tue, 24 Jul 2018 23:13:34 +0300 Subject: [PATCH] Update flow to 0.77 --- .flowconfig | 2 +- package.json | 2 +- src/collector/pragmas.js | 9 +++++---- src/types.js | 35 ++++++++++++++++++++++------------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.flowconfig b/.flowconfig index fcacdb4..be6489b 100644 --- a/.flowconfig +++ b/.flowconfig @@ -9,13 +9,13 @@ declarations/ [lints] all=error +unsafe-getters-setters=off [options] all=true module.use_strict=true munge_underscores=true include_warnings=true -unsafe.enable_getters_and_setters=true suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe suppress_comment= \\(.\\|\n\\)*\\$FlowIssue suppress_type=$FlowFixMe diff --git a/package.json b/package.json index a08c458..25f8388 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "@babel/preset-flow": "^7.0.0-beta.32", "@babel/register": "^7.0.0-beta.32", "ajv": "^5.5.1", - "flow-bin": "^0.60.1", + "flow-bin": "^0.77.0", "jasmine": "^2.8.0", "mocha": "^4.0.1", "nyc": "^11.3.0" diff --git a/src/collector/pragmas.js b/src/collector/pragmas.js index 2ee10f6..3350711 100644 --- a/src/collector/pragmas.js +++ b/src/collector/pragmas.js @@ -1,10 +1,11 @@ import {invariant} from '../utils'; import type {Type} from '../types'; -import * as t from '../types'; +import {createNumber, isRepr} from '../types'; export type Pragma = - | TypePragma; + | TypePragma + ; export type TypePragma = { kind: 'type', @@ -20,11 +21,11 @@ export function extractPragmas(text: string): Pragma[] { while ((match = PRAGMA_RE.exec(text))) { const repr = match[1]; - invariant(['i32', 'i64', 'u32', 'u64', 'f32', 'f64'].includes(repr)); + invariant(isRepr(repr)); pragmas.push({ kind: 'type', - value: t.createNumber(repr), + value: createNumber(repr), }); } diff --git a/src/types.js b/src/types.js index beb2ffe..6ba70fd 100644 --- a/src/types.js +++ b/src/types.js @@ -12,7 +12,8 @@ export type Type = | LiteralType | AnyType | MixedType - | ReferenceType; + | ReferenceType + ; export type TypeId = string[]; @@ -64,9 +65,11 @@ export type MaybeType = BaseType & { export type NumberType = BaseType & { kind: 'number', - repr: 'i32' | 'i64' | 'u32' | 'u64' | 'f32' | 'f64', + repr: Repr, }; +export type Repr = 'i32' | 'i64' | 'u32' | 'u64' | 'f32' | 'f64'; + export type StringType = BaseType & { kind: 'string', }; @@ -77,9 +80,11 @@ export type BooleanType = BaseType & { export type LiteralType = BaseType & { kind: 'literal', - value: string | number | boolean | null | void, + value: LiteralValue, }; +export type LiteralValue = string | number | boolean | null | void; + export type AnyType = BaseType & { kind: 'any', }; @@ -93,20 +98,20 @@ export type ReferenceType = BaseType & { to: TypeId, }; -export const createRecord = (fields: *): RecordType => ({kind: 'record', fields}); -export const createArray = (items: *): ArrayType => ({kind: 'array', items}); -export const createTuple = (items: *): TupleType => ({kind: 'tuple', items}); -export const createMap = (keys: *, values: *): MapType => ({kind: 'map', keys, values}); -export const createUnion = (variants: *): UnionType => ({kind: 'union', variants}); -export const createIntersection = (parts: *): IntersectionType => ({kind: 'intersection', parts}); -export const createMaybe = (value: *): MaybeType => ({kind: 'maybe', value}); -export const createNumber = (repr: *): NumberType => ({kind: 'number', repr}); +export const createRecord = (fields: Field[]): RecordType => ({kind: 'record', fields}); +export const createArray = (items: Type): ArrayType => ({kind: 'array', items}); +export const createTuple = (items: Array): TupleType => ({kind: 'tuple', items}); +export const createMap = (keys: Type, values: Type): MapType => ({kind: 'map', keys, values}); +export const createUnion = (variants: Type[]): UnionType => ({kind: 'union', variants}); +export const createIntersection = (parts: Type[]): IntersectionType => ({kind: 'intersection', parts}); +export const createMaybe = (value: Type): MaybeType => ({kind: 'maybe', value}); +export const createNumber = (repr: Repr): NumberType => ({kind: 'number', repr}); export const createString = (): StringType => ({kind: 'string'}); export const createBoolean = (): BooleanType => ({kind: 'boolean'}); -export const createLiteral = (value: *): LiteralType => ({kind: 'literal', value}); +export const createLiteral = (value: LiteralValue): LiteralType => ({kind: 'literal', value}); export const createAny = () => ({kind: 'any'}); export const createMixed = () => ({kind: 'mixed'}); -export const createReference = (to: *) => ({kind: 'reference', to}); +export const createReference = (to: TypeId) => ({kind: 'reference', to}); declare function clone(Type): Type; declare function clone(TypeId): TypeId; @@ -162,3 +167,7 @@ function cloneType(type: Type): Type { return createReference(type.to.slice()); } } + +export function isRepr(v: string): boolean %checks { + return v === 'i32' || v === 'i64' || v === 'u32' || v === 'u64' || v === 'f32' || v === 'f64'; +}