2017-10-17 31 views
0

我遇到了一個問題,其中使用了babel和ES2015預設來編譯以下代碼(redux reducer)。我(錯誤地)認爲這是可以被轉譯的代碼。巴別不使用ES2015進行處理,但使用了Stage0預設

const todos = (state = [], action) => { 
    switch (action.type) { 
     case 'TOGGLE_TODO': 
     return state.map(todo => 
      (todo.id === action.id) 
       ? { 
       ...todo, 
       completed: !todo.completed 
       } 
       : todo 
      ) 

     default: 
     return state 
    } 
} 

export default todos 

該錯誤消息

repl: Unexpected token (7:16) 
    5 |    (todo.id === action.id) 
    6 |     ? { 
> 7 |     ...todo, 

Transpiling與STAGE0預設正常工作。我確實用Babel online驗證了這個行爲。

回答

1

因爲preset-2016不支持對象休息蔓延的一部分。現在是第3階段

+0

感謝您的回答。這確實是問題所在。我仍然想知道爲什麼我的同事能夠使用babel默認預設來傳輸這個數據,我需要明確地設置它 – Christoph

+0

我認爲他在開發中使用它,但是您正嘗試創建生產構建。這是真的嗎? – imcvampire

+0

不,我們都使用'''babel src --out-file index.js --source-maps'''版本6.26.0來傳輸有問題的文件。我們這樣做是爲了在私有模塊中共享移動應用程序和Web應用程序之間的代碼,因爲使用npm鏈接和符號鏈接時webpack安裝程序存在問題。無論如何,再次感謝! – Christoph