fixing pretty print issue. AND making it so it only looks for object's own properties when doing getAt
This commit is contained in:
parent
3132b79aae
commit
6acec5641c
2 changed files with 4 additions and 1 deletions
|
|
@ -279,7 +279,9 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
||||||
? `...${prettyPrint(entry.expr, indent + 1)}`
|
? `...${prettyPrint(entry.expr, indent + 1)}`
|
||||||
: `${needsQuotes(entry.key) ? JSON.stringify(entry.key) : entry.key} = ${prettyPrint(entry.value, indent + 1)}`
|
: `${needsQuotes(entry.key) ? JSON.stringify(entry.key) : entry.key} = ${prettyPrint(entry.value, indent + 1)}`
|
||||||
);
|
);
|
||||||
if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
|
const oneLine = `{ ${parts.join(', ')} }`;
|
||||||
|
if (oneLine.length <= 60 || parts.length <= 1) return oneLine;
|
||||||
|
// if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
|
||||||
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n');
|
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n');
|
||||||
return `{\n${inner}\n${i}}`;
|
return `{\n${inner}\n${i}}`;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ export const _rt = {
|
||||||
let obj: any = store[path[0]];
|
let obj: any = store[path[0]];
|
||||||
for (let i = 1; i < path.length; i++) {
|
for (let i = 1; i < path.length; i++) {
|
||||||
if (obj === undefined || obj === null) return { _tag: 'None' };
|
if (obj === undefined || obj === null) return { _tag: 'None' };
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(obj, path[i])) return { _tag: 'None' };
|
||||||
obj = obj[path[i]];
|
obj = obj[path[i]];
|
||||||
}
|
}
|
||||||
return obj === undefined ? { _tag: 'None' } : { _tag: 'Some', _0: obj };
|
return obj === undefined ? { _tag: 'None' } : { _tag: 'Some', _0: obj };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue