observablehq / framework

A static site generator for data apps, dashboards, reports, and more. Observable Framework combines JavaScript on the front-end for interactive graphics with any language on the back-end for data analysis.
https://observablehq.com/framework/
ISC License
2.58k stars 125 forks source link

Unresolved imports should error in fenced code blocks #1659

Open mbostock opened 2 months ago

mbostock commented 2 months ago

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

import {doesNotExist} from "./module.js";
mbostock commented 1 week ago

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.