标签: google-closure-compiler

在谷歌闭包编译器中使用模块

我只是想让一个基本模块正常工作:

测试A.js:

goog.module('foo');

exports.bar = function(){
  console.log('here');
};
Run Code Online (Sandbox Code Playgroud)

测试B.js:

var bar = goog.require('foo.bar');
bar();
Run Code Online (Sandbox Code Playgroud)

我正在跑步:

java -jar ~/Downloads/compiler.jar --js testA.js testB.js
Run Code Online (Sandbox Code Playgroud)

产生:

testB.js:1: ERROR - Closure dependency methods(goog.provide, goog.require, etc) must be called at file scope.
var bar = goog.require('foo.bar');
          ^

1 error(s), 0 warning(s)
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

javascript compiler-errors google-closure-compiler

4
推荐指数
1
解决办法
1815
查看次数

是否有适用于Notepad ++的Google Closure Compiler插件

我在"互联网"上环顾四周,但找不到合适的答案:

是否有适用于Notepad ++Google Closure Compiler插件或使用NppExec.Execute(F6-key)的方法.

javascript notepad++ google-closure-compiler

3
推荐指数
1
解决办法
899
查看次数

是否有相当于Google Closure对Java的javascript优化?

我们在以下博客文章中看到:http://blog.fogus.me/2011/07/21/compiling-clojure-to-javascript-pt1/一些非常令人难以置信的语法转换,简化了javascript编程语言,完成了Google Closure编译器.

我的问题是 - 有没有为Java提供这些语法转换的东西?

java optimization refactoring compiler-optimization google-closure-compiler

3
推荐指数
1
解决办法
308
查看次数

针对Google Closure Compiler的Underscore.js externs

我正在使用Luke Rodgers的Backbone和Underscore externs,无法解决为什么_.extend在编译输出中被修改.

例如在Backbone 0.9.2中,以下代码(193:195):

if (defaults = getValue(this, 'defaults')) {
  attributes = _.extend({}, defaults, attributes);
}
Run Code Online (Sandbox Code Playgroud)

编译为:

if(c=r(this,"defaults"))a=f.extend({},c,a);
Run Code Online (Sandbox Code Playgroud)

我使用了以下编译命令:

java -jar compiler.jar 
     --externs backbone-0.9.2-externs.js 
     --externs underscore-1.3.3-externs.js 
     --compilation_level ADVANCED_OPTIMIZATIONS 
     --js underscore-1.3.3.js  
     --js backbone-0.9.2.js 
     --js_output_file compiled.js
Run Code Online (Sandbox Code Playgroud)

如果我包含另一个JavaScript文件:

     --js test.js
Run Code Online (Sandbox Code Playgroud)

包含以下内容:

_.extend({}, {name: 'test'});
Run Code Online (Sandbox Code Playgroud)

它未被修改compiled.js.

有谁知道为什么_.extend要修改backbone.js中的调用?

javascript google-closure-compiler backbone.js underscore.js

3
推荐指数
1
解决办法
1780
查看次数

Google Closure Compiler中"危险使用全局此对象"警告

我有一些看起来像这样的代码:

var MyObject = function () {
  this.Prop1 = "";
  this.Prop2 = [];
  this.Prop3 = {};
  this.Prop4 = 0;
}
Run Code Online (Sandbox Code Playgroud)

然后我有了这个:

var SomeObject = new MyObject();
Run Code Online (Sandbox Code Playgroud)

当我在高级模式下通过闭包编译器运行我的代码时,我会dangerous use of the global this object在我拥有的每一行上收到警告this.Prop =

我在做什么,这是"危险的",我应该如何重写我的代码?

谢谢你的建议.

javascript google-closure-compiler

3
推荐指数
1
解决办法
2307
查看次数

Javascript Closure Compiler Error Trailing Comma?

当谷歌通过名为Closure Compiler的方便工具中缩小JavaScript时,它会出现以下错误(并且不会缩小某个内容):

错误数:1 JSC_TRAILING_COMMA:解析错误.IE8(及以下)将错误地解析数组和对象文字中的尾随逗号.如果您要定位较新版本的JS,请设置相应的language_in选项.在all.js的第389行第1字符

theme : 'default', // The theme of the slider (default, theme1, theme2, t...
Run Code Online (Sandbox Code Playgroud)

故障在哪里以及需要更改哪些以修复错误?

