Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix object extension #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions src/runtime/browser/util.inspect.polyfil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,18 @@ function reduceToSingleString(output: string[], base: string, braces: string[]):
return braces[0] + (base === "" ? "" : base + "\n") + " " + output.join(",\n ") + " " + braces[1];
}

function _extend(origin: object, add: object): object {
const typedOrigin = { ...origin } as { [key: string]: unknown };
function _extend(origin: object, add: object): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return value is not used anywhere, it only confuses what exactly is done here. Apparently this method is meant to only alter provided origin and not to return anything.

const typedOrigin = origin as {[key: string]: unknown};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has to be exactly the same object. If it is cloned, only typedOrigin is extended, not origin.

// Don't do anything if add isn't an object
if (!add || !isObject(add)) return origin;
if (!add || !isObject(add)) return;

const clonedAdd = { ...add } as { [key: string]: unknown };
const clonedAdd = {...add} as {[key: string]: unknown};

const keys = Object.keys(add);
let i = keys.length;
while (i--) {
typedOrigin[keys[i]] = clonedAdd[keys[i]];
}
return typedOrigin;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used anywhere

}

export function formatWithOptions(inspectOptions: InspectOptions, ...args: unknown[]) {
Expand Down
Loading