framework icon indicating copy to clipboard operation
framework copied to clipboard

Unresolved imports should error in fenced code blocks

Open mbostock opened this issue 1 year ago • 1 comments

We translate static imports to dynamic imports, but this should error rather than resolve to undefined:

import {doesNotExist} from "./module.js";

mbostock avatar Sep 13 '24 16:09 mbostock

Currently the above is translated into (approximately):

const {doesNotExist} = await import("./_import/module.js");

We’ll need to do something like this instead:

const $module = await import("./_import/module.js");
if (!("doesNotExist" in $module)) throw new SyntaxError("The requested module './module.js' does not provide an export named 'doesNotExist'");
const {doesNotExist} = $module;

Where $module doesn’t collide with any referenced symbol.

mbostock avatar Nov 13 '24 16:11 mbostock