ClojureScript

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

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: 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.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: