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


TypeScript astNodesAreEquivalent.assert方法代碼示例

本文整理匯總了TypeScript中ast-types.astNodesAreEquivalent.assert方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript astNodesAreEquivalent.assert方法的具體用法?TypeScript astNodesAreEquivalent.assert怎麽用?TypeScript astNodesAreEquivalent.assert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ast-types.astNodesAreEquivalent的用法示例。


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

示例1: check

 function check(source: string) {
   var ast1 = parse(source, parseOptions);
   var ast2 = parse(
     printer.printGenerically(ast1).code,
     parseOptions
   );
   types.astNodesAreEquivalent.assert(ast1, ast2);
 }
開發者ID:benjamn,項目名稱:recast,代碼行數:8,代碼來源:jsx.ts

示例2: check

 function check(source: string, parseOptions?: any) {
   parseOptions = parseOptions || esprimaParserParseOptions;
   var ast1 = parse(source, parseOptions);
   var code = printer.printGenerically(ast1).code;
   var ast2 = parse(code, parseOptions);
   types.astNodesAreEquivalent.assert(ast1, ast2);
   assert.strictEqual(source, code);
 }
開發者ID:benjamn,項目名稱:recast,代碼行數:8,代碼來源:flow.ts

示例3: function

    fs.readFile(path, "utf-8", function(err, source) {
        assert.equal(err, null);
        assert.strictEqual(typeof source, "string");

        var ast = recast.parse(source, options);
        types.astNodesAreEquivalent.assert(ast.original, ast);
        var code = recast.print(ast).code;
        assert.strictEqual(source, code);
    });
開發者ID:benjamn,項目名稱:recast,代碼行數:9,代碼來源:identity.ts

示例4: it

  it("ReprintedParens", function () {
    var code = "a(function g(){}.call(this));";
    var ast1 = parse(code);
    var body = ast1.program.body;

    // Copy the function from a position where it does not need
    // parentheses to a position where it does need parentheses.
    body.push(b.expressionStatement(
      body[0].expression.arguments[0]));

    var generic = printer.printGenerically(ast1).code;
    var ast2 = parse(generic);
    types.astNodesAreEquivalent.assert(ast1, ast2);

    var reprint = printer.print(ast1).code;
    var ast3 = parse(reprint);
    types.astNodesAreEquivalent.assert(ast1, ast3);

    body.shift();
    reprint = printer.print(ast1).code;
    var ast4 = parse(reprint);
    assert.strictEqual(ast4.program.body.length, 1);
    var callExp = ast4.program.body[0].expression;
    n.CallExpression.assert(callExp);
    n.MemberExpression.assert(callExp.callee);
    n.FunctionExpression.assert(callExp.callee.object);
    types.astNodesAreEquivalent.assert(ast1, ast4);

    var objCode = "({ foo: 42 }.foo);";
    var objAst = parse(objCode);
    var memExp = objAst.program.body[0].expression;
    n.MemberExpression.assert(memExp);
    n.ObjectExpression.assert(memExp.object);
    n.Identifier.assert(memExp.property);
    assert.strictEqual(memExp.property.name, "foo");
    var blockStmt = b.blockStatement([b.expressionStatement(memExp)]);
    reprint = printer.print(blockStmt).code;
    types.astNodesAreEquivalent.assert(
      blockStmt,
      parse(reprint).program.body[0]
    );
  });
開發者ID:benjamn,項目名稱:recast,代碼行數:42,代碼來源:parens.ts

示例5: check

function check(expr: any) {
  const ast = parse(expr);
  const reprinted = printer.print(ast).code;
  assert.strictEqual(reprinted, expr);

  const expressionAst = parseExpression(expr);
  const generic = printer.printGenerically(expressionAst).code;
  types.astNodesAreEquivalent.assert(
    expressionAst,
    parseExpression(generic)
  );
}
開發者ID:benjamn,項目名稱:recast,代碼行數:12,代碼來源:parens.ts


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