ClojureScript

Unnecessarily escaped forward-slash in regex produces invalid JS

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

When compiling an escaped forward slash in a regex literal (muscle memory from Javascript syntax), ClojureScript will emit invalid Javascript, ie. it will emit an escaped back slash instead, and a terminating forward slash.

In bare node repl:

(re-find #"\/" "a/b")

generates the invalid expression:

(function (){var ret__3746__auto__ = cljs.core.re_find.call(null,/\\//,"a/b");

Interestingly both this and the unescaped variation (#"/") work correctly in Planck (and regular Clojure).

Creating the regex manually throws a reader error, because the string literal is illegal:

cljs.user=> "\/"
clojure.lang.ExceptionInfo: Unsupported escape character: \/ {:type :reader-exception, ...}

Unsure of whether a reader error or "we know what you meant" behaviour is preferable.

Activity

Hide
David Nolen added a comment -

Wary of "we know what you meant". I suspect there will be many cases like this. By the same token wary of specific error messages here, how many cases will we need to cover?

Show
David Nolen added a comment - Wary of "we know what you meant". I suspect there will be many cases like this. By the same token wary of specific error messages here, how many cases will we need to cover?
Hide
Chris Truter added a comment -

Thanks for the help David, I've confirmed this is an issue in tools.reader.

Show
Chris Truter added a comment - Thanks for the help David, I've confirmed this is an issue in tools.reader.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: