Coffeescript没有在rails中正确编译

问题描述 投票:0回答:2

我在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.2ruby 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

my gemlock file

为什么会这样以及如何解决它。

我需要通过我的资产管道适当的异步/等待语法

我在我的assets / javascript目录#COFFEE SCRIPT CODE类TestClass中有类似的咖啡脚本,例如:()-> response = await fetch(location.url)console.log(response)...

ruby-on-rails coffeescript ruby-on-rails-5 asset-pipeline
2个回答
2
投票

[不幸的是,coffee-rails宝石没有使用最新版本的CoffeeScript,因此缺少了您正在寻找的ES2017某些功能,例如await

coffee-rails本身取决于您使用CoffeeScript v1.12.6将coffee-script-source定义为[[still


0
投票
# 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而不是资产管道。但这可能是一个很大的重组。
© www.soinside.com 2019 - 2024. All rights reserved.