google-closure-compiler

How to make angular decorators minification friendly?

拈花ヽ惹草 提交于 2019-12-06 02:06:27
问题 How to can I make this code that I have minification friendly? MyModule.config(['$provide',function($provide) { $provide.decorator("$exceptionHandler", function($delegate,$injector) { I can't seem to do this: $provide.decorator("$exceptionHandler" , "$delegate","$injector", function($delegate,$injector) { 回答1: You are missing the [ . The pattern is the same that you successfully applied for config : $provide.decorator("$exceptionHandler" , [ "$delegate","$injector", function($delegate,

Google Closure Compiler: How to preserve code that caches “this”?

元气小坏坏 提交于 2019-12-05 21:57:19
Introduction I use Google Closure Compiler frequently for compressing my JavaScript files. Now, it seems to compress my code fairly well. Now, I try to make a habit of storing the this object in a local variable, because this cannot be obfuscated, but a local variable certainly can be obfuscated. However, Google Closure Compiler does not recognize this, and instead removes all instances of the local variable, replacing it with this . Regarding optimization... I am well aware that one should avoid pre-optimization when writing code. However, I feel that caching this is acceptable because doing

How do I use Google Closure compiler to remove unused JavaScript code?

泄露秘密 提交于 2019-12-05 21:34:58
问题 How do I use Google Closure compiler to remove unused code? I am using the JQuery Slider control but am not using anything else within JQuery. So I read that Google Closure compiler in Advanced mode can remove unused code, but I don't know how . I have frontpage.html that links to an external JQuery, JQuery UI and JQuery Slider control from that html page hosted on my site. On my frontpage.html, I also have JavaScript embedded within the HTML that initiates the JQuery Slider control. How do I

Why is Google Closure Compiler failing on my ES6 object which extends Date()?

风格不统一 提交于 2019-12-05 15:39:29
Please note: this question relates to the use of Google's Closure Compiler. It's not directly about ES6, since that part is working. I've written a class in ES6 which extends the native Date object. It's a large class, but this is a simplified version: class Dative extends Date { constructor (dateData) { super(); super.setTime(Date.parse(dateData)); } addMilliseconds (ms) { super.setTime(super.getTime() + ms); } } The code above works fine in Chrome and Firefox. However, when I pass it through Closure Compiler, it throws errors: Uncaught TypeError: Method Date.prototype.setTime called on

Adding sub-properties to an existing property-list in jsdoc

邮差的信 提交于 2019-12-05 14:54:47
I am trying to automate a particular module in our JS library and am stuck at a point where I want to define a set of properties (lets say an object that goes as construction parameter of a class). /** * This function initiates world peace! * @constructor * @param {object} defaults - The options to initiate peace. * @param {number} defaults.issues - The number of issues being taken up. * @param {string} defaults.source - The name of the location where process starts. */ var WorldPeace = function (defaults) { // code here }; It is well and good had all properties of the construction was defined

Why does Google Closure Compiler adds variable to the global namespace when the original namespace was empty?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 14:35:25
I have a long script nicely wrapped into a (function() {/.../})() to avoid all kind of name pollution. It is 100% typed with zero warning. I found out that Google Closure compiler starts by redefining i and j in the global namespace which feels both unnecessary and dangerous, especially since I am compiling a script that has zero interference with the namespace. (the compiled script starts with var i=null,j=!1; , for compactness reasons I believe). I can think of a work around which is to wrap it using the --output_wrapper but I can't think of a reason why Google would pollute the namespace

Typescript and Google Closure

 ̄綄美尐妖づ 提交于 2019-12-05 14:27:16
I use Typescript command (tsc) to create a single Javascript file containing all plateform classes. tsc "./Main.ts" -out "./script/myProject_debug.js" --declarations Then, I want to obfuscate this file with Google Closure (compiler.jar) like this : java -jar ./compiler/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js "./script/myProject_debug.js" > "./script/myProject.js". But when I execute the resulting obfuscated/optimized code, I got this following error : Uncaught TypeError: Cannot read property 'prototype' of undefined Which matches the following non-obfuscated JS code

Google closure variable window/event/console/… is undeclared error

妖精的绣舞 提交于 2019-12-05 11:59:20
I'm trying to compile one of my HTML5 project using Google Closure. I'm recieving several errors that I don't know how to solve. In fact, it's the same error but for different variables. Here the errors messages: variable window is undeclared variable event is undeclared variable console is undeclared variable Audio is undeclared These variables are Javascript built-in variables. If I compile this same project directly in command-line, it works. But, in my case, I need to compile this project using an ant file (build process). My ant build script is using the same jar file that I use in

What is the current state of JavaScript static type checking?

陌路散爱 提交于 2019-12-05 10:02:44
问题 I know that the Google Closure Compiler does type checking—but are there any alternatives, preferably that aren't so tightly coupled with a library and optimizer? If not, is there any way to have the Google Closure Compiler only do static analysis? (By static analysis here, I mean things like defining types for arguments and so on that I can run through something to give me warnings if I make a typo or pass the wrong type.) 回答1: There's Doctor JS, which is a Mozilla project that primarily (as

Why does Google's Closure Compiler leave a few unnecessary spaces or line breaks?

送分小仙女□ 提交于 2019-12-05 09:08:26
问题 I've noticed that every time I use Google's Closure Compiler Service, it leaves a few unnecessary spaces in the compiled code presented on the right-hand side of the page. These correspond to line breaks in the hosted version of the compiled code. For example (note the line breaks, each of which seems unnecessary): http://troy.onespot.com/static/stack_overflow/closure_spaces.js To date, I've just been removing them manually, but I'm curious why they're there. Is it to limit the line length of