framework icon indicating copy to clipboard operation
framework copied to clipboard

Import attributes

Open mbostock opened this issue 1 year ago • 2 comments

We should support import assertions. This may require the acorn-import-assertions plugin.

Static imports with assertions look like this:

import data from "./data.json" assert {type: "json"};

Dynamic imports with assertions look like this:

const data = await import("./data.json", {assert: {type: "json"}});

Both of these currently generate syntax errors with Acorn, but are supported by most browsers.

mbostock avatar Nov 15 '23 19:11 mbostock

Maybe worth mentioning that ESLint won't add support for import attributes until they become Stage 4 and fails to parse a file that contains them.

mootari avatar Jan 20 '24 12:01 mootari

These are now called “import attributes” and use with instead of assert. Still not widely supported though.

mbostock avatar Mar 04 '24 05:03 mbostock