Update flow to 0.77

master
Paul Loyd 2018-07-24 23:13:34 +03:00
parent 38c0a8b804
commit c9b24ee574
4 changed files with 29 additions and 19 deletions

View File

@ -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

View File

@ -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"

View File

@ -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),
});
}

View File

@ -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<?Type>): 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';
}