@babel/parser
- Version 7.22.16
- Published
- 1.88 MB
- No dependencies
- MIT license
Install
npm i @babel/parser
yarn add @babel/parser
pnpm add @babel/parser
Overview
A JavaScript parser
Index
Variables
variable tokTypes
const tokTypes: { [name: string]: any };
Functions
function parse
parse: ( input: string, options?: ParserOptions) => ParseResult<_babel_types.File>;
Parse the provided code as an entire ECMAScript program.
function parseExpression
parseExpression: ( input: string, options?: ParserOptions) => ParseResult<_babel_types.Expression>;
Parse the provided code as a single expression.
Interfaces
interface DecoratorsPluginOptions
interface DecoratorsPluginOptions {}
property allowCallParenthesized
allowCallParenthesized?: boolean;
property decoratorsBeforeExport
decoratorsBeforeExport?: boolean;
interface FlowPluginOptions
interface FlowPluginOptions {}
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 allowNewTargetOutsideFunction
allowNewTargetOutsideFunction?: boolean;
By default, new.target use is not allowed outside of a function or class. Set this to true to accept such code.
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 annexB
annexB?: boolean;
By default, Babel parser JavaScript code according to Annex B syntax. Set this to
false
to disable such behavior.
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
totrue
as needed. When this option istrue
the parser createsParenthesizedExpression
AST nodes instead of using theextra
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 = PluginConfig;
type ParserPluginWithOptions
type ParserPluginWithOptions = | ['decorators', DecoratorsPluginOptions] | ['estree', { classFeatures?: boolean }] | ['importAttributes', { deprecatedAssertSyntax: boolean }] // @deprecated | ['moduleAttributes', { version: 'may-2020' }] | ['pipelineOperator', PipelineOperatorPluginOptions] | ['recordAndTuple', RecordAndTuplePluginOptions] | ['flow', FlowPluginOptions] | ['typescript', TypeScriptPluginOptions];
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (6)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto 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[](https://www.jsdocs.io/package/@babel/parser)
- 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>
- Updated .
Package analyzed in 3170 ms. - Missing or incorrect documentation? Open an issue for this package.