rescript-lang / rescript-lang/rescript

ESM default imports when using @scope

Open
#8,335 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

Playground: https://rescript-lang.org/try?version=v12.0.0-beta.12&module=esmodule&code=LYewJgrgNgpgBAWXARjgXjgbwFBzgFwE8AHefXOAAVElgAoAiG5BgSjhgA98YAnAOwCGUAgC4C6OAzAwAZoOj4GFSgGcY-MFVUBjEKUac2HbnyEjZ-cXXwAaOAEt++dmgB8cCPwf5JDS8p4sL6WkpY29gD6rNgAvtjYNNDwSGAATJI4eNTgyYw0acZqegaMMvKKDPYMRqzsXDwCwnCW4k6+7p7eHVIBFMEt-GH8cdhAA

module Mod1 = {
  type t
  @module("mod1") external t: t = "default"
  @send @scope("x") external fn: (t, int) => unit = "fn"
  let fn = fn(t, _)
}

module Mod2 = {
  @module("mod2") @scope(("default", "x")) external fn: int => unit = "fn"
  let fn = fn
}

Using @scope results in a namespace import instead of a default import:

import Mod1 from "mod1";
import * as Mod2 from "mod2";

This shouldn't effect modern tree shakers, but I've noticed tooling, like linters, can be less effective.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground example and compare the generated imports for Mod1 and Mod2 when @scope is used. Trace the compiler path that handles scoped module imports, then verify that the affected default-import cases preserve default imports rather than emitting namespace imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, ocaml
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.