refactor(transformer): rename EnvOptions to BabelEnvOptions (#7036)

This commit is contained in:
Boshen 2024-10-31 10:00:51 +00:00
parent 1d906c64e7
commit e921df6199
5 changed files with 13 additions and 13 deletions

View file

@ -6,7 +6,7 @@ use oxc_codegen::CodeGenerator;
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use oxc_transformer::{EnvOptions, Targets, TransformOptions, Transformer};
use oxc_transformer::{BabelEnvOptions, Targets, TransformOptions, Transformer};
use pico_args::Arguments;
// Instruction:
@ -55,9 +55,9 @@ fn main() {
let (symbols, scopes) = ret.semantic.into_symbol_table_and_scope_tree();
let transform_options = if let Some(targets) = &targets {
TransformOptions::try_from(&EnvOptions {
TransformOptions::try_from(&BabelEnvOptions {
targets: Targets::try_from_query(targets).unwrap(),
..EnvOptions::default()
..BabelEnvOptions::default()
})
.unwrap()
} else {

View file

@ -54,7 +54,7 @@ pub use crate::{
compiler_assumptions::CompilerAssumptions,
es2015::{ArrowFunctionsOptions, ES2015Options},
jsx::{JsxOptions, JsxRuntime, ReactRefreshOptions},
options::{BabelOptions, EnvOptions, Targets, TransformOptions},
options::{BabelEnvOptions, BabelOptions, Targets, TransformOptions},
plugins::*,
typescript::{RewriteExtensionsMode, TypeScriptOptions},
};

View file

@ -12,7 +12,7 @@ fn default_as_true() -> bool {
#[derive(Default, Debug, Clone, Deserialize)]
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
pub struct EnvOptions {
pub struct BabelEnvOptions {
#[serde(default)]
pub targets: Targets,
@ -56,7 +56,7 @@ pub struct EnvOptions {
pub shipped_proposals: bool,
}
impl EnvOptions {
impl BabelEnvOptions {
pub fn can_enable_plugin(&self, plugin_name: &str) -> bool {
let versions = if self.bugfixes {
bugfix_features().get(plugin_name).unwrap_or_else(|| &features()[plugin_name])

View file

@ -22,7 +22,7 @@ use crate::{
};
pub use babel::{
env::{EnvOptions, Targets},
env::{BabelEnvOptions, Targets},
BabelOptions,
};
@ -121,11 +121,11 @@ impl TransformOptions {
}
}
impl TryFrom<&EnvOptions> for TransformOptions {
impl TryFrom<&BabelEnvOptions> for TransformOptions {
type Error = Vec<Error>;
/// If there are any errors in the `options.targets``, they will be returned as a list of errors.
fn try_from(o: &EnvOptions) -> Result<Self, Self::Error> {
fn try_from(o: &BabelEnvOptions) -> Result<Self, Self::Error> {
Ok(Self {
regexp: RegExpOptions {
sticky_flag: o.can_enable_plugin("transform-sticky-regex"),
@ -255,7 +255,7 @@ impl TryFrom<&BabelOptions> for TransformOptions {
.get_preset("env")
.flatten()
.and_then(|value| {
serde_json::from_value::<EnvOptions>(value)
serde_json::from_value::<BabelEnvOptions>(value)
.inspect_err(|err| report_error("env", err, true, &mut errors))
.ok()
})

View file

@ -21,7 +21,7 @@ use oxc::{
ScopeFlags, ScopeId, ScopeTree, SemanticBuilder, SymbolTable,
},
span::SourceType,
transformer::{EnvOptions, Targets, TransformOptions, Transformer},
transformer::{BabelEnvOptions, Targets, TransformOptions, Transformer},
};
use oxc_index::Idx;
use oxc_linter::Linter;
@ -242,9 +242,9 @@ impl Oxc {
}
if run_options.transform.unwrap_or_default() {
if let Ok(options) = TransformOptions::try_from(&EnvOptions {
if let Ok(options) = TransformOptions::try_from(&BabelEnvOptions {
targets: Targets::try_from_query("chrome 51").unwrap_or_default(),
..EnvOptions::default()
..BabelEnvOptions::default()
}) {
let result = Transformer::new(&allocator, &path, options)
.build_with_symbols_and_scopes(symbols, scopes, &mut program);