---
title: "ParsingContext | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Class ParsingContext

State associated parsing at a given point in an expression tree.

#### Private[](#private)

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Properties[](#properties)

[errors](#errors) [expectedType](#expectedtype) [key](#key) [path](#path) [registry](#registry) [scope](#scope)

### Methods[](#methods)

[checkSubtype](#checksubtype) [concat](#concat) [error](#error) [parse](#parse)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new ParsingContext(  
        registry: [ExpressionRegistry](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.ExpressionRegistry/),  
        isConstantFunc: (expression: [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)) \=> boolean,  
        path?: number\[\],  
        expectedType?: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/) | null,  
        scope?: [Scope](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Scope/),  
        errors?: [ExpressionParsingError](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.ExpressionParsingError/)\[\],  
    ): ParsingContext[](#constructorparsingcontext)
    
    #### Parameters
    
    -   registry: [ExpressionRegistry](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.ExpressionRegistry/)
    -   isConstantFunc: (expression: [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)) \=> boolean
    -   `Optional`path: number\[\]
    -   `Optional`expectedType: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/) | null
    -   `Optional`scope: [Scope](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Scope/)
    -   `Optional`errors: [ExpressionParsingError](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.ExpressionParsingError/)\[\]
    
    #### Returns ParsingContext
    

## Properties[](#properties-1)

### errors[](#errors)

errors: [ExpressionParsingError](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.ExpressionParsingError/)\[\]

### expectedType[](#expectedtype)

expectedType: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/)

### key[](#key)

key: string

### path[](#path)

path: number\[\]

### registry[](#registry)

registry: [ExpressionRegistry](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.ExpressionRegistry/)

### scope[](#scope)

scope: [Scope](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Scope/)

## Methods[](#methods-1)

### checkSubtype[](#checksubtype)

-   checkSubtype(expected: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/), t: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/)): string[](#checksubtype-1)
    
    Returns null if `t` is a subtype of `expected`; otherwise returns an error message and also pushes it to `this.errors`.
    
    #### Parameters
    
    -   expected: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/)
        
        The expected type
        
    -   t: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/)
        
        The actual type
        
    
    #### Returns string
    
    null if `t` is a subtype of `expected`; otherwise returns an error message
    

### concat[](#concat)

-   concat(  
        index: number,  
        expectedType?: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/) | null,  
        bindings?: \[string, [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)\]\[\],  
    ): ParsingContext[](#concat-1)
    
    Returns a copy of this context suitable for parsing the subexpression at index `index`, optionally appending to 'let' binding map.
    
    Note that `errors` property, intended for collecting errors while parsing, is copied by reference rather than cloned.
    
    #### Parameters
    
    -   index: number
    -   `Optional`expectedType: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/) | null
    -   `Optional`bindings: \[string, [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)\]\[\]
    
    #### Returns ParsingContext
    
    #### Private[](#private-1)
    

### error[](#error)

-   error(error: string, ...keys: number\[\]): void[](#error-1)
    
    Push a parsing (or type checking) error into the `this.errors`
    
    #### Parameters
    
    -   error: string
        
        The message
        
    -   ...keys: number\[\]
        
        Optionally specify the source of the error at a child of the current expression at `this.key`.
        
    
    #### Returns void
    
    #### Private[](#private-2)
    

### parse[](#parse)

-   parse(  
        expr: unknown,  
        index?: number,  
        expectedType?: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/) | null,  
        bindings?: \[string, [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)\]\[\],  
        options?: { typeAnnotation?: "assert" | "coerce" | "omit" },  
    ): [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)[](#parse-1)
    
    #### Parameters
    
    -   expr: unknown
        
        the JSON expression to parse
        
    -   `Optional`index: number
        
        the optional argument index if this expression is an argument of a parent expression that's being parsed
        
    -   `Optional`expectedType: [Type](https://docs.maptiler.com/sdk-js/api-reference/types/Type/) | null
    -   `Optional`bindings: \[string, [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)\]\[\]
    -   `Optional`options: { typeAnnotation?: "assert" | "coerce" | "omit" }
    
    #### Returns [Expression](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Expression/)
    
    #### Private[](#private-3)
