I've found what I believe to be a bug in ClojureScript regarding compilation of certain regex literals to JavaScript, a specific example being #"(?i)"
.
In some cases, #"(?i)"
will be compiled to the JavaScript syntax //i
, which is in fact not a JavaScript regex literal, but rather a JavaScript single line comment. This then comments out all remaining code on the same generated line, resulting in a syntax error when the code is run on a JavaScript runtime.
This minimal unit test example demonstrates the issue:
(ns regex-test
(:require [cljs.test :refer-macros [deftest testing is]]))
(deftest failing-test
(testing "Minimal reproduction"
(is (not (nil? #"(?i)")))))
As a side note, it's worth mentioning that (?i)
is not a valid native JavaScript regex in the first place, so I assume ClojureScript is trying to emulate compatibility with JVM regexes (where this is valid), and converting it to the nearest valid JS equivalent - either (?i:)
(e.g. at the REPL), or //i
(in compiled code, but which is syntactically not a JS regex literal at all).