Skip to content

Commit

Permalink
refactor: Apply all pending breaking changes (#9966)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jan 27, 2025
1 parent 6f781d8 commit 1c2f7e9
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 102 deletions.
8 changes: 8 additions & 0 deletions .changeset/violet-jobs-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
swc_ecma_parser: major
swc_ecma_lints: major
swc_ecma_transforms_base: major
swc_ecma_utils: major
---

refactor: Apply all pending breaking changes
10 changes: 2 additions & 8 deletions crates/swc/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ use swc_ecma_loader::resolvers::{
};
pub use swc_ecma_minifier::js::*;
use swc_ecma_minifier::option::terser::TerserTopLevelOptions;
#[allow(deprecated)]
pub use swc_ecma_parser::JscTarget;
use swc_ecma_parser::{parse_file_as_expr, Syntax, TsSyntax};
pub use swc_ecma_transforms::proposals::DecoratorVersion;
use swc_ecma_transforms::{
Expand All @@ -53,7 +51,7 @@ use swc_ecma_transforms::{
optimization::{const_modules, json_parse, simplifier},
proposals::{
decorators, explicit_resource_management::explicit_resource_management,
export_default_from, import_assertions,
export_default_from, import_attributes,
},
react::{self, default_pragma, default_pragma_frag},
resolver,
Expand Down Expand Up @@ -729,7 +727,7 @@ impl Options {
// 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_attributes(), !keep_import_attributes),
Optional::new(
typescript::tsx::<Option<&dyn Comments>>(
cm.clone(),
Expand Down Expand Up @@ -1466,10 +1464,6 @@ pub struct TransformConfig {
#[serde(default)]
pub regenerator: regenerator::Config,

#[serde(default)]
#[deprecated]
pub treat_const_enum_as_enum: BoolConfig<false>,

/// https://www.typescriptlang.org/tsconfig#useDefineForClassFields
#[serde(default)]
pub use_define_for_class_fields: BoolConfig<true>,
Expand Down
2 changes: 0 additions & 2 deletions crates/swc_ecma_lints/src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use std::sync::Arc;
use swc_common::{SourceMap, SyntaxContext};
use swc_ecma_ast::*;

#[deprecated = "Use lint_pass instead"]
pub use self::lint_pass as lint_to_fold;
use crate::{config::LintConfig, rule::Rule};

mod const_assign;
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/scripts/_/samply-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
const lib = row.querySelector(".lib");
const libText = lib.textContent.trim();
if (
libText.endsWith("/swc_ecma_visit/src/") ||
libText.includes("/swc_ecma_visit/src/") ||
libText.endsWith("/swc_ecma_utils/src/parallel.rs") ||
libText.includes("/.rustup/") ||
libText.includes("/std/") ||
Expand Down
1 change: 0 additions & 1 deletion crates/swc_ecma_minifier/src/pass/mangle_names/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub(crate) fn mangle_names(
top_level_mark,
ignore_eval: options.eval,
preserved_symbols: options.reserved.iter().cloned().collect(),
..Default::default()
},
ManglingRenamer {
chars,
Expand Down
6 changes: 2 additions & 4 deletions crates/swc_ecma_minifier/tests/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use serde::Deserialize;
use swc_common::{
comments::{Comments, SingleThreadedComments},
errors::{Handler, HANDLER},
input::SourceFileInput,
sync::Lrc,
util::take::Take,
EqIgnoreSpan, FileName, Mark, SourceMap,
Expand All @@ -34,10 +35,7 @@ use swc_ecma_minifier::{
MinifyOptions, TopLevelOptions,
},
};
use swc_ecma_parser::{
lexer::{input::SourceFileInput, Lexer},
EsSyntax, Parser, Syntax,
};
use swc_ecma_parser::{lexer::Lexer, EsSyntax, Parser, Syntax};
use swc_ecma_testing::{exec_node_js, JsExecOptions};
use swc_ecma_transforms_base::{
fixer::{fixer, paren_remover},
Expand Down
6 changes: 2 additions & 4 deletions crates/swc_ecma_minifier/tests/terser_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde::Deserialize;
use swc_common::{
comments::SingleThreadedComments,
errors::{Handler, HANDLER},
input::SourceFileInput,
sync::Lrc,
Mark, SourceMap,
};
Expand All @@ -28,10 +29,7 @@ use swc_ecma_minifier::{
optimize,
option::{terser::TerserCompressorOptions, CompressOptions, ExtraOptions, MinifyOptions},
};
use swc_ecma_parser::{
lexer::{input::SourceFileInput, Lexer},
EsSyntax, Parser, Syntax,
};
use swc_ecma_parser::{lexer::Lexer, EsSyntax, Parser, Syntax};
use swc_ecma_transforms_base::{
fixer::{fixer, paren_remover},
hygiene::hygiene,
Expand Down
13 changes: 6 additions & 7 deletions crates/swc_ecma_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,27 @@ use std::{cell::RefCell, char, iter::FusedIterator, mem::transmute, rc::Rc};
use either::Either::{Left, Right};
use smallvec::{smallvec, SmallVec};
use swc_atoms::{Atom, AtomStoreCell};
use swc_common::{comments::Comments, input::StringInput, BytePos, Span};
use swc_common::{
comments::Comments,
input::{Input, StringInput},
BytePos, Span,
};
use swc_ecma_ast::{op, AssignOp, EsVersion, Ident};

pub use self::state::{TokenContext, TokenContexts};
use self::{
comments_buffer::CommentsBuffer,
state::State,
table::{ByteHandler, BYTE_HANDLERS},
util::*,
};
pub use self::{
input::Input,
state::{TokenContext, TokenContexts},
};
use crate::{
error::{Error, SyntaxError},
token::{BinOpToken, IdentLike, Token, Word},
Context, Syntax,
};

mod comments_buffer;
#[deprecated = "Directly use swc_common::input instead"]
pub mod input;
mod jsx;
mod number;
mod state;
Expand Down
6 changes: 2 additions & 4 deletions crates/swc_ecma_parser/src/lexer/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use std::char;

use swc_common::{
comments::{Comment, CommentKind},
input::Input,
BytePos, Span,
};
use swc_ecma_ast::Ident;
use tracing::warn;

use super::{
comments_buffer::BufferedComment, input::Input, whitespace::SkipWhitespace, Char, LexResult,
Lexer,
};
use super::{comments_buffer::BufferedComment, whitespace::SkipWhitespace, Char, LexResult, Lexer};
use crate::{
error::{Error, SyntaxError},
lexer::comments_buffer::BufferedCommentKind,
Expand Down
14 changes: 2 additions & 12 deletions crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,11 @@
use error::Error;
use lexer::Lexer;
use serde::{Deserialize, Serialize};
pub use swc_common::input::{Input, StringInput};
use swc_common::{comments::Comments, input::SourceFileInput, SourceFile};
use swc_ecma_ast::*;

pub use self::{
lexer::input::{Input, StringInput},
parser::*,
};
#[deprecated(note = "Use `EsVersion` instead")]
pub type JscTarget = EsVersion;
pub use self::parser::*;

#[macro_use]
mod macros;
Expand Down Expand Up @@ -331,9 +327,6 @@ pub struct TsSyntax {
pub disallow_ambiguous_jsx_like: bool,
}

#[deprecated(note = "Use 'TsSyntax' instead")]
pub type TsConfig = TsSyntax;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EsSyntax {
Expand Down Expand Up @@ -376,9 +369,6 @@ pub struct EsSyntax {
pub explicit_resource_management: bool,
}

#[deprecated(note = "Use 'EsSyntax' instead")]
pub type EsConfig = EsSyntax;

/// Syntactic context.
#[derive(Debug, Clone, Copy, Default)]
pub struct Context {
Expand Down
5 changes: 0 additions & 5 deletions crates/swc_ecma_transforms_base/src/assumptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ pub struct Assumptions {
/// https://babeljs.io/docs/en/assumptions#superiscallableconstructor
#[serde(default)]
pub super_is_callable_constructor: bool,

#[serde(default)]
#[deprecated(note = "This value will be always true")]
pub ts_enum_is_readonly: bool,
}

#[allow(deprecated)]
Expand Down Expand Up @@ -127,7 +123,6 @@ impl Assumptions {
set_spread_properties: true,
skip_for_of_iterator_closing: true,
super_is_callable_constructor: true,
ts_enum_is_readonly: true,
}
}
}
4 changes: 0 additions & 4 deletions crates/swc_ecma_transforms_base/src/hygiene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ pub struct Config {
/// If true, the `hygiene` pass will preserve class names.
pub keep_class_names: bool,

/// If true, the bug of safari 10 is avoided.
#[deprecated = "This field is no longer required to work around bugs in Safari 10."]
pub safari_10: bool,

/// The marks derived from this marks will treated as `specified by user`
/// and other marks will be treated as `generated by swc`.
pub top_level_mark: Mark,
Expand Down
5 changes: 4 additions & 1 deletion crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ impl Scope {
true
}

#[cfg_attr(not(feature = "concurrent-renamer"), allow(unused))]
#[cfg_attr(
not(feature = "concurrent-renamer"),
allow(unused, clippy::only_used_in_recursion)
)]
pub(crate) fn rename_in_mangle_mode<R>(
&mut self,
renamer: &R,
Expand Down
16 changes: 0 additions & 16 deletions crates/swc_ecma_transforms_module/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,6 @@ impl<R> NodeImportResolver<R>
where
R: Resolve,
{
#[deprecated(note = "Use `with_config`")]
pub fn new(resolver: R) -> Self {
Self::with_config(resolver, Default::default())
}

#[deprecated(note = "Use `with_config`")]
pub fn with_base_dir(resolver: R, base_dir: Option<PathBuf>) -> Self {
Self::with_config(
resolver,
Config {
base_dir,
..Default::default()
},
)
}

pub fn with_config(resolver: R, config: Config) -> Self {
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
if let Some(base_dir) = &config.base_dir {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport, Pass};
use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut};

#[deprecated(note = "Please use `import_assertions` instead")]
pub use self::import_attributes as import_assertions;

pub fn import_attributes() -> impl Pass {
visit_mut_pass(ImportAssertions)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_transforms_proposal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};

pub use self::{
decorators::decorators, export_default_from::export_default_from,
import_assertions::import_assertions,
import_attributes::import_attributes,
};

#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
Expand All @@ -27,4 +27,4 @@ mod decorator_impl;
pub mod decorators;
pub mod explicit_resource_management;
mod export_default_from;
mod import_assertions;
mod import_attributes;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use swc_ecma_ast::Pass;
use swc_ecma_parser::{EsSyntax, Syntax};
use swc_ecma_transforms_proposal::import_assertions;
use swc_ecma_transforms_proposal::import_attributes;
use swc_ecma_transforms_testing::test;

fn tr() -> impl Pass {
import_assertions()
import_attributes()
}

fn syntax() -> Syntax {
Expand Down
3 changes: 0 additions & 3 deletions crates/swc_ecma_transforms_typescript/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,3 @@ pub enum ImportsNotUsedAsValues {
#[serde(rename = "preserve")]
Preserve,
}

#[deprecated = "ImportNotUsedAsValues is renamed to ImportsNotUsedAsValues"]
pub type ImportNotUsedAsValues = ImportsNotUsedAsValues;
6 changes: 0 additions & 6 deletions crates/swc_ecma_utils/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,3 @@ impl IdentLike for UnsafeId {
unreachable!("UnsafeId.into_id() is not allowed because it is very likely to be unsafe")
}
}

#[deprecated = "Use i.to_id() instead"]
#[inline(always)]
pub fn id(i: &Ident) -> Id {
(i.sym.clone(), i.ctxt)
}
18 changes: 1 addition & 17 deletions crates/swc_ecma_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,11 +1361,6 @@ pub fn prop_name_to_member_prop(prop_name: PropName) -> MemberProp {
}
}

#[deprecated(note = "Use default_constructor_with_span instead")]
pub fn default_constructor(has_super: bool) -> Constructor {
default_constructor_with_span(has_super, DUMMY_SP)
}

/// `super_call_span` should be the span of the class definition
/// Use value of [`Class::span`].
pub fn default_constructor_with_span(has_super: bool, super_call_span: Span) -> Constructor {
Expand Down Expand Up @@ -1479,18 +1474,7 @@ pub fn prepend_stmts<T: StmtLike>(to: &mut Vec<T>, stmts: impl ExactSizeIterator

pub trait IsDirective {
fn as_ref(&self) -> Option<&Stmt>;
#[deprecated(note = "use directive_continue instead")]
fn is_directive(&self) -> bool {
match self.as_ref() {
Some(Stmt::Expr(expr)) => match &*expr.expr {
Expr::Lit(Lit::Str(Str {
raw: Some(value), ..
})) => value.starts_with("\"use ") || value.starts_with("'use "),
_ => false,
},
_ => false,
}
}

fn directive_continue(&self) -> bool {
self.as_ref().map_or(false, Stmt::can_precede_directive)
}
Expand Down

0 comments on commit 1c2f7e9

Please sign in to comment.