Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

update ResultInspector options #6074

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions packages/codec/lib/format/utils/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export interface ResultInspectorOptions {
* the address. (By default it displays only the ENS name.)
*/
noHideAddress?: boolean;
/**
* This flag, if set, causes mappings to be rendered via objects
* rather than Maps. This is intended for compatibility and not
* recommended for normal use.
*/
renderMappingsViaObjects?: boolean;
}

/**
Expand Down Expand Up @@ -149,17 +155,37 @@ export class ResultInspector {
);
}
case "mapping":
return util.inspect(
new Map(
(<Format.Values.MappingValue>this.result).value.map(
({ key, value }) => [
new ResultInspector(key, this.options),
new ResultInspector(value, this.options)
]
)
),
options
);
if (!this.options.renderMappingsViaObjects) {
//normal case
return util.inspect(
new Map(
(<Format.Values.MappingValue>this.result).value.map(
({ key, value }) => [
new ResultInspector(key, this.options),
new ResultInspector(value, this.options)
]
)
),
options
);
} else {
//compatibility case
return util.inspect(
Object.assign(
{},
...(<Format.Values.MappingValue>this.result).value.map(
({ key, value }) => ({
//need to stringify key
[util.inspect(
new ResultInspector(key, this.options),
options
)]: new ResultInspector(value, this.options)
})
)
),
options
);
}
case "struct": {
let coercedResult = <Format.Values.StructValue>this.result;
if (coercedResult.reference !== undefined) {
Expand Down