From 8a7ceda7a71fd608dc5a40e3d89181f734fe8550 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Mon, 5 Oct 2020 16:17:09 +0100 Subject: [PATCH] Typecheck sources/JavaScriptBreakpointsSidebarPane.js with TypeScript R=szuend@chromium.org Bug: 1011811 Change-Id: Ia028fe9189fe55d77b636d7d60fc4dbc5714c5bf Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2450036 Commit-Queue: Tim van der Lippe Reviewed-by: Paul Lewis --- .../JavaScriptBreakpointsSidebarPane.js | 32 +++++++++---------- front_end/sources/sources-legacy.js | 8 ----- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/front_end/sources/JavaScriptBreakpointsSidebarPane.js b/front_end/sources/JavaScriptBreakpointsSidebarPane.js index 3b89d5674b..dac4487078 100644 --- a/front_end/sources/JavaScriptBreakpointsSidebarPane.js +++ b/front_end/sources/JavaScriptBreakpointsSidebarPane.js @@ -2,11 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @ts-nocheck -// TODO(crbug.com/1011811): Enable TypeScript compiler checks - import * as Bindings from '../bindings/bindings.js'; import * as Common from '../common/common.js'; +import * as Platform from '../platform/platform.js'; import * as SDK from '../sdk/sdk.js'; import * as TextUtils from '../text_utils/text_utils.js'; import * as UI from '../ui/ui.js'; @@ -14,8 +12,7 @@ import * as Workspace from '../workspace/workspace.js'; /** * @implements {UI.ContextFlavorListener.ContextFlavorListener} - * @implements {UI.ListControl.ListDelegate} - * @unrestricted + * @implements {UI.ListControl.ListDelegate} */ export class JavaScriptBreakpointsSidebarPane extends UI.ThrottledWidget.ThrottledWidget { constructor() { @@ -277,8 +274,8 @@ export class JavaScriptBreakpointsSidebarPane extends UI.ThrottledWidget.Throttl lineText.substring(item.showColumn ? uiLocation.columnNumber : 0).trimEndWithMaxLength(maxSnippetLength); } - element[breakpointLocationsSymbol] = item.locations; - element[locationSymbol] = uiLocation; + elementToBreakpointMap.set(element, item.locations); + elementToUILocationMap.set(element, uiLocation); return element; } @@ -304,8 +301,8 @@ export class JavaScriptBreakpointsSidebarPane extends UI.ThrottledWidget.Throttl * @override * @param {?BreakpointItem} from * @param {?BreakpointItem} to - * @param {?Element} fromElement - * @param {?Element} toElement + * @param {?HTMLElement} fromElement + * @param {?HTMLElement} toElement */ selectedItemChanged(from, to, fromElement, toElement) { if (fromElement) { @@ -350,7 +347,7 @@ export class JavaScriptBreakpointsSidebarPane extends UI.ThrottledWidget.Throttl if (!node) { return []; } - return node[breakpointLocationsSymbol] || []; + return elementToBreakpointMap.get(node) || []; } /** @@ -359,7 +356,7 @@ export class JavaScriptBreakpointsSidebarPane extends UI.ThrottledWidget.Throttl _breakpointCheckboxClicked(event) { const hadFocus = this.hasFocus(); const breakpoints = this._breakpointLocations(event).map(breakpointLocation => breakpointLocation.breakpoint); - const newState = event.target.checkboxElement.checked; + const newState = /** @type {!UI.UIUtils.CheckboxLabel} */ (event.target).checkboxElement.checked; for (const breakpoint of breakpoints) { breakpoint.setEnabled(newState); const item = @@ -523,16 +520,19 @@ class BreakpointItem { } } -export const locationSymbol = Symbol('location'); +/** @type {!WeakMap} */ +const elementToUILocationMap = new WeakMap(); + /** * @param {!Element} element */ export function retrieveLocationForElement(element) { - return element[locationSymbol]; + return elementToUILocationMap.get(element); } -export const checkboxLabelSymbol = Symbol('checkbox-label'); -export const snippetElementSymbol = Symbol('snippet-element'); -export const breakpointLocationsSymbol = Symbol('locations'); + +/** @type {!WeakMap>} */ +const elementToBreakpointMap = new WeakMap(); /** @typedef {{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLocation: !Workspace.UISourceCode.UILocation}} */ +// @ts-ignore typedef export let BreakpointLocation; diff --git a/front_end/sources/sources-legacy.js b/front_end/sources/sources-legacy.js index 0fde3fbddd..e119b0e4d0 100644 --- a/front_end/sources/sources-legacy.js +++ b/front_end/sources/sources-legacy.js @@ -91,14 +91,6 @@ Sources.JavaScriptBreakpointsSidebarPane = Sources.JavaScriptBreakpointsSidebarPane.retrieveLocationForElement = SourcesModule.JavaScriptBreakpointsSidebarPane.retrieveLocationForElement; -Sources.JavaScriptBreakpointsSidebarPane._locationSymbol = - SourcesModule.JavaScriptBreakpointsSidebarPane.locationSymbol; -Sources.JavaScriptBreakpointsSidebarPane._checkboxLabelSymbol = - SourcesModule.JavaScriptBreakpointsSidebarPane.checkboxLabelSymbol; -Sources.JavaScriptBreakpointsSidebarPane._snippetElementSymbol = - SourcesModule.JavaScriptBreakpointsSidebarPane.snippetElementSymbol; -Sources.JavaScriptBreakpointsSidebarPane._breakpointLocationsSymbol = - SourcesModule.JavaScriptBreakpointsSidebarPane.breakpointLocationsSymbol; /** @constructor */ Sources.JavaScriptCompilerPlugin = SourcesModule.JavaScriptCompilerPlugin.JavaScriptCompilerPlugin;