Odd behavior in code prettifier when using destructed assignment

While it’s taken a bit of getting used to, I generally really like the code editor in Observable. Here’s one exception that might be a bug. Suppose I type in the following:

  let a,b,c
  let x=0
  [a,b,c] = [1,2,3]

After entering this, the auto-prettifier (perhaps you have another term?) reformats this as:

  let a, b, c;
  let x = ((0)[(a, b, c)] = [1, 2, 3]);

Which generates an error.

Of course, it’s easy enough to avoid this by terminating the lines with a semi-colon myself but I’ve rather grown to like not worrying about that. :slight_smile:

This is one of the few gotchas of writing semicolon-free Javascript — if the next line begins with [, it will attach to the previous line.

The formatting is actually helping you here by showing you what your code means.


Ahh, it’s a Javascript thing rather than an Observable thing - thanks!

1 Like