mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
It will be used in a check to enforce license headers DISABLE_THIRD_PARTY_CHECK=Adds recast to node_modules Change-Id: I822a368d9ba22058ac2586ea3638089a2f5b1d18 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2016746 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
45 lines
956 B
JavaScript
Executable File
45 lines
956 B
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
var recast = require("recast");
|
|
var types = recast.types;
|
|
var n = types.namedTypes;
|
|
var b = types.builders;
|
|
|
|
require("recast").run(function(ast, callback) {
|
|
recast.visit(ast, {
|
|
visitIfStatement: function(path) {
|
|
var stmt = path.node;
|
|
stmt.consequent = fix(stmt.consequent);
|
|
|
|
var alt = stmt.alternate;
|
|
if (!n.IfStatement.check(alt)) {
|
|
stmt.alternate = fix(alt);
|
|
}
|
|
|
|
this.traverse(path);
|
|
},
|
|
|
|
visitWhileStatement: visitLoop,
|
|
visitForStatement: visitLoop,
|
|
visitForInStatement: visitLoop
|
|
});
|
|
|
|
callback(ast);
|
|
});
|
|
|
|
function visitLoop(path) {
|
|
var loop = path.node;
|
|
loop.body = fix(loop.body);
|
|
this.traverse(path);
|
|
}
|
|
|
|
function fix(clause) {
|
|
if (clause) {
|
|
if (!n.BlockStatement.check(clause)) {
|
|
clause = b.blockStatement([clause]);
|
|
}
|
|
}
|
|
|
|
return clause;
|
|
}
|