當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript glimmer-syntax.traverse函數代碼示例

本文整理匯總了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");
}
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:32,代碼來源:visiting-keys-node-test.ts

示例2: traverse

 assert.throws(() => {
   traverse(ast, {
     MustacheStatement: {
       [eventName](node) {
         if (node.path.parts[0] === 'z') {
           return [];
         }
       }
     }
   });
 }, cannotRemoveNode(attr.value, attr, 'value'));
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:11,代碼來源:manipulating-node-test.ts

示例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);
});
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:13,代碼來源:manipulating-node-test.ts

示例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}} />`);
  });
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:15,代碼來源:manipulating-node-test.ts

示例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}}`);
  });
開發者ID:GCheung55,項目名稱:glimmer,代碼行數:15,代碼來源:manipulating-node-test.ts


注:本文中的glimmer-syntax.traverse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。