@iarenaza thanks for bringing it up 🙂
What is standard behavior for ratio literals in CLJS? We're seeing different behavior from the https://cljs.io/ REPL and from running tests via npx shadow-cljs compile test (https://github.com/jank-lang/clojure-test-suite/blob/main/bb.edn for more context)
CC @jeaye @droberts3
Yes no ratios, getting ratios to work is a biggish project, since it means adding a tower CLJS, also how not to slow down the reliance of the data structures on 32bit integer ops
What exactly is the difference in the behaviors? FWIW, the web REPL is made with self-hosted CLJS. I assume your tests use regular CLJS.
Ratios are not supported in .cljs and .cljc files/REPL's
https://github.com/clojure/clojurescript/blob/v1.12/src/main/clojure/cljs/compiler.cljc#L307-L308
cljs.user=> 1/2
Unexpected error (ExceptionInfo) compiling at (REPL:1).
failed compiling constant: 1/2; clojure.lang.Ratio is not a valid ClojureScript constant.
this replumb self-hosted REPL is a "custom build", that (maybe unintentionally) end up supporting ratios.IIRC it's just a self-hosted version of CLJS and there's nothing special about it.
CLJS, when self-hosted, uses a CLJS reader and not a CLJ one - so there can be no errors about clojure.lang.Ratio.
Here's how it behaves in a vanilla self-hosted CLJS:
(cljs/eval-str st "1/2"
nil
{:eval node-eval
:context :expr}
(fn [res]
(println res)))
{:ns cljs.user, :value 0.5}
nil
cljs.user=>The culprit is cljs.tools.reader.impl.commons/match-number - it matches against (def ratio-pattern #"([-+]?[0-9]+)/([0-9]+)") and emits a plain division via cljs.tools.reader.impl.commons/match-ratio.
@dnolen Great! Thank you. I must have looked at the wrong commit version, because I saw that 1.12 was still depending on the vulnerable version of the dependency. Sorry for the noise!