Uploaded image for project: 'ClojureScript'
  1. CLJS-2040

Fix assumption that all closure-compliant JS is goog.*

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • Affects versions: None
    • Fix versions: None
    • Labels:
      None
    • Patch:
      Code and Test

      Description

      The CLJS compiler assumes that all Closure compatible JS will be in the `goog.*` namespace.

      This assumption is bad and produces non-optimal code if there is any other Closure JS files in a build.

      (ns foo.main
        (:require [dummy.foo :as x]
                  [goog.string :as gstr]))
      
      ;; good
      (gstr/urlEncode "foo")
      
      ;; bad
      (x/demo 1 2)
      

      With dummy.foo being the Closure JS file will produce:

      // Compiled by ClojureScript 1.9.521 {:static-fns true}
      goog.provide('foo.main');
      goog.require('cljs.core');
      goog.require('dummy.foo');
      goog.require('goog.string');
      goog.string.urlEncode("foo");
      (dummy.foo.demo.cljs$core$IFn$_invoke$arity$2 ? dummy.foo.demo.cljs$core$IFn$_invoke$arity$2((1),(2)) : dummy.foo.demo.call(null,(1),(2)));
      
      //# sourceMappingURL=main.js.map
      

      The gstr/urlEncode uses the good form but the x/demo invoke uses the CLJS style invoke and will always end up in .call.

      The code still works but should be optimized.

      dummy.foo.demo((1),(2));
      

      The added patch adds an additional check to see if we have analyzer data for a given invoke, if that is not the case it will treat it as a goog? call.

        Attachments

          Activity

            People

            • Assignee:
              dnolen David Nolen
              Reporter:
              thheller Thomas Heller
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: