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 <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 > -- ----- Isiah Meadows cont...@isiahmeadows.com www.isiahmeadows.com
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss