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 position as the "name", with a more convoluted fallback
algorithm to handle destructuring and local references sensibly. (It should
only consider parse-time data, and it should always strip whitespace and
unnecessary parentheses to keep it on a single line.) The required stack
space for this is just a single object pointer, and it's not like you can
do weird things with `eval` with it.

For security, there is the concern of unexpected passing of data through
parameters (think: `getSensitive("sensitive string")` as a parameter), but
this can be addressed on the minifier side via a directive and on the
language side by blocking all name sharing cross-realm (making them just
canonical strings derived from values instead).

On Fri, Jun 14, 2019 at 09:05 Stas Berkov  wrote:

> 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 in TypeScript
> unless it is available in ES (
> https://github.com/microsoft/TypeScript/issues/1579 )
>
> This feature is eagarly being asked by TypeScript community.
>
>
> I understand there are couple issues related to `nameof` feature in ES.
> They are: minification and what to do if user already has `nameof` function.
>
>
> Minification.
>
> 1. If your code to be minimized be prepared that variable names will also
> change.
>
> 2. (just a possibility) Minimizer can have option to replace
> `nameof(someVar)` with result of `nameof` function.
>
>
>
> What if user already has `nameof` function.
>
> 1. To maintain status quo we can user `nameof` function having priority
> over newly introduced language feature.
>
> 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns
> "userName" string)
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-- 
-

Isiah Meadows
cont...@isiahmeadows.com
www.isiahmeadows.com
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


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

2019-06-15 Thread Ron Buckton
> What should occur where the code is

It would be "y" in all 3 places.

> ... is a proposal for _more_ than only getting the _name_ of an _declared_ 
> and _initialized_ variable?

It is a proposal for getting the name of a _declared_ variable. Whether it is 
_initialized_ does not matter.

