guest271314 (2019-06-16T00:14:55.000Z)
Would posit that ```nameof``` should be used only _after_ a variable has
been initialized. A variable lookahead could lead to false-positives and
unexpected results.

What is the use case for ```nameof``` being used _before_ variable
initialization?

On Sun, Jun 16, 2019 at 12:03 AM Ron Buckton <Ron.Buckton at microsoft.com>
wrote:

> > 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 at mozilla.org
>
>
>
>
> What should occur where the code is
>
> ```
> const x = nameof y
> await new Promise(resolve => setTimeout(resolve, 100000)); // should x be
> "y" here?
> await new Promise(resolve => setTimeout(resolve, 200000)); // should x be
> "y" here?
> await Promise.all([new Promise(resolve => setTimeout(resolve, 300000)),
> ...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 <Ron.Buckton at 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 <guest271314 at gmail.com>
> *Sent:* Saturday, June 15, 2019 3:57 PM
> *To:* Ron Buckton <Ron.Buckton at microsoft.com>
> *Cc:* es-discuss at 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 <Ron.Buckton at microsoft.com>
> wrote:
>
> Sorry, I meant to say “not entirely correct”.
>
> *From:* Ron Buckton
> *Sent:* Saturday, June 15, 2019 3:03 PM
> *To:* guest271314 <guest271314 at gmail.com>
> *Cc:* es-discuss at 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:
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190616/33353811/attachment.html>
guest271314 at gmail.com (2019-06-16T01:09:25.961Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:5}, {name:"y", line:7}] 
// should resolve be in the list even if not declared using const or let?
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000))); 
const x = nameof y
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000)));
const y = 1;
```

guest271314 at gmail.com (2019-06-16T01:09:07.124Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:35}, {name:"y", line:7}] 
// should resolve be in the list even if not declared using const or let?
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000))); 
const x = nameof y
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000)));
const y = 1;
```

guest271314 at gmail.com (2019-06-16T01:08:15.141Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:3}, {name:"y", line:4}] 
// should resolve be in the list even if not declared using const or let?
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000))); 
const x = nameof y
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000)));
const y = 1;
```

guest271314 at gmail.com (2019-06-16T01:07:35.514Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:3}, {name:"y", line:4}] 
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000))); // should resolve be in the list?
const x = nameof y
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000)));
const y = 1;
```

guest271314 at gmail.com (2019-06-16T01:06:09.965Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:3}, {name:"y", line:4}]
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000)));
const x = nameof y
await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * 1000)));
const y = 1;
```

guest271314 at gmail.com (2019-06-16T01:03:52.578Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:2}, {name:"y", line:3}]
const x = nameof y
const y = 1;
```

guest271314 at gmail.com (2019-06-16T01:01:12.334Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:2}, {name:"y", line:3}]
const x = nameof y
const y = 1;
// (NAMEOFALL: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T01:00:41.809Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
// NAMEOF is always dynamic list of let, const declarations in current scope 
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:1}, {name:"y", line:2}]
const x = nameof y
const y = 1;
// (NAMEOFALL: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T00:59:30.031Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
const x = nameof y
const y = 1;
console.log(NAMEOF); // ["x", "y"]; [{name:"x", line:1}, {name:"y", line:2}]
// NAMEOF is always dynamic list of let, const declarations in current scope 
// (NAMEOFALL: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T00:55:53.883Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
const x = nameof y
const y = 1;
console.log(NAMEOF); // ["y", "y"]; 
// NAMEOF is always dynamic list of let, const declarations in current scope 
// (NAMEOFALL: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T00:55:14.979Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value. ```MapInstance.get("key")```

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
const x = nameof y
const y = 1;
console.log(NAMEOF); // ["y", "y"]; 
NAMEOF is always dynamic list of let, const declarations in current scope (NAMEOFALL: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T00:53:04.600Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value.

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
const x = nameof y
const y = 1;
console.log(NAMEOF); // ["y", "y"]; 
NAMEOF is always dynamic list of let, const declarations in current scope (NAMEOFALL: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T00:52:16.080Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value.

For the purposes of ```nameof``` as descibed in this proposal a ```Set``` might suffice

```
const x = nameof y
const y = 1;
console.log(NAMEOF); // ["y", "y"]; 
NAMEOF is always dynamic list of let, const declarations in current scope (SUPERNAMEOF: any, all scopes; TODO what happens when duplicates are encountered?)
```

guest271314 at gmail.com (2019-06-16T00:36:46.956Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (handle variables not set at ```Map```, if allowed, based on requirement). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value.
guest271314 at gmail.com (2019-06-16T00:35:28.024Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (else throw error if that is requirement?). Which would remedy using ```const``` and ```let``` or ```var``` at all - all variables are set at a ```Map``` immediately having a unique name and a value.
guest271314 at gmail.com (2019-06-16T00:33:38.757Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any and all declared variables in any scope could be set at a ```Map``` object with key, value pair being name, value (else throw error if that is requirement?).
guest271314 at gmail.com (2019-06-16T00:31:24.462Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?

Taking the proposal a step further, any declared variable in any scope could be set at a ```Map``` object with key, value pair being name, value.
guest271314 at gmail.com (2019-06-16T00:23:58.189Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?

Since some human _has_ to write ```const``` and ```let``` and _choose_ the variable name, why cannot the same human write the variable name as a string and maintain a map of all variable names in each required scope?
guest271314 at gmail.com (2019-06-16T00:20:14.610Z)
What is the use case for ```nameof``` being used as a lookahead _before_ variable
initialization?
guest271314 at gmail.com (2019-06-16T00:19:26.214Z)
What is the use case for ```nameof``` being used _before_ variable
initialization?