使用正式的跟踪模块,是否可以为compile和require设置默认选项
例如,此代码工作如下:
var traceur = require('traceur');
console.log(
traceur.compile('{ let x = 1; }', { experimental:true }).js
);现在,如果我移除traceur.compile的第二个参数( options对象):
console.log(
traceur.compile('{ let x = 1; }').js
);由于未启用blockBinding选项,Traceur将抛出一个错误。是否有任何方法来更改默认选项,以便编译文件而不总是传递options对象?
除了应用do原则之外,我主要关心的是让traceur.require函数编译带有自定义选项的文件--据我所见,traceur.require和traceur.require.makeDefault()甚至不使用options参数。
例如,考虑到这个代码示例:
require('traceur').require('./index');这段代码是:
require('traceur').require.makeDefault();
require('./index');是否有任何方法在启用experimental选项的情况下编译所需的文件?
最好通过改变默认的选项,因为我看不到任何其他可行的方式。
使用节点0.10.29和跟踪器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。
用Traceur与Node.js Wiki页面没有提到编译选项。编译选项页面没有提到Node.js中的Traceur,实际上,我在Node.js中找不到任何关于Traceur的文档。
发布于 2014-07-17 00:39:18
)增加了对makeDefault()提供默认选项的支持,请参见https://github.com/google/traceur-compiler/blob/master/src/node/require.js#L58
今天修复了一个带有选项experimental的单独错误,即16JUL 14。
https://stackoverflow.com/questions/24624175
复制相似问题