Typecheck bindings/CSSWorkspaceBinding.js with TypeScript
R=szuend@chromium.org
Bug: 1011811
Change-Id: I8b9b4f3daf3d6687699c18d4763b0ee07536c8f5
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2372392
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
diff --git a/front_end/bindings/CSSWorkspaceBinding.js b/front_end/bindings/CSSWorkspaceBinding.js
index bc0fc30..eda5fab 100644
--- a/front_end/bindings/CSSWorkspaceBinding.js
+++ b/front_end/bindings/CSSWorkspaceBinding.js
@@ -1,10 +1,9 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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 Common from '../common/common.js';
+import * as Platform from '../platform/platform.js';
import * as SDK from '../sdk/sdk.js';
import * as Workspace from '../workspace/workspace.js'; // eslint-disable-line no-unused-vars
@@ -36,7 +35,7 @@
this._sourceMappings = [];
targetManager.observeModels(SDK.CSSModel.CSSModel, this);
- /** @type {!Set.<!Promise>} */
+ /** @type {!Set.<!Promise<?>>} */
this._liveLocationPromises = new Set();
}
@@ -58,6 +57,14 @@
}
/**
+ * @param {!SDK.CSSModel.CSSModel} cssModel
+ * @return {!ModelInfo}
+ */
+ _getCSSModelInfo(cssModel) {
+ return /** @type {!ModelInfo} */ (this._modelToInfo.get(cssModel));
+ }
+
+ /**
* @override
* @param {!SDK.CSSModel.CSSModel} cssModel
*/
@@ -70,7 +77,7 @@
* @param {!SDK.CSSModel.CSSModel} cssModel
*/
modelRemoved(cssModel) {
- this._modelToInfo.get(cssModel)._dispose();
+ this._getCSSModelInfo(cssModel)._dispose();
this._modelToInfo.delete(cssModel);
}
@@ -78,14 +85,14 @@
* The promise returned by this function is resolved once all *currently*
* pending LiveLocations are processed.
*
- * @return {!Promise}
+ * @return {!Promise<?>}
*/
- pendingLiveLocationChangesPromise() {
- return Promise.all(this._liveLocationPromises);
+ async pendingLiveLocationChangesPromise() {
+ await Promise.all(this._liveLocationPromises);
}
/**
- * @param {!Promise} promise
+ * @param {!Promise<?>} promise
*/
_recordLiveLocationChange(promise) {
promise.then(() => {
@@ -96,23 +103,23 @@
/**
* @param {!SDK.CSSStyleSheetHeader.CSSStyleSheetHeader} header
- * @return {!Promise}
+ * @return {!Promise<void>}
*/
async updateLocations(header) {
- const updatePromise = this._modelToInfo.get(header.cssModel())._updateLocations(header);
+ const updatePromise = this._getCSSModelInfo(header.cssModel())._updateLocations(header);
this._recordLiveLocationChange(updatePromise);
await updatePromise;
}
/**
* @param {!SDK.CSSModel.CSSLocation} rawLocation
- * @param {function(!LiveLocationInterface)} updateDelegate
+ * @param {function(!LiveLocationInterface):!Promise<void>} updateDelegate
* @param {!LiveLocationPool} locationPool
* @return {!Promise<!LiveLocation>}
*/
createLiveLocation(rawLocation, updateDelegate, locationPool) {
const locationPromise =
- this._modelToInfo.get(rawLocation.cssModel())._createLiveLocation(rawLocation, updateDelegate, locationPool);
+ this._getCSSModelInfo(rawLocation.cssModel())._createLiveLocation(rawLocation, updateDelegate, locationPool);
this._recordLiveLocationChange(locationPromise);
return locationPromise;
}
@@ -155,7 +162,7 @@
return uiLocation;
}
}
- return this._modelToInfo.get(rawLocation.cssModel())._rawLocationToUILocation(rawLocation);
+ return this._getCSSModelInfo(rawLocation.cssModel())._rawLocationToUILocation(rawLocation);
}
/**
@@ -193,6 +200,7 @@
* @return {?Workspace.UISourceCode.UILocation}
*/
rawLocationToUILocation(rawLocation) {
+ throw new Error('Not implemented yet');
}
/**
@@ -200,6 +208,7 @@
* @return {!Array<!SDK.CSSModel.CSSLocation>}
*/
uiLocationToRawLocations(uiLocation) {
+ throw new Error('Not implemented yet');
}
}
@@ -236,7 +245,7 @@
/**
* @param {!SDK.CSSModel.CSSLocation} rawLocation
- * @param {function(!LiveLocationInterface)} updateDelegate
+ * @param {function(!LiveLocationInterface):!Promise<void>} updateDelegate
* @param {!LiveLocationPool} locationPool
* @return {!Promise<!LiveLocation>}
*/
@@ -351,7 +360,7 @@
/**
* @param {!SDK.CSSModel.CSSLocation} rawLocation
* @param {!ModelInfo} info
- * @param {function(!LiveLocationInterface)} updateDelegate
+ * @param {function(!LiveLocationInterface):!Promise<void>} updateDelegate
* @param {!LiveLocationPool} locationPool
*/
constructor(rawLocation, info, updateDelegate, locationPool) {
@@ -360,6 +369,7 @@
this._lineNumber = rawLocation.lineNumber;
this._columnNumber = rawLocation.columnNumber;
this._info = info;
+ /** @type {?SDK.CSSStyleSheetHeader.CSSStyleSheetHeader} */
this._header = null;
}