簡體   English   中英

CoffeeScript 不能對類字段使用擴展運算符

[英]CoffeeScript can't use spread operator with class fields

我不明白為什么這種傳播方法的語法對於 WebStorm 中的 CoffeeScript 是錯誤的

class Test
 fruit: {apple: "apple"}
 
 init: ->
     console.log 1, @fruit
     
 spread: ->
     console.log 2, {@fruit...}
     
 spreadWithVar: ->
     fruit = @fruit
     console.log 3, {fruit...}

test = new Test()

test.init()
test.spread()
test.spreadWithVar()

編譯后我得到這個 JS 代碼:

(function() {
  var Test, test;

  Test = (function() {
    class Test {
      init() {
        return console.log(1, this.fruit);
      }

      spread() {
        return console.log(2, {...this.fruit});
      }

      spreadWithVar() {
        var fruit;
        fruit = this.fruit;
        return console.log(3, {...fruit});
      }

    };

    Test.prototype.fruit = {
      apple: "apple"
    };

    return Test;

  }).call(this);

  test = new Test();

  test.init();

  test.spread();

  test.spreadWithVar();

}).call(this);
1 { apple: 'apple' }
2 { apple: 'apple' }
3 { apple: 'apple' }

在在線編譯器中運行代碼並查看結果: jdoodle.com/ia/qQh

這三種方法在編譯時都能正常工作,並給我一個預期的 JavaScript 代碼。 但就像在 WebStorm 的在線編輯器中一樣,我收到有關語法@name...的錯誤:

在此處輸入圖像描述

在此處輸入圖像描述

我不明白為什么? 如果它給了我一個正確的 JavaScript 代碼,為什么它認為這對 CoffeeScript 來說是錯誤的?

當您通過將 gulp gulp-coffee更新到最新版本來修復 gulp 中的錯誤時,我認為 webstorm 問題可能有類似的解決方案。

查看webstorm 咖啡腳本文檔,他們提到它依賴於全局安裝的coffeescript包。

首先檢查您的全球咖啡腳本是否已過時:

npm outdated -g --depth=0

然后你可以繼續更新它:

npm update -g coffeescript

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM