feat(es): Add options to disable all esnext transforms and lints (#9597)
Some checks are pending
CI / Cargo fmt (push) Waiting to run
CI / Cargo clippy (push) Waiting to run
CI / Check license of dependencies (push) Waiting to run
CI / Check (macos-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / Test wasm (binding_core_wasm) (push) Waiting to run
CI / Test wasm (binding_minifier_wasm) (push) Waiting to run
CI / Test wasm (binding_typescript_wasm) (push) Waiting to run
CI / List crates (push) Waiting to run
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Blocked by required conditions
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Waiting to run
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Waiting to run
CI / Test with @swc/cli (push) Waiting to run
CI / Miri (better_scoped_tls) (push) Waiting to run
CI / Miri (string_enum) (push) Waiting to run
CI / Miri (swc) (push) Waiting to run
CI / Miri (swc_bundler) (push) Waiting to run
CI / Miri (swc_ecma_codegen) (push) Waiting to run
CI / Miri (swc_ecma_minifier) (push) Waiting to run
CI / Done (push) Blocked by required conditions
Benchmark / Bench everything (push) Waiting to run

This commit is contained in:
Donny/강동윤 2024-10-01 14:00:59 +09:00 committed by GitHub
parent b28047a48b
commit f2b07665bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 13 deletions

View File

@ -0,0 +1,7 @@
---
swc: patch
swc_core: patch
swc_ecma_lints: patch
---
feat(es): Add options to disable all `esnext` transforms and lints

View File

@ -506,6 +506,6 @@ impl VisitMut for MinifierPass<'_> {
}
}
fn should_enable(target: EsVersion, feature: EsVersion) -> bool {
pub(crate) fn should_enable(target: EsVersion, feature: EsVersion) -> bool {
target < feature
}

View File

@ -74,7 +74,9 @@ use swc_ecma_visit::{Fold, VisitMutWith};
pub use crate::plugin::PluginConfig;
use crate::{
builder::PassBuilder, dropped_comments_preserver::dropped_comments_preserver, SwcImportResolver,
builder::{should_enable, PassBuilder},
dropped_comments_preserver::dropped_comments_preserver,
SwcImportResolver,
};
#[cfg(test)]
@ -579,6 +581,7 @@ impl Options {
);
let keep_import_attributes = experimental.keep_import_attributes.into_bool();
let disable_all_lints = experimental.disable_all_lints.into_bool();
#[cfg(feature = "plugin")]
let plugin_transforms = {
@ -697,23 +700,33 @@ impl Options {
};
Box::new(chain!(
lint_to_fold(swc_ecma_lints::rules::all(LintParams {
program: &program,
lint_config: &lints,
top_level_ctxt,
unresolved_ctxt,
es_version,
source_map: cm.clone(),
})),
Optional::new(
lint_to_fold(swc_ecma_lints::rules::all(LintParams {
program: &program,
lint_config: &lints,
top_level_ctxt,
unresolved_ctxt,
es_version,
source_map: cm.clone(),
})),
!disable_all_lints
),
// Decorators may use type information
Optional::new(decorator_pass, syntax.decorators()),
Optional::new(
decorator_pass,
should_enable(es_version, EsVersion::EsNext) && syntax.decorators()
),
Optional::new(
explicit_resource_management(),
syntax.explicit_resource_management()
should_enable(es_version, EsVersion::EsNext)
&& syntax.explicit_resource_management()
),
// The transform strips import assertions, so it's only enabled if
// keep_import_assertions is false.
Optional::new(import_assertions(), !keep_import_attributes),
Optional::new(
import_assertions(),
should_enable(es_version, EsVersion::EsNext) && !keep_import_attributes
),
Optional::new(
typescript::tsx::<Option<&dyn Comments>>(
cm.clone(),
@ -1229,6 +1242,9 @@ pub struct JscExperimental {
/// This requires `isolatedDeclartion` feature of TypeScript 5.5.
#[serde(default)]
pub emit_isolated_dts: BoolConfig<false>,
#[serde(default)]
pub disable_all_lints: BoolConfig<false>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]

View File

@ -20,6 +20,10 @@ pub trait Rule: Debug + Send + Sync {
macro_rules! for_vec {
($name:ident, $program:ident, $s:expr) => {{
if $s.is_empty() {
return;
}
let program = $program;
if cfg!(target_arch = "wasm32") {
for rule in $s {