Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-23 Thread guest271314
FWIW a start to ```nameofall``` using ```RegExp``` https://gist.github.com/guest271314/daa1c6455ec8a2b6b89aff245e95c615 ```const nameofall = /((const|let)\s+)\w+(?=\s+(=|in|of))|class\s+\w+(?=\s)/gi;``` TODO: handle destructuring assignment, default values, shorthand assignments, e.g., ```

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-19 Thread guest271314
se a > `cwd` option to gulp has a special meaning. Since the editor doesn’t know > the intent of the user may be to rename *both* symbols, it remains > conservative and choses only to rename the binding and its references, > producing: > >> > >> > >> > >&

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-19 Thread Frederick Stark
; >> > > >> const cwd /*1*/ = "."; > > >> > > >> gulp.src("*.js", { cwd /*2*/ }); > > >> > > >> ``` > > >> > > >> > > >> > > >> If you were to rename `cwd` at (1) and

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-19 Thread guest271314
nces, > producing: > >> > >> > >> > >> ``` > >> > >> const currentDir = "."; > >> > >> gulp.src("*.js", { cwd: currentDir }); > >> > >> ``` > >> > >> > >> &

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-19 Thread Isiah Meadows
roducing: >> >> >> >> ``` >> >> const currentDir = "."; >> >> gulp.src("*.js", { cwd: currentDir }); >> >> ``` >> >> >> >> There is also the issue of collisions: >> >> >> >

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-19 Thread Isiah Meadows
>> >> No, an error is not thrown. ECMAScript is much more nuanced. Block scoped >> >> variables from 'let' or 'const' exist and can be *referenced* (via >> >> closure or export, currently) anywhere within the same block scope, even >> >> before

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-17 Thread guest271314
perty at (2) as well as it would > introduce a semantic error that would prevent the entire script from > executing. > > > > In the context of Jordan’s email, that means that `Object.keys({ y })[0]` > would **not** necessarily survive refactoring tools. > > > > *From:* es-

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-17 Thread Ron Buckton
Stark Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for again, `Object.keys({ y })[0]` will give you the string `y`, and will survive refactoring tools. you can even do `function nameof(obj) { return Object.keys(obj)[0]; }` and then `name

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-17 Thread Ron Buckton
e a semantic error that would prevent the entire script from executing. In the context of Jordan’s email, that means that `Object.keys({ y })[0]` would *not* necessarily survive refactoring tools. From: es-discuss On Behalf Of guest271314 Sent: Monday, June 17, 2019 7:40 AM Cc: es-discuss@mozilla.or

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-17 Thread guest271314
> In VSCode, if you rename ‘foo’ to ‘bar’ at /*1*/, you get this: How is VSCode related to JavaScript? Is the proposal really based on creating ```nameof``` in JavaScript to workaround output at a text editor? Why not file a bug with the individuals who write the code for VSCode or just write a

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread Ron Buckton
derick Stark Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for again, `Object.keys({ y })[0]` will give you the string `y`, and will survive refactoring tools. you can even do `function nameof(obj) { return Object.keys(obj)[0]; }` and then `name

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread Jordan Harband
_not_ be thrown simple because > ```nameof``` is used? > >> > >> No, an error is not thrown. ECMAScript is much more nuanced. Block > scoped variables from 'let' or 'const' exist and can be *referenced* (via > closure or export, currently) anywhere within the same block scope

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread Frederick Stark
gt;> > > > > >> The immediately invoked arrow function example (where a > > > > >> ```RefeferenceError``` is thrown) appears to demonstrate that to > > > > >> output the expected result of ```nameof``` within the context of the > > >

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread guest271314
*value* of `y` until you > execute the function. > >> > >> From: guest271314 > >> Sent: Saturday, June 15, 2019 3:57 PM > >> To: Ron Buckton > >> Cc: es-discuss@mozilla.org > >> Subject: Re: Re: What do you think about a C# 6 like name

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread guest271314
a > closure or export, currently) anywhere within the same block scope, even > before they are initialized. Until they have been *initialized* (the line > of code contain the declaration has been reached and evaluated), they exist > in a "Temporal Dead Zone" (TDZ). Atte

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread Frederick Stark
gt; > >> ```nameof``` is used? > > >> > > >> On Sat, Jun 15, 2019 at 11:16 PM Ron Buckton > >> (mailto:ron.buck...@microsoft.com)> wrote: > > >> > > >> ``` > > >> const x = nameof y > > >> const y = 1; > > >

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread guest271314
ized. Until they have been *initialized* (the line > of code contain the declaration has been reached and evaluated), they exist > in a "Temporal Dead Zone" (TDZ). Attempting to *dereference* them (i.e. > access or store a value) while in this TDZ is what results in the > Re

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread Isiah Meadows
hem (i.e. access or >> store a value) while in this TDZ is what results in the ReferenceError. >> >> At no point does the `nameof` operator *dereference* the variable, so no >> error need be thrown. >> >> From: guest271314 >> Sent: Saturday, June 15, 4:29

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread Isiah Meadows
I've got a few code bases where I do a lot of stuff like `func(person, "person")`, and it'd be pretty useful to avoid the duplication. I'd prefer something more direct like `nameof binding`, `nameof binding.key`, and `nameof binding[key]`, where it returns the expression at that parameter

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread Ron Buckton
while in this TDZ is what results in the ReferenceError. At no point does the `nameof` operator *dereference* the variable, so no error need be thrown. From: guest271314 Sent: Saturday, June 15, 4:29 PM Subject: Re: Re: What do you think about a C# 6 like nameof() expression for To: Ron Buckton Cc: es-discus

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread guest271314
the **value** of `y` > until you execute the function. > > > > *From:* guest271314 > *Sent:* Saturday, June 15, 2019 3:57 PM > *To:* Ron Buckton > *Cc:* es-discuss@mozilla.org > *Subject:* Re: Re: What do you think about a C# 6 like nameof() > expression for > >

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread guest271314
June 15, 2019 3:03 PM > *To:* guest271314 > *Cc:* es-discuss@mozilla.org > *Subject:* RE: Re: What do you think about a C# 6 like nameof() > expression for > > > > > At that point in the example code the identifer ```y``` does not exist. > > > > That is not entirely incorrec

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread guest271314
be as much of a game changer to > the language as async/await or yield were, but it would be a fairly easily > spec’d and nice-to-have capability. > > > > *From:* guest271314 > *Sent:* Saturday, June 15, 2019 2:50 PM > *To:* Ron Buckton > *Cc:* es-discuss@mozilla.org

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread Ron Buckton
ec’d and nice-to-have capability. From: guest271314 Sent: Saturday, June 15, 2019 2:50 PM To: Ron Buckton Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for > It doesn’t matter what the value of ‘y’ is, just what the lexical name of `y` > is. `

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread guest271314
`y` as an expression, its just > pointing to the identifier. > > > > *From:* guest271314 > *Sent:* Friday, June 14, 2019 10:03 PM > *To:* Ron Buckton > *Cc:* es-discuss@mozilla.org > *Subject:* Re: Re: What do you think about a C# 6 like nameof() > expression for

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-15 Thread Ron Buckton
rantee that by the string `'foo'` you meant “the text of the identifier `foo`”. From: es-discuss mailto:es-discuss-boun...@mozilla.org>> On Behalf Of Jordan Harband Sent: Friday, June 14, 2019 2:29 PM To: guest271314 mailto:guest271...@gmail.com>> Cc: es-discuss mailto:es-discuss@m

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
} > > ``` > > > > If you rename the parameter `value` of the function `setValue` in an > editor with a rename refactoring, you want to rename the symbols at 1, 2, > 3, and 5, but not the string at 4. > > > > Ron > > > > *From:* guest271314 > *Se

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
kton Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for How is that behaviour related to the use cases presented by OP? Would such behaviour not lead to false-positive relevant to the 2 use cases? On Fri, Jun 14, 2019 at 9:36 PM Ron Buck

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Augusto Moura
Fri, 14 jun 2019 - 18:29, Jordan Harband wrote: > > `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused > why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you > change `foo` to `bar`, you have to change both of them anyways. > Exactly, if you

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
n > Harband > *Sent:* Friday, June 14, 2019 2:29 PM > *To:* guest271314 > *Cc:* es-discuss > *Subject:* Re: Re: What do you think about a C# 6 like nameof() > expression for > > > > `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused > why it'

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
From: es-discuss On Behalf Of Jordan Harband Sent: Friday, June 14, 2019 2:29 PM To: guest271314 Cc: es-discuss Subject: Re: Re: What do you think about a C# 6 like nameof() expression for `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `n

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Jordan Harband
`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways. On Fri, Jun 14, 2019 at 1:31 PM guest271314 wrote: > Am neither for nor

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
uss On Behalf Of guest271314 Sent: Friday, June 14, 2019 12:09 PM To: Stas Berkov Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for > A module namespace isn’t an instance of Module, it’s a module namespace spec > object. If it has a na

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s in any field of endeavor. Am certainly not in a position to prohibit anything relevant JavaScript. Do what thou wilt shall be the whole of the Law. Have yet to view a case where code will be "broken" by ```nameof```

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
guest271314, what is you point against `nameof` feature? If you don't like it - don't use it. Why prohibit this feature for those who find it beneficial? I see `nameof` beneficial in following cases Case 1. Function guard. ``` function func1(options) { ... if (options.userName == undefined)

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
> A module namespace isn’t an instance of Module, it’s a module namespace spec object. If it has a name member, that is because the module you imported has an exported binding called name. But what kind of thing it is isn’t what matters. If ```Object.getOwnPropertyDescriptors(ns)``` is used

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
e overhead, because it would be handled during static semantics. From: es-discuss On Behalf Of guest271314 Sent: Friday, June 14, 2019 11:17 AM To: Stas Berkov Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for Terms such as "more robust&

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for Not following the module example. Would not ```ns``` be an instance of ```Module``` where ```* as ns``` is used? For the ```class``` example would ```nameof``` be equivalent

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Terms such as "more robust", "Less fragile." , "Less mess." are subjective. "Fragile" how? What is meant by "mess"? If the proposal is that ```nameof``` is briefer than using shorthand property names or computed property names to get an identifier as a string, then ```nameof``` would be less

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
> Is Case 1 equivalent to a briefer version of > ``` if (userName == undefined) { throw new Error(`Argument cannot be null: ${Object.keys({userName})[0]}`); } ``` Less readable but in this simple case might work. What if we do the following: Case 1. Function guard. ``` function

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
Less fragile. Less mess. You can rename field/property without fear you break something (using IDE refactoring tools). With high probablity you will break something when you refactor and have fields hardcoded as strings. Someone can object that you can rename strings as well. Issue here that you

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Is Case 1 equivalent to a briefer version of ``` if (userName == undefined) { throw new Error(`Argument cannot be null: ${Object.keys({userName})[0]}`); } ``` ? If not, how is ```nameof``` different? What is the difference between the use of ```message.hasOwnProperty(property)```

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
ES can befit from `nameof` feature the same way as TS. There is no TS specific in it. It was ask to introduce in TS as a workaround since TS is considered as extention of ES. Case 1. Function guard. ``` function func1(param1, param2, param3, userName, param4, param5) { if (userName ==

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
aScript language > service would benefit from it. > > Ron > ------------------ > *From:* es-discuss on behalf of > guest271314 > *Sent:* Friday, June 14, 2019 9:05:55 AM > *To:* Stas Berkov > *Cc:* es-discuss@mozilla.org > *Subject:* Re: Re: What do

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
From: es-discuss on behalf of guest271314 Sent: Friday, June 14, 2019 9:05:55 AM To: Stas Berkov Cc: es-discuss@mozilla.org Subject: Re: Re: What do you think about a C# 6 like nameof() expression for Have not tried TypeScript. What are the use cases for JavaScr

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Have not tried TypeScript. What are the use cases for JavaScript where TypeScript is not used? Does ```nameof()``` check if an object has a specific property name defined (```"MutationObserver" in window```; ```window.MutationObserver```; ```"document" in globalThis```)? On Fri, Jun 14, 2019 at

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Augusto Moura
Can you list the benefits of having this operators? Maybe with example use cases If I understand it correctly, the operator fits better in compiled (and typed) languages, most of the use cases don't apply to dynamic Javascript The only legit use case I can think of is helping refactor tools to

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
Can we revisit this issue? In C# there is `nameof`, in Swift you can do the same by calling ``` let keyPath = \Person.mother.firstName NSPredicate(format: "%K == %@", keyPath, "Andrew") ``` Let's introduce `nameof` in ES, please. Devs from TypeScript don't want to introduce this feature

Re: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-09-10 Thread Behrang Saeedzadeh
It depends I guess. Should be a configuration option. On Thu, Sep 10, 2015 at 10:37 AM Waldemar Horwat wrote: > This would have interesting consequences if you run your code via a > minifier. Should the minifier return a string with the old name or the new > name? > >

Re: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-09-09 Thread Waldemar Horwat
This would have interesting consequences if you run your code via a minifier. Should the minifier return a string with the old name or the new name? Waldemar ___ es-discuss mailing list es-discuss@mozilla.org

RE: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-08-09 Thread Ron Buckton
Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed

Re: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-08-08 Thread Behrang Saeedzadeh
Forgot to mention that nameof works with local variables too: function foo() { var aNum = 1; console.log(nameof(aNmum), aNum); } On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh behran...@gmail.com wrote: So basically we could use it like this: function aFunc(aParam) { throw new

Re: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-08-08 Thread Isiah Meadows
Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this? ```js function foo(x) { return nameof(x); } foo(bar); // bar; ``` In that case, the engine would have to keep track of usages as well, in a similar sense

RE: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-08-08 Thread Ron Buckton
. Ron From: Isiah Meadowsmailto:isiahmead...@gmail.com Sent: ‎8/‎8/‎2015 7:23 PM To: Behrang Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression

Re: What do you think about a C# 6 like nameof() expression for JavaScript.

2015-08-08 Thread Isiah Meadows
: Re: What do you think about a C# 6 like nameof() expression for JavaScript. Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this? ```js function foo(x) { return nameof(x); } foo(bar); // bar