> Should a ```RefefenceError``` _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, 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). Attempting to *dereference* them (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 PM
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for
To: Ron Buckton
Cc: es-discuss@mozilla.org




What should occur where the code is

```
const x = nameof y
await new Promise(resolve => setTimeout(resolve, 10)); // should x be "y" 
here?
await new Promise(resolve => setTimeout(resolve, 20)); // should x be "y" 
here?
await Promise.all([new Promise(resolve => setTimeout(resolve, 30)), 
...doStuff()]); // should x be "y" here?
const y = 1;
```

?

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 code example

```
const x = nameof y
const y = 1;
```

is a proposal for _more_ than only getting the _name_ of an _declared_ and 
_initialized_ variable?

Should a ```RefefenceError``` _not_ be thrown simple because ```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;
```

`x` would have the value “y”. It would not matter if `y` were initialized or 
had yet been reached during execution. It does not deviate from the purpose of 
`let` or `const`, because you are not accessing the value of the identifier.

Also consider that this is legal ECMAScript in a module:

```
export { y }
const y = 1;
```

The binding for `y` exists within the same block scope, it just has not yet 
been initialized. Exporting it via `export { y }`, closing over it via `() => 
y`, or accessing it via `nameof y` would all be the same. In all three cases 
you are accessing the *binding* of `y`, not the *value* of `y`. Even in the `() 
=> y` case, you don’t access the *value* of `y` until you execute the function.

From: guest271314 mailto:guest271...@gmail.com>>
Sent: Saturday, June 15, 2019 3:57 PM
To: Ron Buckton mailto:ron.buck...@microsoft.com>>
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

> Sorry, I meant to say “not entirely correct”.

You have not yet confirmed if in fact the expected output is referencing a 
variable declared using ```const``` on the current line _before_ initialization 
_on the next line_.

That example appears to deviate from the purpose and usage of ```const```, 
beyond the scope of ```nameof```, and if were implemented, a 
```ReferenceError``` should _not_ be thrown when a ```const``` variable that 
has yet to be initialized _on the next line_ is referred to _on the current 
line_?

Aside from that example, the code which essentially already implements 
```nameof``` should be able to be found in the code which implements 
```ReferenceError``` relevant to ```const```.

On Sat, Jun 15, 2019 at 10:47 PM Ron Buckton 
mailto:ron.buck...@microsoft.com>> wrote:
Sorry, I meant to say “not entirely correct”.

From: Ron Buckton
Sent: Saturday, June 15, 2019 3:03 PM
To: guest271314 mailto:guest271...@gmail.com>>
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 incorrect. The identifier `y` exists, but its binding has 
not been initialized, otherwise you couldn’t refer to y in this case:



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


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

2019-06-15 Thread guest271314
What should occur where the code is


```

const x = nameof y

await new Promise(resolve => setTimeout(resolve, 10)); // should x be
"y" here?

await new Promise(resolve => setTimeout(resolve, 20)); // should x be
"y" here?

await Promise.all([new Promise(resolve => setTimeout(resolve, 30)),
...doStuff()]); // should x be "y" here?

const y = 1;

```


?


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 code example


```

const x = nameof y

const y = 1;

```


is a proposal for _more_ than only getting the _name_ of an _declared_ and
_initialized_ variable?


Should a ```RefefenceError``` _not_ be thrown simple because ```nameof```
is used?

On Sat, Jun 15, 2019 at 11:16 PM Ron Buckton 
wrote:

> ```
>
> const x = nameof y
>
> const y = 1;
>
> ```
>
>
>
> `x` would have the value “y”. It would not matter if `y` were initialized
> or had yet been reached during execution. It does not deviate from the
> purpose of `let` or `const`, because you are not accessing the *value* of
> the identifier.
>
>
>
> Also consider that this is legal ECMAScript in a module:
>
>
>
> ```
>
> export { y }
>
> const y = 1;
>
> ```
>
>
>
> The binding for `y` exists within the same block scope, it just has not
> yet been initialized. Exporting it via `export { y }`, closing over it via
> `() => y`, or accessing it via `nameof y` would all be the same. In all
> three cases you are accessing the **binding** of `y`, not the **value**
> of `y`. Even in the `() => y` case, you don’t access 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
>
>
>
> > Sorry, I meant to say “not entirely correct”.
>
>
>
> You have not yet confirmed if in fact the expected output is referencing a
> variable declared using ```const``` on the current line _before_
> initialization _on the next line_.
>
>
>
> That example appears to deviate from the purpose and usage of ```const```,
> beyond the scope of ```nameof```, and if were implemented, a
> ```ReferenceError``` should _not_ be thrown when a ```const``` variable
> that has yet to be initialized _on the next line_ is referred to _on the
> current line_?
>
>
>
> Aside from that example, the code which essentially already implements
> ```nameof``` should be able to be found in the code which implements
> ```ReferenceError``` relevant to ```const```.
>
>
>
> On Sat, Jun 15, 2019 at 10:47 PM Ron Buckton 
> wrote:
>
> Sorry, I meant to say “not entirely correct”.
>
>
>
> *From:* Ron Buckton
> *Sent:* Saturday, 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 incorrect. The identifier `y` exists, but its binding
> has not been initialized, otherwise you couldn’t refer to y in this case:
>
>
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


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

2019-06-15 Thread guest271314
> Sorry, I meant to say “not entirely correct”.

You have not yet confirmed if in fact the expected output is referencing a
variable declared using ```const``` on the current line _before_
initialization _on the next line_.

That example appears to deviate from the purpose and usage of ```const```,
beyond the scope of ```nameof```, and if were implemented, a
```ReferenceError``` should _not_ be thrown when a ```const``` variable
that has yet to be initialized _on the next line_ is referred to _on the
current line_?

Aside from that example, the code which essentially already implements
```nameof``` should be able to be found in the code which implements
```ReferenceError``` relevant to ```const```.

On Sat, Jun 15, 2019 at 10:47 PM Ron Buckton 
wrote:

> Sorry, I meant to say “not entirely correct”.
>
>
>
> *From:* Ron Buckton
> *Sent:* Saturday, 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 incorrect. The identifier `y` exists, but its binding
> has not been initialized, otherwise you couldn’t refer to y in this case:
>
>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


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

2019-06-15 Thread guest271314
```

const f = () => y;

let y = 1;

```


is different (dissimilar) code than the original reference example code.


> I don’t disagree that there are “alternative approaches” to ‘nameof’ for
many cases, but they all incur overhead.


Given that a ```ReferenceError``` is thrown when attempting to reference a
variable declared using ```const``` where the ```message``` property
includes the name of the variable, either the specification and, or the
implementers are already getting the name of the idetifier as a string and
outputing the described requirement of ```nameof``` in a similar context.
Thus, the code already exists. It would appear it is now a matter of
locating that source code in browser implementations and abstracting the
process to a ```nameof``` function or operator.


Have you looked into the source code of browsers that implement ```const```
to determine the issues, if any, as to utilizing the existiing
implementation(s) of ```ReferenceError``` to facilitate ```nameof``` while
avoiding incurring the described "overhead" of using workarounds to achieve
the same output?

On Sat, Jun 15, 2019 at 10:03 PM Ron Buckton 
wrote:

> > At that point in the example code the identifer ```y``` does not exist.
>
>
>
> That is not entirely incorrect. The identifier `y` exists, but its binding
> has not been initialized, otherwise you couldn’t refer to y in this case:
>
>
>
> ```
>
> const f = () => y;
>
> let y = 1;
>
> ```
>
>
>
> > That fact can be utilized for an alternative approach to meet
> requirement of "Case 1. Function guard.".
>
>
>
> I don’t disagree that there are “alternative approaches” to ‘nameof’ for
> many cases, but they all incur overhead.
>
>
>
> At the end of the day, ‘nameof’ is a convenience feature that provides an
> incremental “quality of life” improvement, much like shorthand property
> assignments were a convenience feature (i.e. how hard is it to write `{
> foo: foo }`). It’s not something that would 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
> *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. `nameof` wouldn’t refer to `y` as an expression, its just
> pointing to the identifier.
>
>
>
> Was not referring to the _value_ of ```y```. At that point in the example
> code the identifer ```y``` does not exist. That is, unless there was an
> expected presumption that ```y``` was defined globally prior to the
> ```const y = 1;``` declaration at the next line. Even then a variable
> declared using ```const``` cannot be referenced before "lexical
> declaration" or "initialization". That fact can be utilized for an
> alternative approach to meet requirement of "Case 1. Function guard.".
> Tested at Chromium 76 and Firefox 69. Have not used MS browser (or
> browserstack) in some time. Have not tried the code at Safari either,
> though the code is capable of adjustment for any JavaScript environment
> which throws a ```ReferenceError``` under the same case
>
>
>
> ```
>
> function func1(param1, param2, param3, userName, param4, param5) {
>   if (userName === undefined) {
> try {
>   // throws ReferenceError
>   // Firefox 69: ReferenceError: "can't access lexical declaration
> `userName' before initialization"
>   // Chromium 76: ReferenceError: Cannot access 'userName' before
> initialization
>   const userName = userName;
> } catch (e) {
>   // match identifier at Firefox, Chromium ReferenceError message
>   // adjust RegExp for IE/Edge, Safari, etc.
>   const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop();
>   throw new Error(`"Argument cannot be null: ${nameof}"`);
> }
>   } else {
> // do stuff
> console.log(userName);
>   }
> }
>
> try {
>   func1(1, 2, 3); // throws error
> } catch (e) {
>   console.error(e); // get name of variable identifier
> }
>
> try {
>   func1(1, 2, 3, 4); // logs userName at console
> } catch (e) {
>   console.error(e); // should not be reached
> }
>
> ```
>
>
>
> On Sat, Jun 15, 2019 at 9:37 PM Ron Buckton 
> wrote:
>
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name
> of `y` is. `nameof` wouldn’t refer to `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
>
>
>
> > I’m not sure I understand what you mean by “false-positive” in this
> instance.
>
>
>
> Was referring to
>
>
>
> const x = nameof y; // "y"
>
> const y = 1;
>
>
>
> Where ```y``` is ```undefined``` an error is not expected to be thrown? Is
> ```y``` 

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

