From 2eea19e451fa50cf00b55762ae3cf523a5e04663 Mon Sep 17 00:00:00 2001 From: "DESKTOP-2UPTE7B\\Sadra" Date: Mon, 8 Mar 2021 20:50:29 +0330 Subject: [PATCH] Refactored pushStack function --- packages/next/build/tracer.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/next/build/tracer.ts b/packages/next/build/tracer.ts index e1da864eb6f07..166300110a299 100644 --- a/packages/next/build/tracer.ts +++ b/packages/next/build/tracer.ts @@ -9,20 +9,14 @@ export function stackPush(compiler: any, spanName: string, attrs?: any): any { let stack = compilerStacks.get(compiler) let span - if (!stack) { - compilerStacks.set(compiler, (stack = [])) + const fillSpan = () => { span = tracer.startSpan(spanName, attrs ? attrs() : undefined) - } else { - const parent = stack[stack.length - 1] - if (parent) { - tracer.withSpan(parent, () => { - span = tracer.startSpan(spanName, attrs ? attrs() : undefined) - }) - } else { - span = tracer.startSpan(spanName, attrs ? attrs() : undefined) - } } + !stack && compilerStacks.set(compiler, (stack = [])) + const parent = stack[stack.length - 1] + parent ? tracer.withSpan(parent, fillSpan) : fillSpan() + stack.push(span) return span }