Closed Bug 1626423 Opened 5 years ago Closed 5 years ago

Devtools claims invalid syntax for {...obj} alone

Categories

(DevTools :: Console, enhancement)

74 Branch
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 972530

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.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Console
Product: Firefox → DevTools

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.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE

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!

You need to log in before you can comment on or make changes to this bug.