Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLJS-3375: Bridge tools.reader #178

Merged
merged 4 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
<configuration>
<cleanAOTNamespaces>true</cleanAOTNamespaces>
<namespaces>
<namespace>!clojure.tools.reader.*</namespace>
<namespace>!cljs.vendor.bridge</namespace>
</namespaces>
</configuration>
</execution>
Expand Down
12 changes: 10 additions & 2 deletions src/main/clojure/cljs/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4395,6 +4395,14 @@
((juxt :requires :require-macros :as-aliases)
(get-namespace ns))))

(defn get-bridged-alias-map
"Returns clojure.tools.reader/*alias-map* for bridging"
[]
(try
@(ns-resolve 'clojure.tools.reader '*alias-map*)
(catch Throwable t
nil)))

#?(:clj
(defn forms-seq*
"Seq of Clojure/ClojureScript forms from rdr, a java.io.Reader. Optionally
Expand Down Expand Up @@ -4795,7 +4803,7 @@
*unchecked-arrays* false])
*cljs-ns* 'cljs.user
*cljs-file* nil
reader/*alias-map* (or reader/*alias-map* {})]
reader/*alias-map* (or (get-bridged-alias-map) reader/*alias-map* {})]
(loop [ns nil forms forms last-ast nil]
(if (some? forms)
(let [form (first forms)
Expand Down Expand Up @@ -4853,7 +4861,7 @@
(if (or skip-cache (not cache) (requires-analysis? res cache output-dir opts))
(binding [*cljs-ns* 'cljs.user
*cljs-file* path
reader/*alias-map* (or reader/*alias-map* {})]
reader/*alias-map* (or (get-bridged-alias-map) reader/*alias-map* {})]
(when (or *verbose* (:verbose opts))
(util/debug-prn "Analyzing" (str res)))
(let [env (assoc (empty-env) :build-options opts)
Expand Down
2 changes: 1 addition & 1 deletion src/main/clojure/cljs/compiler.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@
(binding [*out* out
ana/*cljs-ns* 'cljs.user
ana/*cljs-file* (.getPath ^File src)
reader/*alias-map* (or reader/*alias-map* {})
reader/*alias-map* (or (ana/get-bridged-alias-map) reader/*alias-map* {})
ana/*checked-arrays* (or ana/*checked-arrays* (:checked-arrays opts))
ana/*cljs-static-fns* (or ana/*cljs-static-fns* (:static-fns opts))
*source-map-data* (when (:source-map opts)
Expand Down
4 changes: 4 additions & 0 deletions src/main/clojure/cljs/repl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,10 @@
[cljs.pprint :refer [pprint] :refer-macros [pp]]]
bind-err true}
:as opts}]
;; bridge clojure.tools.reader to satisfy the old contract
(when (and (find-ns 'clojure.tools.reader)
(not (find-ns 'cljs.vendor.bridge)))
(clojure.core/load "vendor/bridge"))
(doseq [[unknown-opt suggested-opt] (util/unknown-opts (set (keys opts)) (set/union known-repl-opts cljsc/known-opts))]
(when suggested-opt
(println (str "WARNING: Unknown option '" unknown-opt "'. Did you mean '" suggested-opt "'?"))))
Expand Down
42 changes: 42 additions & 0 deletions src/main/clojure/cljs/vendor/bridge.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

(ns cljs.vendor.bridge
(:require [cljs.vendor.clojure.tools.reader.reader-types :as vendor]
[clojure.tools.reader.reader-types :as readers]))

(extend-protocol vendor/Reader
clojure.tools.reader.reader_types.Reader
(read-char [reader]
(readers/read-char reader))
(peek-char [reader]
(readers/peek-char reader)))

(extend-protocol vendor/IPushbackReader
clojure.tools.reader.reader_types.IPushbackReader
(unread [reader ch]
(readers/unread reader ch)))

(extend-protocol vendor/IndexingReader
clojure.tools.reader.reader_types.IndexingReader
(get-line-number [reader]
(readers/get-line-number reader))
(get-column-number [reader]
(readers/get-column-number reader))
(get-file-name [reader]
(readers/get-file-name reader)))

(extend-protocol vendor/ReaderCoercer
clojure.tools.reader.reader_types.ReaderCoercer
(to-rdr [reader]
(readers/to-rdr reader)))

(extend-protocol vendor/PushbackReaderCoercer
clojure.tools.reader.reader_types.PushbackReaderCoercer
(to-pbr [reader buflen]
(readers/to-pbr reader buflen)))