Skip to content

Import the default export for @scope starting with "default" - #8923

Merged
cknitt merged 1 commit into
masterfrom
esm-default-import-scope
Oct 20, 2026
Merged

cknitt merged 1 commit into
masterfrom
esm-default-import-scope

Conversation

@cknitt

@cknitt cknitt commented Oct 19, 2026

Copy link
Copy Markdown
Member

A @module external whose @scope starts with "default" now uses a default import (import Mod from "mod", accessing Mod.x.fn) instead of import * as Mod plus Mod.default.x.fn, reusing the mechanism external x: t = "default" already uses. CommonJS output becomes require("mod").default; other scopes are unchanged.

Fixes #8335.

New tests: tests/tests/src/scope_default_import.res (ES module snapshot) and tests/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

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>
@github-actions

Copy link
Copy Markdown

@pkg-pr-new

pkg-pr-new Bot commented Oct 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8923

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8923

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8923

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8923

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8923

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8923

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8923

commit: 2ae8c99

@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T06:14:30.598959Z 2ae8c99 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 2ae8c9919f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@cknitt
cknitt marked this pull request as ready for review October 20, 2026 15:08
@cknitt
cknitt requested a review from cristianoc October 20, 2026 15:09
@cknitt
cknitt merged commit 0076143 into master Oct 20, 2026
28 checks passed
@cknitt
cknitt deleted the esm-default-import-scope branch October 20, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESM default imports when using @scope

2 participants