Keep bodies that call relative-path externals out of other modules
Why
An external with a package-relative path, such as @module("./helper.js"), is imported relative to its own file. The type checker keeps the external itself out of other modules, but with -bs-cross-module-opt the wrapper it is exported through, and any small function calling it, were stored in the .cmj and inlined into modules in other directories, which then imported ./helper.js relative to themselves. This is PR 3 of the plan in #8733 (problem 2.8).
modifiedJS with -bs-cross-module-opt
// src/ffi/Hidden.res@module("./helper.js") external raw: int => int = "raw"@inline let wrapped = x => raw(x) + 1 // src/app/App.reslet direct = Hidden.raw(1)let wrapped = Hidden.wrapped(2)
js
Before src/app/App.mjs
After src/app/App.mjs
import * as Hidden from "../ffi/Hidden.mjs";import * as Hidden from "../ffi/Hidden.mjs";import * as HelperJs from "./helper.js"; let direct = HelperJs.raw(1);let direct = Hidden.raw(1); let wrapped = HelperJs.raw(2) + 1 | 0;let wrapped = Hidden.wrapped(2);
Review
- Does inlining change otherwise? No. A body that calls an external with a package path, such as
@module("node:path"), is still inlined, and the runtime's and Belt's JS, built with the flag, are unchanged.