11/* This file is a part of @mdn/browser-compat-data
22 * See LICENSE file for more information. */
3+
4+ /**
5+ * @import { BrowserName, SupportStatement, SimpleSupportStatement } from '../../types/types.js'
6+ * @import { Logger } from '../utils.js'
7+ */
8+
39import chalk from 'chalk-template' ;
410import { compareVersions } from 'compare-versions' ;
511
612import { createStatementGroupKey } from '../utils.js' ;
713import compareStatements from '../../scripts/lib/compare-statements.js' ;
814/**
915 * Groups statements by group key.
10- * @param data The support statements to group.
11- * @returns the statement groups
16+ * @param { SimpleSupportStatement[] } data The support statements to group.
17+ * @returns { Map<string, SimpleSupportStatement[]> } the statement groups
1218 */
1319const groupByStatementKey = ( data ) => {
20+ /** @type {Map<string, SimpleSupportStatement[]> } */
1421 const groups = new Map ( ) ;
1522 for ( const support of data ) {
1623 const key = createStatementGroupKey ( support ) ;
@@ -25,10 +32,11 @@ const groupByStatementKey = (data) => {
2532} ;
2633/**
2734 * Formats a support statement as a simplified JSON-like version range.
28- * @param support The statement to format
29- * @returns The formatted range
35+ * @param { SimpleSupportStatement } support The statement to format
36+ * @returns { string } The formatted range
3037 */
3138const formatRange = ( support ) => {
39+ /** @type {string[] } */
3240 const result = [ ] ;
3341 if ( support . version_added ) {
3442 result . push ( `added: ${ support . version_added } ` ) ;
@@ -40,12 +48,12 @@ const formatRange = (support) => {
4048} ;
4149/**
4250 * Process data and check to make sure there aren't support statements whose version ranges overlap.
43- * @param data The data to test
44- * @param browser The name of the browser
51+ * @param { SupportStatement } data The data to test
52+ * @param { BrowserName } browser The name of the browser
4553 * @param {object } options The check options
46- * @param [options.logger] The logger to output errors to
47- * @param [options.fix] Whether the statements should be fixed (if possible)
48- * @returns the data (with fixes, if specified)
54+ * @param { Logger } [options.logger] The logger to output errors to
55+ * @param { boolean } [options.fix] Whether the statements should be fixed (if possible)
56+ * @returns { SupportStatement } the data (with fixes, if specified)
4957 */
5058export const checkOverlap = ( data , browser , { logger, fix = false } ) => {
5159 if ( ! Array . isArray ( data ) ) {
@@ -57,8 +65,8 @@ export const checkOverlap = (data, browser, { logger, fix = false }) => {
5765 for ( const [ groupKey , groupData ] of groups . entries ( ) ) {
5866 const statements = groupData . slice ( ) . sort ( compareStatements ) . reverse ( ) ;
5967 for ( let i = 0 ; i < statements . length - 1 ; i ++ ) {
60- const current = statements . at ( i ) ;
61- const next = statements . at ( i + 1 ) ;
68+ const current = /** @type { SimpleSupportStatement } */ ( statements . at ( i ) ) ;
69+ const next = /** @type { SimpleSupportStatement } */ ( statements . at ( i + 1 ) ) ;
6270 if ( ! statementsOverlap ( current , next ) ) {
6371 continue ;
6472 }
@@ -85,9 +93,9 @@ export const checkOverlap = (data, browser, { logger, fix = false }) => {
8593} ;
8694/**
8795 * Checks if the support statements overlap in terms of their version ranges.
88- * @param current the current statement.
89- * @param next the chronologically following statement.
90- * @returns Whether the support statements overlap.
96+ * @param { SimpleSupportStatement } current the current statement.
97+ * @param { SimpleSupportStatement } next the chronologically following statement.
98+ * @returns { boolean } Whether the support statements overlap.
9199 */
92100const statementsOverlap = ( current , next ) => {
93101 if ( typeof current . version_removed === 'string' ) {
0 commit comments