【发布时间】:2020-02-26 22:20:21
【问题描述】:
我的assets/javascript 目录中有类似的咖啡脚本
#COFFEE SCRIPT CODE
class TestClass
speak: ()->
response = await fetch(location.url)
console.log(response)
它在coffee-script's official playground 中使用正确的async/await 语法正确编译
# COMPILED JS FROM COFFEESCRIPT OFFICIAL PLAYGROUND
var TestClass;
TestClass = class TestClass {
async speak() {
var response;
response = (await fetch(location.url));
return console.log(response);
}
};
但是当我把它写在一个文件中并让它通过资产管道编译时,它会被错误地编译
# COMPILED JS FROM COFFEESCRIPT ASSESTS PIPELINE
TestClass = (function() {
function TestClass() {}
TestClass.prototype.speak = function() {
var response;
response = await(fetch(location.url));
return console.log(response);
};
return TestClass;
})();
我在 macOS v10.14
上使用 rails v5.2 和 ruby v2.6.4$ bundle info coffee-script
* coffee-script (2.4.1)
Summary: Ruby CoffeeScript Compiler
Homepage: http://github.com/josh/ruby-coffee-script
Path: /Users/<username>/.rvm/gems/ruby-2.6.4/gems/coffee-script-2.4.1
为什么会发生这种情况以及如何解决。
我需要通过我的资产管道使用正确的 async/await 语法
【问题讨论】:
标签: ruby-on-rails coffeescript ruby-on-rails-5 asset-pipeline