2019-06-15 Thread Ron Buckton
> At that point in the example code the identifer ```y``` does not exist.

That is not entirely incorrect. The identifier `y` exists, but its binding has 
not been initialized, otherwise you couldn’t refer to y in this case:

```
const f = () => y;
let y = 1;
```

> That fact can be utilized for an alternative approach to meet requirement of 
> "Case 1. Function guard.".

I don’t disagree that there are “alternative approaches” to ‘nameof’ for many 
cases, but they all incur overhead.

At the end of the day, ‘nameof’ is a convenience feature that provides an 
incremental “quality of life” improvement, much like shorthand property 
assignments were a convenience feature (i.e. how hard is it to write `{ foo: 
foo }`). It’s not something that would 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
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. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the 
> identifier.

Was not referring to the _value_ of ```y```. At that point in the example code 
the identifer ```y``` does not exist. That is, unless there was an expected 
presumption that ```y``` was defined globally prior to the ```const y = 1;``` 
declaration at the next line. Even then a variable declared using ```const``` 
cannot be referenced before "lexical declaration" or "initialization". That 
fact can be utilized for an alternative approach to meet requirement of "Case 
1. Function guard.". Tested at Chromium 76 and Firefox 69. Have not used MS 
browser (or browserstack) in some time. Have not tried the code at Safari 
either, though the code is capable of adjustment for any JavaScript environment 
which throws a ```ReferenceError``` under the same case

