Loose idea on "try import"

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Mar 1 19:19:40 UTC 2019


honestly this look like an `or` would've been great as reserved

try import fs from 'fs'
 or import fs from 'fs-polyfill'
 or import fs from 'another-fs-polyfill'
 catch optional, and triggered only if previous 3 imports failed
 finally optionally do something;

On Fri, Mar 1, 2019 at 12:05 PM Michał Wadas <michalwadas at gmail.com> wrote:

> Syntax:
>
> try import fs from 'fs'
>    else import fs from 'fs-polyfill'
>    else import fs from 'another-fs-polyfill'
>    else do nothing; // Not sure about syntax
>
>
> try import {watchDirectory} from 'fs'
>    else import {watchDirectory} from 'fs-polyfill'
>    else if(process.os === 'ExoticSystem') import {watchDirectory} from
> 'another-fs-polyfill'
>    else throw Error('Your OS doesn\'t support watching directories');
>
> Usages:
>
>    - Optional dependencies
>    - Polyfills
>
> Problems:
>
>    - This can prevent loading modules before execution if presence of
>    modules can't be proved statically
>    - else-if requires execution before loading module - can be dropped
>
>
> I don't have enough time and knowledge about modules to write actual
> proposal.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190301/09514b1a/attachment-0001.html>


More information about the es-discuss mailing list