From 59d25cd7ff0178ed5bf84cbbe8ff674523638cea Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Mon, 31 Aug 2020 16:00:24 +0200 Subject: [PATCH] [ts] Type-check ui/Geometry.js with TypeScript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: chromium:1011811 Change-Id: I4680d84aa2410a050a1d92d523570ac45471ed12 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2382857 Commit-Queue: Mathias Bynens Reviewed-by: Simon Zünd --- front_end/legacy/legacy-defs.d.ts | 5 ++++- front_end/ui/Geometry.js | 28 +++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/front_end/legacy/legacy-defs.d.ts b/front_end/legacy/legacy-defs.d.ts index 2e93017dcd..bd4d5e52e0 100644 --- a/front_end/legacy/legacy-defs.d.ts +++ b/front_end/legacy/legacy-defs.d.ts @@ -25,6 +25,9 @@ type ITemplateArray = TemplateStringsArray // Type alias for the type that has been removed in Chrome 54. type FileError = DOMError; +// Type alias for DOMMatrix, formerly known as WebKitCSSMatrix. +type CSSMatrix = DOMMatrix; + interface String { compareTo(other: string): number; trimEndWithMaxLength(maxLength: number): string; @@ -160,4 +163,4 @@ interface ServicePort { send(message: string): Promise; close(): Promise; -} \ No newline at end of file +} diff --git a/front_end/ui/Geometry.js b/front_end/ui/Geometry.js index 66afbe166f..57ae9faf44 100644 --- a/front_end/ui/Geometry.js +++ b/front_end/ui/Geometry.js @@ -28,9 +28,6 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -// @ts-nocheck -// TODO(crbug.com/1011811): Enable TypeScript compiler checks - /** * @type {number} */ @@ -131,8 +128,8 @@ export class CubicBezier { static parse(text) { const keywordValues = CubicBezier.KeywordValues; const value = text.toLowerCase().replace(/\s+/g, ''); - if (Object.keys(keywordValues).indexOf(value) !== -1) { - return CubicBezier.parse(keywordValues[value]); + if (keywordValues.has(value)) { + return CubicBezier.parse(/** @type {string} */ (keywordValues.get(value))); } const bezierRegex = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^,]+)\)$/; const match = value.match(bezierRegex); @@ -169,8 +166,8 @@ export class CubicBezier { asCSSText() { const raw = 'cubic-bezier(' + this.controlPoints.join(', ') + ')'; const keywordValues = CubicBezier.KeywordValues; - for (const keyword in keywordValues) { - if (raw === keywordValues[keyword]) { + for (const [keyword, value] of keywordValues) { + if (raw === value) { return keyword; } } @@ -181,13 +178,14 @@ export class CubicBezier { /** @type {!RegExp} */ CubicBezier.Regex = /((cubic-bezier\([^)]+\))|\b(linear|ease-in-out|ease-in|ease-out|ease)\b)/g; -CubicBezier.KeywordValues = { - 'linear': 'cubic-bezier(0, 0, 1, 1)', - 'ease': 'cubic-bezier(0.25, 0.1, 0.25, 1)', - 'ease-in': 'cubic-bezier(0.42, 0, 1, 1)', - 'ease-in-out': 'cubic-bezier(0.42, 0, 0.58, 1)', - 'ease-out': 'cubic-bezier(0, 0, 0.58, 1)' -}; +/** @type {!Map} */ +CubicBezier.KeywordValues = new Map([ + ['linear', 'cubic-bezier(0, 0, 1, 1)'], + ['ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)'], + ['ease-in', 'cubic-bezier(0.42, 0, 1, 1)'], + ['ease-in-out', 'cubic-bezier(0.42, 0, 0.58, 1)'], + ['ease-out', 'cubic-bezier(0, 0, 0.58, 1)'], +]); export class EulerAngles { @@ -319,7 +317,7 @@ export const boundsForTransformedPoints = function(matrix, points, aggregateBoun aggregateBounds = {minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -Infinity}; } if (points.length % 3) { - console.assert('Invalid size of points array'); + console.warn('Invalid size of points array'); } for (let p = 0; p < points.length; p += 3) { let vector = new Vector(points[p], points[p + 1], points[p + 2]);