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


TypeScript syntax.preprocess函數代碼示例

本文整理匯總了TypeScript中@glimmer/syntax.preprocess函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript preprocess函數的具體用法?TypeScript preprocess怎麽用?TypeScript preprocess使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了preprocess函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: actionsEqual

function actionsEqual(input, expectedActions) {
  let ast = preprocess(input);

  let templateVisitor = new TemplateVisitor();
  templateVisitor.visit(ast);
  let actualActions = templateVisitor.actions;

  // Remove the AST node reference from the actions to keep tests leaner
  for (let i = 0; i < actualActions.length; i++) {
    actualActions[i][1].shift();
  }

  assert.deepEqual(actualActions, expectedActions);
}
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:14,代碼來源:template-visitor-node-test.ts

示例2: test

test('plugins are provided the syntax package', assert => {
  assert.expect(1);

  preprocess('<div></div>', {
    plugins: {
      ast: [
        ({ syntax }) => {
          assert.equal(syntax.Walker, Walker);

          return { name: 'plugin-a', visitor: {} };
        }
      ]
    }
  });
});
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:15,代碼來源:plugin-node-test.ts

示例3: astEqual

export function astEqual(actual: any | null | undefined, expected: any | null | undefined, message?: string) {
  if (typeof actual === 'string') {
    actual = parse(actual);
  }
  if (typeof expected === 'string') {
    expected = parse(expected);
  }

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

  QUnit.assert.deepEqual(actual, expected, message);
}
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:13,代碼來源:support.ts

示例4: 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

示例5: function

test('Element modifiers', function() {
  let ast = parse(`<div {{modifier}}{{modifier param1 param2 key1=value key2=value}}></div>`);

  traversalEqual(ast, [
    ['enter', ast],
    ['enter', ast.body[0]],
    ['enter', ast.body[0].modifiers[0]],
    ['enter', ast.body[0].modifiers[0].path],
    ['exit',  ast.body[0].modifiers[0].path],
    ['enter', ast.body[0].modifiers[0].hash],
    ['exit',  ast.body[0].modifiers[0].hash],
    ['exit',  ast.body[0].modifiers[0]],
    ['enter', ast.body[0].modifiers[1]],
    ['enter', ast.body[0].modifiers[1].path],
    ['exit',  ast.body[0].modifiers[1].path],
    ['enter', ast.body[0].modifiers[1].params[0]],
    ['exit',  ast.body[0].modifiers[1].params[0]],
    ['enter', ast.body[0].modifiers[1].params[1]],
    ['exit',  ast.body[0].modifiers[1].params[1]],
    ['enter', ast.body[0].modifiers[1].hash],
    ['enter', ast.body[0].modifiers[1].hash.pairs[0]],
    ['enter', ast.body[0].modifiers[1].hash.pairs[0].value],
    ['exit',  ast.body[0].modifiers[1].hash.pairs[0].value],
    ['exit' , ast.body[0].modifiers[1].hash.pairs[0]],
    ['enter', ast.body[0].modifiers[1].hash.pairs[1]],
    ['enter', ast.body[0].modifiers[1].hash.pairs[1].value],
    ['exit',  ast.body[0].modifiers[1].hash.pairs[1].value],
    ['exit' , ast.body[0].modifiers[1].hash.pairs[1]],
    ['exit',  ast.body[0].modifiers[1].hash],
    ['exit',  ast.body[0].modifiers[1]],
    ['exit',  ast.body[0]],
    ['exit',  ast]
  ]);
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:34,代碼來源:visiting-node-test.ts

示例6: Plugin

test('AST plugins can be chained', assert => {
  assert.expect(2);

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

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

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

    return 'BOOM!';
  };

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

  assert.equal(ast, 'BOOM!', 'return value from last AST transform is used');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:28,代碼來源:plugin-node-test.ts

示例7: compareWalkedNodes

function compareWalkedNodes(html, expected) {
  let ast = parse(html);
  let walker = new Walker();
  let nodes = [];

  walker.visit(ast, function(node) {
    nodes.push(node.type);
  });

  QUnit.assert.deepEqual(nodes, expected);
}
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:11,代碼來源:walker-node-test.ts


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