如何防止Closure Compiler重命名"true","false"?和“空" [英] How to prevent Closure Compiler from renaming "true", "false" and "null"

查看:61
本文介绍了如何防止Closure Compiler重命名"true","false"?和“空"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Closure编译器将以下代码中的所有"true","false"和"null"事件重命名;

Google Closure Compiler renames all "true", "false" and "null" occurences in code like;

var s = true, x = null, V = false;

并改用这些简写;在诸如此类的条件下

and uses these shorthands instead; in conditions such as;

if (someVariable == s)

现在; Google Analytics(分析)代码定义了自己的"s"变量;覆盖值"true";如您所见,这会导致很多问题.

now; Google Analytics code defines it's own "s" variable; overriding the value "true"; and as you can see this causes a lot of problems.

我不想更改GA代码;我只希望Closure Compiler退出重命名true等.外部命令不起作用.

I don't want to change GA code; I just want Closure Compiler to quit renaming true etc. Externs do not work.

您知道实现此目的的任何方法吗?

Do you know any way to accomplish this?

推荐答案

事实证明,可以通过命令行中名为"output_wrapper"的参数来阻止Google Closure Compiler打印出全局定义(函数和/或变量)代码;例如

It turns out that one can prevent Google Closure Compiler from printing out global definitions (function and/or variable) by a parameter called "output_wrapper" to the command line code such as;

java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --output_wrapper "(function(){%output%})();" --js input.js --js_output_file output.js

这样,它不会与全局变量冲突,并且会在匿名函数包装器中打印所有代码.

This way, it doesn't collide with global variables and prints all your code in an anonymous function wrapper.

这篇关于如何防止Closure Compiler重命名"true","false"?和“空"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