// Rest properties
require("babel-core").transform("code", {
plugins: ["transform-object-rest-spread"]
});
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
// Spread properties
let n = { x, y, ...z };
console.log(n); // { x: 1, y: 2, a: 3, b: 4 }
我想從http://babeljs.io/docs/plugins/transform-object-rest-spread/上面的例子,它不工作。對象傳播不工作在節點7.5
let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
^^^
SyntaxError: Unexpected token ...
at Object.exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
如果我用babel-node
運行它,那麼它工作正常。任何想法爲什麼?
你不能把你的babel調用與具有實驗功能的代碼放在同一個文件中?對於babel-node,你將該插件放在配置文件 – Bergi
中,那麼我應該如何構造它?如果這是我的index.js – cherhan
你說它在babel-node運行時工作正常。那麼你的目標是什麼? – Bergi