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.,
```
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:
> >>
> >>
> >>
> >&
; >>
> > >> const cwd /*1*/ = ".";
> > >>
> > >> gulp.src("*.js", { cwd /*2*/ });
> > >>
> > >> ```
> > >>
> > >>
> > >>
> > >> If you were to rename `cwd` at (1) and
nces,
> producing:
> >>
> >>
> >>
> >> ```
> >>
> >> const currentDir = ".";
> >>
> >> gulp.src("*.js", { cwd: currentDir });
> >>
> >> ```
> >>
> >>
> >>
&
roducing:
>>
>>
>>
>> ```
>>
>> const currentDir = ".";
>>
>> gulp.src("*.js", { cwd: currentDir });
>>
>> ```
>>
>>
>>
>> There is also the issue of collisions:
>>
>>
>>
>
>> >> 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
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-
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
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
> 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
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
_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
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
> > >
*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
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
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;
> > >
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
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
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
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
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
>
>
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
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
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. `
`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
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
}
>
> ```
>
>
>
> 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
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
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
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'
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
`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
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
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```
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)
> 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
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&
-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
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
> 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
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
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)```
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 ==
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
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
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
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
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
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?
>
>
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
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
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
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
.
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.
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
55 matches
Mail list logo