Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (inheritOptions = {}) => {
// the abstract syntax tree
const ast = recast.parse(code);
// add cli options to object tree
const result = buildObject(inheritOptions);
// put newly created object as right side of the ast
ast.program.body[0].expression.right = result;
return recast.prettyPrint(ast).code;
};
function print(ast) {
/**
* Not using clang-format because certain tests look bad when formatted by it.
* Recast pretty print is smarter about preserving existing spacing.
*/
let code = recast.prettyPrint(ast, {tabWidth: 2, wrapColumn: 120, quote: 'single'}).code;
code = code.replace(/(\/\/\#\s*sourceURL=[\w-]+)\.html/, '$1.js');
code = code.replace(/\s*\$\$SECRET_IDENTIFIER_FOR_LINE_BREAK\$\$\(\);/g, '\n');
return code + '\n';
}
Object.keys(files).forEach(function (absPath) {
if (typeof reject === "function" &&
reject(relative(__dirname, absPath))) {
return;
}
const code = files[absPath];
options.moduleAlias = makeUniqueId("module", code);
const ast = options.parse(code);
transform(ast, options);
assert.strictEqual(
prettyPrint(compile(code, options).ast).code,
prettyPrint(ast).code,
"Transform mismatch for " + absPath
);
});
}
function normalize(source) {
return recast.prettyPrint(recast.parse(source, recastOptions), recastOptions).code;
}
function fallback(node: CNode, meta: Object) {
const compiled = node.compile(meta);
return parse(prettyPrint(
parse(compiled), meta.options)).program.body[0].expression;
}
const generateMigrationScript = async function(environment, contentTypes) {
const migrationContents = await Promise.all(
_.map(contentTypes, async contentType => {
return generateContentTypeMigration(environment, contentType)
})
)
const migration = wrapMigrationWithBase(
b.blockStatement(_.flatten(migrationContents))
)
const output = recast.prettyPrint(migration, { tabWidth: 2 }).code
return prettier.format(output, { parser: 'babel' })
}
path.replace(
typeBuilders.memberExpression(
typeBuilders.identifier(AllVarsVariableName),
typeBuilders.identifier(key)));
return false;
}
});
const modifiedUserCode = recast.prettyPrint(ast).code;
previousCode = astFromUserCode(userCode);
return `const ${AllVarsVariableName} = ${JSON.stringify(vars)}; ${modifiedUserCode}`;
} catch (e) {
return parseCode(recast.prettyPrint(previousCode));
}
}
.map(n => {
const { code } = recast.prettyPrint(n, options);
if (n.type === 'JSXElement') {
return `${code}\n`;
}
return code;
})
.join('\n');