Loose idea on "try import"

Michał Wadas michalwadas at gmail.com
Fri Mar 1 17:35:34 UTC 2019


I don't think so, because:

   - Using promises to import module is not always desirable
   - This mechanism doesn't impact ability to statically analyze modules if
   ifs are excluded - it can only increase resolution time.




On Fri, Mar 1, 2019 at 1:56 PM Herby Vojčík <herby at mailbox.sk> wrote:

> On 1. 3. 2019 12:04, Michał Wadas 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');
>
> I am not an expert, but afaict ES module system was created to be
> statically analysable and this bring uncertainity.
>
> For that probably dynamic import() is there; and your usage should await
> for a promise that tries to load one then the other etc.
>
> Herby
>
> > 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190301/14361a0a/attachment.html>


More information about the es-discuss mailing list