| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import ErrorStackParser from 'error-stack-parser'; |
| 11 | import testErrorStack, { |
| 12 | SOURCE_STACK_FRAME_LINE_NUMBER, |
| 13 | } from './ErrorTesterCompiled'; |
| 14 | |
| 15 | let sourceMapsAreAppliedToErrors: boolean | null = null; |
| 16 | |
| 17 | // Source maps are automatically applied to Error stack frames. |
| 18 | export function areSourceMapsAppliedToErrors(): boolean { |
| 19 | if (sourceMapsAreAppliedToErrors === null) { |
| 20 | try { |
| 21 | testErrorStack(); |
| 22 | sourceMapsAreAppliedToErrors = false; |
| 23 | } catch (error) { |
| 24 | const parsed = ErrorStackParser.parse(error); |
| 25 | const topStackFrame = parsed[0]; |
| 26 | const lineNumber = topStackFrame.lineNumber; |
| 27 | if (lineNumber === SOURCE_STACK_FRAME_LINE_NUMBER) { |
| 28 | sourceMapsAreAppliedToErrors = true; |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return sourceMapsAreAppliedToErrors === true; |
| 34 | } |