我在assets/javascript
目录中有类似的咖啡脚本
#COFFEE SCRIPT CODE
class TestClass
speak: ()->
response = await fetch(location.url)
console.log(response)
使用async/await
中的正确coffee-script's official playground语法正确编译
# 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
为什么会这样以及如何解决它。
我需要通过我的资产管道适当的异步/等待语法
我在我的assets / javascript目录#COFFEE SCRIPT CODE类TestClass中有类似的咖啡脚本,例如:()-> response = await fetch(location.url)console.log(response)...
[不幸的是,coffee-rails
宝石没有使用最新版本的CoffeeScript,因此缺少了您正在寻找的ES2017某些功能,例如await
。
coffee-rails
本身取决于您使用CoffeeScript v1.12.6将coffee-script-source
定义为[[still
# https://github.com/jessedoyle/coffee-script-source/blob/master/src/js/coffee-script.js
/**
* CoffeeScript Compiler v1.12.6
* http://coffeescript.org
*
* Copyright 2011, Jeremy Ashkenas
* Released under the MIT License
*/
宝石已过期。对于较新的js设置,建议使用coffee-script-source
而不是资产管道。但这可能是一个很大的重组。