rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Deprecated decorator w/ let and pipes

Open CarlOlson opened this issue 1 month ago • 0 comments

  1. In my example the deprecated warning and migration will only happen for external functions. I'd expect this to also work with top-level let functions.
  2. The migration will not create pipes unless used by the deprecated code. Somehow allowing migrating to pipes would be very helpful for migrating old pipe-last code that has been formatted into direct function calls.
  3. The migrated code retains unnecessary underscores. This is again something prevalent in code manually migrated from the pipe-last to pipe-first operator.

Example tested on ReScript 12 RC3:

@deprecated({
  reason: "something",
  migrate: %insert.unlabelledArgument(1)->map2(%insert.unlabelledArgument(0)),
})
@val
external map: ('a => 'b, 'a) => 'b = "something"
/* let map = (fn, a) => fn(a) */

let map2 = (a, fn) => fn(a)

let test = a => {
  let fn = x => x * x
  map(fn, a) + a->map(fn, _)
}

Output:

let test = a => {
  let fn = x => x * x
  map2(a, fn) + a->map2(_, fn)
}

Desired output:

let test = a => {
  let fn = x => x * x
  a->map2(fn) + a->map2(fn)
}

CarlOlson avatar Nov 13 '25 09:11 CarlOlson