BuckleScript external bindings code not being generated


#1

I’m following this guide:

I made a new Foo.re file, pasted in:

[@bs.val] external setTimeout : (unit => unit, int) => float = "setTimeout";

I then added a test file, just so that the setTimeout method is referenced and called.

open Jest;

open Expect;

open Foo;

describe("Binding", () =>
  test("setTimeout", () =>
    expect(() =>
      setTimeout(() => (), 0)
    ) |> not_ |> toThrow
  )
);

After compiling with bsb -make-world, the generated Foo.bs.js file is just:

// Generated by BUCKLESCRIPT VERSION 3.1.5, PLEASE EDIT WITH CARE
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

Do I need to do something special to make this work?


#2

Externals are generated on the call site so try to apply it somewhere and check generated code.


#3

Thanks, I can confirm that is the case. Seems like there should be some sort of compiler hint or dev mode to force the generation of unused code, just for verification purposes.