refactor(transformer)!: remove source_type param from Transformer::new (#6251)

Closes #6248.
This commit is contained in:
overlookmotel 2024-10-03 00:21:01 +00:00
parent 115ccc941e
commit 4f6bc79734
10 changed files with 406 additions and 773 deletions

View file

@ -137,7 +137,6 @@ pub trait CompilerInterface {
&mut program,
source_path,
source_text,
source_type,
&trivias,
symbols,
scopes,
@ -208,12 +207,11 @@ pub trait CompilerInterface {
program: &mut Program<'a>,
source_path: &Path,
source_text: &'a str,
source_type: SourceType,
trivias: &Trivias,
symbols: SymbolTable,
scopes: ScopeTree,
) -> TransformerReturn {
Transformer::new(allocator, source_path, source_type, source_text, trivias.clone(), options)
Transformer::new(allocator, source_path, source_text, trivias.clone(), options)
.build_with_symbols_and_scopes(symbols, scopes, program)
}

View file

@ -65,15 +65,8 @@ fn main() {
TransformOptions::enable_all()
};
let ret = Transformer::new(
&allocator,
path,
source_type,
&source_text,
trivias.clone(),
transform_options,
)
.build_with_symbols_and_scopes(symbols, scopes, &mut program);
let ret = Transformer::new(&allocator, path, &source_text, trivias.clone(), transform_options)
.build_with_symbols_and_scopes(symbols, scopes, &mut program);
if !ret.errors.is_empty() {
println!("Transformer Errors:");

View file

@ -43,7 +43,6 @@ pub struct TransformCtx<'a> {
impl<'a> TransformCtx<'a> {
pub fn new(
source_path: &Path,
source_type: SourceType,
source_text: &'a str,
trivias: Trivias,
options: &TransformOptions,
@ -60,7 +59,7 @@ impl<'a> TransformCtx<'a> {
errors: RefCell::new(vec![]),
filename,
source_path,
source_type,
source_type: SourceType::default(),
source_text,
trivias,
module_imports: ModuleImportsStore::new(),

View file

@ -45,7 +45,7 @@ use oxc_allocator::{Allocator, Vec};
use oxc_ast::{ast::*, Trivias};
use oxc_diagnostics::OxcDiagnostic;
use oxc_semantic::{ScopeTree, SymbolTable};
use oxc_span::{SourceType, SPAN};
use oxc_span::SPAN;
use oxc_traverse::{traverse_mut, Traverse, TraverseCtx};
use regexp::RegExp;
@ -76,12 +76,11 @@ impl<'a> Transformer<'a> {
pub fn new(
allocator: &'a Allocator,
source_path: &Path,
source_type: SourceType,
source_text: &'a str,
trivias: Trivias,
options: TransformOptions,
) -> Self {
let ctx = TransformCtx::new(source_path, source_type, source_text, trivias, &options);
let ctx = TransformCtx::new(source_path, source_text, trivias, &options);
Self { ctx, options, allocator }
}
@ -94,6 +93,7 @@ impl<'a> Transformer<'a> {
let allocator = self.allocator;
let ast_builder = AstBuilder::new(allocator);
self.ctx.source_type = program.source_type;
react::update_options_with_comments(&mut self.options, &self.ctx);
let mut transformer = TransformerImpl {

View file

@ -241,15 +241,9 @@ impl Oxc {
targets: Targets::from_query("chrome 51"),
..EnvOptions::default()
}) {
let result = Transformer::new(
&allocator,
&path,
source_type,
source_text,
trivias.clone(),
options,
)
.build_with_symbols_and_scopes(symbols, scopes, &mut program);
let result =
Transformer::new(&allocator, &path, source_text, trivias.clone(), options)
.build_with_symbols_and_scopes(symbols, scopes, &mut program);
if !result.errors.is_empty() {
self.save_diagnostics(
result.errors.into_iter().map(Error::from).collect::<Vec<_>>(),

View file

@ -88,11 +88,6 @@ impl<'a> TransformContext<'a> {
self.declarations.as_ref()
}
#[inline]
pub fn source_type(&self) -> SourceType {
self.source_type
}
#[inline]
pub fn program(&self) -> Ref<'_, Program<'a>> {
self.program.borrow()

View file

@ -122,7 +122,6 @@ fn transpile(ctx: &TransformContext<'_>, options: Option<TransformOptions>) -> C
let ret = Transformer::new(
ctx.allocator,
ctx.file_path(),
ctx.source_type(),
ctx.source_text(),
ctx.trivias.clone(),
options,

View file

@ -50,7 +50,6 @@ fn bench_transformer(criterion: &mut Criterion) {
let ret = Transformer::new(
&allocator,
Path::new(&file.file_name),
source_type,
source_text,
trivias,
options,

View file

@ -762,9 +762,8 @@ semantic error: `export = <value>;` is only supported when compiling modules to
Please consider using `export default <value>;`, or add @babel/plugin-transform-modules-commonjs to your Babel config.
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/input.ts
semantic error: Unresolved references mismatch:
after transform: ["f"]
rebuilt : []
semantic error: `export = <value>;` is only supported when compiling modules to CommonJS.
Please consider using `export default <value>;`, or add @babel/plugin-transform-modules-commonjs to your Babel config.
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/export/export-type/input.ts
semantic error: Bindings mismatch:

File diff suppressed because it is too large Load diff