Repository navigation
Import the default export for @scope starting with "default" - #8923
Conversation
A `@module` external whose `@scope` starts with `"default"` now imports the
module's default export, as `external x: t = "default"` already does, and
accesses the remaining scopes on it. Under ES modules this emits
`import Mod from "mod"` instead of a namespace import plus `.default`;
CommonJS output becomes `require("mod").default`. Other scopes are unchanged.
Example (rescript):
@module("mod2") @scope(("default", "x")) external fn: int => unit = "fn"
let f = () => fn(1)
Before (js):
import * as Mod2 from "mod2";
function f() {
Mod2.default.x.fn(1);
}
After (js):
import Mod2 from "mod2";
function f() {
Mod2.x.fn(1);
}
Source: Before from the issue's playground example on master 58da277;
After from tests/tests/src/scope_default_import.mjs in the diff.
Review: Does CommonJS stay equivalent? Yes: `Mod1.default.x.fn` with
`Mod1 = require("mod1")` becomes `Mod1$1.x.fn` with
`Mod1$1 = require("mod1").default`, the same lowering `= "default"` uses
(tests/commonjs_tests/src/scope_default_import.js).
Area: codegen tests
Output: changed programs with @module externals whose @scope starts with "default"; no existing generated JS in the repository changes
Tests: +tests/tests/src/scope_default_import.res +tests/commonjs_tests/src/scope_default_import.res
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
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-8923 |
|
@codex review |
Codex Review SummaryThis 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. Hooray! 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". |
A
@moduleexternal whose@scopestarts with"default"now uses a default import (import Mod from "mod", accessingMod.x.fn) instead ofimport * as ModplusMod.default.x.fn, reusing the mechanismexternal x: t = "default"already uses. CommonJS output becomesrequire("mod").default; other scopes are unchanged.Fixes #8335.
New tests:
tests/tests/src/scope_default_import.res(ES module snapshot) andtests/commonjs_tests/src/scope_default_import.res(CommonJS snapshot), covering a nested scope, a single"default"scope with@val/@new, a non-default scope on the same module, and= "default"under a"default"scope.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo