Name is already always supplied, no need to add it
This commit is contained in:
parent
7d06c7dce0
commit
669d1b480d
|
@ -109,7 +109,7 @@ class Checker {
|
||||||
p.entries.forEach((np, key) =>
|
p.entries.forEach((np, key) =>
|
||||||
this.checkNamedPattern(
|
this.checkNamedPattern(
|
||||||
scope,
|
scope,
|
||||||
M.promoteNamedSimplePattern(M.addNameIfAbsent(np, key)),
|
M.promoteNamedSimplePattern(np),
|
||||||
`entry ${key.asPreservesText()} in dictionary in ${context}`));
|
`entry ${key.asPreservesText()} in dictionary in ${context}`));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ function converterForCompound(
|
||||||
ctx.block(() =>
|
ctx.block(() =>
|
||||||
converterFor(
|
converterFor(
|
||||||
ctx,
|
ctx,
|
||||||
M.promoteNamedSimplePattern(M.addNameIfAbsent(n, k)),
|
M.promoteNamedSimplePattern(n),
|
||||||
tmpSrc,
|
tmpSrc,
|
||||||
() => loop(i + 1))))];
|
() => loop(i + 1))))];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -76,8 +76,8 @@ function compoundFields(fs: FieldMap, resolver: RefResolver, p: M.CompoundPatter
|
||||||
gatherFields(fs, resolver, M.promoteNamedSimplePattern(p.variable));
|
gatherFields(fs, resolver, M.promoteNamedSimplePattern(p.variable));
|
||||||
break;
|
break;
|
||||||
case 'dict':
|
case 'dict':
|
||||||
p.entries.forEach((n, k) =>
|
p.entries.forEach((n, _k) =>
|
||||||
gatherFields(fs, resolver, M.promoteNamedSimplePattern(M.addNameIfAbsent(n, k))));
|
gatherFields(fs, resolver, M.promoteNamedSimplePattern(n)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
((_p: never) => {})(p);
|
((_p: never) => {})(p);
|
||||||
|
|
|
@ -101,7 +101,7 @@ function unconverterFor(ctx: FunctionContext, p: M.Pattern, src: string): Item {
|
||||||
brackets(... Array.from(p.entries.entries()).map(([k, n]) =>
|
brackets(... Array.from(p.entries.entries()).map(([k, n]) =>
|
||||||
brackets(
|
brackets(
|
||||||
ctx.mod.literal(k),
|
ctx.mod.literal(k),
|
||||||
unconverterForNamedSimple(ctx, M.addNameIfAbsent(n, k), src))))));
|
unconverterForNamedSimple(ctx, n, src))))));
|
||||||
}
|
}
|
||||||
})(p.value);
|
})(p.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,22 +102,6 @@ export function anonymousSimplePattern(p: M.SimplePattern): M.NamedPattern {
|
||||||
return M.NamedPattern.anonymous(M.Pattern.SimplePattern(p));
|
return M.NamedPattern.anonymous(M.Pattern.SimplePattern(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addNameIfAbsent(p: M.NamedSimplePattern, k: M._val): M.NamedSimplePattern {
|
|
||||||
if (p._variant === 'named') {
|
|
||||||
return p;
|
|
||||||
} else {
|
|
||||||
const s = namelike(k);
|
|
||||||
if (s !== void 0) {
|
|
||||||
return M.NamedSimplePattern.named(M.NamedSimplePattern_({
|
|
||||||
name: Symbol.for(s),
|
|
||||||
pattern: p.value
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function namelike(x: Input): string | undefined {
|
export function namelike(x: Input): string | undefined {
|
||||||
if (typeof x === 'string') return x;
|
if (typeof x === 'string') return x;
|
||||||
if (typeof x === 'symbol') return x.description!;
|
if (typeof x === 'symbol') return x.description!;
|
||||||
|
|
Loading…
Reference in New Issue