Skip to content

Commit 82cc71b

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[cleanup] Use Branded type
Bug: none Change-Id: I87d6d224b96f45f6f9b55ca7243cb7d89200ffbe Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6439491 Auto-Submit: Nikolay Vitkov <nvitkov@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
1 parent 2816e66 commit 82cc71b

File tree

4 files changed

+16
-40
lines changed

4 files changed

+16
-40
lines changed

front_end/core/platform/StringUtilities.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import type {Brand} from './Brand.js';
6+
57
export const escapeCharacters = (inputString: string, charsToEscape: string): string => {
68
let foundChar = false;
79
for (let i = 0; i < charsToEscape.length; ++i) {
@@ -487,11 +489,7 @@ export const createPlainTextSearchRegex = function(query: string, flags?: string
487489
return new RegExp(regex, flags || '');
488490
};
489491

490-
class LowerCaseStringTag {
491-
private lowerCaseStringTag: (string|undefined);
492-
}
493-
494-
export type LowerCaseString = string&LowerCaseStringTag;
492+
export type LowerCaseString = Brand<string, 'lowerCaseStringTag'>;
495493

496494
export const toLowerCaseString = function(input: string): LowerCaseString {
497495
return input.toLowerCase() as LowerCaseString;

front_end/models/trace/helpers/TreeHelpers.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import type * as Platform from '../../../core/platform/platform.js';
56
import * as Types from '../types/types.js';
67

78
import {eventIsInBounds} from './Timing.js';
@@ -37,11 +38,7 @@ export interface TraceEntryNode {
3738
children: TraceEntryNode[];
3839
}
3940

40-
class TraceEntryNodeIdTag {
41-
/* eslint-disable-next-line no-unused-private-class-members */
42-
readonly #tag: (symbol|undefined);
43-
}
44-
export type TraceEntryNodeId = number&TraceEntryNodeIdTag;
41+
export type TraceEntryNodeId = Platform.Brand.Brand<number, 'traceEntryNodeIdTag'>;
4542

4643
/**
4744
* Builds a hierarchy of the entries (trace events and profile calls) in

front_end/models/trace/types/TraceEvents.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
/* eslint-disable no-unused-private-class-members */
5+
import type * as Platform from '../../../core/platform/platform.js';
66
import type * as Protocol from '../../../generated/protocol.js';
77

88
import type {Micro, Milli, Seconds, TraceWindowMicro} from './Timing.js';
@@ -1937,55 +1937,37 @@ export function isDebuggerAsyncTaskRun(event: Event): event is DebuggerAsyncTask
19371937
return event.name === Name.DEBUGGER_ASYNC_TASK_RUN;
19381938
}
19391939

1940-
class ProfileIdTag {
1941-
readonly #profileIdTag: (symbol|undefined);
1942-
}
1943-
export type ProfileID = string&ProfileIdTag;
1940+
export type ProfileID = Platform.Brand.Brand<string, 'profileIdTag'>;
19441941

19451942
export function ProfileID(value: string): ProfileID {
19461943
return value as ProfileID;
19471944
}
19481945

1949-
class CallFrameIdTag {
1950-
readonly #callFrameIdTag: (symbol|undefined);
1951-
}
1952-
export type CallFrameID = number&CallFrameIdTag;
1946+
export type CallFrameID = Platform.Brand.Brand<number, 'callFrameIdTag'>;
19531947

19541948
export function CallFrameID(value: number): CallFrameID {
19551949
return value as CallFrameID;
19561950
}
19571951

1958-
class SampleIndexTag {
1959-
readonly #sampleIndexTag: (symbol|undefined);
1960-
}
1961-
export type SampleIndex = number&SampleIndexTag;
1952+
export type SampleIndex = Platform.Brand.Brand<number, 'sampleIndexTag'>;
19621953

19631954
export function SampleIndex(value: number): SampleIndex {
19641955
return value as SampleIndex;
19651956
}
19661957

1967-
class ProcessIdTag {
1968-
readonly #processIdTag: (symbol|undefined);
1969-
}
1970-
export type ProcessID = number&ProcessIdTag;
1958+
export type ProcessID = Platform.Brand.Brand<number, 'processIdTag'>;
19711959

19721960
export function ProcessID(value: number): ProcessID {
19731961
return value as ProcessID;
19741962
}
19751963

1976-
class ThreadIdTag {
1977-
readonly #threadIdTag: (symbol|undefined);
1978-
}
1979-
export type ThreadID = number&ThreadIdTag;
1964+
export type ThreadID = Platform.Brand.Brand<number, 'threadIdTag'>;
19801965

19811966
export function ThreadID(value: number): ThreadID {
19821967
return value as ThreadID;
19831968
}
19841969

1985-
class WorkerIdTag {
1986-
readonly #workerIdTag: (symbol|undefined);
1987-
}
1988-
export type WorkerId = string&WorkerIdTag;
1970+
export type WorkerId = Platform.Brand.Brand<string, 'workerIdTag'>;
19891971

19901972
export function WorkerId(value: string): WorkerId {
19911973
return value as WorkerId;
@@ -2068,7 +2050,7 @@ export function isCommitLoad(
20682050
export function isAnimation(
20692051
event: Event,
20702052
): event is Animation {
2071-
// We've found some rare traces with an Animtation trace event from a different category: https://crbug.com/1472375#comment7
2053+
// We've found some rare traces with an Animation trace event from a different category: https://crbug.com/1472375#comment7
20722054
return event.name === 'Animation' && event.cat.includes('devtools.timeline');
20732055
}
20742056

test/conductor/resultsdb.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ export interface TestResult {
2121
};
2222
}
2323

24-
class SanitizedTestIdTag {
25-
private sanitizedTag: (string|undefined);
26-
}
27-
export type SanitizedTestId = string&SanitizedTestIdTag;
24+
export type SanitizedTestId = string&{
25+
_sanitizedTag?: string,
26+
};
2827

2928
// ResultSink checks the testId against the regex /^[[print]]{1,512}$/:
3029
// https://source.chromium.org/chromium/infra/infra/+/main:go/src/go.chromium.org/luci/resultdb/pbutil/test_result.go;l=43;drc=7ba090da753a71be5a0f37785558e9102e57fa10

0 commit comments

Comments
 (0)