{"version":3,"sources":["../../../../src/next-devtools/server/shared.ts"],"sourcesContent":["import { codeFrameColumns } from '../../shared/lib/errors/code-frame'\nimport type { StackFrame } from '../../server/lib/parse-stack'\nimport { ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric } from '../../server/lib/source-maps'\n\nexport type { StackFrame }\n\nexport interface IgnorableStackFrame extends StackFrame {\n  ignored: boolean\n}\n\nexport interface OriginalStackFramesRequest {\n  frames: readonly StackFrame[]\n  isServer: boolean\n  isEdgeServer: boolean\n  isAppDirectory: boolean\n}\n\nexport type OriginalStackFramesResponse = OriginalStackFrameResponseResult[]\n\nexport type OriginalStackFrameResponseResult =\n  PromiseSettledResult<OriginalStackFrameResponse>\n\nexport interface OriginalStackFrameResponse {\n  originalStackFrame: (StackFrame & { ignored: boolean }) | null\n  originalCodeFrame: string | null\n}\n\ntype CodeFrameRenderOptions = {\n  colors?: boolean\n  maxWidth?: number\n}\n\nexport const DEVTOOLS_CODE_FRAME_MAX_WIDTH = 1000\n\nexport function ignoreListAnonymousStackFramesIfSandwiched(\n  responses: OriginalStackFramesResponse\n): void {\n  ignoreListAnonymousStackFramesIfSandwichedGeneric(\n    responses,\n    (response) => {\n      return (\n        response.status === 'fulfilled' &&\n        response.value.originalStackFrame !== null &&\n        response.value.originalStackFrame.file === '<anonymous>'\n      )\n    },\n    (response) => {\n      return (\n        response.status === 'fulfilled' &&\n        response.value.originalStackFrame !== null &&\n        response.value.originalStackFrame.ignored === true\n      )\n    },\n    (response) => {\n      return response.status === 'fulfilled' &&\n        response.value.originalStackFrame !== null\n        ? response.value.originalStackFrame.methodName\n        : ''\n    },\n    (response) => {\n      ;(\n        response as PromiseFulfilledResult<OriginalStackFrameResponse>\n      ).value.originalStackFrame!.ignored = true\n    }\n  )\n}\n\n/**\n * It looks up the code frame of the traced source.\n * @note It ignores Next.js/React internals, as these can often be huge bundled files.\n */\nexport function getOriginalCodeFrame(\n  frame: IgnorableStackFrame,\n  source: string | null,\n  colorsOrOptions: boolean | CodeFrameRenderOptions = process.stdout?.isTTY ??\n    false\n): string | null {\n  if (!source || frame.line1 == null) {\n    return null\n  }\n\n  const { colors, maxWidth } =\n    typeof colorsOrOptions === 'boolean'\n      ? { colors: colorsOrOptions, maxWidth: undefined }\n      : {\n          colors: colorsOrOptions.colors ?? process.stdout?.isTTY ?? false,\n          maxWidth: colorsOrOptions.maxWidth,\n        }\n\n  return (\n    codeFrameColumns(\n      source,\n      {\n        start: {\n          line: frame.line1,\n          column: frame.column1 ?? undefined,\n        },\n      },\n      {\n        color: colors,\n        maxWidth,\n      }\n    ) ?? null\n  )\n}\n"],"names":["codeFrameColumns","ignoreListAnonymousStackFramesIfSandwiched","ignoreListAnonymousStackFramesIfSandwichedGeneric","DEVTOOLS_CODE_FRAME_MAX_WIDTH","responses","response","status","value","originalStackFrame","file","ignored","methodName","getOriginalCodeFrame","frame","source","colorsOrOptions","process","stdout","isTTY","line1","colors","maxWidth","undefined","start","line","column","column1","color"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,qCAAoC;AAErE,SAASC,8CAA8CC,iDAAiD,QAAQ,+BAA8B;AA8B9I,OAAO,MAAMC,gCAAgC,KAAI;AAEjD,OAAO,SAASF,2CACdG,SAAsC;IAEtCF,kDACEE,WACA,CAACC;QACC,OACEA,SAASC,MAAM,KAAK,eACpBD,SAASE,KAAK,CAACC,kBAAkB,KAAK,QACtCH,SAASE,KAAK,CAACC,kBAAkB,CAACC,IAAI,KAAK;IAE/C,GACA,CAACJ;QACC,OACEA,SAASC,MAAM,KAAK,eACpBD,SAASE,KAAK,CAACC,kBAAkB,KAAK,QACtCH,SAASE,KAAK,CAACC,kBAAkB,CAACE,OAAO,KAAK;IAElD,GACA,CAACL;QACC,OAAOA,SAASC,MAAM,KAAK,eACzBD,SAASE,KAAK,CAACC,kBAAkB,KAAK,OACpCH,SAASE,KAAK,CAACC,kBAAkB,CAACG,UAAU,GAC5C;IACN,GACA,CAACN;;QAEGA,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