Avoid unnecessary use of asLiteral
This commit is contained in:
parent
5afb1469f3
commit
5393308be4
|
@ -357,7 +357,7 @@ export function compile(env: Environment, schema: Schema, options: CompilerOptio
|
|||
case M.$Symbol: return `typeof ${v} === 'symbol'`;
|
||||
}
|
||||
case M.$lit:
|
||||
return `_.asLiteral(${v}, ${literal(p[0])}) !== void 0`;
|
||||
return `_.is(${v}, ${literal(p[0])})`;
|
||||
case M.$ref:
|
||||
return lookup(refPosition(p), p, env,
|
||||
(_p) => `is${Ref._.name(p).description!}(${v})`,
|
||||
|
|
|
@ -109,7 +109,7 @@ export function isSchema(v: any): v is Schema {
|
|||
let _tmp0, _tmp1, _tmp2: any;
|
||||
return (
|
||||
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
||||
_.asLiteral(v.label, $schema) !== void 0 &&
|
||||
_.is(v.label, $schema) &&
|
||||
(
|
||||
(v.length === 1) &&
|
||||
(
|
||||
|
@ -183,7 +183,7 @@ export function decodeSchema(d: _.TypedDecoder<_ptr>): Schema | undefined {
|
|||
return result;
|
||||
}
|
||||
|
||||
export function isVersion(v: any): v is Version {return _.asLiteral(v, $1) !== void 0;}
|
||||
export function isVersion(v: any): v is Version {return _.is(v, $1);}
|
||||
|
||||
export function asVersion(v: any): Version {
|
||||
if (!isVersion(v)) {throw new TypeError(`Invalid Version: ${_.stringify(v)}`);} else {return v;};
|
||||
|
@ -191,7 +191,7 @@ export function asVersion(v: any): Version {
|
|||
|
||||
export function decodeVersion(d: _.TypedDecoder<_ptr>): Version | undefined {let result; result = _.asLiteral(d.nextSignedInteger(), $1); return result;}
|
||||
|
||||
export function isPointerName(v: any): v is PointerName {return (isRef(v) || _.asLiteral(v, __lit5) !== void 0);}
|
||||
export function isPointerName(v: any): v is PointerName {return (isRef(v) || _.is(v, __lit5));}
|
||||
|
||||
export function asPointerName(v: any): PointerName {
|
||||
if (!isPointerName(v)) {throw new TypeError(`Invalid PointerName: ${_.stringify(v)}`);} else {return v;};
|
||||
|
@ -210,26 +210,26 @@ export function isPattern(v: any): v is Pattern {
|
|||
return _.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) && (
|
||||
(
|
||||
(
|
||||
_.asLiteral(v.label, $atom) !== void 0 && (
|
||||
_.is(v.label, $atom) && (
|
||||
(v.length === 1) &&
|
||||
(
|
||||
_.asLiteral(v[0], $Boolean) !== void 0 ||
|
||||
_.asLiteral(v[0], $Float) !== void 0 ||
|
||||
_.asLiteral(v[0], $Double) !== void 0 ||
|
||||
_.asLiteral(v[0], $SignedInteger) !== void 0 ||
|
||||
_.asLiteral(v[0], $String) !== void 0 ||
|
||||
_.asLiteral(v[0], $ByteString) !== void 0 ||
|
||||
_.asLiteral(v[0], $Symbol) !== void 0
|
||||
_.is(v[0], $Boolean) ||
|
||||
_.is(v[0], $Float) ||
|
||||
_.is(v[0], $Double) ||
|
||||
_.is(v[0], $SignedInteger) ||
|
||||
_.is(v[0], $String) ||
|
||||
_.is(v[0], $ByteString) ||
|
||||
_.is(v[0], $Symbol)
|
||||
)
|
||||
)
|
||||
) ||
|
||||
(_.asLiteral(v.label, $pointer) !== void 0 && ((v.length === 0))) ||
|
||||
(_.asLiteral(v.label, $lit) !== void 0 && ((v.length === 1) && true)) ||
|
||||
(_.is(v.label, $pointer) && ((v.length === 0))) ||
|
||||
(_.is(v.label, $lit) && ((v.length === 1) && true)) ||
|
||||
(
|
||||
_.asLiteral(v.label, $ref) !== void 0 && ((v.length === 2) && isModuleRef(v[0]) && typeof v[1] === 'symbol')
|
||||
_.is(v.label, $ref) && ((v.length === 2) && isModuleRef(v[0]) && typeof v[1] === 'symbol')
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $or) !== void 0 && (
|
||||
_.is(v.label, $or) && (
|
||||
(v.length === 1) &&
|
||||
(
|
||||
_.Array.isArray(v[0]) &&
|
||||
|
@ -240,7 +240,7 @@ export function isPattern(v: any): v is Pattern {
|
|||
)
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $and) !== void 0 && (
|
||||
_.is(v.label, $and) && (
|
||||
(v.length === 1) &&
|
||||
(
|
||||
_.Array.isArray(v[0]) &&
|
||||
|
@ -251,10 +251,10 @@ export function isPattern(v: any): v is Pattern {
|
|||
)
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $rec) !== void 0 && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
|
||||
_.is(v.label, $rec) && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $tuple) !== void 0 && (
|
||||
_.is(v.label, $tuple) && (
|
||||
(v.length === 1) &&
|
||||
(
|
||||
_.Array.isArray(v[0]) &&
|
||||
|
@ -265,7 +265,7 @@ export function isPattern(v: any): v is Pattern {
|
|||
)
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $tuple_STAR_) !== void 0 && (
|
||||
_.is(v.label, $tuple_STAR_) && (
|
||||
(v.length === 2) &&
|
||||
(
|
||||
_.Array.isArray(v[0]) &&
|
||||
|
@ -276,14 +276,12 @@ export function isPattern(v: any): v is Pattern {
|
|||
isNamedPattern(v[1])
|
||||
)
|
||||
) ||
|
||||
(_.is(v.label, $setof) && ((v.length === 1) && isPattern(v[0]))) ||
|
||||
(
|
||||
_.asLiteral(v.label, $setof) !== void 0 && ((v.length === 1) && isPattern(v[0]))
|
||||
_.is(v.label, $dictof) && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $dictof) !== void 0 && ((v.length === 2) && isPattern(v[0]) && isPattern(v[1]))
|
||||
) ||
|
||||
(
|
||||
_.asLiteral(v.label, $dict) !== void 0 && (
|
||||
_.is(v.label, $dict) && (
|
||||
(v.length === 1) &&
|
||||
(
|
||||
_.Dictionary.isDictionary<_val, _ptr>(v[0]) &&
|
||||
|
@ -308,7 +306,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
let _tmp10, _tmp11: any;
|
||||
_tmp10 = d.next();
|
||||
_tmp11 = d.mark();
|
||||
if (_.asLiteral(_tmp10, $atom) !== void 0) {
|
||||
if (_.is(_tmp10, $atom)) {
|
||||
let _tmp12, _tmp13, _tmp14: any;
|
||||
_tmp14 = d.mark();
|
||||
_tmp13 = _.asLiteral(d.nextSymbol(), $Boolean);
|
||||
|
@ -351,14 +349,14 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $pointer) !== void 0) {
|
||||
if (_.is(_tmp10, $pointer)) {
|
||||
let _tmp15: any;
|
||||
if (d.closeCompound()) _tmp15 = [];
|
||||
if (_tmp15 !== void 0) result = _.Record<(typeof $pointer), []>(_tmp10 as any, _tmp15 as any);
|
||||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $lit) !== void 0) {
|
||||
if (_.is(_tmp10, $lit)) {
|
||||
let _tmp16, _tmp17: any;
|
||||
_tmp17 = d.next();
|
||||
if (_tmp17 !== void 0) {if (d.closeCompound()) _tmp16 = [_tmp17];};
|
||||
|
@ -366,7 +364,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $ref) !== void 0) {
|
||||
if (_.is(_tmp10, $ref)) {
|
||||
let _tmp18, _tmp19, _tmp20: any;
|
||||
_tmp19 = decodeModuleRef(d);
|
||||
if (_tmp19 !== void 0) {
|
||||
|
@ -377,7 +375,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $or) !== void 0) {
|
||||
if (_.is(_tmp10, $or)) {
|
||||
let _tmp21, _tmp22: any;
|
||||
if (d.openSequence()) {
|
||||
let _tmp23: any;
|
||||
|
@ -397,7 +395,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $and) !== void 0) {
|
||||
if (_.is(_tmp10, $and)) {
|
||||
let _tmp24, _tmp25: any;
|
||||
if (d.openSequence()) {
|
||||
let _tmp26: any;
|
||||
|
@ -417,7 +415,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $rec) !== void 0) {
|
||||
if (_.is(_tmp10, $rec)) {
|
||||
let _tmp27, _tmp28, _tmp29: any;
|
||||
_tmp28 = decodePattern(d);
|
||||
if (_tmp28 !== void 0) {
|
||||
|
@ -428,7 +426,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $tuple) !== void 0) {
|
||||
if (_.is(_tmp10, $tuple)) {
|
||||
let _tmp30, _tmp31: any;
|
||||
if (d.openSequence()) {
|
||||
let _tmp32: any;
|
||||
|
@ -448,7 +446,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $tuple_STAR_) !== void 0) {
|
||||
if (_.is(_tmp10, $tuple_STAR_)) {
|
||||
let _tmp33, _tmp34, _tmp35: any;
|
||||
if (d.openSequence()) {
|
||||
let _tmp36: any;
|
||||
|
@ -471,7 +469,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $setof) !== void 0) {
|
||||
if (_.is(_tmp10, $setof)) {
|
||||
let _tmp37, _tmp38: any;
|
||||
_tmp38 = decodePattern(d);
|
||||
if (_tmp38 !== void 0) {if (d.closeCompound()) _tmp37 = [_tmp38];};
|
||||
|
@ -479,7 +477,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $dictof) !== void 0) {
|
||||
if (_.is(_tmp10, $dictof)) {
|
||||
let _tmp39, _tmp40, _tmp41: any;
|
||||
_tmp40 = decodePattern(d);
|
||||
if (_tmp40 !== void 0) {
|
||||
|
@ -490,7 +488,7 @@ export function decodePattern(d: _.TypedDecoder<_ptr>): Pattern | undefined {
|
|||
};
|
||||
if (result === void 0) {
|
||||
d.restoreMark(_tmp11);
|
||||
if (_.asLiteral(_tmp10, $dict) !== void 0) {
|
||||
if (_.is(_tmp10, $dict)) {
|
||||
let _tmp42, _tmp43: any;
|
||||
if (d.openDictionary()) {
|
||||
let r: _.KeyedDictionary<_val, Pattern, _ptr> | undefined = new _.KeyedDictionary();
|
||||
|
@ -527,7 +525,7 @@ export function isNamedPattern(v: any): v is NamedPattern {
|
|||
return (
|
||||
(
|
||||
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
||||
_.asLiteral(v.label, $named) !== void 0 &&
|
||||
_.is(v.label, $named) &&
|
||||
((v.length === 2) && typeof v[0] === 'symbol' && isPattern(v[1]))
|
||||
) ||
|
||||
isPattern(v)
|
||||
|
@ -562,7 +560,7 @@ export function decodeNamedPattern(d: _.TypedDecoder<_ptr>): NamedPattern | unde
|
|||
export function isRef(v: any): v is Ref {
|
||||
return (
|
||||
_.Record.isRecord<_val, _.Tuple<_val>, _ptr>(v) &&
|
||||
_.asLiteral(v.label, $ref) !== void 0 &&
|
||||
_.is(v.label, $ref) &&
|
||||
((v.length === 2) && isModuleRef(v[0]) && typeof v[1] === 'symbol')
|
||||
);
|
||||
}
|
||||
|
@ -589,7 +587,7 @@ export function decodeRef(d: _.TypedDecoder<_ptr>): Ref | undefined {
|
|||
return result;
|
||||
}
|
||||
|
||||
export function isModuleRef(v: any): v is ModuleRef {return (_.asLiteral(v, $thisModule) !== void 0 || isModulePath(v));}
|
||||
export function isModuleRef(v: any): v is ModuleRef {return (_.is(v, $thisModule) || isModulePath(v));}
|
||||
|
||||
export function asModuleRef(v: any): ModuleRef {
|
||||
if (!isModuleRef(v)) {throw new TypeError(`Invalid ModuleRef: ${_.stringify(v)}`);} else {return v;};
|
||||
|
|
Loading…
Reference in New Issue