mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
parent
637cd1dea4
commit
9479865d9b
2 changed files with 18 additions and 1 deletions
|
|
@ -122,6 +122,13 @@ pub struct ParserReturn<'a> {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct ParserOptions {
|
struct ParserOptions {
|
||||||
pub allow_return_outside_function: bool,
|
pub allow_return_outside_function: bool,
|
||||||
|
/// Emit `ParenthesizedExpression` in AST.
|
||||||
|
///
|
||||||
|
/// If this option is true, parenthesized expressions are represented by
|
||||||
|
/// (non-standard) `ParenthesizedExpression` nodes that have a single `expression` property
|
||||||
|
/// containing the expression inside parentheses.
|
||||||
|
///
|
||||||
|
/// Default: true
|
||||||
pub preserve_parens: bool,
|
pub preserve_parens: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,14 @@ pub struct ParserOptions {
|
||||||
#[napi(ts_type = "'script' | 'module' | 'unambiguous' | undefined")]
|
#[napi(ts_type = "'script' | 'module' | 'unambiguous' | undefined")]
|
||||||
pub source_type: Option<String>,
|
pub source_type: Option<String>,
|
||||||
pub source_filename: Option<String>,
|
pub source_filename: Option<String>,
|
||||||
|
/// Emit `ParenthesizedExpression` in AST.
|
||||||
|
///
|
||||||
|
/// If this option is true, parenthesized expressions are represented by
|
||||||
|
/// (non-standard) `ParenthesizedExpression` nodes that have a single `expression` property
|
||||||
|
/// containing the expression inside parentheses.
|
||||||
|
///
|
||||||
|
/// Default: true
|
||||||
|
pub preserve_parens: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi(object)]
|
#[napi(object)]
|
||||||
|
|
@ -56,7 +64,9 @@ fn parse<'a>(
|
||||||
Some("module") => source_type.with_module(true),
|
Some("module") => source_type.with_module(true),
|
||||||
_ => source_type,
|
_ => source_type,
|
||||||
};
|
};
|
||||||
Parser::new(allocator, source_text, source_type).parse()
|
Parser::new(allocator, source_text, source_type)
|
||||||
|
.preserve_parens(options.preserve_parens.unwrap_or(true))
|
||||||
|
.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse without returning anything.
|
/// Parse without returning anything.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue