Semantic Diff

#9506 Allow import() of a relative-path external in its own file

1 commit

0a686a9a9b6787ea4fcdb1e08dc70fd9d5760a66..pr-9506

8fdb9a4f0 · cknitt + Claude · Dec 03, 2026, 05:39 UTC

Allow import() of a relative-path external in its own file

Why

An external with a relative path, such as @module("./mathLib.js"), is exported as a plain value so other modules don't inline the path. The type checker also showed it as a plain value to the rest of its own file, so import(floor) failed with an error calling it a local value. Now only the exported signature hides the external. Fixes #9405.

removedDiagnostic import of a relative-path external

@module("./mathLib.js") @scope("Math")external floor: float => float = "floor"let f = import(floor)
diagnostic
Before
Invalid argument: Dynamic import requires a module or module value that is a file as argument. Passing a value or local module is not allowed.

modifiedJS import of a relative-path external

@module("./mathLib.js") @scope("Math")external floor: float => float = "floor"let f = import(floor)
js
After
let MathLibJs = require("./mathLib.js"); function floor(prim) {  return MathLibJs.Math.floor(prim);} let f = import("./mathLib.js").then(m => m.Math.floor);

modifiedJS a zero-arity relative-path external used in its own file

@module("./file.js") external foo: int = "foo"let bar = foo + 1
js
Before
After
let foo = FileJs.foo;let foo = FileJs.foo; let bar = foo + 1 | 0;let bar = FileJs.foo + 1 | 0;

Review

  • Can other modules now inline the relative path? No. The exported signature still has the external as a plain value, so other files keep calling it through the exported binding, as before.