feat: 引入 oxc_semantic 早期错误检查与 onlyStrict 注入

This commit is contained in:
2026-08-07 12:04:46 +08:00
parent 91528d9c19
commit b26715742f
4 changed files with 25 additions and 3 deletions
+1
View File
@@ -13,3 +13,4 @@ oxc_ast.workspace = true
oxc_span.workspace = true
oxc_diagnostics.workspace = true
oxc_syntax.workspace = true
oxc_semantic = "0.134.0"
+9 -1
View File
@@ -20,7 +20,7 @@ pub fn parse<'a>(allocator: &'a Allocator, source: &'a str) -> Result<Program<'a
use oxc_parser::Parser;
use oxc_span::SourceType;
let source_type = SourceType::default();
let source_type = SourceType::unambiguous();
let ret = Parser::new(allocator, source, source_type).parse();
if ret.panicked {
@@ -34,5 +34,13 @@ pub fn parse<'a>(allocator: &'a Allocator, source: &'a str) -> Result<Program<'a
return Err(ret.errors.into_iter().map(OxideError::from).collect());
}
// 语法早期错误(Early Errors)检查:oxc parser 把复杂早期错误委托给
// oxc_semantic(strict 绑定标识符、重复参数、NSPL、super 位置等)。
let semantic_ret =
oxc_semantic::SemanticBuilder::new().with_check_syntax_error(true).build(&ret.program);
if !semantic_ret.errors.is_empty() {
return Err(semantic_ret.errors.into_iter().map(OxideError::from).collect());
}
Ok(ret.program)
}