oxygen
oxygen

Reputation: 497

Why can't @babel/parser parse objects?

When i input an object in astexplorer like below code, this will get a mistake: Missing semicolon. (3:9), what is that mean? @babel/parser can't parse object correctly?

{
  name: 'test',
  company: 'test company',
}

mistake

Upvotes: 0

Views: 293

Answers (1)

Felix Kling
Felix Kling

Reputation: 816770

Your code is interpreted as a block statement, not an object literal. However, the contents of the block are not valid statements, hence the error.

If you wrap the code in parenthesis to force the evaluation as an expression (and thus as an object literal) it works as expected:

({
  name: 'test',
  company: 'test company',
})

Upvotes: 3

Related Questions