当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript syntax.traverse函数代码示例

本文整理汇总了TypeScript中@glimmer/syntax.traverse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript traverse函数的具体用法?TypeScript traverse怎么用?TypeScript traverse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了traverse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: traversalEqual

function traversalEqual(node, expectedTraversal) {
  let actualTraversal = [];

  traverse(node, {
    All: {
      enter(node) { actualTraversal.push(['enter', node]); },
      exit(node) { actualTraversal.push(['exit',  node]); }
    }
  });

  QUnit.assert.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;
    }
  }

  QUnit.assert.ok(nodesEqual, "Actual nodes match expected nodes");
}
开发者ID:asakusuma,项目名称:glimmer,代码行数:26,代码来源:visiting-node-test.ts

示例2: parse

QUnit.test('Should recurrsively walk the keys in the transformed node', () => {
  let ast = parse(`{{#foo}}{{#bar}}{{baz}}{{/bar}}{{else}}{{#bar}}{{bat}}{{/bar}}{{/foo}}`);

  traverse(ast, {
    BlockStatement: function(node) {
      if (node.path.original === 'foo') {
        return b.block(b.path('x-foo'), node.params, node.hash, node.program, node.inverse, node.loc);
      } else if (node.path.original === 'bar') {
        return b.block(b.path('x-bar'), node.params, node.hash, node.program, node.inverse, node.loc);
      }
      return;
    },

    MustacheStatement: function(node) {
      if (node.path.original === 'baz') {
        return b.mustache('x-baz');
      } else if (node.path.original === 'bat') {
        return b.mustache('x-bat');
      }
      return;
    }
  });

  astEqual(ast, `{{#x-foo}}{{#x-bar}}{{x-baz}}{{/x-bar}}{{else}}{{#x-bar}}{{x-bat}}{{/x-bar}}{{/x-foo}}`);
});
开发者ID:jayphelps,项目名称:glimmer,代码行数:25,代码来源:manipulating-node-test.ts

示例3: traversalEqual

function traversalEqual(node: AST.Node, expectedTraversal: Array<[string, AST.Node]>) {
  let actualTraversal: Array<[string, AST.BaseNode]> = [];

  traverse(node, {
    All: {
      enter(node) { actualTraversal.push(['enter', node]); },
      exit(node) { actualTraversal.push(['exit',  node]); },
      keys: {
        All: {
          enter(node: AST.BaseNode, key: string) { actualTraversal.push([`enter:${key}`, node]); },
          exit(node: AST.BaseNode, key: string) { actualTraversal.push([`exit:${key}`,  node]); },
        }
      }
    }
  });

  QUnit.assert.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;
    }
  }

  QUnit.assert.ok(nodesEqual, "Actual nodes match expected nodes");
}
开发者ID:jayphelps,项目名称:glimmer,代码行数:32,代码来源:visiting-keys-node-test.ts

示例4: traverse

 assert.throws(() => {
   traverse(ast, {
     MustacheStatement: {
       [eventName](node) {
         if (node.path.parts[0] === 'z') {
           return [];
         }
       }
     }
   });
 }, cannotRemoveNode(attr.value, attr, 'value'));
开发者ID:asakusuma,项目名称:glimmer,代码行数:11,代码来源:manipulating-node-test.ts

示例5: traverse

 assert.throws(() => {
   traverse(ast, {
     MustacheStatement: {
       [eventName](node: AST.MustacheStatement) {
         if (node.path.type === 'PathExpression' && node.path.parts[0] === 'z') {
           return [];
         }
         return;
       }
     }
   });
 }, cannotRemoveNode(attr.value, attr, 'value'));
开发者ID:jayphelps,项目名称:glimmer,代码行数:12,代码来源:manipulating-node-test.ts

示例6: array

  QUnit.test(`[${eventName}] Replacing self in an array (returning null)`, () => {
    let ast = parse(`{{x}}{{y}}{{z}}`);

    traverse(ast, {
      MustacheStatement: {
        [eventName](node) {
          if (node.path.parts[0] === 'y') {
            return null;
          }
        }
      }
    });

    astEqual(ast, `{{x}}{{z}}`);
  });
开发者ID:asakusuma,项目名称:glimmer,代码行数:15,代码来源:manipulating-node-test.ts

示例7: 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:asakusuma,项目名称:glimmer,代码行数:15,代码来源:manipulating-node-test.ts

示例8: parse

QUnit.test('Should recurrsively walk the transformed node', assert => {
  let ast = parse(`{{x}}{{y}}{{z}}`);

  traverse(ast, {
    MustacheStatement: function(node) {
      if (node.path.original === 'x') {
        return b.mustache('y');
      } else if (node.path.original === 'y') {
        return b.mustache('z');
      }
    }
  });

  astEqual(ast, `{{z}}{{z}}{{z}}`);
});
开发者ID:asakusuma,项目名称:glimmer,代码行数:15,代码来源:manipulating-node-test.ts

示例9: key

  QUnit.test(`[${eventName}] Replacing self in a key (returning a node)`, () => {
    let ast = parse(`<x y={{z}} />`);

    traverse(ast, {
      MustacheStatement: {
        [eventName](node: AST.MustacheStatement) {
          if (node.path.type === 'PathExpression' && node.path.parts[0] === 'z') {
            return b.mustache('a');
          }
          return;
        }
      }
    });

    astEqual(ast, `<x y={{a}} />`);
  });
开发者ID:jayphelps,项目名称:glimmer,代码行数:16,代码来源:manipulating-node-test.ts

示例10: array

  QUnit.test(`[${eventName}] Replacing self in an array (returning an array with a single node)`, () => {
    let ast = parse(`{{x}}{{y}}{{z}}`);

    traverse(ast, {
      MustacheStatement: {
        [eventName](node: AST.MustacheStatement) {
          if (node.path.type === 'PathExpression' && node.path.parts[0] === 'y') {
            return [b.mustache('a')];
          }
          return;
        }
      }
    });

    astEqual(ast, `{{x}}{{a}}{{z}}`);
  });
开发者ID:jayphelps,项目名称:glimmer,代码行数:16,代码来源:manipulating-node-test.ts


注:本文中的@glimmer/syntax.traverse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。