This is an automated email from the ASF dual-hosted git repository. jan pushed a commit to branch fix/3517-part7 in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 05628e891b5145c09e429eb79a21631cddf63c43 Author: Jan Lehnardt <j...@apache.org> AuthorDate: Tue Dec 6 12:50:15 2022 +0100 fix(3517): super-simplistic fix to avoid costly AST transforms when they are not needed --- share/server/60/rewrite_fun.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/share/server/60/rewrite_fun.js b/share/server/60/rewrite_fun.js index 1b27a9d14..dc273f012 100644 --- a/share/server/60/rewrite_fun.js +++ b/share/server/60/rewrite_fun.js @@ -16,6 +16,16 @@ // https://github.com/dmunch/couch-chakra/blob/master/js/normalizeFunction.js function rewriteFunInt(fun) { + + // low-key check if we actually have to do an AST transform + // most users’ functions start with the keyword function + // and if that’s the case, we bypass the AST transform + // if users need an AST transform anyway, they can change this to + // ` function` (add a leading whitespace). + if (fun.substr(0, 'function'.length-1) === 'function') { + return fun + } + const ast = esprima.parse(fun); let idx = ast.body.length - 1; let decl = {};