allow return outside function instead of needlessly logging an error

This commit is contained in:
Toshit Chawda 2024-10-27 15:14:26 -07:00
parent 8b62493bcc
commit 4efb930c20
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -15,7 +15,7 @@ use oxc::{
Visit, Visit,
}, },
diagnostics::OxcDiagnostic, diagnostics::OxcDiagnostic,
parser::Parser, parser::{ParseOptions, Parser},
span::{Atom, GetSpan, SourceType, Span}, span::{Atom, GetSpan, SourceType, Span},
syntax::operator::{AssignmentOperator, UnaryOperator}, syntax::operator::{AssignmentOperator, UnaryOperator},
}; };
@ -420,7 +420,13 @@ fn random_string() -> String {
pub fn rewrite(js: &str, url: Url, config: Config) -> Result<(Vec<u8>, Vec<OxcDiagnostic>)> { pub fn rewrite(js: &str, url: Url, config: Config) -> Result<(Vec<u8>, Vec<OxcDiagnostic>)> {
let allocator = Allocator::default(); let allocator = Allocator::default();
let source_type = SourceType::default(); let source_type = SourceType::default();
let ret = Parser::new(&allocator, js, source_type).parse(); let ret = Parser::new(&allocator, js, source_type)
.with_options(ParseOptions {
parse_regular_expression: false, // default
allow_return_outside_function: true,
preserve_parens: true, // default
})
.parse();
let program = ret.program; let program = ret.program;