From 0037050d22ceb6032e7651b584be02e264265236 Mon Sep 17 00:00:00 2001 From: davidnolen Date: Fri, 29 Nov 2024 07:53:07 -0500 Subject: [PATCH] * remove deprecated Closure externs pattern --- src/main/clojure/cljs/closure.clj | 5 +++-- src/main/clojure/cljs/externs.clj | 18 +++++++++++------- .../clojure/cljs/externs_parsing_tests.clj | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/clojure/cljs/closure.clj b/src/main/clojure/cljs/closure.clj index cf589b85c..28faeb04d 100644 --- a/src/main/clojure/cljs/closure.clj +++ b/src/main/clojure/cljs/closure.clj @@ -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] @@ -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"))))))) diff --git a/src/main/clojure/cljs/externs.clj b/src/main/clojure/cljs/externs.clj index 5da818a72..c50cf0c8d 100644 --- a/src/main/clojure/cljs/externs.clj +++ b/src/main/clojure/cljs/externs.clj @@ -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] @@ -23,6 +23,9 @@ (def ^:dynamic *source-file* nil) (def ^:dynamic *goog-ns* nil) +(defn default-externs [] + (CommandLineRunner/getBuiltinExterns CompilerOptions$Environment/BROWSER)) + ;; ------------------------------------------------------------------------------ ;; Externs Parsing @@ -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 @@ -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 @@ -376,13 +380,13 @@ (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) @@ -390,7 +394,7 @@ (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) diff --git a/src/test/clojure/cljs/externs_parsing_tests.clj b/src/test/clojure/cljs/externs_parsing_tests.clj index c2b199cf1..effad773d 100644 --- a/src/test/clojure/cljs/externs_parsing_tests.clj +++ b/src/test/clojure/cljs/externs_parsing_tests.clj @@ -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)))))