Make comma at the end of line optional

classic Classic list List threaded Threaded
56 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Make comma at the end of line optional

Алексей
Hi all

Now we have a great syntax improvement that allows us to put comma at the end of arguments lists, object and array definitions. So in multiline definition last line could have the same signature as others (not only in multiline, but multiline definition benefits the most).

I would like to propose syntax that would allow to each line looks like the last:

const object = {
  x: 1
  y: 2
  z: 3
}

The rule here: for multiline arguments list, object or array declaration if line is a complete statement and next line is not an operator than consider it as complete argument (field, element) declaration.

Not an operator so you could use

const condition = true
const objext = {
  x: condition
    ? 0
    : 1
  y: 2
  z: 3
}

It is really like ASI but without bugs with "[", "(" and "/" - they should be consider as a start of a new declaration

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Bob Myers
Yes, ASI has been such a great success, let's extend it to commas.

On Tue, Sep 12, 2017 at 8:00 PM, Алексей <[hidden email]> wrote:
Hi all

Now we have a great syntax improvement that allows us to put comma at the end of arguments lists, object and array definitions. So in multiline definition last line could have the same signature as others (not only in multiline, but multiline definition benefits the most).

I would like to propose syntax that would allow to each line looks like the last:

const object = {
  x: 1
  y: 2
  z: 3
}

The rule here: for multiline arguments list, object or array declaration if line is a complete statement and next line is not an operator than consider it as complete argument (field, element) declaration.

Not an operator so you could use

const condition = true
const objext = {
  x: condition
    ? 0
    : 1
  y: 2
  z: 3
}

It is really like ASI but without bugs with "[", "(" and "/" - they should be consider as a start of a new declaration

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Claude Pache
There are [no LineTerminator here] rules in the ES grammar, in order to prevent the most pernicious trap when using ASI:

```
return // implicit semicolon here
a = b
```

Those [no LineTerminator here] rules have not been included in constructs that don’t need them. As a result:

```
const object = {
    get // no implicit comma here
    y: 2
   
    z: x // no implicit comma here
    in: "foo"
}
```

So, no, it’s not a good idea.

—Claude

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Алексей
Sorry, but I don't see any problems with example you provide:

const object = {
  get // not a complete declaration statement - so no implicit comma here
  y: 2 // continuation of a previous line

  z: x // complete declaration statement and next line is not an operator - implicit comma here
  in: "foo"
}

2017-09-12 18:53 GMT+03:00 Claude Pache <[hidden email]>:
There are [no LineTerminator here] rules in the ES grammar, in order to prevent the most pernicious trap when using ASI:

```
return // implicit semicolon here
a = b
```

Those [no LineTerminator here] rules have not been included in constructs that don’t need them. As a result:

```
const object = {
    get // no implicit comma here
    y: 2

    z: x // no implicit comma here
    in: "foo"
}
```

So, no, it’s not a good idea.

—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Dante Federici
In reply to this post by Алексей
What benefit does this give the language?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Алексей
Will reduce the noise created around the real essence of a program

2017-09-12 19:27 GMT+03:00 dante federici <[hidden email]>:
What benefit does this give the language?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Naveen Chawla
In reply to this post by Dante Federici
Time saving:

1. Automatically handle accidentally omitted commas, if used
2. Saves having to add them in the first place

On Tue, 12 Sep 2017 at 21:57 dante federici <[hidden email]> wrote:
What benefit does this give the language?
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Jeremy Martin
In reply to this post by Алексей
  const object = {
    get // not a complete declaration statement - so no implicit comma here
    y: 2 // continuation of a previous line
  }

The `get` declaration actually is a valid declaration (see shorthand property names here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).


On Tue, Sep 12, 2017 at 12:00 PM, Алексей <[hidden email]> wrote:
Sorry, but I don't see any problems with example you provide:

const object = {
  get // not a complete declaration statement - so no implicit comma here
  y: 2 // continuation of a previous line

  z: x // complete declaration statement and next line is not an operator - implicit comma here
  in: "foo"
}

2017-09-12 18:53 GMT+03:00 Claude Pache <[hidden email]>:
There are [no LineTerminator here] rules in the ES grammar, in order to prevent the most pernicious trap when using ASI:

