|
37 | 37 | CompilerInput CompilerInput$ModuleType DependencyOptions
|
38 | 38 | CompilerOptions$LanguageMode SourceMap$Format
|
39 | 39 | SourceMap$DetailLevel ClosureCodingConvention SourceFile
|
40 |
| - Result JSError CheckLevel DiagnosticGroups |
41 |
| - CommandLineRunner AnonymousFunctionNamingPolicy |
42 |
| - JSModule SourceMap VariableMap PrintStreamErrorManager] |
| 40 | + Result JSError CheckLevel DiagnosticGroup DiagnosticGroups |
| 41 | + CommandLineRunner |
| 42 | + JSModule SourceMap VariableMap PrintStreamErrorManager DiagnosticType |
| 43 | + VariableRenamingPolicy PropertyRenamingPolicy] |
43 | 44 | [com.google.javascript.jscomp.bundle Transpiler]
|
44 | 45 | [com.google.javascript.jscomp.deps ClosureBundler ModuleLoader$ResolutionMode ModuleNames
|
45 | 46 | SimpleDependencyInfo]
|
46 | 47 | [com.google.javascript.rhino Node]
|
47 | 48 | [java.nio.file Path Paths Files StandardWatchEventKinds WatchKey
|
48 | 49 | WatchEvent FileVisitor FileVisitResult FileSystems]
|
49 | 50 | [java.nio.charset Charset StandardCharsets]
|
50 |
| - [com.sun.nio.file SensitivityWatchEventModifier] |
51 |
| - [com.google.common.base Throwables])) |
| 51 | + [com.sun.nio.file SensitivityWatchEventModifier])) |
52 | 52 |
|
53 | 53 | ;; Copied from clojure.tools.gitlibs
|
54 | 54 |
|
|
162 | 162 | :message-descriptions DiagnosticGroups/MESSAGE_DESCRIPTIONS
|
163 | 163 | :misplaced-msg-annotation DiagnosticGroups/MISPLACED_MSG_ANNOTATION
|
164 | 164 | :misplaced-type-annotation DiagnosticGroups/MISPLACED_TYPE_ANNOTATION
|
165 |
| - :missing-getcssname DiagnosticGroups/MISSING_GETCSSNAME |
166 | 165 | :missing-override DiagnosticGroups/MISSING_OVERRIDE
|
167 | 166 | :missing-polyfill DiagnosticGroups/MISSING_POLYFILL
|
168 | 167 | :missing-properties DiagnosticGroups/MISSING_PROPERTIES
|
|
175 | 174 | :non-standard-jsdoc DiagnosticGroups/NON_STANDARD_JSDOC
|
176 | 175 | :report-unknown-types DiagnosticGroups/REPORT_UNKNOWN_TYPES
|
177 | 176 | :strict-missing-properties DiagnosticGroups/STRICT_MISSING_PROPERTIES
|
178 |
| - :strict-missing-require DiagnosticGroups/STRICT_MISSING_REQUIRE |
179 | 177 | :strict-module-dep-check DiagnosticGroups/STRICT_MODULE_DEP_CHECK
|
180 | 178 | :strict-requires DiagnosticGroups/STRICT_REQUIRES
|
181 | 179 | :suspicious-code DiagnosticGroups/SUSPICIOUS_CODE
|
|
262 | 260 | (when (contains? opts :pseudo-names)
|
263 | 261 | (set! (.generatePseudoNames compiler-options) (:pseudo-names opts)))
|
264 | 262 |
|
265 |
| - (when (contains? opts :anon-fn-naming-policy) |
266 |
| - (let [policy (:anon-fn-naming-policy opts)] |
267 |
| - (set! (.anonymousFunctionNaming compiler-options) |
268 |
| - (case policy |
269 |
| - :off AnonymousFunctionNamingPolicy/OFF |
270 |
| - :unmapped AnonymousFunctionNamingPolicy/UNMAPPED |
271 |
| - :mapped AnonymousFunctionNamingPolicy/MAPPED |
272 |
| - (throw (util/compilation-error (IllegalArgumentException. (str "Invalid :anon-fn-naming-policy value " policy " - only :off, :unmapped, :mapped permitted")))))))) |
273 |
| - |
274 | 263 | (when-let [lang-key (:language-in opts :ecmascript5)]
|
275 | 264 | (.setLanguageIn compiler-options (lang-key->lang-mode lang-key)))
|
276 | 265 |
|
|
816 | 805 | (if (seq requires)
|
817 | 806 | (let [node (or (get (@env/*compiler* :js-dependency-index) (first requires))
|
818 | 807 | (deps/find-classpath-lib (first requires)))
|
819 |
| - new-req (remove #(contains? visited %) (:requires node))] |
| 808 | + new-req (remove #(contains? visited %) |
| 809 | + (into (:requires node) (:require-types node)))] |
820 | 810 | (recur (into (rest requires) new-req)
|
821 | 811 | (into visited new-req)
|
822 | 812 | (conj deps node)))
|
|
2052 | 2042 | (.appendTo bundler sb module source)
|
2053 | 2043 | (.toString sb)))
|
2054 | 2044 |
|
| 2045 | +(defn ^DiagnosticGroup es5-warnings [] |
| 2046 | + (DiagnosticGroup. |
| 2047 | + (into-array DiagnosticType |
| 2048 | + [(DiagnosticType/error "JSC_CANNOT_CONVERT" "")]))) |
| 2049 | + |
| 2050 | +(defn ^CompilerOptions transpile-options [] |
| 2051 | + (doto (CompilerOptions.) |
| 2052 | + (.setQuoteKeywordProperties true) |
| 2053 | + (.setSkipNonTranspilationPasses true) |
| 2054 | + (.setVariableRenaming VariableRenamingPolicy/OFF) |
| 2055 | + (.setPropertyRenaming PropertyRenamingPolicy/OFF) |
| 2056 | + (.setWrapGoogModulesForWhitespaceOnly false) |
| 2057 | + (.setPrettyPrint true) |
| 2058 | + (.setSourceMapOutputPath "/dev/null") |
| 2059 | + (.setSourceMapIncludeSourcesContent true) |
| 2060 | + (.setWarningLevel (es5-warnings) CheckLevel/OFF))) |
| 2061 | + |
| 2062 | +(defn closure-transpile |
| 2063 | + "Transpile a single JavaScript file to JavaScript. Used to lower Closure |
| 2064 | + Library files written in more recent versions of the JavaScript standard." |
| 2065 | + ([rsc opts] |
| 2066 | + (closure-transpile (util/path rsc) (slurp rsc) opts)) |
| 2067 | + ([path source opts] |
| 2068 | + (let [cc (make-closure-compiler) |
| 2069 | + cc-opts (set-options opts (transpile-options)) |
| 2070 | + externs (SourceFile/fromCode "externs.js" "function Symbol() {}") |
| 2071 | + source (SourceFile/fromCode path source) |
| 2072 | + result (.compile cc externs source cc-opts)] |
| 2073 | + ;; TODO: error handling |
| 2074 | + (.toSource cc)))) |
| 2075 | + |
2055 | 2076 | ;; TODO: better error handling
|
2056 |
| -;; TODO: actually respect the target :language-out level |
2057 |
| -;; currently just using default options for Transpiler |
2058 | 2077 | (defn transpile
|
2059 |
| - [{:keys [language-out] :or {language-out :es3}} rsc {:keys [module lang] :as js}] |
| 2078 | + [{:keys [language-out] :or {language-out :es3} :as opts} rsc {:keys [module lang] :as js}] |
2060 | 2079 | (let [source (slurp rsc)
|
2061 | 2080 | source' (if (and lang
|
2062 | 2081 | (< (.indexOf lang-level (expand-lang-key language-out))
|
2063 | 2082 | (.indexOf lang-level (expand-lang-key lang))))
|
2064 |
| - (let [cc (Transpiler/compilerSupplier) |
2065 |
| - result (.compile cc (url->nio-path rsc) source)] |
2066 |
| - (.source result)) |
| 2083 | + (closure-transpile (util/path rsc) source opts) |
2067 | 2084 | source)]
|
2068 | 2085 | (str "/*TRANSPILED*/"
|
2069 | 2086 | (cond-> source'
|
|
3286 | 3303 | (if-let [f (opts-fn :watch-error-fn opts)]
|
3287 | 3304 | (f e)
|
3288 | 3305 | (binding [*out* *err*]
|
3289 |
| - (println (Throwables/getStackTraceAsString e))))))) |
| 3306 | + (println e)))))) |
3290 | 3307 | (watch-all [^Path root]
|
3291 | 3308 | (Files/walkFileTree root
|
3292 | 3309 | (reify
|
|
0 commit comments