bun
bun copied to clipboard
console.log quotation
What version of Bun is running?
0.3.0
What platform is your computer?
Darwin 22.2.0 x86_64 i386
What steps can reproduce the bug?
When use console.log to stdout a object which contain an object there is some inconsistency between quotation.
I see this error after fetching a website, parse the html to get a select options.
export function selectOptions(
document: Document,
querySelector: string
): SelectOptions {
// get select options
const { options } = document.querySelector(
querySelector
) as HTMLSelectElement;
// converted to array
const optionsArray = Array.from(options);
// map the array to get array of arrays to use with Object.fromEntries
const mappedOptions = optionsArray.map((option: HTMLOptionElement) => [
option.value.toString(),
{
id: Number(option.value),
label: option.textContent,
} as SelectOptionsValue,
]);
console.log(mappedOptions); // output correctly here
// [
// [ "33", {
// id: 33,
// label: "text..."
// } ], [ "36", {
// id: 36,
// label: "text..."
// } ], [
// "35", {
// id: 35,
// label: "text..."
// }
// ]
// ]
return Object.fromEntries(mappedOptions);
}
const html = await fetch(...).then(res => res.text());
const {document} = parseHtml(html); // by using linkedom
console.log(selectOptions(document, "#selectId"))
What is the expected behavior?
{
"33": {
id: 33,
label: "text..."
},
"35": {
id: 35,
label: "text..."
},
"36": {
id: 36,
label: "text..."
},
}
What do you see instead?
First quotation in the keys is simple and second one is double quotation.
{
'33": {
id: 33,
label: "text..."
},
'35": {
id: 35,
label: "text..."
},
'36": {
id: 36,
label: "text..."
},
}
Additional information
All works fine, is an output format error that is not happening in all cases... Y tried by using same converted object with fixed quotation and works well.
Thanks for reporting! This is possibly related to #1584, but will keep open.
@gtrabanco , the quotations appear to be set correctly now
const mappedOptions = [
[ "33", {
id: 33,
label: "text..."
} ], [ "36", {
id: 36,
label: "text..."
} ], [
"35", {
id: 35,
label: "text..."
}
]
]
console.log(Object.fromEntries(mappedOptions)())
// {
// "33": {
// id: 33,
// label: "text..."
// },
// "35": {
// id: 35,
// label: "text..."
// },
// "36": {
// id: 36,
// label: "text..."
// }
// }