LoginSignup
0
0

More than 5 years have passed since last update.

npmで6to5をインストールしようと思ってちょっとだけ詰まったのでメモ。

Last updated at Posted at 2014-11-09

jasmineでのAngularのテストをes6で書きたいという話がチームで上がったので6to5を試してみることに。


npm install -g 6to5

npm ERR! 404 Not Found
npm ERR! 404 
npm ERR! 404 'acorn-ast-types' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404 It was specified as a dependency of '6to5'
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

npm install -g acorn

npm ERR! 404 Not Found
npm ERR! 404 
npm ERR! 404 'acorn-recast' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404 It was specified as a dependency of '6to5'
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

動かない。仕方ないので直接cloneしてきてmake buildとかして見るとこんなエラーに。
上記のもpromiseが見つからなかったせいかと思ってpromiseを先に-gでインストールしたら6to5も入った。

Error: Cannot find module 'promise' from '/Users/aizawa/dev/playground/6to5/node_modules/regenerator-6to5'
    at module.exports.cb (/~/6to5/node_modules/browserify/node_modules/resolve/lib/async.js:50:17)
    at process (/~/6to5/node_modules/browserify/node_modules/resolve/lib/async.js:119:43)
    at module.exports (/~/6to5/node_modules/browserify/node_modules/resolve/lib/async.js:128:21)
    at load (/~/6to5/node_modules/browserify/node_modules/resolve/lib/async.js:60:43)
    at module.exports.cb (/~/6to5/node_modules/browserify/node_modules/resolve/lib/async.js:66:22)
    at module.exports.isFile (/~/6to5/node_modules/browserify/node_modules/resolve/lib/async.js:21:47)
    at Object.oncomplete (fs.js:297:15)
make: *** [build] Error 1


npm install -g promise

npm install -g 6to5

試しに、

$ vi es6.js                                                                                   

let hoge = '123';
const hoge = '123';

で、コンパイルすると以下の出力。

$ 6to5 es6.js

"use strict";

var fuga = 111;
var hoge = 222;

block scopingとかどうなってるんだろうとか、_つけてるだけだったり。

"use strict";

var fuga = 111;
var hoge = 222;

if (true) {
  var _fuga = 333;
}

console.log(fuga);

CLIで動くREPLあるし、その他色々試したけどわりと問題なく解釈してくれる(moduleとかにも対応してるんだっけ)。
これだったらAltJS使わなくてもいいじゃないか。
とりあえずテストに関してはgulp-6to5を組み込んで運用してみる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0