Skip to content

How does the js polyfill work with ES6 modules? #252

Closed

Description

@MikeHolman

I think we can agree that one of the big motivators for the polyfill is that it will work in existing browsers. And existing browsers don't have modules. It feels like a bit of chicken/egg problem to me. I can imagine some dynamic js code generation will be necessary on client side which decides whether to use ES6 module syntax or transpile to ES5, but I don't know how feasible this is. Anyway, I don't really have an architecture in mind, so I'm wondering what are you guys thinking?

Activity

  1. added this to the MVP milestone on Jul 6, 2015
  2. kg commented on Jul 7, 2015

    @kg
    Contributor

    Performance/flexibility considerations aside, the simplest approach would be for the polyfill to just generate ES5 with wide compatibility in mind. You could go further and make it do feature detection to figure out whether to generate JS that uses ES6/ES7 features like modules or int64 as appropriate instead of just emulating them, but that's more of an improvement than a feature.

    As far as I'm concerned modules aren't of much use to the polyfill, but you want it to interact well with consumers who want to import a WebAssembly module from ES6. That's a bit easier to tackle.

  3. lukewagner commented on Jul 7, 2015

    @lukewagner
    Member

    Agreed with @kg that, when the containing app isn't explicitly using ES6 modules, the polyfill should just generate ES5 code for maximum portability, even if ES6 modules are natively supported.

    An interesting question is what happens when the containing app is using ES6 modules and importing wasm modules. The challenge is to translate the fetch triggered by import statements. If there is no native ES6 support, we can just hook the wasm polyfill into an ES6 module polyfill, so no problem. Furthermore, it seems like native ES6 module support may not happen much sooner than wasm, so apps could just count on using both and falling back to the ES6 module+wasm polyfill if either was missing. As a last fallback, Service Workers would also allow interception and translation and are coming along nicely. (For a while I was holding out hope for the Loader API, but it seems farther off.)

  4. MikeHolman commented on Mar 1, 2016

    @MikeHolman
    MemberAuthor

    For the time being at least, we will not use es6 modules at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions