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


TypeScript glimmer-syntax.parse函数代码示例

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


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

示例1: astEqual

export function astEqual(actual, expected, message?) {
  if (typeof actual === 'string') {
    actual = parse(actual);
  }
  if (typeof expected === 'string') {
    expected = parse(expected);
  }

  actual = normalizeNode(actual);
  expected = normalizeNode(expected);

  deepEqual(actual, expected, message);
}
开发者ID:GCheung55,项目名称:glimmer,代码行数:13,代码来源:support.ts

示例2: test

test("html elements with nested blocks", function() {
  let ast = parse(`
    <div>
      {{#if isSingleError}}
        Single error here!
      {{else if errors}}
        Multiple errors here!
      {{else}}
        No errors found!
      {{/if}} <p>Hi there!</p>
    </div>
  `);

  let [,div] = ast.body;
  let [,ifBlock,,p] = div.children;
  let inverseBlock = ifBlock.inverse;
  let [nestedIfBlock] = inverseBlock.body;
  let nestedIfInverseBlock = nestedIfBlock.inverse;

  locEqual(div, 2, 4, 10, 10, 'div element');
  locEqual(ifBlock, 3, 6, 9, 13, 'outer if block');
  locEqual(inverseBlock, 5, 6, 9, 6, 'inverse block');
  locEqual(nestedIfBlock, 5, 6, 9, 6, 'nested if block');
  locEqual(nestedIfInverseBlock, 7, 6, 9, 6, 'nested inverse block');
  locEqual(p, 9, 14, 9, 30, 'p');
});
开发者ID:GCheung55,项目名称:glimmer,代码行数:26,代码来源:loc-node-test.ts

示例3: test

test("allow {{undefined}} to be passed as a param", function() {
  let ast = parse("{{foo undefined}}");

  astEqual(ast, b.program([
    b.mustache(b.path('foo'), [b.undefined()])
  ]));
});
开发者ID:byelipk,项目名称:glimmer,代码行数:7,代码来源:parser-node-test.ts

示例4: test

test('Mustaches', function() {
  let ast = parse(
    `{{mustache}}` +
    `{{mustache param1 param2 key1=value key2=value}}`
  );

  traversalEqual(ast, [
    ['enter', ast],
    ['enter', ast.body[0]],
    ['enter', ast.body[0].path],
    ['exit',  ast.body[0].path],
    ['enter', ast.body[0].hash],
    ['exit',  ast.body[0].hash],
    ['exit',  ast.body[0]],
    ['enter', ast.body[1]],
    ['enter', ast.body[1].path],
    ['exit',  ast.body[1].path],
    ['enter', ast.body[1].params[0]],
    ['exit',  ast.body[1].params[0]],
    ['enter', ast.body[1].params[1]],
    ['exit',  ast.body[1].params[1]],
    ['enter', ast.body[1].hash],
    ['enter', ast.body[1].hash.pairs[0]],
    ['enter', ast.body[1].hash.pairs[0].value],
    ['exit',  ast.body[1].hash.pairs[0].value],
    ['exit',  ast.body[1].hash.pairs[0]],
    ['enter', ast.body[1].hash.pairs[1]],
    ['enter', ast.body[1].hash.pairs[1].value],
    ['exit',  ast.body[1].hash.pairs[1].value],
    ['exit',  ast.body[1].hash.pairs[1]],
    ['exit',  ast.body[1].hash],
    ['exit',  ast.body[1]],
    ['exit',  ast]
  ]);
});
开发者ID:GCheung55,项目名称:glimmer,代码行数:35,代码来源:visiting-node-test.ts

示例5: test

test('AST plugins can be chained', function() {
  expect(2);

  let expected = "OOOPS, MESSED THAT UP!";

  function Plugin() { }
  Plugin.prototype.transform = function() {
    return expected;
  };

  function SecondaryPlugin() { }
  SecondaryPlugin.prototype.transform = function(ast) {
    equal(ast, expected, 'return value from AST transform is used');

    return 'BOOM!';
  };

  let ast = parse('<div></div>', {
    plugins: {
      ast: [
        Plugin,
        SecondaryPlugin
      ]
    }
  });

  equal(ast, 'BOOM!', 'return value from last AST transform is used');
});
开发者ID:GCheung55,项目名称:glimmer,代码行数:28,代码来源:plugin-node-test.ts

示例6: test

test("element attribute", function() {
  let ast = parse(`
    <div data-foo="blah"
      data-derp="lolol"
data-barf="herpy"
  data-qux=lolnoquotes
    data-hurky="some {{thing}} here">
      Hi, fivetanley!
    </div>
  `);

  let [,div] = ast.body;
  let [dataFoo,dataDerp,dataBarf, dataQux, dataHurky] = div.attributes;

  locEqual(dataFoo, 2, 9, 2, 24);
  locEqual(dataDerp, 3, 6, 3, 23);
  locEqual(dataBarf, 4, 0, 4, 17);
  locEqual(dataQux, 5, 2, 5, 22);

  locEqual(dataFoo.value, 2, 18, 2, 24);
  locEqual(dataDerp.value, 3, 16, 3, 23);
  locEqual(dataBarf.value, 4, 10, 4, 17);
  locEqual(dataQux.value, 5, 11, 5, 22);
  locEqual(dataHurky.value, 6, 15, 6, 36);
});
开发者ID:Joelkang,项目名称:glimmer,代码行数:25,代码来源:loc-node-test.ts


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