[w3c/webcomponents] HTML Modules: multiple scripts exporting same named export (#831)

I just implemented a polyfill for HTML modules in https://github.com/systemjs/systemjs/pull/2011. In doing so, the spec wasn't clear to me about how to handle the follow situation:

```html
<script type="module">
  export const foo = 1;
</script>
<script type="module">
  export const foo = 2;
</script>
```

[This section of the spec](https://github.com/w3c/webcomponents/blob/gh-pages/proposals/html-modules-explainer.md#specifying-an-html-modules-exports) did not clarify this for me.

Here's the languaging for default exports (but not named exports):

> Additionally, if an inline script element specifies a default export it will be passed through as the default export of the HTML Module (multiple inline scripts specifying a default will result in an instantiation error for the HTML Module). If no script specifies a default export, the HTML Module's document will be the implicit default export of the module. This will allow declarative content of a module to be consumed without the use of inline script elements in the module to specify exports.

And here's the languaging about exports in general:

> An HTML Module will specify its exports using its inline script elements. Inline Script Modules in an HTML Module document will have their exports redirected via the HTML Module Record such that the importer of the HTML Module can access them. This is done by computing the exports for the HTML Module's record during its instantiation phase as per the following pseudocode:

```js
for (ModuleScript in HtmlModuleRecord.[[RequestedModules]]) {
    if (ModuleScript.IsFromInlineScriptElement) {
        export * from ModuleScript;
    }
}
```

The pseudocode comes closest to explaining, but I'm not sure whether it should (1) throw when encountering the same export, or (2) "last script's export wins". If (2), then you have to account for live bindings of the export -- can the first module update the live binding even though it's initial value was ignored? Note that afaik default exports do not have this problem because default exports aren't really a live binding (no way of updating them after the initial export)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/831

Received on Wednesday, 28 August 2019 23:45:42 UTC