```
function func1(param1, param2, param3, userName, param4, param5) {
  if (userName === undefined) {
try {
  // throws ReferenceError
  // Firefox 69: ReferenceError: "can't access lexical declaration 
`userName' before initialization"
  // Chromium 76: ReferenceError: Cannot access 'userName' before 
initialization
  const userName = userName;
} catch (e) {
  // match identifier at Firefox, Chromium ReferenceError message
  // adjust RegExp for IE/Edge, Safari, etc.
  const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop();
  throw new Error(`"Argument cannot be null: ${nameof}"`);
}
  } else {
// do stuff
console.log(userName);
  }
}

try {
  func1(1, 2, 3); // throws error
} catch (e) {
  console.error(e); // get name of variable identifier
}

try {
  func1(1, 2, 3, 4); // logs userName at console
} catch (e) {
  console.error(e); // should not be reached
}
```

On Sat, Jun 15, 2019 at 9:37 PM Ron Buckton 
mailto:ron.buck...@microsoft.com>> wrote:
It doesn’t matter what the value of ‘y’ is, just what the lexical name of `y` 
is. `nameof` wouldn’t refer to `y` as an expression, its just pointing to the 
identifier.

From: guest271314 mailto:guest271...@gmail.com>>
Sent: Friday, June 14, 2019 10:03 PM
To: Ron Buckton mailto:ron.buck...@microsoft.com>>
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

> I’m not sure I understand what you mean by “false-positive” in this instance.

Was referring to


const x = nameof y; // "y"

const y = 1;

Where ```y``` is ```undefined``` an error is not expected to be thrown? Is 
```y``` declared globally, using ```const``` or ```let```, or not at all? The 
use case  described by OP


function func1(param1, param2, param3, userName, param4, param5) {

   if (userName == undefined) {

   throw new ArgumentNullError(nameof userName); // `ArgumentNullError`

is a custom error, derived from `Error`, composes error message like

"Argument cannot be null: userName".

   }
checks if ```userName``` was ```undefined``` before using ```nameof```.  If 
error checking is a substantial portion of the proposal, why should an error 
(```y``` being ```undefined``` though referenced) be ignored when referencing 
an undefined identifier though concentrate on coercing a name from a different 
potentially undefined property?

Consider this case:
```
const someObject = { value: 1 };
function setValue(value /*1*/) {
  if (typeof value /*2*/ !== "number") throw new TypeError(`Number expected: 
${nameof value /*3*/}`);
  someObject["value" /*4*/] = value /*5*/;
}
```
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.

Not gathering the purpose or value of ```nameof``` usage in that case. If the 
value is not a "number" then why does the value 

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

2019-06-15 Thread guest271314
> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name
of `y` is. `nameof` wouldn’t refer to `y` as an expression, its just
pointing to the identifier.

Was not referring to the _value_ of ```y```. At that point in the example
code the identifer ```y``` does not exist. That is, unless there was an
expected presumption that ```y``` was defined globally prior to the
```const y = 1;``` declaration at the next line. Even then a variable
declared using ```const``` cannot be referenced before "lexical
declaration" or "initialization". That fact can be utilized for an
alternative approach to meet requirement of "Case 1. Function guard.".
Tested at Chromium 76 and Firefox 69. Have not used MS browser (or
browserstack) in some time. Have not tried the code at Safari either,
though the code is capable of adjustment for any JavaScript environment
which throws a ```ReferenceError``` under the same case

```
function func1(param1, param2, param3, userName, param4, param5) {
  if (userName === undefined) {
try {
  // throws ReferenceError
  // Firefox 69: ReferenceError: "can't access lexical declaration
`userName' before initialization"
  // Chromium 76: ReferenceError: Cannot access 'userName' before
initialization
  const userName = userName;
} catch (e) {
  // match identifier at Firefox, Chromium ReferenceError message
  // adjust RegExp for IE/Edge, Safari, etc.
  const nameof = e.message.match(/(?!`|')[^\s]+(?=')/g).pop();
  throw new Error(`"Argument cannot be null: ${nameof}"`);
}
  } else {
// do stuff
console.log(userName);
  }
}

