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

`String.length` not inlined in v10

Open cristianoc opened this issue 2 years ago • 2 comments

This:

let stringLengthNoSideEffects = String.length("sdkdl")

now produces

var stringLengthNoSideEffects = "sdkdl".length;

while it used to be

var stringLengthNoSideEffects = 5;

cristianoc avatar Jun 27 '22 03:06 cristianoc

This is because the parser now sends strings as unicode, and the compiler does not have a length function that matches the one of JS (utf16 code units). Otherwise it could compute it at compile time in string_length inside js_exp_make.ml.

cristianoc avatar Jun 30 '22 01:06 cristianoc

The parser might already have such a function and if so one could hook it up to the compiler.

cristianoc avatar Jun 30 '22 01:06 cristianoc