公式のtraceur モジュールcompile
を使用して、およびのデフォルト オプションを設定することは可能require
ですか?
たとえば、次のコードは機能します。
var traceur = require('traceur');
console.log(
traceur.compile('{ let x = 1; }', { experimental:true }).js
);
traceur.compile
の 2 番目の引数 (オプション オブジェクト)を削除すると、次のようになります。
console.log(
traceur.compile('{ let x = 1; }').js
);
blockBinding
オプションが有効になっていないため、Traceur はエラーをスローします。オプションオブジェクトを常に渡さずにファイルをコンパイルするために、デフォルトオプションを変更する方法はありますか?
私の主な関心事は、DRY 原則の適用とは別に、カスタマイズされたオプションを使用してファイルをコンパイルする関数を取得するtraceur.require
ことです。traceur.require
traceur.require.makeDefault()
options
たとえば、次のコード サンプルを考えてみます。
require('traceur').require('./index');
そして、このコード:
require('traceur').require.makeDefault();
require('./index');
experimental
オプションを有効にして必要なファイルをコンパイルする方法はありますか?
他に実行可能な方法が見当たらないので、デフォルトのオプションを変更することをお勧めします。
Node 0.10.29 と Traceur 0.0.49 を使用。
これが私が達成したいことの完全な例です。
bootstrap.js (エントリ ポイント):
var traceur = require('traceur');
traceur.options.experimental = true;
traceur.require.makeDefault();
require('./index');
index.js:
import {x} from './lib';
// using a block binding in order to check
// whether this file was compiled with experimental features enabled
{
let y = x;
console.log(y);
}
lib.js:
export var x = (() => {
if (true) {
// should be compiled with experimental features enabled too
let x = 1;
return x;
}
})();
予想されるコンソール出力:1
traceur.options.experimental=true
オブジェクトの実験的な機能を有効にするセッターとして機能しtraceur.options
ますが、残念ながら私が見る限り、影響を与えていtraceur.options
ないようです。traceur.compile
traceur.require
Using Traceur with Node.js Wiki ページでは、 コンパイル オプションについては何も言及されていません。コンパイルのオプションのページでは、Node.js の Traceur API について言及されていません。実際、Node.js の Traceur API に関するドキュメントは見つかりません。