Re: [w3c/webcomponents] HTML, CSS, and JSON modules shouldn't solely rely on MIME type to change parsing behavior (#839)

> To me, use of import is explicitly saying "this thing is safe to execute in the JS environment", and if i didn't want that, i wouldn't be using import.

Sounds like an argument in favor of [my previous suggestion](https://github.com/w3c/webcomponents/issues/839#issuecomment-551078313) to pick a keyword other than `import` for non-JS modules, to reinforce that they *aren't* safe to execute.

> i'd be curious why <link rel="preload" href="whatever" as="json"> combined with fetch(whatever) isn't sufficient

Because we don't have async modules. I don't see any other way to support a pattern like

````js
import { supportsBar } from "./config.json";

function foo() { ... }
function bar() { ... }

const xp = { foo, supportsBar };
if (supportsBar) { xp.bar = bar; }

module.exports = xp;
````

With JSON modules, the above won't execute until the dependent module (config.json) is loaded, and module loading will fail if the config file fails to load.  (I'm aware this is an oversimplified example but variants on this pattern definitely do make sense.)

-- 
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/839#issuecomment-555401694

Received on Tuesday, 19 November 2019 09:00:16 UTC