【发布时间】:2011-12-13 00:51:19
【问题描述】:
如果我从 NuGet 安装 SassAndCoffee.Core 包,然后让 SassAndCoffee 编译一些 CoffeeScript,它似乎将“裸”选项传递给 CoffeeScript 编译器——即,它不会将我的脚本包装在 CoffeeScript 通常的 @ 987654323@和}).call(this);书挡。
有没有办法让 SassAndCoffee不使用“裸”选项?
注意:这是在桌面应用程序中,我明确调用了 SassAndCoffee 的代码——这不是 ASP.NET 站点中发生的神奇重写。
更多细节:这是我使用 SassAndCoffee 编译 CoffeeScript 的代码。
var sassCompiler = new CoffeeScriptCompiler();
var js = sassCompiler.Compile("alert 'Hello World'");
这会在js 变量中产生以下(裸)输出:
alert('Hello World');
但如果我编写一些简单的 JavaScript 调用 official CoffeeScript compiler 并使用默认选项,例如这个 HTML 文件(将 coffee-script.js 放到同一目录中):
<script src="coffee-script.js"></script>
<script>
document.write("<pre>")
document.write(CoffeeScript.compile("alert 'Hello World'"))
document.write("</pre>")
</script>
我得到了预期的、包装好的 JavaScript 输出:
(function() {
alert('Hello World');
}).call(this);
看起来 SassAndCoffee 正在调用 CoffeeScript.compile(input, {bare: true}) 而不仅仅是 CoffeeScript.compile(input)。
我想使用 SassAndCoffee.Core 来支持 V8,但我希望能够在默认输出和裸输出之间进行选择。没有重写 SassAndCoffee 的 CoffeeScript 编译器(这会有点破坏使用 SassAndCoffee 的意义),或者手动添加和附加包装器代码(我觉得复制编译器应该做的工作很脏),有什么办法可以得到SassAndCoffee 输出非裸 JavaScript?
【问题讨论】:
标签: coffeescript