• Version 7.18.6
  • Published
  • 1.89 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
    ) => ParseResult<import('@babel/types').File>;
    • Parse the provided code as an entire ECMAScript program.

    function parseExpression

    parseExpression: (
    input: string,
    options?: ParserOptions
    ) => ParseResult<import('@babel/types').Expression>;
    • Parse the provided code as a single expression.


    interface DecoratorsPluginOptions

    interface DecoratorsPluginOptions {}

      property decoratorsBeforeExport

      decoratorsBeforeExport?: boolean;

        interface FlowPluginOptions

        interface FlowPluginOptions {}

          property all

          all?: boolean;

            property enums

            enums?: boolean;

              interface ParseError

              interface ParseError {}

                property code

                code: string;

                  property reasonCode

                  reasonCode: string;

                    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 attachComment

                        attachComment?: boolean;
                        • By default, Babel attaches comments to adjacent AST nodes. When this option is set to false, comments are not attached. It can provide up to 30% performance improvement when the input code has many comments. @babel/eslint-parser will set it for you. It is not recommended to use attachComment: false with Babel transform, as doing so removes all the comments in output code, and renders annotations such as /* istanbul ignore next */ nonfunctional.

                        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 startColumn

                        startColumn?: number;
                        • By default, the parsed code is treated as if it starts from line 1, column 0. You can provide a column number to alternatively start with. Useful for integration with other source tools.

                        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: 'minimal' | 'fsharp' | 'hack' | 'smart';

                            property topicToken

                            topicToken?: '%' | '#' | '@@' | '^^' | '^';

                              interface RecordAndTuplePluginOptions

                              interface RecordAndTuplePluginOptions {}

                                property syntaxType

                                syntaxType: 'bar' | 'hash';

                                  interface TypeScriptPluginOptions

                                  interface TypeScriptPluginOptions {}

                                    property disallowAmbiguousJSXLike

                                    disallowAmbiguousJSXLike?: boolean;

                                      property dts

                                      dts?: boolean;

                                        Type Aliases

                                        type ParseResult

                                        type ParseResult<Result> = Result & {
                                        errors: ParseError[];

                                          type ParserPlugin

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

                                            type ParserPluginWithOptions

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

                                              Package Files (1)

                                              Dependencies (0)

                                              No dependencies.

                                              Dev Dependencies (5)

                                              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>