本文整理匯總了TypeScript中ast-types.astNodesAreEquivalent類的典型用法代碼示例。如果您正苦於以下問題:TypeScript astNodesAreEquivalent類的具體用法?TypeScript astNodesAreEquivalent怎麽用?TypeScript astNodesAreEquivalent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了astNodesAreEquivalent類的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)
);
}