Repository navigation
Allow import() of a relative-path external in its own file - #9506
Conversation
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.
Diagnostic removed (import of a relative-path external):
Example:
@module("./mathLib.js") @scope("Math")
external floor: float => float = "floor"
let f = import(floor)
Before (diagnostic):
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.
JS modified (import of a relative-path external):
Example:
@module("./mathLib.js") @scope("Math")
external floor: float => float = "floor"
let f = import(floor)
After (js):
let MathLibJs = require("./mathLib.js");
function floor(prim) {
return MathLibJs.Math.floor(prim);
}
let f = import("./mathLib.js").then(m => m.Math.floor);
JS modified (a zero-arity relative-path external used in its own file):
Example:
@module("./file.js") external foo: int = "foo"
let bar = foo + 1
Before (js):
let foo = FileJs.foo;
let bar = foo + 1 | 0;
After (js):
let foo = FileJs.foo;
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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gGnvaRviGhTLTTUbqs
Signed-off-by: Christoph Knittel <ck@cca.io>
Changelog🐛 Bug fix
Semantic Diff1 commit · Full page Allow import() of a relative-path external in its own file8fdb9a4 · cknitt + Claude · Dec 03, 2026, 05:39 UTC
Diagnostic removed (import of a relative-path external) @module("./mathLib.js") @scope("Math")
external floor: float => float = "floor"
let f = import(floor)
JS modified (import of a relative-path external) @module("./mathLib.js") @scope("Math")
external floor: float => float = "floor"
let f = import(floor)
let MathLibJs = require("./mathLib.js");
function floor(prim) {
return MathLibJs.Math.floor(prim);
}
let f = import("./mathLib.js").then(m => m.Math.floor);JS modified (a zero-arity relative-path external used in its own file) @module("./file.js") external foo: int = "foo"
let bar = foo + 1
let foo = FileJs.foo;
-let bar = foo + 1 | 0;
+let bar = FileJs.foo + 1 | 0;Review
|
✅ Compiler benchmarksAllocated wordsIn total: 653,176,259 → 653,178,805 (±0.00%). Generated projects: 627,030,951 → 627,030,164 (±0.00%). None of the 265 benchmarks changed by 0.1% or more. InstructionsIn total: 8,963,760,124 → 8,964,113,806 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,441,259 → 27,441,437 (±0.00%). None of the 13 benchmarks changed by 0.1% or more. Pull request 8fdb9a4 compared with base 0a686a9 in this run. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #9506 +/- ##
==========================================
- Coverage 82.54% 82.54% -0.01%
==========================================
Files 469 469
Lines 66224 66226 +2
==========================================
+ Hits 54666 54667 +1
- Misses 11558 11559 +1
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
Developer playground preview: https://rescript-lang.github.io/rescript/dev-playground/?version=pr-9506 |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #9405.
An external with a relative path, such as
@module("./mathLib.js"), is exported as a plain value, so other modules don't inline a path that is only valid from its own file. The type checker also showed it as a plain value to the rest of its own file, soimport(floor)failed with an error calling it a local value.Now only the exported signature hides the external. In its own file it is an external again, so
compiles to
import("./mathLib.js").then(m => m.Math.floor), the same as for a package. Other files still call it through the exported binding.A side effect: a zero-arity relative external used in its own file is now read directly (
FileJs.foo + 1instead offoo + 1), as package externals already are. That changes four generated test files.New tests: the scoped and default cases from the issue in
tests/compiler_tests/src/import_external.res.Not covered:
import(M.inner)whereMis a local module of the same file andinnera relative external still fails, becauseM's signature hides the external.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gGnvaRviGhTLTTUbqs