This commit is contained in:
Mark Probst 2018-06-10 08:10:13 -07:00
Родитель 84a2a60e84
Коммит 089ddf9c70
2 изменённых файлов: 12 добавлений и 20 удалений

Просмотреть файл

@ -1,6 +1,6 @@
import { mapMerge, mapUpdateInto, mapMap, setUnionInto } from "collection-utils";
import { TypeKind, PrimitiveStringTypeKind, Type, UnionType } from "./Type";
import { TypeKind, PrimitiveStringTypeKind, Type, UnionType, PrimitiveTypeKind } from "./Type";
import { matchTypeExhaustive } from "./TypeUtils";
import {
TypeAttributes,
@ -102,17 +102,9 @@ export class UnionAccumulator<TArray, TObject> implements UnionTypeProvider<TArr
addAttributesToBuilder(this._nonStringTypeAttributes, "any", attributes);
this._lostTypeAttributes = true;
}
addNull(attributes: TypeAttributes): void {
addAttributesToBuilder(this._nonStringTypeAttributes, "null", attributes);
}
addBool(attributes: TypeAttributes): void {
addAttributesToBuilder(this._nonStringTypeAttributes, "bool", attributes);
}
addInteger(attributes: TypeAttributes): void {
addAttributesToBuilder(this._nonStringTypeAttributes, "integer", attributes);
}
addDouble(attributes: TypeAttributes): void {
addAttributesToBuilder(this._nonStringTypeAttributes, "double", attributes);
addPrimitive(kind: PrimitiveTypeKind, attributes: TypeAttributes): void {
assert(kind !== "any", "any must be added with addAny");
addAttributesToBuilder(this._nonStringTypeAttributes, kind, attributes);
}
protected addFullStringType(attributes: TypeAttributes, stringTypes: StringTypes | undefined): void {
@ -295,10 +287,10 @@ export class TypeRefUnionAccumulator extends UnionAccumulator<TypeRef, TypeRef>
t,
_noneType => this.addNone(attributes),
_anyType => this.addAny(attributes),
_nullType => this.addNull(attributes),
_boolType => this.addBool(attributes),
_integerType => this.addInteger(attributes),
_doubleType => this.addDouble(attributes),
_nullType => this.addPrimitive("null", attributes),
_boolType => this.addPrimitive("bool", attributes),
_integerType => this.addPrimitive("integer", attributes),
_doubleType => this.addPrimitive("double", attributes),
_stringType => this.addStringType("string", attributes),
arrayType => this.addArray(arrayType.items.typeRef, attributes),
classType => this.addObject(classType.typeRef, attributes),

Просмотреть файл

@ -83,17 +83,17 @@ export class TypeInference {
const t = valueTag(value);
switch (t) {
case Tag.Null:
accumulator.addNull(emptyTypeAttributes);
accumulator.addPrimitive("null", emptyTypeAttributes);
break;
case Tag.False:
case Tag.True:
accumulator.addBool(emptyTypeAttributes);
accumulator.addPrimitive("bool", emptyTypeAttributes);
break;
case Tag.Integer:
accumulator.addInteger(emptyTypeAttributes);
accumulator.addPrimitive("integer", emptyTypeAttributes);
break;
case Tag.Double:
accumulator.addDouble(emptyTypeAttributes);
accumulator.addPrimitive("double", emptyTypeAttributes);
break;
case Tag.InternedString:
if (this._inferEnums) {