@@ -2,7 +2,7 @@ import {createExpression, findGlobalStateRefs} from '../expression';
22import type { GlobalProperties , Feature } from '../expression' ;
33import { ICanonicalTileID } from '../tiles_and_coordinates' ;
44import { StylePropertySpecification } from '..' ;
5- import { ExpressionFilterSpecification } from '../types.g' ;
5+ import { ExpressionFilterSpecification , type FilterSpecification } from '../types.g' ;
66
77type FilterExpression = (
88 globalProperties : GlobalProperties ,
@@ -75,19 +75,20 @@ const filterSpec = {
7575 * passes its test.
7676 *
7777 * @private
78- * @param {Array } filter MapLibre filter
79- * @returns {Function } filter-evaluating function
78+ * @param filter MapLibre filter
79+ * @param [globalState] Global state object to be used for evaluating 'global-state' expressions
80+ * @returns filter-evaluating function
8081 */
81- export function featureFilter ( filter : any ) : FeatureFilter {
82+ export function featureFilter ( filter : FilterSpecification | void , globalState ?: Record < string , any > ) : FeatureFilter {
8283 if ( filter === null || filter === undefined ) {
8384 return { filter : ( ) => true , needGeometry : false , getGlobalStateRefs : ( ) => new Set ( ) } ;
8485 }
8586
8687 if ( ! isExpressionFilter ( filter ) ) {
87- filter = convertFilter ( filter ) ;
88+ filter = convertFilter ( filter ) as ExpressionFilterSpecification ;
8889 }
8990
90- const compiled = createExpression ( filter , filterSpec as StylePropertySpecification ) ;
91+ const compiled = createExpression ( filter , filterSpec as StylePropertySpecification , globalState ) ;
9192 if ( compiled . result === 'error' ) {
9293 throw new Error ( compiled . value . map ( err => `${ err . key } : ${ err . message } ` ) . join ( ', ' ) ) ;
9394 } else {
@@ -114,7 +115,7 @@ function geometryNeeded(filter) {
114115 return false ;
115116}
116117
117- function convertFilter ( filter ?: Array < any > | null ) : unknown {
118+ function convertFilter ( filter ?: Array < any > | null | void ) : unknown {
118119 if ( ! filter ) return true ;
119120 const op = filter [ 0 ] ;
120121 if ( filter . length <= 1 ) return ( op !== 'any' ) ;
0 commit comments