mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(transformer): call build module record (#2529)
This commit is contained in:
parent
0ddfc856d2
commit
f760108094
6 changed files with 22 additions and 4 deletions
|
|
@ -146,7 +146,7 @@ impl<'a> SemanticBuilder<'a> {
|
|||
pub fn build_module_record(
|
||||
mut self,
|
||||
resolved_absolute_path: PathBuf,
|
||||
program: &'a Program<'a>,
|
||||
program: &Program<'a>,
|
||||
) -> Self {
|
||||
let mut module_record_builder = ModuleRecordBuilder::new(resolved_absolute_path);
|
||||
module_record_builder.visit(program);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
use std::{env, path::Path};
|
||||
use std::{
|
||||
env,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_codegen::{Codegen, CodegenOptions};
|
||||
|
|
@ -37,6 +40,7 @@ fn main() {
|
|||
|
||||
let semantic = SemanticBuilder::new(&source_text, source_type)
|
||||
.with_trivias(ret.trivias)
|
||||
.build_module_record(PathBuf::new(), &ret.program)
|
||||
.build(&ret.program)
|
||||
.semantic;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_codegen::{Codegen, CodegenOptions};
|
||||
use oxc_diagnostics::Error;
|
||||
|
|
@ -31,8 +33,13 @@ impl Tester {
|
|||
|
||||
fn transform(&self, source_text: &str) -> Result<std::string::String, std::vec::Vec<Error>> {
|
||||
let program = Parser::new(&self.allocator, source_text, self.source_type).parse().program;
|
||||
let semantic = SemanticBuilder::new(source_text, self.source_type).build(&program).semantic;
|
||||
let semantic = SemanticBuilder::new(source_text, self.source_type)
|
||||
.build_module_record(PathBuf::new(), &program)
|
||||
.build(&program)
|
||||
.semantic;
|
||||
|
||||
let program = self.allocator.alloc(program);
|
||||
|
||||
Transformer::new(&self.allocator, self.source_type, semantic, self.options.clone())
|
||||
.build(program)
|
||||
.map(move |()| {
|
||||
|
|
|
|||
|
|
@ -189,7 +189,10 @@ impl Oxc {
|
|||
if run_options.transform() {
|
||||
// FIXME: this should not be duplicated with the linter semantic,
|
||||
// we need to fix the API so symbols and scopes can be shared.
|
||||
let semantic = SemanticBuilder::new(source_text, source_type).build(program).semantic;
|
||||
let semantic = SemanticBuilder::new(source_text, source_type)
|
||||
.build_module_record(PathBuf::new(), program)
|
||||
.build(program)
|
||||
.semantic;
|
||||
let options =
|
||||
TransformOptions { target: TransformTarget::ES2015, ..TransformOptions::default() };
|
||||
let result =
|
||||
|
|
|
|||
|
|
@ -165,8 +165,10 @@ pub trait TestCase {
|
|||
|
||||
let semantic = SemanticBuilder::new(&source_text, source_type)
|
||||
.with_trivias(ret.trivias)
|
||||
.build_module_record(PathBuf::new(), &ret.program)
|
||||
.build(&ret.program)
|
||||
.semantic;
|
||||
|
||||
let transformed_program = allocator.alloc(ret.program);
|
||||
|
||||
let result = Transformer::new(&allocator, source_type, semantic, self.transform_options())
|
||||
|
|
@ -231,6 +233,7 @@ impl TestCase for ConformanceTestCase {
|
|||
let ret = Parser::new(&allocator, &input, source_type).parse();
|
||||
let semantic = SemanticBuilder::new(&input, source_type)
|
||||
.with_trivias(ret.trivias)
|
||||
.build_module_record(PathBuf::new(), &ret.program)
|
||||
.build(&ret.program)
|
||||
.semantic;
|
||||
let program = allocator.alloc(ret.program);
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ impl TypeScriptFixtures {
|
|||
let semantic_ret = SemanticBuilder::new(&source_text, source_type)
|
||||
.with_trivias(parser_ret.trivias)
|
||||
.with_check_syntax_error(true)
|
||||
.build_module_record(PathBuf::new(), &parser_ret.program)
|
||||
.build(&parser_ret.program);
|
||||
|
||||
let errors = parser_ret.errors.into_iter().chain(semantic_ret.errors).collect::<Vec<_>>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue