diff --git a/implementations/javascript/packages/core/src/compound.ts b/implementations/javascript/packages/core/src/compound.ts index 198eebe..eaaf0d1 100644 --- a/implementations/javascript/packages/core/src/compound.ts +++ b/implementations/javascript/packages/core/src/compound.ts @@ -6,3 +6,7 @@ export function isCompound(x: Value): x is Compound { return (Array.isArray(x) || Set.isSet(x) || Dictionary.isDictionary(x)); } + +export function isSequence(x: Value): x is Array> { + return (Array.isArray(x) && !('label' in x)); +} diff --git a/implementations/javascript/packages/schema/src/compiler/genconverter.ts b/implementations/javascript/packages/schema/src/compiler/genconverter.ts index 0c809bf..a8bc8ae 100644 --- a/implementations/javascript/packages/schema/src/compiler/genconverter.ts +++ b/implementations/javascript/packages/schema/src/compiler/genconverter.ts @@ -91,7 +91,7 @@ function converterForTuple(ctx: FunctionContext, return knownArray ? loop(0) - : [seq(`if (_.Array.isArray(${src})`, lengthCheck, `) `, ctx.block(() => loop(0)))]; + : [seq(`if (_.isSequence(${src})`, lengthCheck, `) `, ctx.block(() => loop(0)))]; } function converterFor( @@ -157,7 +157,7 @@ export function converterForSimple( return kKnownArray(); } else { return [`${dest} = void 0`, - seq(`if (_.Array.isArray(${src})) `, ctx.block(kKnownArray))]; + seq(`if (_.isSequence(${src})) `, ctx.block(kKnownArray))]; } } case 'setof': diff --git a/implementations/javascript/packages/schema/src/gen/schema.ts b/implementations/javascript/packages/schema/src/gen/schema.ts index 181a450..327c96d 100644 --- a/implementations/javascript/packages/schema/src/gen/schema.ts +++ b/implementations/javascript/packages/schema/src/gen/schema.ts @@ -969,7 +969,7 @@ export function toDefinition<_embedded = _.GenericEmbedded>(v: _.Value<_embedded let _tmp0: ({}) | undefined; _tmp0 = _.is(v.label, $or) ? {} : void 0; if (_tmp0 !== void 0) { - if (_.Array.isArray(v[0]) && v[0].length >= 2) { + if (_.isSequence(v[0]) && v[0].length >= 2) { let _tmp1: (NamedAlternative<_embedded>) | undefined; _tmp1 = toNamedAlternative(v[0][0]); if (_tmp1 !== void 0) { @@ -1006,7 +1006,7 @@ export function toDefinition<_embedded = _.GenericEmbedded>(v: _.Value<_embedded let _tmp7: ({}) | undefined; _tmp7 = _.is(v.label, $and) ? {} : void 0; if (_tmp7 !== void 0) { - if (_.Array.isArray(v[0]) && v[0].length >= 2) { + if (_.isSequence(v[0]) && v[0].length >= 2) { let _tmp8: (NamedPattern<_embedded>) | undefined; _tmp8 = toNamedPattern(v[0][0]); if (_tmp8 !== void 0) { @@ -1317,7 +1317,7 @@ export function toCompoundPattern<_embedded = _.GenericEmbedded>(v: _.Value<_emb if (_tmp3 !== void 0) { let _tmp4: (Array>) | undefined; _tmp4 = void 0; - if (_.Array.isArray(v[0])) { + if (_.isSequence(v[0])) { _tmp4 = []; for (const _tmp5 of v[0]) { let _tmp6: (NamedPattern<_embedded>) | undefined; @@ -1343,7 +1343,7 @@ export function toCompoundPattern<_embedded = _.GenericEmbedded>(v: _.Value<_emb if (_tmp7 !== void 0) { let _tmp8: (Array>) | undefined; _tmp8 = void 0; - if (_.Array.isArray(v[0])) { + if (_.isSequence(v[0])) { _tmp8 = []; for (const _tmp9 of v[0]) { let _tmp10: (NamedPattern<_embedded>) | undefined; @@ -1543,7 +1543,7 @@ export function asNamedAlternative<_embedded = _.GenericEmbedded>(v: _.Value<_em export function toNamedAlternative<_embedded = _.GenericEmbedded>(v: _.Value<_embedded>): undefined | (NamedAlternative<_embedded> & {__as_preserve__(): _.Value<_embedded>}) { let result: undefined | (NamedAlternative<_embedded> & {__as_preserve__(): _.Value<_embedded>}); - if (_.Array.isArray(v) && v.length === 2) { + if (_.isSequence(v) && v.length === 2) { let _tmp0: (string) | undefined; _tmp0 = typeof v[0] === 'string' ? v[0] : void 0; if (_tmp0 !== void 0) { @@ -1717,7 +1717,7 @@ export function toModulePath<_embedded = _.GenericEmbedded>(v: _.Value<_embedded let _tmp0: (Array) | undefined; let result: undefined | ModulePath; _tmp0 = void 0; - if (_.Array.isArray(v)) { + if (_.isSequence(v)) { _tmp0 = []; for (const _tmp1 of v) { let _tmp2: (symbol) | undefined;