@@ -38,6 +38,7 @@ import {NumberArray} from './types/number_array';
3838import { ColorArray } from './types/color_array' ;
3939import { VariableAnchorOffsetCollection } from './types/variable_anchor_offset_collection' ;
4040import { ProjectionDefinition } from './types/projection_definition' ;
41+ import { GlobalState } from './definitions/global_state' ;
4142
4243export type Feature = {
4344 readonly type : 0 | 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon' ;
@@ -165,12 +166,14 @@ export function createExpression(expression: unknown, propertySpec?: StyleProper
165166export class ZoomConstantExpression < Kind extends EvaluationKind > {
166167 kind : Kind ;
167168 isStateDependent : boolean ;
169+ globalStateRefs : Set < string > ;
168170 _styleExpression : StyleExpression ;
169171
170172 constructor ( kind : Kind , expression : StyleExpression ) {
171173 this . kind = kind ;
172174 this . _styleExpression = expression ;
173175 this . isStateDependent = kind !== ( 'constant' as EvaluationKind ) && ! isStateConstant ( expression . expression ) ;
176+ this . globalStateRefs = findGlobalStateRefs ( expression . expression ) ;
174177 }
175178
176179 evaluateWithoutErrorHandling (
@@ -200,7 +203,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
200203 kind : Kind ;
201204 zoomStops : Array < number > ;
202205 isStateDependent : boolean ;
203-
206+ globalStateRefs : Set < string > ;
204207 _styleExpression : StyleExpression ;
205208 interpolationType : InterpolationType ;
206209
@@ -209,6 +212,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
209212 this . zoomStops = zoomStops ;
210213 this . _styleExpression = expression ;
211214 this . isStateDependent = kind !== ( 'camera' as EvaluationKind ) && ! isStateConstant ( expression . expression ) ;
215+ this . globalStateRefs = findGlobalStateRefs ( expression . expression ) ;
212216 this . interpolationType = interpolationType ;
213217 }
214218
@@ -249,6 +253,7 @@ export function isZoomExpression(expression: any): expression is ZoomConstantExp
249253
250254export type ConstantExpression = {
251255 kind : 'constant' ;
256+ globalStateRefs : Set < string > ;
252257 readonly evaluate : (
253258 globals : GlobalProperties ,
254259 feature ?: Feature ,
@@ -261,6 +266,7 @@ export type ConstantExpression = {
261266export type SourceExpression = {
262267 kind : 'source' ;
263268 isStateDependent : boolean ;
269+ globalStateRefs : Set < string > ;
264270 readonly evaluate : (
265271 globals : GlobalProperties ,
266272 feature ?: Feature ,
@@ -273,6 +279,7 @@ export type SourceExpression = {
273279
274280export type CameraExpression = {
275281 kind : 'camera' ;
282+ globalStateRefs : Set < string > ;
276283 readonly evaluate : (
277284 globals : GlobalProperties ,
278285 feature ?: Feature ,
@@ -288,6 +295,7 @@ export type CameraExpression = {
288295export type CompositeExpression = {
289296 kind : 'composite' ;
290297 isStateDependent : boolean ;
298+ globalStateRefs : Set < string > ;
291299 readonly evaluate : (
292300 globals : GlobalProperties ,
293301 feature ?: Feature ,
@@ -406,6 +414,7 @@ export function normalizePropertyExpression<T>(
406414 constant = ProjectionDefinition . parse ( value ) ;
407415 }
408416 return {
417+ globalStateRefs : new Set < string > ( ) ,
409418 kind : 'constant' ,
410419 evaluate : ( ) => constant
411420 } ;
@@ -453,6 +462,17 @@ function findZoomCurve(expression: Expression): Step | Interpolate | ExpressionP
453462 return result ;
454463}
455464
465+ export function findGlobalStateRefs ( expression : Expression , results = new Set < string > ( ) ) : Set < string > {
466+ if ( expression instanceof GlobalState ) {
467+ results . add ( expression . key ) ;
468+ }
469+
470+ expression . eachChild ( childExpression => {
471+ findGlobalStateRefs ( childExpression , results ) ;
472+ } ) ;
473+ return results ;
474+ }
475+
456476function getExpectedType ( spec : StylePropertySpecification ) : Type {
457477 const types = {
458478 color : ColorType ,
0 commit comments