Proposal: expression mode (=)

Isiah Meadows isiahmeadows at gmail.com
Mon Oct 31 20:58:44 UTC 2016


Not quite. I did some later thinking, and hage found probably a simpler
solution.

On Mon, Oct 31, 2016, 16:10 Yongxu Ren <renyongxu at gmail.com> wrote:

> Isiah,
> The reason for `=` instead of the `do expression` is to write functional
> code without extra syntax. I do not think there are any indistinguishable
> or 'very confusing' case, though I am aware the *Object Property Shorthand`
> that been introduced in ES6 might cause some problems.
>
> Here is what I think that may resolve this problem
> for your concern,
> ```
> var b = 1
> var a = b
> = { c }
> ```
>
> the solution is to make `Object literals` to have higher parsing priority.
>

Actually, the above example should read as this:

```js
a
= { b }
```

First, most linters will complain, anyways.

Second, it could be resolved by requiring no line terminator appears
between the assignee and `=` operator. The Closure Compiler is okay with
emitting such code normally, but no other minifier does by default. And
those can be fixed.


> if `c` is a variable, it will be parsed as `object literal`, otherwise it
> is considered as scope and been parsed as expression block.
>
> ex.
> `var x = { a }` will be parsed as `var x = { a: a }`
> `var x = { a() }` will be parsed as `var x = a()`, under current specs it
> would be syntax error.
>

You missed the original proposal here. Your examples should be this (with
the preceding `=`):

```js
var x = = { a }
var x = = { a() }
```


> In this case, this proposal should not cause any confusion IMO.
>

To clarify, I'm mentioning parser ambiguity, not visual (which does exist
to some extent).

_______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161031/af2ae6fe/attachment.html>


More information about the es-discuss mailing list