mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(transformer): rename EnvOptions to BabelEnvOptions (#7036)
This commit is contained in:
parent
1d906c64e7
commit
e921df6199
5 changed files with 13 additions and 13 deletions
|
|
@ -6,7 +6,7 @@ use oxc_codegen::CodeGenerator;
|
||||||
use oxc_parser::Parser;
|
use oxc_parser::Parser;
|
||||||
use oxc_semantic::SemanticBuilder;
|
use oxc_semantic::SemanticBuilder;
|
||||||
use oxc_span::SourceType;
|
use oxc_span::SourceType;
|
||||||
use oxc_transformer::{EnvOptions, Targets, TransformOptions, Transformer};
|
use oxc_transformer::{BabelEnvOptions, Targets, TransformOptions, Transformer};
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
|
|
||||||
// Instruction:
|
// Instruction:
|
||||||
|
|
@ -55,9 +55,9 @@ fn main() {
|
||||||
let (symbols, scopes) = ret.semantic.into_symbol_table_and_scope_tree();
|
let (symbols, scopes) = ret.semantic.into_symbol_table_and_scope_tree();
|
||||||
|
|
||||||
let transform_options = if let Some(targets) = &targets {
|
let transform_options = if let Some(targets) = &targets {
|
||||||
TransformOptions::try_from(&EnvOptions {
|
TransformOptions::try_from(&BabelEnvOptions {
|
||||||
targets: Targets::try_from_query(targets).unwrap(),
|
targets: Targets::try_from_query(targets).unwrap(),
|
||||||
..EnvOptions::default()
|
..BabelEnvOptions::default()
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ pub use crate::{
|
||||||
compiler_assumptions::CompilerAssumptions,
|
compiler_assumptions::CompilerAssumptions,
|
||||||
es2015::{ArrowFunctionsOptions, ES2015Options},
|
es2015::{ArrowFunctionsOptions, ES2015Options},
|
||||||
jsx::{JsxOptions, JsxRuntime, ReactRefreshOptions},
|
jsx::{JsxOptions, JsxRuntime, ReactRefreshOptions},
|
||||||
options::{BabelOptions, EnvOptions, Targets, TransformOptions},
|
options::{BabelEnvOptions, BabelOptions, Targets, TransformOptions},
|
||||||
plugins::*,
|
plugins::*,
|
||||||
typescript::{RewriteExtensionsMode, TypeScriptOptions},
|
typescript::{RewriteExtensionsMode, TypeScriptOptions},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ fn default_as_true() -> bool {
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Deserialize)]
|
#[derive(Default, Debug, Clone, Deserialize)]
|
||||||
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
|
#[serde(default, rename_all = "camelCase", deny_unknown_fields)]
|
||||||
pub struct EnvOptions {
|
pub struct BabelEnvOptions {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub targets: Targets,
|
pub targets: Targets,
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ pub struct EnvOptions {
|
||||||
pub shipped_proposals: bool,
|
pub shipped_proposals: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EnvOptions {
|
impl BabelEnvOptions {
|
||||||
pub fn can_enable_plugin(&self, plugin_name: &str) -> bool {
|
pub fn can_enable_plugin(&self, plugin_name: &str) -> bool {
|
||||||
let versions = if self.bugfixes {
|
let versions = if self.bugfixes {
|
||||||
bugfix_features().get(plugin_name).unwrap_or_else(|| &features()[plugin_name])
|
bugfix_features().get(plugin_name).unwrap_or_else(|| &features()[plugin_name])
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use babel::{
|
pub use babel::{
|
||||||
env::{EnvOptions, Targets},
|
env::{BabelEnvOptions, Targets},
|
||||||
BabelOptions,
|
BabelOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -121,11 +121,11 @@ impl TransformOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&EnvOptions> for TransformOptions {
|
impl TryFrom<&BabelEnvOptions> for TransformOptions {
|
||||||
type Error = Vec<Error>;
|
type Error = Vec<Error>;
|
||||||
|
|
||||||
/// If there are any errors in the `options.targets``, they will be returned as a list of errors.
|
/// 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 {
|
Ok(Self {
|
||||||
regexp: RegExpOptions {
|
regexp: RegExpOptions {
|
||||||
sticky_flag: o.can_enable_plugin("transform-sticky-regex"),
|
sticky_flag: o.can_enable_plugin("transform-sticky-regex"),
|
||||||
|
|
@ -255,7 +255,7 @@ impl TryFrom<&BabelOptions> for TransformOptions {
|
||||||
.get_preset("env")
|
.get_preset("env")
|
||||||
.flatten()
|
.flatten()
|
||||||
.and_then(|value| {
|
.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))
|
.inspect_err(|err| report_error("env", err, true, &mut errors))
|
||||||
.ok()
|
.ok()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ use oxc::{
|
||||||
ScopeFlags, ScopeId, ScopeTree, SemanticBuilder, SymbolTable,
|
ScopeFlags, ScopeId, ScopeTree, SemanticBuilder, SymbolTable,
|
||||||
},
|
},
|
||||||
span::SourceType,
|
span::SourceType,
|
||||||
transformer::{EnvOptions, Targets, TransformOptions, Transformer},
|
transformer::{BabelEnvOptions, Targets, TransformOptions, Transformer},
|
||||||
};
|
};
|
||||||
use oxc_index::Idx;
|
use oxc_index::Idx;
|
||||||
use oxc_linter::Linter;
|
use oxc_linter::Linter;
|
||||||
|
|
@ -242,9 +242,9 @@ impl Oxc {
|
||||||
}
|
}
|
||||||
|
|
||||||
if run_options.transform.unwrap_or_default() {
|
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(),
|
targets: Targets::try_from_query("chrome 51").unwrap_or_default(),
|
||||||
..EnvOptions::default()
|
..BabelEnvOptions::default()
|
||||||
}) {
|
}) {
|
||||||
let result = Transformer::new(&allocator, &path, options)
|
let result = Transformer::new(&allocator, &path, options)
|
||||||
.build_with_symbols_and_scopes(symbols, scopes, &mut program);
|
.build_with_symbols_and_scopes(symbols, scopes, &mut program);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue