<< Back to previous view

[CLJS-300] RegExp objects print incorrectly Created: 04/Jun/12  Updated: 27/Jul/13  Resolved: 04/Jun/12

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Brandon Bloom Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: patch, patch,

Attachments: Text File print-regexp2.patch     Text File print-regex.patch    
Patch: Code and Test

 Description   

#"x" is currently printing as #</x/>

js/RegExp needs an IPrintable implementation: (-pr-seq [re _] (list "#\"" (.-source re) "\""))

Unfortunately, this is blocked by the same GClosure issue as http://dev.clojure.org/jira/browse/CLJS-68



 Comments   
Comment by David Nolen [ 04/Jun/12 3:58 PM ]

The simplest solution is to add a RegExp case to pr-seq.

Comment by Brandon Bloom [ 04/Jun/12 6:09 PM ]

That was surprisingly not that simple...

(instance? js/RegExp obj) compiles to `cljs.core.instance_QMARK_.call(null, RegExp, obj)` which also triggers the GClosure warning. So I thought I could inline `instance?` with a macro, but the instanceof operator's operands are in reverse order of instance?'s arguments. To preserve evaluation order, the expansion would be `(let t# ~t ('js* "({} instanceof ~{})" ~o t#))) however even that triggers the warning because the output leaves RegExp as an expression by itself again. I wound up just special-casing simple instanceof checks against symbols in the macro.

Attached patch fixes printing of RegExp objects and also enables calling (instance? js/RegExp X) without triggering the warning. Sadly, any more complex expression which evaluates to js/RegExp, or any higher order usage of instance? against that type will still trigger the warning.

Comment by Brandon Bloom [ 04/Jun/12 7:15 PM ]

As discussed, will make a separate ticket for inlining 'instance? and will (defn regexp? [o] (js* "~{o} instanceof RegExp"))

Comment by Brandon Bloom [ 04/Jun/12 8:46 PM ]

Updated with simplified patch

Comment by David Nolen [ 04/Jun/12 11:52 PM ]

fixed, http://github.com/clojure/clojurescript/commit/63cd8ce9c7c9a8864deb676f2b855b8018698d57

Generated at Sun Apr 20 11:17:51 CDT 2014 using JIRA 4.4#649-r158309.