本文整理汇总了TypeScript中glimmer-syntax.traverse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript traverse函数的具体用法?TypeScript traverse怎么用?TypeScript traverse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了traverse函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: traversalEqual
function traversalEqual(node, expectedTraversal) {
let actualTraversal = [];
traverse(node, {
All: {
enter(node) { actualTraversal.push(['enter', node]); },
exit(node) { actualTraversal.push(['exit', node]); },
keys: {
All: {
enter(node, key) { actualTraversal.push([`enter:${key}`, node]); },
exit(node, key) { actualTraversal.push([`exit:${key}`, node]); },
}
}
}
});
deepEqual(
actualTraversal.map(a => `${a[0]} ${a[1].type}`),
expectedTraversal.map(a => `${a[0]} ${a[1].type}`)
);
let nodesEqual = true;
for (let i = 0; i < actualTraversal.length; i++) {
if (actualTraversal[i][1] !== expectedTraversal[i][1]) {
nodesEqual = false;
break;
}
}
ok(nodesEqual, "Actual nodes match expected nodes");
}
示例2: traverse
assert.throws(() => {
traverse(ast, {
MustacheStatement: {
[eventName](node) {
if (node.path.parts[0] === 'z') {
return [];
}
}
}
});
}, cannotRemoveNode(attr.value, attr, 'value'));
示例3: parse
QUnit.test('Exit event is not triggered if the node is replaced during the enter event', assert => {
let ast = parse(`{{x}}`);
let didExit = false;
traverse(ast, {
MustacheStatement: {
enter() { return b.mustache('y'); },
exit() { didExit = true; }
}
});
assert.strictEqual(didExit, false);
});
示例4: key
QUnit.test(`[${eventName}] Replacing self in a key (returning an array with a single node)`, () => {
let ast = parse(`<x y={{z}} />`);
traverse(ast, {
MustacheStatement: {
[eventName](node) {
if (node.path.parts[0] === 'z') {
return [b.mustache('a')];
}
}
}
});
astEqual(ast, `<x y={{a}} />`);
});
示例5: array
QUnit.test(`[${eventName}] Replacing self in an array (returning a node)`, () => {
let ast = parse(`{{x}}{{y}}{{z}}`);
traverse(ast, {
MustacheStatement: {
[eventName](node) {
if (node.path.parts[0] === 'y') {
return b.mustache('a');
}
}
}
});
astEqual(ast, `{{x}}{{a}}{{z}}`);
});