本文整理汇总了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);
}
示例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);
}
示例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);
});
示例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]
);
});
示例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)
);
}