Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active February 18, 2016 18:24
Show Gist options
  • Select an option

  • Save ochafik/f6b0a2fe02b4f6f01bc2 to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/f6b0a2fe02b4f6f01bc2 to your computer and use it in GitHub Desktop.
// http://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F**%250A%2520*%2520%2540template%2520T%250A%2520*%2520%2540param%2520%257BT%257D%2520t%250A%2520*%2520%2540return%2520%257BT%257D%250A%2520*%252F%250Afunction%2520pass(t)%2520%257B%2520return%2520t%2520%257D%250A%250Aclass%2520Foo%2520%257B%250A%2520%2520bar()%2520%257B%2520return%25201%2520%257D%250A%257D%250A%250Aconsole.log(pass(new%2520Foo()).bar())%253B%2520%252F%252F%2520console.log(1)%253B%250Aconsole.log(pass(null).bar())%253B%2520%2520%2520%2520%2520%2520%252F%252F%2520console.log(1)%253B%250A
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @formatting pretty_print
// ==/ClosureCompiler==
/**
* @template T
* @param {T} t
* @return {T}
*/
function pass(t) { return t }
class Foo {
bar() { return 1 }
}
console.log(pass(new Foo()).bar()); // console.log(1);
console.log(pass(null).bar()); // console.log(1);
// ^ warning: No properties on this expression
// http://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250Aclass%2520Foo%2520%257B%250A%2509bar()%2520%257B%2520return%25201%2520%257D%250A%257D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257BFoo%257D%2520x%250A%2520*%2520%2540return%2520boolean%250A%2520*%252F%250Afunction%2520checkIsFoo(x)%2520%257B%250A%2520%2520if%2520(!(x%2520instanceof%2520Foo))%2520throw%2520new%2520Error('Not%2520a%2520Foo!')%253B%250A%257D%250A%250A%252F**%2520%2540param%2520%257B!Foo%257D%2520foo%2520*%252F%250Afunction%2520takeFooCheck(foo)%2520%257B%250A%2520%2520checkIsFoo(foo)%253B%250A%2520%2520console.log(foo.bar())%253B%250A%2520%2520console.log(foo)%253B%250A%257D%250A%250AtakeFooCheck(new%2520Foo())%253B%2520%252F%252F%2520var%2520c%2520%253D%2520new%2520a%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520b(c)%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520console.log(1)%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520console.log(c)%253B%250A%250AtakeFooCheck(null)%253B%250A%252F%252F%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%255E%2520warning%253A%2520actual%2520parameter%25201%2520of%2520takeFooCheck%2520does%2520not%2520match%2520formal%2520parameter%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520b(null)%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520console.log(1)%253B%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%252F%252F%2520console.log(null)%253B%250A%250A
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @formatting pretty_print
// ==/ClosureCompiler==
class Foo {
bar() { return 1 }
}
/**
* @param {Foo} x
* @return boolean
*/
function checkIsFoo(x) {
if (!(x instanceof Foo)) throw new Error('Not a Foo!');
}
/** @param {!Foo} foo */
function takeFooCheck(foo) {
checkIsFoo(foo);
console.log(foo.bar());
console.log(foo);
}
takeFooCheck(new Foo()); // var c = new a;
// b(c);
// console.log(1);
// console.log(c);
takeFooCheck(null);
// ^ warning: actual parameter 1 of takeFooCheck does not match formal parameter
// b(null);
// console.log(1);
// console.log(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment