Browse Source

Removes emptyStr references

main
Eric Amodio 1 year ago
parent
commit
8d11021cf8
6 changed files with 39 additions and 51 deletions
  1. +2
    -4
      src/git/parsers/remoteParser.ts
  2. +3
    -5
      src/git/parsers/statusParser.ts
  3. +6
    -7
      src/git/parsers/treeParser.ts
  4. +9
    -13
      src/system/decorators/log.ts
  5. +2
    -3
      src/system/function.ts
  6. +17
    -19
      src/system/logger.ts

+ 2
- 4
src/git/parsers/remoteParser.ts View File

@ -4,8 +4,6 @@ import type { GitRemoteType } from '../models/remote';
import { GitRemote } from '../models/remote';
import type { getRemoteProviderMatcher } from '../remotes/remoteProviders';
const emptyStr = '';
const remoteRegex = /^(.*)\t(.*)\s\((.*)\)$/gm;
export function parseGitRemotes(
@ -117,11 +115,11 @@ export const remoteUrlRegex =
export function parseGitRemoteUrl(url: string): [scheme: string, domain: string, path: string] {
const match = remoteUrlRegex.exec(url);
if (match == null) return [emptyStr, emptyStr, url];
if (match == null) return ['', '', url];
return [
match[1] || match[3] || match[6],
match[2] || match[4] || match[5] || match[7] || match[8],
match[9].replace(/\.git\/?$/, emptyStr),
match[9].replace(/\.git\/?$/, ''),
];
}

+ 3
- 5
src/git/parsers/statusParser.ts View File

@ -2,8 +2,6 @@ import { normalizePath } from '../../system/path';
import { maybeStopWatch } from '../../system/stopwatch';
import { GitStatus, GitStatusFile } from '../models/status';
const emptyStr = '';
const aheadStatusV1Regex = /(?:ahead ([0-9]+))/;
const behindStatusV1Regex = /(?:behind ([0-9]+))/;
@ -53,7 +51,7 @@ function parseStatusV1(lines: string[], repoPath: string): GitStatus {
const rawStatus = line.substring(0, 2);
const fileName = line.substring(3);
if (rawStatus.startsWith('R') || rawStatus.startsWith('C')) {
const [file1, file2] = fileName.replace(/"/g, emptyStr).split('->');
const [file1, file2] = fileName.replace(/"/g, '').split('->');
files.push(parseStatusFile(repoPath, rawStatus, file2.trim(), file1.trim()));
} else {
files.push(parseStatusFile(repoPath, rawStatus, fileName));
@ -61,7 +59,7 @@ function parseStatusV1(lines: string[], repoPath: string): GitStatus {
}
}
return new GitStatus(normalizePath(repoPath), branch ?? emptyStr, emptyStr, files, state, upstream);
return new GitStatus(normalizePath(repoPath), branch ?? '', '', files, state, upstream);
}
function parseStatusV2(lines: string[], repoPath: string): GitStatus {
@ -117,7 +115,7 @@ function parseStatusV2(lines: string[], repoPath: string): GitStatus {
}
}
return new GitStatus(normalizePath(repoPath), branch ?? emptyStr, sha ?? emptyStr, files, state, upstream);
return new GitStatus(normalizePath(repoPath), branch ?? '', sha ?? '', files, state, upstream);
}
function parseStatusFile(

+ 6
- 7
src/git/parsers/treeParser.ts View File

@ -1,7 +1,6 @@
import { maybeStopWatch } from '../../system/stopwatch';
import type { GitLsFilesEntry, GitTreeEntry } from '../models/tree';
const emptyStr = '';
const treeRegex = /(?:.+?)\s+(.+?)\s+(.+?)\s+(.+?)\s+(.+)/gm;
const filesRegex = /^(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/gm;
@ -25,12 +24,12 @@ export function parseGitTree(data: string | undefined): GitTreeEntry[] {
trees.push({
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
commitSha: sha == null || sha.length === 0 ? emptyStr : ` ${sha}`.substr(1),
commitSha: sha == null || sha.length === 0 ? '' : ` ${sha}`.substr(1),
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
path: filePath == null || filePath.length === 0 ? emptyStr : ` ${filePath}`.substr(1),
path: filePath == null || filePath.length === 0 ? '' : ` ${filePath}`.substr(1),
size: Number(size) || 0,
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
type: (type == null || type.length === 0 ? emptyStr : ` ${type}`.substr(1)) as 'blob' | 'tree',
type: (type == null || type.length === 0 ? '' : ` ${type}`.substr(1)) as 'blob' | 'tree',
});
} while (true);
@ -59,11 +58,11 @@ export function parseGitLsFiles(data: string | undefined): GitLsFilesEntry[] {
files.push({
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
path: filePath == null || filePath.length === 0 ? emptyStr : ` ${filePath}`.substr(1),
path: filePath == null || filePath.length === 0 ? '' : ` ${filePath}`.substr(1),
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
object: object == null || object.length === 0 ? emptyStr : ` ${object}`.substr(1),
object: object == null || object.length === 0 ? '' : ` ${object}`.substr(1),
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
mode: mode == null || mode.length === 0 ? emptyStr : ` ${mode}`.substr(1),
mode: mode == null || mode.length === 0 ? '' : ` ${mode}`.substr(1),
stage: parseInt(stage, 10),
});
} while (true);

+ 9
- 13
src/system/decorators/log.ts View File

@ -8,8 +8,6 @@ import { clearLogScope, getNextLogScopeId, setLogScope } from '../logger.scope';
import { isPromise } from '../promise';
import { getDurationMilliseconds } from '../string';
const emptyStr = '';
export interface LogContext {
id: number;
instance: any;
@ -124,7 +122,7 @@ export function log any>(options?: LogOptions, deb
{
id: scopeId,
instance: this,
instanceName: instanceName ?? emptyStr,
instanceName: instanceName ?? '',
name: key,
prefix: prefix,
},
@ -138,11 +136,11 @@ export function log any>(options?: LogOptions, deb
setLogScope(scopeId, scope);
}
const enter = enterFn != null ? enterFn(...args) : emptyStr;
const enter = enterFn != null ? enterFn(...args) : '';
let loggableParams: string;
if (overrides === false || args.length === 0) {
loggableParams = emptyStr;
loggableParams = '';
if (!singleLine) {
logFn.call(Logger, `${prefix}${enter}`);
@ -193,7 +191,7 @@ export function log any>(options?: LogOptions, deb
const start = timed ? hrtime() : undefined;
const logError = (ex: Error) => {
const timing = start !== undefined ? ` [${getDurationMilliseconds(start)}ms]` : emptyStr;
const timing = start !== undefined ? ` [${getDurationMilliseconds(start)}ms]` : '';
if (singleLine) {
Logger.error(
ex,
@ -235,7 +233,7 @@ export function log any>(options?: LogOptions, deb
timing = ` [${duration}ms]`;
}
} else {
timing = emptyStr;
timing = '';
exitLogFn = logFn;
}
@ -262,18 +260,16 @@ export function log any>(options?: LogOptions, deb
exitLogFn.call(
Logger,
loggableParams
? `${prefix}${enter}(${loggableParams}) ${exit}${
scope?.exitDetails || emptyStr
}${timing}`
: `${prefix}${enter} ${exit}${scope?.exitDetails || emptyStr}${timing}`,
? `${prefix}${enter}(${loggableParams}) ${exit}${scope?.exitDetails || ''}${timing}`
: `${prefix}${enter} ${exit}${scope?.exitDetails || ''}${timing}`,
);
}
} else {
exitLogFn.call(
Logger,
loggableParams
? `${prefix}(${loggableParams}) ${exit}${scope?.exitDetails || emptyStr}${timing}`
: `${prefix} ${exit}${scope?.exitDetails || emptyStr}${timing}`,
? `${prefix}(${loggableParams}) ${exit}${scope?.exitDetails || ''}${timing}`
: `${prefix} ${exit}${scope?.exitDetails || ''}${timing}`,
);
}

+ 2
- 3
src/system/function.ts View File

@ -103,7 +103,6 @@ export function debounce ReturnType>(fn: T, wai
}
const comma = ',';
const emptyStr = '';
const equals = '=';
const openBrace = '{';
const openParen = '(';
@ -119,7 +118,7 @@ export function getParameters(fn: Function): string[] {
if (fn.length === 0) return [];
let fnBody: string = Function.prototype.toString.call(fn);
fnBody = fnBody.replace(fnBodyStripCommentsRegex, emptyStr) || fnBody;
fnBody = fnBody.replace(fnBodyStripCommentsRegex, '') || fnBody;
fnBody = fnBody.slice(0, fnBody.indexOf(openBrace));
let open = fnBody.indexOf(openParen);
@ -133,7 +132,7 @@ export function getParameters(fn: Function): string[] {
const match = fnBodyRegex.exec(fnBody);
return match != null
? match[1].split(comma).map(param => param.trim().replace(fnBodyStripParamDefaultValueRegex, emptyStr))
? match[1].split(comma).map(param => param.trim().replace(fnBodyStripParamDefaultValueRegex, ''))
: [];
}

+ 17
- 19
src/system/logger.ts View File

@ -1,8 +1,6 @@
import type { LogLevel } from './logger.constants';
import type { LogScope } from './logger.scope';
const emptyStr = '';
const enum OrderedLevel {
Off = 0,
Error = 1,
@ -77,16 +75,16 @@ export const Logger = new (class Logger {
message = params.shift();
if (scopeOrMessage != null) {
message = `${scopeOrMessage.prefix} ${message ?? emptyStr}`;
message = `${scopeOrMessage.prefix} ${message ?? ''}`;
}
}
if (this.isDebugging) {
console.log(this.timestamp, `[${this.provider!.name}]`, message ?? emptyStr, ...params);
console.log(this.timestamp, `[${this.provider!.name}]`, message ?? '', ...params);
}
if (this.output == null || this.level < OrderedLevel.Debug) return;
this.output.appendLine(`${this.timestamp} ${message ?? emptyStr}${this.toLoggableParams(true, params)}`);
this.output.appendLine(`${this.timestamp} ${message ?? ''}${this.toLoggableParams(true, params)}`);
}
error(ex: Error | unknown, message?: string, ...params: any[]): void;
@ -98,7 +96,7 @@ export const Logger = new (class Logger {
if (scopeOrMessage == null || typeof scopeOrMessage === 'string') {
message = scopeOrMessage;
} else {
message = `${scopeOrMessage.prefix} ${params.shift() ?? emptyStr}`;
message = `${scopeOrMessage.prefix} ${params.shift() ?? ''}`;
}
if (message == null) {
@ -113,15 +111,15 @@ export const Logger = new (class Logger {
if (this.isDebugging) {
if (ex != null) {
console.error(this.timestamp, `[${this.provider!.name}]`, message ?? emptyStr, ...params, ex);
console.error(this.timestamp, `[${this.provider!.name}]`, message ?? '', ...params, ex);
} else {
console.error(this.timestamp, `[${this.provider!.name}]`, message ?? emptyStr, ...params);
console.error(this.timestamp, `[${this.provider!.name}]`, message ?? '', ...params);
}
}
if (this.output == null || this.level < OrderedLevel.Error) return;
this.output.appendLine(
`${this.timestamp} ${message ?? emptyStr}${this.toLoggableParams(false, params)}${
`${this.timestamp} ${message ?? ''}${this.toLoggableParams(false, params)}${
ex != null ? `\n${String(ex)}` : ''
}`,
);
@ -139,16 +137,16 @@ export const Logger = new (class Logger {
message = params.shift();
if (scopeOrMessage != null) {
message = `${scopeOrMessage.prefix} ${message ?? emptyStr}`;
message = `${scopeOrMessage.prefix} ${message ?? ''}`;
}
}
if (this.isDebugging) {
console.log(this.timestamp, `[${this.provider!.name}]`, message ?? emptyStr, ...params);
console.log(this.timestamp, `[${this.provider!.name}]`, message ?? '', ...params);
}
if (this.output == null || this.level < OrderedLevel.Info) return;
this.output.appendLine(`${this.timestamp} ${message ?? emptyStr}${this.toLoggableParams(false, params)}`);
this.output.appendLine(`${this.timestamp} ${message ?? ''}${this.toLoggableParams(false, params)}`);
}
warn(message: string, ...params: any[]): void;
@ -163,16 +161,16 @@ export const Logger = new (class Logger {
message = params.shift();
if (scopeOrMessage != null) {
message = `${scopeOrMessage.prefix} ${message ?? emptyStr}`;
message = `${scopeOrMessage.prefix} ${message ?? ''}`;
}
}
if (this.isDebugging) {
console.warn(this.timestamp, `[${this.provider!.name}]`, message ?? emptyStr, ...params);
console.warn(this.timestamp, `[${this.provider!.name}]`, message ?? '', ...params);
}
if (this.output == null || this.level < OrderedLevel.Warn) return;
this.output.appendLine(`${this.timestamp} ${message ?? emptyStr}${this.toLoggableParams(false, params)}`);
this.output.appendLine(`${this.timestamp} ${message ?? ''}${this.toLoggableParams(false, params)}`);
}
showOutputChannel(preserveFocus?: boolean): void {
@ -198,11 +196,11 @@ export const Logger = new (class Logger {
private toLoggableParams(debugOnly: boolean, params: any[]) {
if (params.length === 0 || (debugOnly && this.level < OrderedLevel.Debug && !this.isDebugging)) {
return emptyStr;
return '';
}
const loggableParams = params.map(p => this.toLoggable(p)).join(', ');
return loggableParams.length !== 0 ? ` \u2014 ${loggableParams}` : emptyStr;
return loggableParams.length !== 0 ? ` \u2014 ${loggableParams}` : '';
}
})();
@ -228,9 +226,9 @@ export function getLoggableName(instance: Function | object) {
if (typeof instance === 'function') {
if (instance.prototype?.constructor == null) return instance.name;
name = instance.prototype.constructor.name ?? emptyStr;
name = instance.prototype.constructor.name ?? '';
} else {
name = instance.constructor?.name ?? emptyStr;
name = instance.constructor?.name ?? '';
}
// Strip webpack module name (since I never name classes with an _)

Loading…
Cancel
Save