ClojureScript

goog.global.Date/String etc don't work in non-browser advanced mode

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

goog.global resolves to something undefined in advanced mode when not in the browser. This prevents us from using e.g. goog.global.String

We should experiment with --use_only_custom_externs=true flag for these builds. The book also mentions:
http://code.google.com/p/closure-compiler/source/browse/trunk/externs/es3.js?r=996

Not having this is causing all kinds of ick as people use js* for everything

Activity

Hide
Stuart Halloway added a comment -

It appears that the disabled warnings in script/compile

--jscomp_off=undefinedVars \
  --jscomp_off=missingProperties \

are disabled because of js* stuff that would go away if this issue was solved. Can these warnings be re-enabled or are they necessary for some other reason?

Show
Stuart Halloway added a comment - It appears that the disabled warnings in script/compile
--jscomp_off=undefinedVars \
  --jscomp_off=missingProperties \
are disabled because of js* stuff that would go away if this issue was solved. Can these warnings be re-enabled or are they necessary for some other reason?
Hide
Stuart Halloway added a comment -

While experimenting with Advanced mode codegen, I found a workaround:

(defn ^:export _ggfn [] [goog.global])
(set! goog.global.String.prototype.call ...

compiles to

ba("cljs.core._ggfn", function() {
  return T([n])
});
n.H.prototype.call = function() {

The important thing above is the n. which refers to goog.global. Without the exported fn mentioning goog.global, the same set! code compiles to an invalid reference to this:

this.H.prototype.call = function() {

Interestingly, an exported def that refers to goog.global does not fix the problem, it has to be a defn.

Show
Stuart Halloway added a comment - While experimenting with Advanced mode codegen, I found a workaround:
(defn ^:export _ggfn [] [goog.global])
(set! goog.global.String.prototype.call ...
compiles to
ba("cljs.core._ggfn", function() {
  return T([n])
});
n.H.prototype.call = function() {
The important thing above is the n. which refers to goog.global. Without the exported fn mentioning goog.global, the same set! code compiles to an invalid reference to this:
this.H.prototype.call = function() {
Interestingly, an exported def that refers to goog.global does not fix the problem, it has to be a defn.
Hide
Rich Hickey added a comment -

I'm taking this. I understand the problem (we were looking at goog.global completely backwards), and a fix will require some language (or at least ns) magic.

Show
Rich Hickey added a comment - I'm taking this. I understand the problem (we were looking at goog.global completely backwards), and a fix will require some language (or at least ns) magic.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: