• Version 7.14.4
  • Published
  • 1.61 MB
  • No dependencies
  • MIT license


npm i @babel/parser
yarn add @babel/parser
pnpm add @babel/parser


A JavaScript parser



variable tokTypes

const tokTypes: { [name: string]: any };


    function parse

    parse: (input: string, options?: ParserOptions) => any;
    • Parse the provided code as an entire ECMAScript program.

    function parseExpression

    parseExpression: (input: string, options?: ParserOptions) => any;
    • Parse the provided code as a single expression.


    interface DecoratorsPluginOptions

    interface DecoratorsPluginOptions {}

      property decoratorsBeforeExport

      decoratorsBeforeExport?: boolean;

        interface FlowPluginOptions

        interface FlowPluginOptions {}

          property all

          all?: boolean;

            interface ParserOptions

            interface ParserOptions {}

              property allowAwaitOutsideFunction

              allowAwaitOutsideFunction?: boolean;
              • By default, await use is not allowed outside of an async function. Set this to true to accept such code.

              property allowImportExportEverywhere

              allowImportExportEverywhere?: boolean;
              • By default, import and export declarations can only appear at a program's top level. Setting this option to true allows them anywhere where a statement is allowed.

              property allowReturnOutsideFunction

              allowReturnOutsideFunction?: boolean;
              • By default, a return statement at the top level raises an error. Set this to true to accept such code.

              property allowSuperOutsideMethod

              allowSuperOutsideMethod?: boolean;

                property allowUndeclaredExports

                allowUndeclaredExports?: boolean;
                • By default, exported identifiers must refer to a declared variable. Set this to true to allow export statements to reference undeclared variables.

                property createParenthesizedExpressions

                createParenthesizedExpressions?: boolean;
                • By default, the parser adds information about parentheses by setting extra.parenthesized to true as needed. When this option is true the parser creates ParenthesizedExpression AST nodes instead of using the extra property.

                property errorRecovery

                errorRecovery?: boolean;
                • By default, Babel always throws an error when it finds some invalid code. When this option is set to true, it will store the parsing error and try to continue parsing the invalid input file.

                property plugins

                plugins?: ParserPlugin[];
                • Array containing the plugins that you want to enable.

                property ranges

                ranges?: boolean;
                • Adds a ranges property to each node: [node.start, node.end]

                property sourceFilename

                sourceFilename?: string;
                • Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.

                property sourceType

                sourceType?: 'script' | 'module' | 'unambiguous';
                • Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". Defaults to "script". "unambiguous" will make @babel/parser attempt to guess, based on the presence of ES6 import or export statements. Files with ES6 imports and exports are considered "module" and are otherwise "script".

                property startLine

                startLine?: number;
                • By default, the first line of code parsed is treated as line 1. You can provide a line number to alternatively start with. Useful for integration with other source tools.

                property strictMode

                strictMode?: boolean;
                • Should the parser work in strict mode. Defaults to true if sourceType === 'module'. Otherwise, false.

                property tokens

                tokens?: boolean;
                • Adds all parsed tokens to a tokens property on the File node.

                interface PipelineOperatorPluginOptions

                interface PipelineOperatorPluginOptions {}

                  property proposal

                  proposal: 'fsharp' | 'minimal' | 'smart';

                    interface RecordAndTuplePluginOptions

                    interface RecordAndTuplePluginOptions {}

                      property syntaxType

                      syntaxType: 'bar' | 'hash';

                        Type Aliases

                        type ParserPlugin

                        type ParserPlugin =
                        | 'asyncDoExpressions'
                        | 'asyncGenerators'
                        | 'bigInt'
                        | 'classPrivateMethods'
                        | 'classPrivateProperties'
                        | 'classProperties'
                        | 'classStaticBlock'
                        | 'decimal'
                        | 'decorators'
                        | 'decorators-legacy'
                        | 'doExpressions'
                        | 'dynamicImport'
                        | 'estree'
                        | 'exportDefaultFrom'
                        | 'exportNamespaceFrom' // deprecated
                        | 'flow'
                        | 'flowComments'
                        | 'functionBind'
                        | 'functionSent'
                        | 'importMeta'
                        | 'jsx'
                        | 'logicalAssignment'
                        | 'importAssertions'
                        | 'moduleStringNames'
                        | 'nullishCoalescingOperator'
                        | 'numericSeparator'
                        | 'objectRestSpread'
                        | 'optionalCatchBinding'
                        | 'optionalChaining'
                        | 'partialApplication'
                        | 'pipelineOperator'
                        | 'placeholders'
                        | 'privateIn'
                        | 'throwExpressions'
                        | 'topLevelAwait'
                        | 'typescript'
                        | 'v8intrinsic'
                        | ParserPluginWithOptions;

                          type ParserPluginWithOptions

                          type ParserPluginWithOptions =
                          | ['decorators', DecoratorsPluginOptions]
                          | ['pipelineOperator', PipelineOperatorPluginOptions]
                          | ['recordAndTuple', RecordAndTuplePluginOptions]
                          | ['flow', FlowPluginOptions];

                            Package Files (1)

                            Dependencies (0)

                            No dependencies.

                            Dev Dependencies (6)

                            Peer Dependencies (0)

                            No peer dependencies.


                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@babel/parser.

                            • Markdown
                            • HTML
                              <a href="https://www.jsdocs.io/package/@babel/parser"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>