```
return // implicit semicolon here
a = b
```

Those [no LineTerminator here] rules have not been included in constructs that don’t need them. As a result:

```
const object = {
    get // no implicit comma here
    y: 2

    z: x // no implicit comma here
    in: "foo"
}
```

So, no, it’s not a good idea.

—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Jeremy Martin
661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Claude Pache
In reply to this post by Алексей

> Le 12 sept. 2017 à 18:00, Алексей <[hidden email]> a écrit :
>
> Sorry, but I don't see any problems with example you provide:
>
> const object = {
>   get // not a complete declaration statement - so no implicit comma here
>   y: 2 // continuation of a previous line
>
>   z: x // complete declaration statement and next line is not an operator - implicit comma here
>   in: "foo"
> }


This is not how ASI works. A implicit semicolon is not added when a declaration would be complete, but when the next token would produce a syntax error. —Claude

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Алексей
In reply to this post by Jeremy Martin
Yes, I have correct my self about it in a next letter. The point is that it doesn't change the rule

2017-09-12 19:32 GMT+03:00 Jeremy Martin <[hidden email]>:
  const object = {
    get // not a complete declaration statement - so no implicit comma here
    y: 2 // continuation of a previous line
  }

The `get` declaration actually is a valid declaration (see shorthand property names here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).


On Tue, Sep 12, 2017 at 12:00 PM, Алексей <[hidden email]> wrote:
Sorry, but I don't see any problems with example you provide:

const object = {
  get // not a complete declaration statement - so no implicit comma here
  y: 2 // continuation of a previous line

  z: x // complete declaration statement and next line is not an operator - implicit comma here
  in: "foo"
}

2017-09-12 18:53 GMT+03:00 Claude Pache <[hidden email]>:
There are [no LineTerminator here] rules in the ES grammar, in order to prevent the most pernicious trap when using ASI:

```
return // implicit semicolon here
a = b
```

Those [no LineTerminator here] rules have not been included in constructs that don’t need them. As a result:

```
const object = {
    get // no implicit comma here
    y: 2

    z: x // no implicit comma here
    in: "foo"
}
```

So, no, it’s not a good idea.

—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Jeremy Martin
<a href="tel:(661)%20312-3853" value="+16613123853" target="_blank">661.312.3853


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Naveen Chawla
I don't think ASI matters in relation to this proposal

On Tue, 12 Sep 2017 at 22:05 Алексей <[hidden email]> wrote:
Yes, I have correct my self about it in a next letter. The point is that it doesn't change the rule

2017-09-12 19:32 GMT+03:00 Jeremy Martin <[hidden email]>:
  const object = {
    get // not a complete declaration statement - so no implicit comma here
    y: 2 // continuation of a previous line
  }

The `get` declaration actually is a valid declaration (see shorthand property names here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).


On Tue, Sep 12, 2017 at 12:00 PM, Алексей <[hidden email]> wrote:
Sorry, but I don't see any problems with example you provide:

const object = {
  get // not a complete declaration statement - so no implicit comma here
  y: 2 // continuation of a previous line

  z: x // complete declaration statement and next line is not an operator - implicit comma here
  in: "foo"
}

2017-09-12 18:53 GMT+03:00 Claude Pache <[hidden email]>:
There are [no LineTerminator here] rules in the ES grammar, in order to prevent the most pernicious trap when using ASI:

```
return // implicit semicolon here
a = b
```

Those [no LineTerminator here] rules have not been included in constructs that don’t need them. As a result:

```
const object = {
    get // no implicit comma here
    y: 2

    z: x // no implicit comma here
    in: "foo"
}
```

So, no, it’s not a good idea.

—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Jeremy Martin
<a href="tel:(661)%20312-3853" value="+16613123853" target="_blank">661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Алексей
Yes you are right it is not related to ASI in the implementation details. Only in form of usage

2017-09-12 19:40 GMT+03:00 Naveen Chawla <[hidden email]>:
I don't think ASI matters in relation to this proposal

On Tue, 12 Sep 2017 at 22:05 Алексей <[hidden email]> wrote:
Yes, I have correct my self about it in a next letter. The point is that it doesn't change the rule

