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

Remove deprecated Closure externs pattern #239

Merged
merged 2 commits into from
Nov 29, 2024
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
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
16 changes: 10 additions & 6 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,7 +233,7 @@

(defn externs-map*
([]
(externs-map* (CommandLineRunner/getDefaultExterns)))
(externs-map* (default-externs)))
([sources]
(externs-map* sources
'{eval {}
Expand All @@ -242,7 +246,7 @@
([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
Loading