Skip to content

Commit

Permalink
inst literals can now appear in source code
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrand committed Jun 30, 2023
1 parent 36f8074 commit cbc9e59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clj/src/cljd/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3176,6 +3176,9 @@
(symbol? x) (emit-symbol x env)
#?@(:clj [(char? x) (str x)])
(or (number? x) (boolean? x) (string? x)) x
(instance? java.util.Date x)
(let [[_ s] (re-matches #"#inst *\"(.*)\"" (pr-str x))]
(emit (list 'dart:core/DateTime.parse s) env))
(instance? java.util.regex.Pattern x)
(emit (list 'new 'dart:core/RegExp
#_(list '. 'dart:core/RegExp 'escape (.pattern ^java.util.regex.Pattern x))
Expand Down
3 changes: 3 additions & 0 deletions clj/test/cljd/test_clojure/core_test_cljd.cljd
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,6 @@
"hello"
.bar "world")))
(is (= #dart ("hey" .bar "foo") (.method2 obj #dart ("hey" .bar "foo"))))))

(deftest inst-literals-in-code
(is (= 1978 (.-year #inst "1978-10-11"))))

0 comments on commit cbc9e59

Please sign in to comment.