This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-08
Channels
- # announcements (2)
- # asami (2)
- # babashka (7)
- # beginners (59)
- # cider (12)
- # cljdoc (1)
- # cljs-dev (18)
- # clojure (23)
- # clojure-europe (15)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-uk (5)
- # clojured (16)
- # clojurescript (22)
- # core-typed (8)
- # cursive (3)
- # datomic (24)
- # events (2)
- # fulcro (4)
- # gratitude (1)
- # helix (13)
- # hoplon (18)
- # integrant (2)
- # introduce-yourself (1)
- # jobs-discuss (1)
- # joyride (5)
- # minecraft (1)
- # off-topic (76)
- # pathom (18)
- # podcasts (8)
- # polylith (11)
- # remote-jobs (4)
- # rewrite-clj (22)
- # sci (4)
- # shadow-cljs (152)
- # sql (4)
- # tools-build (26)
- # tools-deps (34)
Seems like some RegEx patterns are broken. This just popped up: https://clojurians.slack.com/archives/C03S1L9DN/p1654705094721129 And there have been questions just like this throughout the years - just do a Slack search for "Invalid regular expression flag". The culprit seems to be this code:
(defmethod emit-constant* #?(:clj java.util.regex.Pattern :cljs js/RegExp) [x]
(if (= "" (str x))
(emits "(new RegExp(\"\"))")
(let [[_ flags pattern] (re-find #"^(?:\(\?([idmsux]*)\))?(.*)" (str x))]
#?(:clj (emits \/
(.replaceAll (re-matcher #"/" pattern) "\\\\/")
\/ flags)
:cljs (emits pattern)))))
In the context of the linked thread, what once was #"(\/\/).*"
in CLJS becomes /(\\/\\/).*/
in JS, which is obviously invalid.I don't think there is much actionable here though - unless you trying are to propose something
I think you would need to review what Google Closure does here under advanced compilation - I thought it optimized some obvious cases. Also the ticket should probably at least reference what the VMs optimize if at all.
How is Closure relevant here if the current approach doesn't work without any optimizations?
so just suggested what you're proposing if you'd like try it out, then make an issue a patch and back it up w/ some facts about the performance impact
Oh, so GCC rewrites regular expressions themselves, like e.g. turning aa|ab
into a[ab]
? Huh!
googling for this brought up https://github.com/google/closure-compiler/issues/423