doo
doo copied to clipboard
Support :none compilation with Rhino
Perhaps my googling was just weak, but was unable to find a good shim to use Rhino with {:optimizations :none, :main 'some.ns}
style builds, or to alter the builds to "just work" with Rhino.
Came up with a very hacky modification (paste at the top) to the runner script to get this working:
global = this;
this.console = {log: print};
var base = new java.io.File(arguments[0]).getParent();
this.document = {};
this.document.getElementsByTagName = function () {
return [{src: (base + '/output.out/goog/base.js')}];
}
this.document.write = function (source) {
var src = source.match(/^<script src="([^"]+)"/)
if (src) {
var src = src[1];
if ('/' !== src[0]) src = base + '/' + src;
load(src);
} else {
var code = source.substring(8, source.length - 9);
eval(code);
}
};
this.CLOSURE_IMPORT_SCRIPT = function(src) { load(src); };
Note that {:output-dir ...}
from the CLJS compilation options is used (know you were interested in possible uses for other params).
... obviously hope there is a better way however!
We could try out but I wouldn't want to run it for every other optimization mode. I'll think about the best way to communicate to the runners the compiler settings so that they can make decisions. This might open new possibilities in every runner.
Also, we need to find a reason to support rhino :none
besides "for completeness sake". It might not be worth the trouble if people never use it.
Passing in the options is interesting, but not sure the best way to pass named arguments in - positional would be awkward and hard to extend.
I'll add an error in boot-cljs-test
for this combination for now - unfortunately wasted some time looking in completely the wrong direction last night stumbling on this and thinking it was a regression due to boot-clj
updates, and would spare others the pain.
On a loose tangent, this demonstrated a false positive with the "cljs.test not required" heuristic ("was goog loaded?" and "was runner namespace loaded?" are perhaps useful additional pre-checks)
Are you talking about this?
The check for "what has been properly loaded" should be more comprehensive. The only thing that prevented me was that it would be the exact same code in every runner and I hadn't figure out how to share code among the runners (still can't!). New issue for this at #21
After looking at CLJS-1076, I realize two things:
- All efforts should be directed at working with Nashorn not Rhino
- Getting Rhino/Nashorn to work with
:none
needs to be sorted out in the compiler first.
Once CLJS-1076 is solved (which implies community interest) we can support it in doo
. In the meanwhile, assert-compiler-opts
will continue to warn about a case that the compiler doesn't support.
https://dev.clojure.org/jira/browse/CLJS-1076
Look at the status, that issue was closed, so can we get this done as well? Thanks.
Hi @huahaiy ,
Thanks for noticing it! A PR would be welcome.