Re: Destructuring object outside of var declaration

2016-12-14 Thread Jeff Walden
On 11/13/2016 12:33 PM, Isiah Meadows wrote:
> Okay. Is it a spec bug then? Throwing a ReferenceError is surprising and odd 
> IMHO.

I think so -- having different sorts of early errors makes it a little less 
clear what sort of error should be thrown when two early errors of different 
types are in the same script.  Last I knew, the spec was basically just waiting 
on someone to experiment with pulling the trigger to make everything a 
SyntaxError.  I've been meaning to do that for awhile, but it's not a high 
priority.

Jeff
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-15 Thread Boris Zbarsky

On 11/15/16 1:57 PM, Claude Pache wrote:

My guess is that Thaddee Tyl was confused by a Chrome DevTools feature, as in:


I considered that, but I actually got consistent results both in 
Chrome's console and in a webpage...


-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-15 Thread Claude Pache


> Le 14 nov. 2016 à 22:53, Boris Zbarsky  a écrit :
> 
>> On 11/13/16 1:28 PM, Thaddee Tyl wrote:
>>var foo, bar;
>>{foo, bar} = {foo: 2, bar: 3};
>> 
>> is a "SyntaxError: expected expression, got '='" in Firefox, and *it
>> works in Google Chrome*.
> 
> I get "Uncaught SyntaxError: Unexpected token =" in Chrome "56.0.2914.3 dev" 
> and in Chrome "54.0.2840.9" (release).
> 
> -Boris

My guess is that Thaddee Tyl was confused by a Chrome DevTools feature, as in:

https://esdiscuss.org/topic/incosistency#content-6

—Claude
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-14 Thread Boris Zbarsky

On 11/13/16 1:28 PM, Thaddee Tyl wrote:

var foo, bar;
{foo, bar} = {foo: 2, bar: 3};

is a "SyntaxError: expected expression, got '='" in Firefox, and *it
works in Google Chrome*.


I get "Uncaught SyntaxError: Unexpected token =" in Chrome "56.0.2914.3 
dev" and in Chrome "54.0.2840.9" (release).


-Boris
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-13 Thread Isiah Meadows
Okay. Is it a spec bug then? Throwing a ReferenceError is surprising and
odd IMHO.

On Sun, Nov 13, 2016, 14:45 Allen Wirfs-Brock  wrote:

> On Nov 13, 2016, at 10:49 AM, Isiah Meadows 
> wrote:
>
> Firefox likely has a parser bug (it should never throw a ReferenceError in
> that situation).
>
> FireFox is correct, Chrome is wrong. See the second early error rule at
> http://www.ecma-international.org/ecma-262/7.0/index.html#sec-assignment-operators-static-semantics-early-errors
>
>
>
>
>- It is an early Reference
>
> 
>  Error
>if LeftHandSideExpression
>
> 
>  is
>neither an ObjectLiteral
>
> 
>  nor
>an ArrayLiteral
>
>  
> and
>IsValidSimpleAssignmentTarget of LeftHandSideExpression
>
> 
> is false.
>
>
>
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-13 Thread Allen Wirfs-Brock

> On Nov 13, 2016, at 10:49 AM, Isiah Meadows  wrote:
> 
> Firefox likely has a parser bug (it should never throw a ReferenceError in 
> that situation).
> 
> 
FireFox is correct, Chrome is wrong. See the second early error rule at 
http://www.ecma-international.org/ecma-262/7.0/index.html#sec-assignment-operators-static-semantics-early-errors
 

 


It is an early Reference 

 Error if LeftHandSideExpression 

 is neither an ObjectLiteral 
 
nor an ArrayLiteral 
 
and IsValidSimpleAssignmentTarget of LeftHandSideExpression 

 is false.



___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-13 Thread Bob Myers
I thought it was

```
({x, y} = obj);
```

On Sun, Nov 13, 2016 at 11:58 PM, Thaddee Tyl <thaddee@gmail.com> wrote:

