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., ``` const [{ a = 1, b = 2 }, cd] = [...[source]]; ``` Usage: ```sourceCode.match(nameofall); // ["const x", "let z", "class G"]``` On Fri, Jun 14, 2019 at 1:05 PM Stas Berkov <stas.ber...@gmail.com> 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 >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss