lib: refactor source map stack trace prepare

• Make use of the logical OR  operator (`||`) for better
readability.
• Remove unnecessary conditional and wrapping.

PR-URL: https://github.com/nodejs/node/pull/41698
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Mohammed Keyvanzadeh 2022-01-30 01:31:55 +03:30 committed by GitHub
parent 05e9cb6f22
commit 85eca3d2c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -89,12 +89,12 @@ const prepareStackTrace = (globalThis, error, trace) => {
// Construct call site name based on: v8.dev/docs/stack-trace-api:
const fnName = t.getFunctionName() ?? t.getMethodName();
const originalName = `${t.getTypeName() !== 'global' ?
`${t.getTypeName()}.` : ''}${fnName ? fnName : '<anonymous>'}`;
`${t.getTypeName()}.` : ''}${fnName || '<anonymous>'}`;
// The original call site may have a different symbol name
// associated with it, use it:
const prefix = (name && name !== originalName) ?
`${name}` :
`${originalName ? originalName : ''}`;
`${originalName}`;
const hasName = !!(name || originalName);
const originalSourceNoScheme =
StringPrototypeStartsWith(originalSource, 'file://') ?
@ -160,7 +160,7 @@ function getErrorSource(
let prefix = '';
for (const character of new SafeStringIterator(
StringPrototypeSlice(line, 0, originalColumn + 1))) {
prefix += (character === '\t') ? '\t' :
prefix += character === '\t' ? '\t' :
StringPrototypeRepeat(' ', getStringWidth(character));
}
prefix = StringPrototypeSlice(prefix, 0, -1); // The last character is '^'.