$(window).load(function(){
jQuery('#slider1').autoSlider({
    theme               : 'default',    // The theme of the slider (default, theme1, theme2, theme3)
    width               : '960',    // The width of the slider, 100% for auto full width, set to 0 it will take the width of the largest image
    autoHidePlayBtn     : true,     //
Run Code Online (Sandbox Code Playgroud)

javascript minify google-closure-compiler

3
推荐指数
1
解决办法
3696
查看次数

Google JavaScript闭包:定义传递给许多函数的结构

当我使用Google闭包编译器加强我的JavaScript代码时,我遇到了一个问题,我没有看到我喜欢的答案.

我有一个简单的类,有4个函数:

open:  function(settings) { ... },
close: function(settings) { ... },
hide:  function(settings) { ... },
show:  function(settings) { ... }
Run Code Online (Sandbox Code Playgroud)

如您所见,所有函数都包含一个名为settings的对象.我可以使用强类型定义轻松声明设置,例如:

/**
 * @param {{p1: string, p2: number, p3: function(string)}} settings The settings.
 */
open: function(settings) { ... };
Run Code Online (Sandbox Code Playgroud)

这是有效的,只需要为打开,关闭,隐藏和显示功能中的每一个复制/粘贴@param定义.所以如果我添加一个参数,我要确保我更新所有4个函数!

有没有办法声明一个类型,然后多次重用它,而不必声明一个真正的JavaScript对象?这样的事可能吗?

/**
 * @deftype {{...}} some_name
 */
Run Code Online (Sandbox Code Playgroud)

或者你会把它作为一个外部定义,所以至少执行环境没有看到这个定义?

PS有问题的对象永远不会保存设置.它使用该结构来保存它生成的数据(例如标识符)并知道用户想要执行的不同功能.每个用户都可以有不同的设置集和对象本身仍可以像单(我所需要的对象只有一个实例来管理任意数量的窗口).

javascript types google-closure-compiler

3
推荐指数
1
解决办法
310
查看次数

理解Clojurescript和Google Closure编译器之间的关系

许多教程都将该goog/base.js文件包含在脚本标记中,然后用于goog.require('your_script')启动运行的应用程序.例如,以下是链接教程中HTML文件的标题:

<script type="text/javascript" src="out/goog/base.js"></script>
<script type="text/javascript" src="hello.js"></script>
<script type="text/javascript">goog.require('hello');</script>
Run Code Online (Sandbox Code Playgroud)

我知道Google Closure Library用于将Clojurescript编译成Javascript.为什么HTML页面也需要它?它不能hello.js在上面的例子中编译自己(或使用高级编译的必要组件)吗?

我真正想要的只是需要一个javascript文件而不是几十个文件/goog/.这不是编译器的用途吗?我只是不明白为什么它需要包含在页面中.

javascript google-closure-compiler clojurescript

3
推荐指数
1
解决办法
472
查看次数

Closure Compiler不支持ES6

我正在使用Google Closure Compiler,我收到以下错误:

ES6_FEATURE:此语言功能仅在es6模式下受支持:computed属性.使用--language_in = ECMASCRIPT6或ECMASCRIPT6_STRICT启用ES6功能.

触发此错误的行是这样的:

var TheCellRef = LeadImport2ExcelLibrary['utils']['encode_cell']({ ['c']: C, ['r']: R });
Run Code Online (Sandbox Code Playgroud)

基本上我传递的是我在同一条线上创建的对象.我知道我可以简单地在JavaScript源代码头中添加对ES6的支持,但我想知道为什么会出现这个错误以及如何修复它?

javascript google-closure-compiler ecmascript-6

3
推荐指数
1
解决办法
1756
查看次数

Google Closure编译REST Api突然引发错误405“方法不允许”

我已经使用Closure作为y应用程序的一部分来压缩Javascript了一段时间,但是刚开始出现错误 405 - Method not allowed

我下面的代码已经工作了几年,但是现在已经停止了。

注意:仅当我的应用程序中的Javascript文件中检测到任何更改时,才经常调用此方法。

除了此,我从Closure应用程序中没有得到更多的错误信息。

显然,此代码执行POST操作。如果我使用在https://closure-compiler.appspot.com/home上找到的表单,它可以工作,但是如果我浏览到URL或使用我的代码得到Error 405,则几乎就像我的代码正在尝试一种GET方法。 ..但不是...

有任何想法吗?

Public Class Closure

    Property OriginalCode As String
    Property CompiledCode As String
    Property Errors As ArrayList
    Property Warnings As ArrayList
    Property Statistics As Dictionary(Of String, Object)

    Public Sub New(Input As String, Optional CompliationLevel As String = "SIMPLE_OPTIMIZATIONS")

        Dim _HttpWebRequest As HttpWebRequest
        Dim _Result As StringBuilder
        Dim ClosureWebServiceURL As String = "http://closure-compiler.appspot.com/compile?"
        Dim ClosureWebServicePOSTData As String = "output_format=json&output_info=compiled_code" &
                                                                        "&output_info=warnings" & …
Run Code Online (Sandbox Code Playgroud)

post httpwebrequest google-closure-compiler

3
推荐指数
1
解决办法
188
查看次数