Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es): Add options to disable all esnext transforms and lints #9597

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/swc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
40 changes: 28 additions & 12 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_lints/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading