Questions tagged [bucklescript]

BuckleScript was previously known as a compiler for compiling OCaml to efficient JavaScript code. It has now evolved into the ReScript language. Use the [rescript] tag instead.

BuckleScript was previously known as a back-end for which emits readable, modular and highly performant JavaScript.

On July 2020, BuckleScript (and some parts of the ReasonML syntax) evolved into the ReScript language platform. The term "BuckleScript" is therefore deprecated. Use the tag for BuckleScript specific questions instead.

Useful resources

Related tags

181 questions
1
vote
2 answers

How to catch the Failure exception raised during number parsing in ReasonML

I'm new to Reason. I want to parse a float from a string with proper exception handling. This works: let number = try (float_of_string("1,")) { | _ => 0.0; }; But I want to do something like this: let number = try (float_of_string("1,")) { |…
Jakub Zawiślak
  • 5,122
  • 2
  • 16
  • 21
1
vote
2 answers

How to decode GeoJson in ReasonML?

Please comment how to decode a GeoJson file in ReasonML? I try to decode coordinates without "field latitude & longitude" in decoder, but I cannot find any information how to parse the field coordinates in the JSON file. GeoJson file "features":…
madeinQuant
  • 1,721
  • 1
  • 18
  • 29
1
vote
1 answer

How to add a listener for all scroll events?

I need to add a listener for all scroll events in Reason React or all scroll affects affecting the main window (either would work). Trying this but the event does not trigger: open Webapi.Dom; Document.addEventListener("scroll", onScroll); P.S.…
Peteris
  • 3,548
  • 4
  • 28
  • 44
1
vote
1 answer

"exports is not defined" when loading svg icon

I'm using the svg-sprite-loader plug-in when trying to load an icon from an svg sprite file, however, the page fails with webpack error "exports is not defined". What could be happening? How can one debug webpack loaders like this and get more…
Peteris
  • 3,548
  • 4
  • 28
  • 44
1
vote
1 answer

bs-platform version mismatch

I have a global bs-platform installation and a local one for a local project. They are in different versions. Everything was fine until today. Every time I try to run my local project, the following error is thrown: bs-platform version mismatch…
Jefferson Carvalho
  • 298
  • 1
  • 5
  • 9
1
vote
1 answer

Can I use OCaml regular expressions from BuckleScript? (Str.search_forward in particular)

I am porting an OCaml project to ReasonML, but first to BuckleScript. I seeded the project directory with bsb init . and copied over the *.ml files. Compiling with npm run build gives me error: [1/6] Building src/demo.cmj File…
user3603546
  • 325
  • 2
  • 11
1
vote
3 answers

Piping first multiple variables into functions

I have code in BuckleScript: let add = (x, y) => x+y; 2 -> (3 -> add); I would expect it to compile for obvious reasons. But it doesn't. I get '|.' is not a valid value identifier. Why? Cheers.
Dominik Teiml
  • 505
  • 1
  • 4
  • 12
1
vote
1 answer

How to flatten a list of options

I have this piece of code now: results |> List.filter(Belt.Option.isSome) |> List.map(item => switch (item) { | Some(item) => item } ) Can anyone make it shorter? It is a filter that removes the non-valid values followed by…
FelixHJ
  • 1,071
  • 3
  • 12
  • 26
1
vote
2 answers

Reason React using js component

I'm having trouble with js interop. I'm trying to use a js component react-slick like this: // src/interop/Carousel.js import React from 'react' import Slider from 'react-slick' export function Carousel(props) { return (
Minh Thai
  • 568
  • 6
  • 18
1
vote
1 answer

How do I update a JS Typed Array from Reason?

I'm trying to update the ImageData of a Canvas's image context, and when I try to set elements in the data array, I get an error saying the array has type Js.Typed_array.Uint8ClampedArray.t when something expected array('a). Why can't I update a JS…
Brendan Berg
  • 1,918
  • 2
  • 19
  • 22
1
vote
1 answer

how to properly handle the result type of raw js function call in bucklescript

Bucklescript allows one to define raw js function calls, but it's not clear to me how the return type should be handled. It seems one can use any type and it'll still work. For example, this code compiles and runs without problems: let f = [%raw {| …
yewang
  • 585
  • 7
  • 14
1
vote
1 answer

Reason: Error: Unbound value not__ for bs-jest

Trying to test a binding of lit-html method html open Jest; let write = () => LitHtml.html("
"); open Expect; describe("LitHtml", () => test("#html", () => expect(() => write() ) |> not_ |> toThrow ) ); I am told this…
1
vote
0 answers

reason-react cannot find module bs-platform

Setup I have an existing elixir/phoenix web app with a frontend of vanillajs / React (via react-phoenix). I'm using brunch to bundle everything. Goal I want my existing js react components to be able to import and use reason-react components. I…
AaronCoding
  • 158
  • 1
  • 6
1
vote
1 answer

Turn on stack traces for exceptions in bucklescript

I'm trying to port some OCaml tests from OUnit2 to bs-jest, but I get a Not_found exception raised from some test and I don't know where it's coming from; is there a way to enable stack traces in bucklescript? In OCaml, I would pass the -g option to…
Lionel Parreaux
  • 1,115
  • 1
  • 9
  • 22
1
vote
1 answer

How to get current year?

Is there a way to get the current year in Reason? I found a library called bs-luxon, but I can't use it. I've installed it as the site says, but I don't know how to import it. How can I use this library or other way to get the current year?
Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43