Fix benchmark require (#4792)

master
Lucas Duailibe 2018-07-02 13:17:08 -03:00 committed by GitHub
parent e9f489cea1
commit 6a6e8cada0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -200,11 +200,21 @@ function format(context, input, opt) {
return { formatted: pp, filepath: opt.filepath || "(stdin)\n" };
}
/* istanbul ignore if */
if (context.argv["debug-benchmark"]) {
let benchmark;
try {
benchmark = eval("require")("benchmark");
} catch (err) {
context.logger.debug(
"'--debug-benchmark' requires the 'benchmark' package to be installed."
);
process.exit(2);
}
context.logger.debug(
"'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module."
);
const suite = new require("benchmark").Suite();
const suite = new benchmark.Suite();
suite
.add("format", () => {
prettier.formatWithCursor(input, opt);