Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/scope-default-import.polish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Import the default export, instead of the module namespace, for `@module` externals whose `@scope` starts with `"default"`.
5 changes: 3 additions & 2 deletions compiler/core/lam_compile_external_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ let translate_scoped_module_val
E.external_var_field ?import_attributes ~external_name:bundle ~field:fn
~default id
| x :: rest ->
(* TODO: what happens when scope contains "default" ?*)
let default = false in
(* A leading "default" scope is the module's default export: import
it as such, like [external x: t = "default"] *)
let default = x = "default" in
let id =
Lam_compile_env.add_js_module ?import_attributes module_bind_name bundle
default ~dynamic_import:false
Expand Down
18 changes: 18 additions & 0 deletions tests/commonjs_tests/src/scope_default_import.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/commonjs_tests/src/scope_default_import.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// A leading "default" scope imports the module's default export

@module("mod1") @scope(("default", "x")) external fn: int => unit = "fn"
@module("mod1") @scope("default") external value: int = "value"
@module("mod1") @new @scope("default") external make: unit => {"a": int} = "Klass"
@module("mod1") @scope("other") external other: int = "other"

@module("mod2") @scope("default") external defaultOfDefault: int = "default"

let f = () => fn(value + other + defaultOfDefault)
let g = () => make()
19 changes: 19 additions & 0 deletions tests/tests/src/scope_default_import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

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

function f() {
Mod1$1.x.fn((Mod1$1.value + Mod1.other.other | 0) + Mod2.default | 0);
}

function g() {
return new (Mod1$1.Klass)();
}

export {
f,
g,
}
/* mod1 Not a pure module */
11 changes: 11 additions & 0 deletions tests/tests/src/scope_default_import.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// A leading "default" scope imports the module's default export

@module("mod1") @scope(("default", "x")) external fn: int => unit = "fn"
@module("mod1") @scope("default") external value: int = "value"
@module("mod1") @new @scope("default") external make: unit => {"a": int} = "Klass"
@module("mod1") @scope("other") external other: int = "other"

@module("mod2") @scope("default") external defaultOfDefault: int = "default"

let f = () => fn(value + other + defaultOfDefault)
let g = () => make()
Loading