try {
  func1(1, 2, 3); // throws error
} catch (e) {
  console.error(e); // get name of variable identifier
}

try {
  func1(1, 2, 3, 4); // logs userName at console
} catch (e) {
  console.error(e); // should not be reached
}
```

On Sat, Jun 15, 2019 at 9:37 PM Ron Buckton 
wrote:

> It doesn’t matter what the *value* of ‘y’ is, just what the lexical name
> of `y` is. `nameof` wouldn’t refer to `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
>
>
>
> > I’m not sure I understand what you mean by “false-positive” in this
> instance.
>
>
>
> Was referring to
>
>
>
> const x = nameof y; // "y"
>
> const y = 1;
>
>
>
> Where ```y``` is ```undefined``` an error is not expected to be thrown? Is
> ```y``` declared globally, using ```const``` or ```let```, or not at all?
> The use case  described by OP
>
>
>
> function func1(param1, param2, param3, userName, param4, param5) {
>
>if (userName == undefined) {
>
>throw new ArgumentNullError(nameof userName); // `ArgumentNullError`
>
> is a custom error, derived from `Error`, composes error message like
>
> "Argument cannot be null: userName".
>
>}
>
> checks if ```userName``` was ```undefined``` before using ```nameof```.
> If error checking is a substantial portion of the proposal, why should an
> error (```y``` being ```undefined``` though referenced) be ignored when
> referencing an undefined identifier though concentrate on coercing a name
> from a different potentially undefined property?
>
>
>
> Consider this case:
> ```
> const someObject = { value: 1 };
> function setValue(value /*1*/) {
>   if (typeof value /*2*/ !== "number") throw new TypeError(`Number
> expected: ${nameof value /*3*/}`);
>   someObject["value" /*4*/] = value /*5*/;
> }
> ```
>
> 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.
>
>
>
> Not gathering the purpose or value of ```nameof``` usage in that case. If
> the value is not a "number" then why does the value or name matter?
>
>
>
> Since the primary use case appears to be an editor environment, why cannot
> the editor be programmed to recognize the custom JavaScript ```nameof
> function or operator? Then it would not matter if this board concurred with
> the ```nameof``` functionality or not. Both CLI and GUI editors (and
> JavaScript) are generally extensible. FWIW, some time ago incorporated
> features into gedit for HTML templates; should be a similar process to
> create custom scripts for the various editor environments where users rely
> on such programs for code composition; now simply write the code by hand
> and test in different environments, without taking the time to customize or
> rely on an editor - take the time to test the code where the code will
> actually be run where errors, if any, can be evaluated in the context in
> which a specific output is expected. To each their own. What needs to be
> implemented outside of what the users which advocate for ```nameof```
> cannot implement themselves?
>
>
>
> As mentioned earlier do not rely on "an editor with name 

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

2019-06-15 Thread Ron Buckton
It doesn’t matter what the value of ‘y’ is, just what the lexical name of `y` 
is. `nameof` wouldn’t refer to `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

> I’m not sure I understand what you mean by “false-positive” in this instance.

Was referring to


const x = nameof y; // "y"

const y = 1;

Where ```y``` is ```undefined``` an error is not expected to be thrown? Is 
```y``` declared globally, using ```const``` or ```let```, or not at all? The 
use case  described by OP


function func1(param1, param2, param3, userName, param4, param5) {

   if (userName == undefined) {

   throw new ArgumentNullError(nameof userName); // `ArgumentNullError`

is a custom error, derived from `Error`, composes error message like

"Argument cannot be null: userName".

   }
checks if ```userName``` was ```undefined``` before using ```nameof```.  If 
error checking is a substantial portion of the proposal, why should an error 
(```y``` being ```undefined``` though referenced) be ignored when referencing 
an undefined identifier though concentrate on coercing a name from a different 
potentially undefined property?

Consider this case:
```
const someObject = { value: 1 };
function setValue(value /*1*/) {
  if (typeof value /*2*/ !== "number") throw new TypeError(`Number expected: 
${nameof value /*3*/}`);
  someObject["value" /*4*/] = value /*5*/;
}
```
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.

Not gathering the purpose or value of ```nameof``` usage in that case. If the 
value is not a "number" then why does the value or name matter?

Since the primary use case appears to be an editor environment, why cannot the 
editor be programmed to recognize the custom JavaScript ```nameof function 
or operator? Then it would not matter if this board concurred with the 
```nameof``` functionality or not. Both CLI and GUI editors (and JavaScript) 
are generally extensible. FWIW, some time ago incorporated features into gedit 
for HTML templates; should be a similar process to create custom scripts for 
the various editor environments where users rely on such programs for code 
composition; now simply write the code by hand and test in different 
environments, without taking the time to customize or rely on an editor - take 
the time to test the code where the code will actually be run where errors, if 
any, can be evaluated in the context in which a specific output is expected. To 
each their own. What needs to be implemented outside of what the users which 
advocate for ```nameof``` cannot implement themselves?

As mentioned earlier do not rely on "an editor with name refactoring" to 
compose code. The code has to be tested (outside of the editor environments) 
anyway. Test the code itself, here, not the editor.

On Fri, Jun 14, 2019 at 9:49 PM Ron Buckton 
mailto:ron.buck...@microsoft.com>> wrote:
I’m not sure I understand what you mean by “false-positive” in this instance.

Consider this case:

```
const someObject = { value: 1 };
function setValue(value /*1*/) {
  if (typeof value /*2*/ !== "number") throw new TypeError(`Number expected: 
${nameof value /*3*/}`);
  someObject["value" /*4*/] = value /*5*/;
}
```

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 mailto:guest271...@gmail.com>>
Sent: Friday, June 14, 2019 2:43 PM
To: Ron Buckton mailto:ron.buck...@microsoft.com>>
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 Buckton 
mailto:ron.buck...@microsoft.com>> 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.

If you are using an editor that supports rename refactoring, its generally 
easier to rename the symbol `foo` and have all references (including `nameof 
foo`) be updated. You cannot safely automatically rename `'foo'` to `'bar'` 
since an editor or language service cannot guarantee 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@mozilla.org>>
Subject: Re: Re: What do