Devtools claims invalid syntax for {...obj} alone
Categories
(DevTools :: Console, enhancement)
Tracking
(Not tracked)
People
(Reporter: leonardo.okuma, Unassigned)
Details
User Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
Steps to reproduce:
Open a single-line console and run this code in 2 steps:
let obj = {a: 1, b: 2}
{...obj}
Actual results:
SyntaxError: expected expression, got '...'
Expected results:
Google Chrome prints the object as if there was no spread operator, effectively printing out the very same as just writing 'obj' in the console.
Personally I believe that giving a SyntaxError can be misleading.
Comment 1•5 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Comment 2•5 years ago
|
||
Hello Leonardo, thanks for the report.
I think this bug is a duplicate of Bug 972530.
The expression is not valid Javascript. If you open a tab with the following address:
data:text/html,<meta charset=utf8><script>x={a: 1}; {...x}</script>
You'll see an error in the console (even in Chrome).
Your second line is creating a block statement (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block), and that's why you are getting a syntax error.
Reporter | ||
Comment 3•5 years ago
|
||
Hi Nicolas, thank you for the answer.
You're right. My mistake.
Chrome's devtools accept such code, but now I think it's Chrome that is misleading us for doing that.
Cheers!
Description
•