本文整理汇总了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);
}
开发者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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论