/core-rules)
    * [ Governance ](/docs/latest/contribute/governance)
    * [ Report a Security Vulnerability ](/docs/latest/contribute/report-security-vulnerability)
  * [ Maintain ESLint ](/docs/latest/maintain/)
    * [ How ESLint is Maintained ](/docs/latest/maintain/overview)
    * [ Manage Issues and Pull Requests ](/docs/latest/maintain/manage-issues)
    * [ Review Pull Requests ](/docs/latest/maintain/review-pull-requests)
    * [ Manage Releases ](/docs/latest/maintain/manage-releases)
    * [ Working Groups ](/docs/latest/maintain/working-groups)

#  Custom Parsers

##  Table of Contents

  1. Creating a Custom Parser 
    1. Methods in Custom Parsers 
    2. parse Return Object 
    3. parseForESLint Return Object 
    4. Meta Data in Custom Parsers 
  2. AST Specification 
    1. All Nodes 
    2. The Program Node 
    3. The Literal Node 
  3. Packaging a Custom Parser 
  4. Example 

ESLint custom parsers let you extend ESLint to support linting new non-
standard JavaScript language features or custom syntax in your code. A parser
is responsible for taking your code and transforming it into an abstract
syntax tree (AST) that ESLint can then analyze and lint.

##  Creating a Custom Parser

###  Methods in Custom Parsers

A custom parser is a JavaScript object with either a ` parse ` or `
parseForESLint ` method. The ` parse ` method only returns the AST, whereas `
parseForESLint ` also returns additional values that let the parser customize
the behavior of ESLint even more.

Both methods should take in the source code as the first argument, and an
optional configuration object as the second argument, which is provided as [ `
parserOptions ` ](../use/configure/language-options#specifying-parser-options)
in a configuration file.

    
    
    // customParser.js
    
    const espree = require("espree");
    
    // Logs the duration it takes to parse each file.
    function parse(code, options) {
        const label = `Parsing file "${options.filePath}"`;
        console.time(label);
        const ast = espree.parse(code, options);
        console.timeEnd(label);
        return ast; // Only the AST is returned.
    };
    
    module.exports = { parse };
    
    
    1  
    2  
    3  
    4  
    5  
    6  
    7  
    8  
    9  
    10  
    11  
    12  
    13  
    14  
    

###  ` parse ` Return Object

The ` parse ` method should simply return the  AST  object.

###  ` parseForESLint ` Return Object

The ` parseForESLint ` method should return an object that contains the
required property ` ast ` and optional properties ` services ` , `
scopeManager ` , and ` visitorKeys ` .

  * ` ast ` should contain the  AST  object. 
  * ` services ` can contain any parser-dependent services (such as type checkers for nodes). The value of the ` services ` property is available to rules as ` context.sourceCode.parserServices ` . Default is an empty object. 
  * ` scopeManager ` can be a [ ScopeManager ](./scope-manager-interface) object. Custom parsers can use customized scope analysis for experimental/enhancement syntaxes. The default is the ` ScopeManager ` object which is created by [ eslint-scope ](https://github.com/eslint/eslint-scope) . 
    * Support for ` scopeManager ` was added in ESLint v4.14.0. ESLint versions that support ` scopeManager ` will provide an ` eslintScopeManager: true ` property in ` parserOptions ` , which can be used for feature detection. 
  * ` visitorKeys ` can be an object to customize AST traversal. The keys of the object are the type of AST nodes. Each value is an array of the property names which should be traversed. The default is [ KEYS of ` eslint-visitor-keys ` ](https://github.com/eslint/eslint-visitor-keys#evkkeys) . 
    * Support for ` visitorKeys ` was added in ESLint v4.14.0. ESLint versions that support ` visitorKeys ` will provide an ` eslintVisitorKeys: true ` property in ` parserOptions ` , which can be used for feature detection. 

###  Meta Data in Custom Parsers