本文整理汇总了TypeScript中traverse.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: coerceValues
function coerceValues(configData: any) {
return traverse(configData).forEach(function(value: any) {
if (this.isLeaf && !_.isUndefined(value)) {
// Allow env vars to define boolean values
if (value === 'true') {
this.update(true);
}
else if (value === 'false') {
this.update(false);
}
else if (value === 'undefined') {
this.update(void 0);
}
}
});
}
示例2: if
napkin.addGenerator("text", (obj) => {
var s = "";
traverse(obj).forEach(function to_s(node) {
if (Array.isArray(node)) {
// this.post(function (child) {
// if (!child.isLast) s += ',';
//});
//this.after(function () { s += ']' });
}
else if (typeof node == 'object') {
this.before(function () {
if (node.node) {
s += Array(Math.floor(this.level/2)).join("\t") + node.node + "\n";
}
});
//this.pre(function (x, key) {
// to_s(key);
// s += ':';
//});
//this.post(function (child) {
// if (!child.isLast) s += ',';
//});
//this.after(function () { s += '}' });
}
else if (typeof node == 'string') {
//s += '"' + node.toString().replace(/"/g, '\\"') + '"';
}
else {
s += node.toString();
}
});
return s;
});
示例3: traverse
napkin.addGenerator("cs", (obj) => {
var s = "";
traverse(obj).forEach(function to_s(node) {
if (typeof node == 'object') {
this.before(function () {
if (node.node) {
if (this.level == 1) {
s += "namespace " + node.node + " {\n";
}
if (this.level == 3) {
s += "\tpublic class " + node.node + " {\n";
}
if (this.level == 5) {
s += "\t\tpublic string " + node.node + " {get;set;}\n";
}
}
});
this.after(function () {
if (this.level == 1) {
s += "}\n";
}
if (this.level == 3) {
s += "\t}\n";
}
});
}
});
return s;
});
示例4: getHighlightedCode
function getHighlightedCode(lscAst: ILambdaScriptAstNode, lambdaScriptCode: string) {
const codeByLines = _str.lines(lambdaScriptCode),
colorActions = traverse(lscAst)
.reduce(function(colorActions: ILineColorAction[], astNode: ILambdaScriptAstNode) {
const color = colorMap[astNode.type];
if (color) {
const colorFn = chalk[color].bind(chalk),
locKey = alternateLocMap[astNode.type] || 'loc',
// I'm just using _.result to avoid TS7017
loc: ILoc = _.result(astNode, locKey);
/**
* Originally, I just colored as soon as I found a node. However, this does not work,
* because other coloring may have occurred on the line already, which will offset our
* column indices. And it is not sufficient just to drop all color from the line and
* see what the length difference is, because some of that color could be *after* our
* column indices and thus irrelevant. To solve this, we will gather all the colorings
* we want to do, and then apply them in sorted order. This makes the offset caclulation trivial.
*/
return colorActions.concat({
// I don't know why but jison does not 0-index the line number.
lineIndex: loc.first_line - 1,
colStart: loc.first_column,
colEnd: loc.last_column,
colorFn: colorFn
});
}
return colorActions;
}, []),
coloredCode = _(colorActions)
.sortByAll(['lineIndex', 'colStart'])
.reduce(function(lines: string[], colorAction: ILineColorAction) {
const linesClone = _.clone(lines),
lineToColor = linesClone[colorAction.lineIndex],
existingColorOffset = lineToColor.length - chalk.stripColor(lineToColor).length,
colStartWithOffset = colorAction.colStart + existingColorOffset,
colEndWithOffset = colorAction.colEnd + existingColorOffset;
// One potential way to fail fast here would be to detect when we are coloring
// over an existing highlight. I have yet to encounter a case where that was expected behavior.
linesClone[colorAction.lineIndex] =
lineToColor.slice(0, colStartWithOffset) +
colorAction.colorFn(lineToColor.slice(colStartWithOffset, colEndWithOffset)) +
lineToColor.slice(colEndWithOffset);
logger.debug({
original: lines[colorAction.lineIndex],
colored: linesClone[colorAction.lineIndex]
}, 'Coloring line');
return linesClone;
}, codeByLines);
return coloredCode.join(os.EOL);
}
示例5: runCommands
function runCommands(objectToParse: idocument): any {
function cmd_include(filename, type) {
var included = parseFile(filename, false);
if (included) {
var arr = [];
for (var i = 0; i < included.length; i++) {
var item = included[i];
item["included"] = type;
arr.push(item);
}
objectToParse.document = arr.concat(objectToParse.document);
}
}
function cmd_map(filename) {
var req = require("./" + filename);
objectToParse = req(objectToParse);
}
function cmd_out(filename, type?) {
if (!type) {
type = path.extname(filename);
if (type.indexOf(".") == 0)
type = type.substring(1);
else
type = "text";
}
if (!objectToParse.processed) {
objectToParse.processed = objectToParse.document.slice(0);
//processAll(objectToParse.processed);
var newChildArray = [];
for (var ii in objectToParse.processed) {
var node = objectToParse.processed[ii];
if (!(node["included"] && node["included"] == "reference")) {
newChildArray.push(objectToParse.processed[ii]);
} else {
console.log("excluded " + node.name);
}
}
objectToParse.processed = newChildArray;
}
var formatted = generate(objectToParse.processed, type);
fs.writeFileSync(filename, formatted);
}
traverse(objectToParse.document).forEach(function on_item(item) {
if (item.name) {
if (item.name.indexOf("/") == 0) {
item.isCommand = true;
if (item.name == "/out") {
cmd_out(item.attributes[0]);
}
if (item.name == "/reference") {
cmd_include(item.attributes[0], "reference");
}
if (item.name == "/include") {
cmd_include(item.attributes[0], "include");
}
}
}
});
//if (objectToParse.commands) {
// var commands = objectToParse.commands.splice(0);
// for (var c in commands) {
// var cmd = commands[c];
// if (cmd.type == "include" || cmd.type == "reference") cmd_include(cmd.attributes[0].attr, cmd.type);
// if (cmd.type == "map") cmd_map(cmd.attributes[0].attr);
// if (cmd.type == "processall") processAll(objectToParse.model);
//.........这里部分代码省略.........
示例6: assignStateDeep
function assignStateDeep(self, callback, stateList, parseFunc, newValue) {
traverse(self.state).set(stateList, parseFunc(newValue));
//setState
self.setState(self.state, callback);
}