2017-09-12 19:32 GMT+03:00 Jeremy Martin <[hidden email]>:
  const object = {
    get // not a complete declaration statement - so no implicit comma here
    y: 2 // continuation of a previous line
  }

The `get` declaration actually is a valid declaration (see shorthand property names here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015).


On Tue, Sep 12, 2017 at 12:00 PM, Алексей <[hidden email]> wrote:
Sorry, but I don't see any problems with example you provide:

const object = {
  get // not a complete declaration statement - so no implicit comma here
  y: 2 // continuation of a previous line

  z: x // complete declaration statement and next line is not an operator - implicit comma here
  in: "foo"
}

2017-09-12 18:53 GMT+03:00 Claude Pache <[hidden email]>:
There are [no LineTerminator here] rules in the ES grammar, in order to prevent the most pernicious trap when using ASI:

```
return // implicit semicolon here
a = b
```

Those [no LineTerminator here] rules have not been included in constructs that don’t need them. As a result:

```
const object = {
    get // no implicit comma here
    y: 2

    z: x // no implicit comma here
    in: "foo"
}
```

So, no, it’s not a good idea.

—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




--
Jeremy Martin
<a href="tel:(661)%20312-3853" value="+16613123853" target="_blank">661.312.3853

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Dante Federici
In reply to this post by Алексей
I think the only place I see as a current inconsistency is with class definitions vs object definitions. It probably should have been looped into the object shorthand definition:

```js
class MyClass {
  prop = 123
  constructor() {}
  method() {}
}
```
vs
```js
const myObj = {
  prop: 123,
  constructor(){},
  method(){},
};
```

Also, to wit on the class-fields proposal and this issue: https://github.com/tc39/proposal-class-fields/issues/7

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Jordan Harband
Punctuation isn't noise.

On Tue, Sep 12, 2017 at 9:51 AM, dante federici <[hidden email]> wrote:
I think the only place I see as a current inconsistency is with class definitions vs object definitions. It probably should have been looped into the object shorthand definition:

```js
class MyClass {
  prop = 123
  constructor() {}
  method() {}
}
```
vs
```js
const myObj = {
  prop: 123,
  constructor(){},
  method(){},
};
```

Also, to wit on the class-fields proposal and this issue: https://github.com/tc39/proposal-class-fields/issues/7

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Алексей
Don't you think that line break is a strong punctuation by itself?

2017-09-12 19:54 GMT+03:00 Jordan Harband <[hidden email]>:
Punctuation isn't noise.

On Tue, Sep 12, 2017 at 9:51 AM, dante federici <[hidden email]> wrote:
I think the only place I see as a current inconsistency is with class definitions vs object definitions. It probably should have been looped into the object shorthand definition:

```js
class MyClass {
  prop = 123
  constructor() {}
  method() {}
}
```
vs
```js
const myObj = {
  prop: 123,
  constructor(){},
  method(){},
};
```

Also, to wit on the class-fields proposal and this issue: https://github.com/tc39/proposal-class-fields/issues/7

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Re: Make comma at the end of line optional

Jordan Harband
Of course not:
```js
var arr = [
  1, 2, 3
  4
];
```

If JS was the kind of language where a line break definitively ended a statement, that'd be a different story - but it's not.

On Tue, Sep 12, 2017 at 9:57 AM, Алексей <[hidden email]> wrote:
Don't you think that line break is a strong punctuation by itself?

2017-09-12 19:54 GMT+03:00 Jordan Harband <[hidden email]>:
Punctuation isn't noise.

On Tue, Sep 12, 2017 at 9:51 AM, dante federici <[hidden email]> wrote:
I think the only place I see as a current inconsistency is with class definitions vs object definitions. It probably should have been looped into the object shorthand definition:

```js
class MyClass {
  prop = 123
  constructor() {}
  method() {}
}
```
vs
```js
const myObj = {
  prop: 123,
  constructor(){},
  method(){},
};
```

Also, to wit on the class-fields proposal and this issue: https://github.com/tc39/proposal-class-fields/issues/7

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

kdex
In reply to this post by Алексей
I'm not sure how your text editor is set up, but you may or may not be able to
tell soft-wrapping apart from an actual EOL character if you have long lines.

I don't like the idea of making whitespace of any kind significant, which is
why I would agree with Jordan.

