Skip to content

Commit

Permalink
* remove deprecated Closure externs pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Nov 29, 2024
1 parent 9696bac commit 0037050
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/main/clojure/cljs/closure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

(ns cljs.closure
(:refer-clojure :exclude [compile])
(:require [cljs.util :as util :refer [distinct-by]]
(:require [cljs.externs :as externs]
[cljs.util :as util :refer [distinct-by]]
[cljs.core :as cljsm]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]
Expand Down Expand Up @@ -402,7 +403,7 @@
(cond->
(if use-only-custom-externs
all-sources
(into all-sources (CommandLineRunner/getDefaultExterns)))
(into all-sources (externs/default-externs)))
infer-externs
(conj (js-source-file nil
(io/file (util/output-directory opts) "inferred_externs.js")))))))
Expand Down
18 changes: 11 additions & 7 deletions src/main/clojure/cljs/externs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[clojure.java.io :as io]
[clojure.string :as string])
(:import [com.google.javascript.jscomp
CompilerOptions SourceFile JsAst CommandLineRunner]
CompilerOptions CompilerOptions$Environment SourceFile JsAst CommandLineRunner]
[com.google.javascript.jscomp.parsing Config$JsDocParsing]
[com.google.javascript.rhino
Node Token JSTypeExpression JSDocInfo$Visibility]
Expand All @@ -23,6 +23,9 @@
(def ^:dynamic *source-file* nil)
(def ^:dynamic *goog-ns* nil)

(defn default-externs []
(CommandLineRunner/getBuiltinExterns CompilerOptions$Environment/BROWSER))

;; ------------------------------------------------------------------------------
;; Externs Parsing

Expand Down Expand Up @@ -207,6 +210,7 @@
(.init (list source-file) '() compiler-options))
js-ast (JsAst. source-file)
^Node root (.getAstRoot js-ast closure-compiler)
;; TODO: switch to getFirstChild + getNext in the loop
nodes (.children root)]
(loop [nodes (cond-> nodes
;; handle goog.modules which won't have top-levels
Expand All @@ -229,20 +233,20 @@

(defn externs-map*
([]
(externs-map* (CommandLineRunner/getDefaultExterns)))
(externs-map* (default-externs)))
([sources]
(externs-map* sources
'{eval {}
global {}
goog {nodeGlobalRequire {}}
COMPILED {}
COMPILED {}v0900909
TypeError {}
Error {prototype {number {} columnNumber {}}}
ReferenceError {}}))
([sources defaults]
(let [sources (if-not (empty? sources)
sources
(CommandLineRunner/getDefaultExterns))]
(default-externs))]
(reduce
(fn [externs externs-file]
(util/map-merge
Expand Down Expand Up @@ -376,21 +380,21 @@
(fn [s]
(let [m (-> s parse-externs index-externs)]
(get-in m '[Window prototype console])))
(CommandLineRunner/getDefaultExterns))
(default-externs))

(->
(filter
(fn [s]
(= "externs.zip//webkit_dom.js" (.getName s)))
(CommandLineRunner/getDefaultExterns))
(default-externs))
first parse-externs index-externs
(find 'console) first meta)

(->
(filter
(fn [s]
(= "externs.zip//webkit_dom.js" (.getName s)))
(CommandLineRunner/getDefaultExterns))
(default-externs))
first parse-externs index-externs
(get-in '[Console prototype])
(find 'log) first meta)
Expand Down
2 changes: 1 addition & 1 deletion src/test/clojure/cljs/externs_parsing_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(filter
(fn [s]
(= "externs.zip//w3c_dom2.js" (.getName s)))
(CommandLineRunner/getDefaultExterns))
(externs/default-externs))
first externs/parse-externs externs/index-externs
(find 'HTMLDocument) first meta)]
(is (= 'Document (:super info)))))
Expand Down

0 comments on commit 0037050

Please sign in to comment.