1- import { Identifier } from '@mdn/browser-compat-data/types' ;
1+ import { CompatStatement , Identifier } from '@mdn/browser-compat-data/types' ;
22import { getUnprefixed , getVendorPrefix } from '@hint/utils-css' ;
33
44import { mdn } from './browser-compat-data' ;
@@ -60,9 +60,14 @@ const getTokens = (nodes: any[]): [string, string][] => {
6060 * Check if any parts of a value align with an MDN feature's matches clause.
6161 * If so, return browser support based on that feature's data.
6262 */
63- const getValueMatchesUnsupported = ( context : Identifier , featureSupport : Identifier , value : ParsedValue , browsers : string [ ] ) : UnsupportedBrowsers | null => {
63+ const getValueMatchesUnsupported = ( context : Identifier & { __compat ?: CompatStatement } , featureSupport : Identifier & { __compat ?: CompatStatement } , value : ParsedValue , browsers : string [ ] ) : UnsupportedBrowsers | null => {
6464 const { prefix, tokens, unprefixedValue } = value ;
65- const matches = featureSupport . __compat && ( featureSupport . __compat as IMatchesCompatStatement ) . matches ;
65+ let matches = featureSupport . __compat && ( featureSupport . __compat as IMatchesCompatStatement ) . matches ;
66+
67+ // Matches Block property could be available either as matches or match.
68+ if ( ! matches ) {
69+ matches = featureSupport . __compat && ( featureSupport . __compat as IMatchesCompatStatement ) . match ;
70+ }
6671
6772 if ( ! matches ) {
6873 return null ;
@@ -97,7 +102,7 @@ const getValueMatchesUnsupported = (context: Identifier, featureSupport: Identif
97102 * Check if any parts of a value align with an MDN feature's name.
98103 * If so, return browser support based on that feature's data.
99104 */
100- const getValueTokenUnsupported = ( context : Identifier , featureName : string , featureSupport : Identifier , value : ParsedValue , browsers : string [ ] ) : UnsupportedBrowsers | null => {
105+ const getValueTokenUnsupported = ( context : Identifier & { __compat ?: CompatStatement } , featureName : string , featureSupport : Identifier & { __compat ?: CompatStatement } , value : ParsedValue , browsers : string [ ] ) : UnsupportedBrowsers | null => {
101106 for ( const [ tokenPrefix , tokenValue ] of value . tokens ) {
102107 if ( featureName === tokenValue ) {
103108 return getUnsupportedBrowsers ( featureSupport , tokenPrefix , browsers , tokenValue , context ) ;
@@ -112,15 +117,15 @@ const getValueTokenUnsupported = (context: Identifier, featureName: string, feat
112117 * sub-features in the provided context, using keys and `matches` data
113118 * to test each tokenized string from the value.
114119 */
115- const getPartialValueUnsupported = ( context : Identifier , value : ParsedValue , browsers : string [ ] ) : UnsupportedBrowsers | null => {
120+ const getPartialValueUnsupported = ( context : Identifier & { __compat ?: CompatStatement } , value : ParsedValue , browsers : string [ ] ) : UnsupportedBrowsers | null => {
116121 for ( const [ featureName , featureSupport ] of Object . entries ( context ) ) {
117122 if ( featureName === '__compat' ) {
118123 continue ;
119124 }
120125
121- const unsupported = getValueMatchesUnsupported ( context , featureSupport , value , browsers ) ||
122- getValueTokenUnsupported ( context , featureName , featureSupport , value , browsers ) ||
123- getPartialValueUnsupported ( featureSupport , value , browsers ) ;
126+ const unsupported = getValueMatchesUnsupported ( context , featureSupport as Identifier & { __compat ?: CompatStatement } , value , browsers ) ||
127+ getValueTokenUnsupported ( context , featureName , featureSupport as Identifier & { __compat ?: CompatStatement } , value , browsers ) ||
128+ getPartialValueUnsupported ( featureSupport as Identifier & { __compat ?: CompatStatement } , value , browsers ) ;
124129
125130 if ( unsupported ) {
126131 return unsupported ;
@@ -138,11 +143,11 @@ const getPartialValueUnsupported = (context: Identifier, value: ParsedValue, bro
138143 * (to reduce bundle size), but referenced CSS types with partial support may
139144 * still exist (e.g. "color" and alpha_hex_value).
140145 */
141- const getValueUnsupported = ( context : Identifier | undefined , property : string , value : string , browsers : string [ ] ) : UnsupportedBrowsers | null => {
146+ const getValueUnsupported = ( context : ( Identifier & { __compat ?: CompatStatement } ) | undefined , property : string , value : string , browsers : string [ ] ) : UnsupportedBrowsers | null => {
142147 const [ data , prefix , unprefixedValue ] = getFeatureData ( context , value ) ;
143148
144149 if ( data ) {
145- return getUnsupportedBrowsers ( data , prefix , browsers , unprefixedValue , data . __compat ?. mdn_url ? undefined : context ) ;
150+ return getUnsupportedBrowsers ( data as ( Identifier & { __compat ?: CompatStatement } ) , prefix , browsers , unprefixedValue , ( data as ( Identifier & { __compat ?: CompatStatement } ) ) . __compat ?. mdn_url ? undefined : context ) ;
146151 }
147152
148153 const parsedValue : ParsedValue = {
@@ -154,7 +159,7 @@ const getValueUnsupported = (context: Identifier | undefined, property: string,
154159 // Check browser support for each CSS type associated with the property (if any).
155160 if ( types . has ( property ) ) {
156161 for ( const type of types . get ( property ) ! ) {
157- const typeContext = mdn . css . types [ type ] ;
162+ const typeContext : Identifier & { __compat ?: CompatStatement } = mdn . css . types [ type ] as ( Identifier & { __compat ?: CompatStatement } ) ;
158163 const result = typeContext && getPartialValueUnsupported ( typeContext , parsedValue , browsers ) ;
159164
160165 if ( result ) {
@@ -174,13 +179,13 @@ export const getDeclarationUnsupported = (feature: DeclarationQuery, browsers: s
174179 const key = `css-declaration:${ feature . property } |${ feature . value || '' } ` ;
175180
176181 return getCachedValue ( key , browsers , ( ) => {
177- const [ data , prefix , unprefixed ] = getFeatureData ( mdn . css . properties , feature . property ) ;
182+ const [ data , prefix , unprefixed ] = getFeatureData ( mdn . css . properties as ( Identifier & { __compat ?: CompatStatement } ) , feature . property ) ;
178183
179184 if ( feature . value ) {
180- return getValueUnsupported ( data , unprefixed , feature . value , browsers ) ;
185+ return getValueUnsupported ( data as ( Identifier & { __compat ?: CompatStatement } ) , unprefixed , feature . value , browsers ) ;
181186 }
182187
183- return getUnsupportedBrowsers ( data , prefix , browsers , unprefixed ) ;
188+ return getUnsupportedBrowsers ( data as ( Identifier & { __compat ?: CompatStatement } ) , prefix , browsers , unprefixed ) ;
184189 } ) ;
185190} ;
186191
@@ -189,19 +194,19 @@ export const getDeclarationUnsupported = (feature: DeclarationQuery, browsers: s
189194 */
190195export const getRuleUnsupported = ( feature : RuleQuery , browsers : string [ ] ) : UnsupportedBrowsers | null => {
191196 return getCachedValue ( `css-rule:${ feature . rule } ` , browsers , ( ) => {
192- const [ data , prefix , unprefixed ] = getFeatureData ( mdn . css [ 'at-rules' ] , feature . rule ) ;
197+ const [ data , prefix , unprefixed ] = getFeatureData ( mdn . css [ 'at-rules' ] as ( Identifier & { __compat ?: CompatStatement } ) , feature . rule ) ;
193198
194- return getUnsupportedBrowsers ( data , prefix , browsers , unprefixed ) ;
199+ return getUnsupportedBrowsers ( data as ( Identifier & { __compat ?: CompatStatement } ) , prefix , browsers , unprefixed ) ;
195200 } ) ;
196201} ;
197202
198203const getPseudoSelectorUnsupported = ( value : string , browsers : string [ ] ) : UnsupportedBrowsers | null => {
199204 const name = value . replace ( / ^ : : ? / , '' ) ; // Strip leading `:` or `::`.
200205
201206 return getCachedValue ( `css-pseudo-selector:${ name } ` , browsers , ( ) => {
202- const [ data , prefix , unprefixed ] = getFeatureData ( mdn . css . selectors , name ) ;
207+ const [ data , prefix , unprefixed ] = getFeatureData ( mdn . css . selectors as ( Identifier & { __compat ?: CompatStatement } ) , name ) ;
203208
204- return getUnsupportedBrowsers ( data , prefix , browsers , unprefixed ) ;
209+ return getUnsupportedBrowsers ( data as ( Identifier & { __compat ?: CompatStatement } ) , prefix , browsers , unprefixed ) ;
205210 } ) ;
206211} ;
207212
0 commit comments