How do I force the native version of google-closure-compiler to be used? - google-closure-compiler

I can import the closure-compiler like this:
const ClosureCompiler = require('google-closure-compiler').compiler;
but that uses the java version. I have a limitation on the build machines at work such that I can't make use of java. I was hoping to force the compilation to use the native version. I've tried doing something like this:
const ClosureCompiler = require('google-closure-compiler-osx').compiler;
That seems to result in ClosureCompiler being undefined. I've gone around and around trying to find any documentation on the API exposed to javascript but I keep coming up with nothing.
If anyone has an idea about how to force native compilation rather than java compilation it would be much appreciated.

I think I've made some progress on this by looking at what's going on in the cli.js and util.js files inside node_modules/google-closer-compiler.
This pattern appears to be working:
const ClosureCompiler = require('google-closure-compiler').compiler,
compilerInstance = new ClosureCompiler({... setup opts ...});
// Force native compilation
let compilerPlatform = 'linux';
switch (process.platform) {
case 'win32': compilerPlatform = 'windows'; break;
case 'darwin': compilerPlatform = 'osx'; break;
}
compilerInstance.JAR_PATH = null;
compilerInstance.javaPath = require('google-closure-compiler-' + compilerPlatform);
compilerInstance.run((exitCode, stdOut, stdErr) => {
... do some stuff ...
});

Related

How to stop warnings for functions without DefinitelyTyped?

If some function or library does not have DefinitelyTyped, I know these two ways to stop warnings.
interface Navigator {
getUserMedia: any
}
declare let RTCIceCandidate: any;
But right now, this 3rd-part library Collection2 is used like this:
let ProductSchema = {};
let Products = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);
It give me a warning:
Property 'attachSchema' does not exist on type 'Collection'.
I tried the way below, but it does not work.
interface Collection {
attachSchema: any
}
How can I stop this warning? Thanks
EDIT:
Eric's adding any way solves the problem.
let Products:any = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);
But now a new trouble comes:
let UserSchema = {};
Meteor.users.attachSchema(UserSchema);
Since Meteor.users is built in, so there is no place to add any. How to solve this? Thanks
Thanks for Amid's help. So the way is:
(<any>Meteor.users).attachSchema(UserSchema);

document.querySelectorAll not defined

I am following a calculator tutorial from here: http://thecodeplayer.com/walkthrough/javascript-css3-calculator
However I am using nitrous as the IDE and Meteor. In this part of the code in the js file:
// Get all the keys from document
var keys = **document.querySelectorAll**("#calculator span");
var operators = ['+', '-', 'x', 'รท'];
var decimalAdded = false;
The 'document.querySelector All' part comes up with a not defined error. I have tried replacing it with the more Meteor friendly 'template. find' however then it just says that template is not defined. Any help would be very much appreciated. :)

Get quickshare url with javascript

I want to share a document with JavaScript and get its share_id programatically.
There is a REST API that can do that but I didn't know how to call it from script.
Any clues?
The following hack will do the trick. (edit: Must be executed from the classpath in the repository)
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var qsService = ctx.getBean("QuickShareService");
var sId = document.properties['qshare:sharedId'];
if (!sId) {
sId = qsService.shareContent(document.nodeRef).id;
}
PS: It looks even more ugly on 5.0.a due to rhino-1.7.

Handlebars.js: how does partials gets invoked in a helper? I got: TypeError: fn is not a function

I am learning Handlebars. It still appears to be a mystery to me that how a partials gets invoked in a helper.
I read this tutorial: http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers
From this example in the tutorial,
Handlebars.registerHelper("stripes", function(array, even, odd, fn) {
var buffer = "";
for (var i = 0, j = array.length; i < j; i++) {
var item = array[i];
// we'll just put the appropriate stripe class name onto the item for now
item.stripeClass = (i % 2 == 0 ? even : odd);
// show the inside of the block
buffer += fn(item); <!-- this is where a partials gets invoked -->
}
// return the finished buffer
return buffer;
});
it appears the partial is added and applied by Handlebars. However, I used this same approach in Handablebars 1.3.0 and 2.0 Alpha-2, it seems no longer the case. I always got the error:
TypeError: fn is not a function
buffer += fn(item);
I did quite online search and found a number tutorials, but none of them shows how partials is hooked up with a helper in version 1.3.0 or later.
Can someone help me out?
Thanks a lot!
OK. I believed I solved this problem. In v1.0 or later, Handlebars puts everything in a hash, not just fn. So, everything in the above post still is valid except these two lines:
Handlebars.registerHelper("stripes", function(array, even, odd, options)
...
buffer += options.fn(item);
Hope this helps someone else. Any confirmation is welcome. I feel bad that there is no direct example on this, at least I did not find it.
Regards.

JSHint and "Tolerate Variable Shadowing"

Does anybody know why this code does not produce errors in JSHint?
I think it should give me a variable shadowing warning but I'm not getting one.
I have "Tolerate Variable shadowing" as false am using the visual studio plugin.
RES.test = function () {
var test, f;
f = function () {
var test;
window.alert(test);
};
};
Thanks.
I just stumbled onto this too. Apparently JSHint developers' definition of "shadowing" is not what you expect. For them, hiding a variable name coming from a closure is not shadowing. And yes, I find it strange too :-)
If you look at their test suite, they mean something like "redefinition", where you do
var a = 1;
...
var a = 2;
look at their test case: https://github.com/jshint/jshint/blob/master/tests/stable/unit/fixtures/redef.js

Resources