On Thu, Sep 5, 2019 at 2:39 PM Andrea Giammarchi <[email protected]> wrote: > > This is basically a solution to a common problem we have these days, where > modules published in the wild might have a `default` property, to support ESM > logic, or not. > > ```js > // current optional chaining logic > const imported = exported?.default ?? exported; > > // my "mice operator" proposal > const imported = exported<?.default; > ``` > > Semantically speaking, not only `<?` actually looks like a mice, it also > points at its previous value in case the chaining didn't work. > > Beside the basic example, the "mice operator" might save CPU cycles when it > comes to involving more complex expressions, i.e. > > ```js > // current "solution" > const thing = require('thing')?.default ?? require('thing'); > > // mice operator > const thing = require('thing')<?.default; > ``` > > This is also easily tranpilable, so kinda a no-brainer for modern dev tools > to bring in. > > TL;DR specially for cases where an accessed property should fallback to its > source, this operator might save both typing and CPU time whenever it's > needed.
I find it a rather curious pattern, that I'd never seen before! Is it used in anything besides this ESM-compat thing you're talking about? (Saving CPU cycles is not a convincing argument; it's trivial to write such a line over two declarations and avoid any expensive recomputations.) ~TJ _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

