Fix perf timers for object hooks (#4707)

pull/4720/head
Lukas Taegert-Atkinson 1 year ago committed by GitHub
parent 7307bfa151
commit e228fc71fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,6 +18,9 @@ export default function esmDynamicImport(): Plugin {
importsFound++;
return { left: 'import(', right: ')' };
}
},
renderStart() {
importsFound = 0;
}
};
}

@ -148,7 +148,7 @@ function printMeasurements(average, existingAverage, filter = /.*/) {
}
function clearLines(numberOfLines) {
console.info('\33[A' + '\33[2K\33[A'.repeat(numberOfLines));
console.info('\u001B[A' + '\u001B[2K\u001B[A'.repeat(numberOfLines));
}
function getExistingTimings() {
@ -203,4 +203,6 @@ function getFormattedMemory(currentMemory, persistedMemory = currentMemory) {
return color(formattedMemory);
}
const identity = x => x;
function identity(x) {
return x;
}

@ -113,14 +113,21 @@ function getPluginWithTimers(plugin: any, index: number): Plugin {
}
timerLabel += ` - ${hook}`;
const hookFunction = plugin[hook];
plugin[hook] = function (...parameters: readonly unknown[]) {
const handler = function (this: any, ...parameters: readonly unknown[]) {
timeStart(timerLabel, 4);
const result = hookFunction.apply(this, parameters);
timeEnd(timerLabel, 4);
return result;
};
let hookFunction: any;
if (typeof plugin[hook].handler === 'function') {
hookFunction = plugin[hook].handler;
plugin[hook].handler = handler;
} else {
hookFunction = plugin[hook];
plugin[hook] = handler;
}
}
}
return plugin;

@ -0,0 +1,16 @@
module.exports = {
description: 'Supports object hooks with perf=true',
options: {
perf: true,
plugins: [
{
transform: {
order: 'pre',
handler(code) {
return code.replace('FOO', 'BAR');
}
}
}
]
}
};
Loading…
Cancel
Save