tc39 / proposal-import-attributes

Proposal for syntax to import ES modules with assertions
https://tc39.es/proposal-import-attributes/
Apache License 2.0
586 stars 26 forks source link

return of dynamic import() #143

Closed erosman closed 1 year ago

erosman commented 1 year ago

Has the return been finalised?

Some documents mention default as the returned object property e.g.

const obj = await import("foo.json", { with: { type: "json" } });
// Object { default: {…} }
nicolo-ribaudo commented 1 year ago

This proposal doesn't define what JSON modules are, but only that there can be some attributes whose interpretation will be defined somewhere else.

JSON modules are currently defined in the JSON modules proposal. The are equivalent to a module with a single default export.

This code:

// main.js
const obj = await import("foo.json", { with: { type: "json" } });

// foo.json
{ "hello": "world" }

if equivalent to this code:

// main.js
const obj = await import("foo.js");

// foo.js
export default { "hello": "world" }

See https://github.com/tc39/proposal-json-modules#why-dont-json-modules-support-named-exports for more info.