On Tuesday, September 12, 2017 6:57:10 PM CEST Алексей wrote:

> Don't you think that line break is a strong punctuation by itself?
>
> 2017-09-12 19:54 GMT+03:00 Jordan Harband <[hidden email]>:
> > Punctuation isn't noise.
> >
> > On Tue, Sep 12, 2017 at 9:51 AM, dante federici <
> >
> > [hidden email]> wrote:
> >> I think the only place I see as a current inconsistency is with class
> >> definitions vs object definitions. It probably should have been looped
> >> into
> >> the object shorthand definition:
> >>
> >> https://github.com/tc39/proposal-class-fields
> >> ```js
> >> class MyClass {
> >>
> >>   prop = 123
> >>   constructor() {}
> >>   method() {}
> >>
> >> }
> >> ```
> >> vs
> >> ```js
> >> const myObj = {
> >>
> >>   prop: 123,
> >>   constructor(){},
> >>   method(){},
> >>
> >> };
> >> ```
> >>
> >> Also, to wit on the class-fields proposal and this issue:
> >> https://github.com/tc39/proposal-class-fields/issues/7
> >>
> >> _______________________________________________
> >> es-discuss mailing list
> >> [hidden email]
> >> https://mail.mozilla.org/listinfo/es-discuss
> >
> > _______________________________________________
> > es-discuss mailing list
> > [hidden email]
> > https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Claude Pache
In reply to this post by Алексей

> Le 12 sept. 2017 à 18:57, Алексей <[hidden email]> a écrit :
>
> Don't you think that line break is a strong punctuation by itself?

It could have been. Unfortunately, in JS, it is not.

Automatic semi-colon insertion (ASI) could be seen as an attempt to have their cake and eat it too. Or, as a compromise between the two options by making *some* line breaks significant (e.g., the one after `return`).

But in general, line breaks are not significant enough to allow to introduce ASI-like rules after the fact, that would work reliably enough.

BTW, the title of the thread, “Make comma at the end of line optional”, reveals a probable misunderstanding of the feature. In JS, semicolons are not “optional”, they are “automatically inserted”. That makes a difference when parsing:

```js
a = b
+c
```


—Claude

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Jordan Harband
I prefer to describe semicolons as *so* required that the engine inserts them for you if you forget ;-)

On Tue, Sep 12, 2017 at 10:32 AM, Claude Pache <[hidden email]> wrote:

> Le 12 sept. 2017 à 18:57, Алексей <[hidden email]> a écrit :
>
> Don't you think that line break is a strong punctuation by itself?

It could have been. Unfortunately, in JS, it is not.

Automatic semi-colon insertion (ASI) could be seen as an attempt to have their cake and eat it too. Or, as a compromise between the two options by making *some* line breaks significant (e.g., the one after `return`).

But in general, line breaks are not significant enough to allow to introduce ASI-like rules after the fact, that would work reliably enough.

BTW, the title of the thread, “Make comma at the end of line optional”, reveals a probable misunderstanding of the feature. In JS, semicolons are not “optional”, they are “automatically inserted”. That makes a difference when parsing:

```js
a = b
+c
```


—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Make comma at the end of line optional

Алексей
In reply to this post by Claude Pache
The reason why we have a discussions about whether to rely on ASI or insert them manually is because ASI has problems (return is one of them). And they can't be fixed because fixes are not backward compatible. Based on this experience it would be possible to determine the rules that would not have that gaps or their kind.

2017-09-12 20:32 GMT+03:00 Claude Pache <[hidden email]>:

> Le 12 sept. 2017 à 18:57, Алексей <[hidden email]> a écrit :
>
> Don't you think that line break is a strong punctuation by itself?

It could have been. Unfortunately, in JS, it is not.

Automatic semi-colon insertion (ASI) could be seen as an attempt to have their cake and eat it too. Or, as a compromise between the two options by making *some* line breaks significant (e.g., the one after `return`).

But in general, line breaks are not significant enough to allow to introduce ASI-like rules after the fact, that would work reliably enough.

BTW, the title of the thread, “Make comma at the end of line optional”, reveals a probable misunderstanding of the feature. In JS, semicolons are not “optional”, they are “automatically inserted”. That makes a difference when parsing:

```js
a = b
+c
```


—Claude



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
123