> On Tue, Sep 17, 2013 at 4:27 PM, Brendan Eich <bren...@mozilla.com> wrote:
> >> Nathan Wall <mailto:nathan.w...@live.com>
> >> September 17, 2013 10:06 AM
> >> I'm wondering what the best syntax is for object destructuring outside
> of
> >> a var declaration.  For instance, the following works in Firefox
> Nightly and
> >> Traceur:
> >>
> >> […]
> >>
> >> var a, b;
> >> ({ a, b }) = foo;
> >>
> >> Is the above what people are expected to use (when they need to use
> >> destructuring outside of a var/let declaration or function arguments),
> or is
> >> there another form available?
> >
> > That's it. Lars Hansen originated destructuring for ES4 and implemented
> > array patterns in Futhark (Opera's engine of the time), but not object
> > patterns. His first proposal used
> >
> > &{a: x, b: y} = foo
> >
> > for just the reason you cite, but no one was keen on the ASI hazard
> > (previous line must end with a semicolon). We cut the & pretty soon in
> ES4's
> > evolution.
> >
> > I say use var/let/const, it's better style; or else suffer a parentheses
> > tax. This is pretty much a non-issue in practice, AFAICT.
>
> Have things evolved?
>
> var foo, bar;
> ({foo, bar}) = {foo: 2, bar: 3};
>
> is a "ReferenceError: invalid assignment left-hand side" in Firefox
> Nightly 51.0a2, and a "SyntaxError: Unexpected token (" in Google
> Chrome  54.0.2840.90.
>
> var foo, bar;
> {foo, bar} = {foo: 2, bar: 3};
>
> is a "SyntaxError: expected expression, got '='" in Firefox, and *it
> works in Google Chrome*.
>
> var extract = () => ({foo:1, bar:2});
> var foo, bar;
> {foo, bar} = extract();  // SyntaxError: expected expression, got
> '=' in Firefox and Chrome
> ({foo, bar}) = extract();  // ReferenceError: invalid assignment
> left-hand side in Firefox, SyntaxError: Unexpected token ( in Chrome
>
> I tried figuring out what the correct behaviour is from
> http://www.ecma-international.org/ecma-262/7.0/index.html#
> sec-destructuring-assignment,
> but the rabbit hole goes deep, so I have no idea who to file a bug
> with.
>
> (Obviously, the "right" way to do it, `({foo, bar} = extract())`,
> works in both Firefox and Chrome. They, hum, could use some better
> error messages, too, to guide users towards that.)
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-13 Thread Isiah Meadows
Firefox likely has a parser bug (it should never throw a ReferenceError in
that situation).

As for the assignment, I wish that `{foo, bar} = extract()` was accepted as
a statement in more places.

On Sun, Nov 13, 2016, 13:28 Thaddee Tyl <thaddee@gmail.com> wrote:

> On Tue, Sep 17, 2013 at 4:27 PM, Brendan Eich <bren...@mozilla.com> wrote:
> >> Nathan Wall <mailto:nathan.w...@live.com>
> >> September 17, 2013 10:06 AM
> >> I'm wondering what the best syntax is for object destructuring outside
> of
> >> a var declaration.  For instance, the following works in Firefox
> Nightly and
> >> Traceur:
> >>
> >> […]
> >>
> >> var a, b;
> >> ({ a, b }) = foo;
> >>
> >> Is the above what people are expected to use (when they need to use
> >> destructuring outside of a var/let declaration or function arguments),
> or is
> >> there another form available?
> >
> > That's it. Lars Hansen originated destructuring for ES4 and implemented
> > array patterns in Futhark (Opera's engine of the time), but not object
> > patterns. His first proposal used
> >
> > &{a: x, b: y} = foo
> >
> > for just the reason you cite, but no one was keen on the ASI hazard
> > (previous line must end with a semicolon). We cut the & pretty soon in
> ES4's
> > evolution.
> >
> > I say use var/let/const, it's better style; or else suffer a parentheses
> > tax. This is pretty much a non-issue in practice, AFAICT.
>
> Have things evolved?
>
> var foo, bar;
> ({foo, bar}) = {foo: 2, bar: 3};
>
> is a "ReferenceError: invalid assignment left-hand side" in Firefox
> Nightly 51.0a2, and a "SyntaxError: Unexpected token (" in Google
> Chrome  54.0.2840.90.
>
> var foo, bar;
> {foo, bar} = {foo: 2, bar: 3};
>
> is a "SyntaxError: expected expression, got '='" in Firefox, and *it
> works in Google Chrome*.
>
> var extract = () => ({foo:1, bar:2});
> var foo, bar;
> {foo, bar} = extract();  // SyntaxError: expected expression, got
> '=' in Firefox and Chrome
> ({foo, bar}) = extract();  // ReferenceError: invalid assignment
> left-hand side in Firefox, SyntaxError: Unexpected token ( in Chrome
>
> I tried figuring out what the correct behaviour is from
>
> http://www.ecma-international.org/ecma-262/7.0/index.html#sec-destructuring-assignment
> ,
> but the rabbit hole goes deep, so I have no idea who to file a bug
> with.
>
> (Obviously, the "right" way to do it, `({foo, bar} = extract())`,
> works in both Firefox and Chrome. They, hum, could use some better
> error messages, too, to guide users towards that.)
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2016-11-13 Thread Thaddee Tyl
On Tue, Sep 17, 2013 at 4:27 PM, Brendan Eich <bren...@mozilla.com> wrote:
>> Nathan Wall <mailto:nathan.w...@live.com>
>> September 17, 2013 10:06 AM
>> I'm wondering what the best syntax is for object destructuring outside of
>> a var declaration.  For instance, the following works in Firefox Nightly and
>> Traceur:
>>
>> […]
>>
>> var a, b;
>> ({ a, b }) = foo;
>>
>> Is the above what people are expected to use (when they need to use
>> destructuring outside of a var/let declaration or function arguments), or is
>> there another form available?
>
> That's it. Lars Hansen originated destructuring for ES4 and implemented
> array patterns in Futhark (Opera's engine of the time), but not object
> patterns. His first proposal used
>
> &{a: x, b: y} = foo
>
> for just the reason you cite, but no one was keen on the ASI hazard
> (previous line must end with a semicolon). We cut the & pretty soon in ES4's
> evolution.
>
> I say use var/let/const, it's better style; or else suffer a parentheses
> tax. This is pretty much a non-issue in practice, AFAICT.

Have things evolved?

var foo, bar;
({foo, bar}) = {foo: 2, bar: 3};

is a "ReferenceError: invalid assignment left-hand side" in Firefox
Nightly 51.0a2, and a "SyntaxError: Unexpected token (" in Google
Chrome  54.0.2840.90.

var foo, bar;
{foo, bar} = {foo: 2, bar: 3};

is a "SyntaxError: expected expression, got '='" in Firefox, and *it
works in Google Chrome*.

var extract = () => ({foo:1, bar:2});
var foo, bar;
{foo, bar} = extract();  // SyntaxError: expected expression, got
'=' in Firefox and Chrome
({foo, bar}) = extract();  // ReferenceError: invalid assignment
left-hand side in Firefox, SyntaxError: Unexpected token ( in Chrome

I tried figuring out what the correct behaviour is from
http://www.ecma-international.org/ecma-262/7.0/index.html#sec-destructuring-assignment,
but the rabbit hole goes deep, so I have no idea who to file a bug
with.

(Obviously, the "right" way to do it, `({foo, bar} = extract())`,
works in both Firefox and Chrome. They, hum, could use some better
error messages, too, to guide users towards that.)
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Destructuring object outside of var declaration

2013-09-17 Thread Nathan Wall
I'm wondering what the best syntax is for object destructuring outside of a var 
declaration.  For instance, the following works in Firefox Nightly and Traceur:
var { a, b } = foo;
but the following doesn't:
var a, b;{ a, b } = foo;
I presume this is because in the second case the { a, b } is a block.
However, the following does work:
var a, b;({ a, b }) = foo;
Is the above what people are expected to use (when they need to use 
destructuring outside of a var/let declaration or function arguments), or is 
there another form available?
Thanks,Nathan ___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2013-09-17 Thread Brendan Eich

Nathan Wall mailto:nathan.w...@live.com
September 17, 2013 10:06 AM
I'm wondering what the best syntax is for object destructuring outside 
of a var declaration.  For instance, the following works in Firefox 
Nightly and Traceur:


var { a, b } = foo;

but the following doesn't:

var a, b;
{ a, b } = foo;

I presume this is because in the second case the { a, b } is a block.

However, the following does work:

var a, b;
({ a, b }) = foo;

Is the above what people are expected to use (when they need to use 
destructuring outside of a var/let declaration or function arguments), 
or is there another form available?


That's it. Lars Hansen originated destructuring for ES4 and implemented 
array patterns in Futhark (Opera's engine of the time), but not object 
patterns. His first proposal used


{a: x, b: y} = foo

for just the reason you cite, but no one was keen on the ASI hazard 
(previous line must end with a semicolon). We cut the  pretty soon in 
ES4's evolution.


I say use var/let/const, it's better style; or else suffer a parentheses 
tax. This is pretty much a non-issue in practice, AFAICT.


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2013-09-17 Thread Brendan Eich
Allen reminded me to mention that destructuring assignment, as opposed 
to binding, allows arbitrary LeftHandSideExpression in the patterns, as 
opposed to Identifiers. If someone wants to use that extravagence in an 
object pattern destructuring assignment, they can put parens around the 
whole thing.


/be


Brendan Eich mailto:bren...@mozilla.com
September 17, 2013 10:27 AM

That's it. Lars Hansen originated destructuring for ES4 and 
implemented array patterns in Futhark (Opera's engine of the time), 
but not object patterns. His first proposal used


{a: x, b: y} = foo

for just the reason you cite, but no one was keen on the ASI hazard 
(previous line must end with a semicolon). We cut the  pretty soon in 
ES4's evolution.


I say use var/let/const, it's better style; or else suffer a 
parentheses tax. This is pretty much a non-issue in practice, AFAICT.


/be
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Nathan Wall mailto:nathan.w...@live.com
September 17, 2013 10:06 AM
I'm wondering what the best syntax is for object destructuring outside 
of a var declaration.  For instance, the following works in Firefox 
Nightly and Traceur:


var { a, b } = foo;

but the following doesn't:

var a, b;
{ a, b } = foo;

I presume this is because in the second case the { a, b } is a block.

However, the following does work:

var a, b;
({ a, b }) = foo;

Is the above what people are expected to use (when they need to use 
destructuring outside of a var/let declaration or function arguments), 
or is there another form available?


Thanks,
Nathan
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Destructuring object outside of var declaration

2013-09-17 Thread Axel Rauschmayer
 I say use var/let/const, it's better style; or else suffer a parentheses tax. 
 This is pretty much a non-issue in practice, AFAICT.


I don’t think so, either. But error message could give appropriate hints, just 
in case (beyond the scope of TC39/ECMA-262, but still important, 
usability-wise).

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss