Skip to content

Commit 7b2d29a

Browse files
authored
fix: memory leak in dprint-swc-ext (#613)
1 parent b937def commit 7b2d29a

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed

Cargo.lock

Lines changed: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tracing = ["dprint-core/tracing"]
2626

2727
[dependencies]
2828
anyhow = "1.0.64"
29-
deno_ast = { version = "0.33.2", features = ["view"] }
29+
deno_ast = { version = "0.34.0", features = ["view"] }
3030
dprint-core = { version = "0.63.3", features = ["formatting"] }
3131
percent-encoding = "2.3.1"
3232
rustc-hash = "1.1.0"

src/generation/generate.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ fn gen_node_with_inner_gen<'a>(node: Node<'a>, context: &mut Context<'a>, inner_
335335
// decorators in these cases will have starts before their parent so they need to be handled specially
336336
if let Node::ExportDecl(decl) = node {
337337
if let Decl::Class(class_decl) = &decl.decl {
338-
items.extend(gen_decorators(&class_decl.class.decorators, false, context));
338+
items.extend(gen_decorators(class_decl.class.decorators, false, context));
339339
}
340340
} else if let Node::ExportDefaultDecl(decl) = node {
341341
if let DefaultDecl::Class(class_expr) = &decl.decl {
342-
items.extend(gen_decorators(&class_expr.class.decorators, false, context));
342+
items.extend(gen_decorators(class_expr.class.decorators, false, context));
343343
}
344344
}
345345

@@ -386,8 +386,8 @@ fn gen_node_with_inner_gen<'a>(node: Node<'a>, context: &mut Context<'a>, inner_
386386

387387
fn get_has_ignore_comment<'a>(leading_comments: &CommentsIterator<'a>, node: Node<'a>, context: &mut Context<'a>) -> bool {
388388
let comments = match node.parent() {
389-
Some(Node::JSXElement(jsx_element)) => get_comments_for_jsx_children(&jsx_element.children, &node.start(), context),
390-
Some(Node::JSXFragment(jsx_fragment)) => get_comments_for_jsx_children(&jsx_fragment.children, &node.start(), context),
389+
Some(Node::JSXElement(jsx_element)) => get_comments_for_jsx_children(jsx_element.children, &node.start(), context),
390+
Some(Node::JSXFragment(jsx_fragment)) => get_comments_for_jsx_children(jsx_fragment.children, &node.start(), context),
391391
_ => leading_comments.clone(),
392392
};
393393

@@ -438,7 +438,7 @@ fn gen_class_method<'a>(node: &'a ClassMethod<'a>, context: &mut Context<'a>) ->
438438
ClassOrObjectMethod {
439439
node: node.into(),
440440
parameters_range: node.get_parameters_range(context),
441-
decorators: Some(&node.function.decorators),
441+
decorators: Some(node.function.decorators),
442442
accessibility: node.accessibility(),
443443
is_static: node.is_static(),
444444
is_async: node.function.is_async(),
@@ -465,7 +465,7 @@ fn gen_auto_accessor<'a>(node: &AutoAccessor<'a>, context: &mut Context<'a>) ->
465465
value: node.value,
466466
type_ann: node.type_ann,
467467
is_static: node.is_static(),
468-
decorators: &node.decorators,
468+
decorators: node.decorators,
469469
computed: false,
470470
is_auto_accessor: true,
471471
is_declare: false,
@@ -485,7 +485,7 @@ fn gen_private_method<'a>(node: &PrivateMethod<'a>, context: &mut Context<'a>) -
485485
ClassOrObjectMethod {
486486
node: node.into(),
487487
parameters_range: node.get_parameters_range(context),
488-
decorators: Some(&node.function.decorators),
488+
decorators: Some(node.function.decorators),
489489
accessibility: node.accessibility(),
490490
is_static: node.is_static(),
491491
is_async: node.function.is_async(),
@@ -512,7 +512,7 @@ fn gen_class_prop<'a>(node: &ClassProp<'a>, context: &mut Context<'a>) -> PrintI
512512
value: node.value,
513513
type_ann: node.type_ann,
514514
is_static: node.is_static(),
515-
decorators: &node.decorators,
515+
decorators: node.decorators,
516516
computed: matches!(node.key, PropName::Computed(_)),
517517
is_auto_accessor: false,
518518
is_declare: node.declare(),
@@ -560,7 +560,7 @@ fn gen_decorator<'a>(node: &Decorator<'a>, context: &mut Context<'a>) -> PrintIt
560560

561561
fn gen_parameter_prop<'a>(node: &TsParamProp<'a>, context: &mut Context<'a>) -> PrintItems {
562562
let mut items = PrintItems::new();
563-
items.extend(gen_decorators(&node.decorators, true, context));
563+
items.extend(gen_decorators(node.decorators, true, context));
564564
if let Some(accessibility) = node.accessibility() {
565565
items.push_string(format!("{} ", accessibility_to_str(accessibility)));
566566
}
@@ -589,7 +589,7 @@ fn gen_private_prop<'a>(node: &PrivateProp<'a>, context: &mut Context<'a>) -> Pr
589589
value: node.value,
590590
type_ann: node.type_ann,
591591
is_static: node.is_static(),
592-
decorators: &node.decorators,
592+
decorators: node.decorators,
593593
computed: false,
594594
is_auto_accessor: false,
595595
is_declare: false,
@@ -610,7 +610,7 @@ struct GenClassPropCommon<'a, 'b> {
610610
pub value: Option<Expr<'a>>,
611611
pub type_ann: Option<&'a TsTypeAnn<'a>>,
612612
pub is_static: bool,
613-
pub decorators: &'b Vec<&'a Decorator<'a>>,
613+
pub decorators: &'b [&'a Decorator<'a>],
614614
pub computed: bool,
615615
pub is_declare: bool,
616616
pub accessibility: Option<Accessibility>,
@@ -805,7 +805,7 @@ fn gen_class_decl<'a>(node: &ClassDecl<'a>, context: &mut Context<'a>) -> PrintI
805805
ClassDeclOrExpr {
806806
node: node.into(),
807807
member_node: node.class.into(),
808-
decorators: &node.class.decorators,
808+
decorators: node.class.decorators,
809809
is_class_expr: false,
810810
is_declare: node.declare(),
811811
is_abstract: node.class.is_abstract(),
@@ -824,7 +824,7 @@ fn gen_class_decl<'a>(node: &ClassDecl<'a>, context: &mut Context<'a>) -> PrintI
824824
struct ClassDeclOrExpr<'a> {
825825
node: Node<'a>,
826826
member_node: Node<'a>,
827-
decorators: &'a Vec<&'a Decorator<'a>>,
827+
decorators: &'a [&'a Decorator<'a>],
828828
is_class_expr: bool,
829829
is_declare: bool,
830830
is_abstract: bool,
@@ -1023,7 +1023,7 @@ fn gen_export_named_decl<'a>(node: &NamedExport<'a>, context: &mut Context<'a>)
10231023
let mut namespace_export: Option<&ExportNamespaceSpecifier> = None;
10241024
let mut named_exports: Vec<&ExportNamedSpecifier> = Vec::new();
10251025

1026-
for specifier in &node.specifiers {
1026+
for specifier in node.specifiers {
10271027
match specifier {
10281028
ExportSpecifier::Default(node) => default_export = Some(node),
10291029
ExportSpecifier::Namespace(node) => namespace_export = Some(node),
@@ -1197,7 +1197,7 @@ fn gen_function_decl_or_expr<'a>(node: FunctionDeclOrExprNode<'a>, context: &mut
11971197

11981198
fn gen_param<'a>(node: &Param<'a>, context: &mut Context<'a>) -> PrintItems {
11991199
let mut items = PrintItems::new();
1200-
items.extend(gen_decorators(&node.decorators, true, context));
1200+
items.extend(gen_decorators(node.decorators, true, context));
12011201
items.extend(gen_node(node.pat.into(), context));
12021202
items
12031203
}
@@ -1208,7 +1208,7 @@ fn gen_import_decl<'a>(node: &ImportDecl<'a>, context: &mut Context<'a>) -> Prin
12081208
let mut namespace_import: Option<&ImportStarAsSpecifier> = None;
12091209
let mut named_imports: Vec<&ImportNamedSpecifier> = Vec::new();
12101210

1211-
for specifier in &node.specifiers {
1211+
for specifier in node.specifiers {
12121212
match specifier {
12131213
ImportSpecifier::Default(node) => default_import = Some(node),
12141214
ImportSpecifier::Namespace(node) => namespace_import = Some(node),
@@ -1451,7 +1451,7 @@ fn gen_using_decl<'a>(node: &UsingDecl<'a>, context: &mut Context<'a>) -> PrintI
14511451
}
14521452
items.push_str("using ");
14531453

1454-
items.extend(gen_var_declarators(node.into(), &node.decls, context));
1454+
items.extend(gen_var_declarators(node.into(), node.decls, context));
14551455

14561456
if context.config.semi_colons.is_true() {
14571457
items.push_str(";");
@@ -2167,7 +2167,7 @@ fn gen_call_or_opt_expr<'a>(node: CallOrOptCallExpr<'a>, context: &mut Context<'
21672167
fn gen_test_library_call_expr<'a>(node: &CallExpr<'a>, context: &mut Context<'a>) -> PrintItems {
21682168
let mut items = PrintItems::new();
21692169
items.extend(gen_test_library_callee(&node.callee, context));
2170-
items.extend(gen_test_library_arguments(&node.args, context));
2170+
items.extend(gen_test_library_arguments(node.args, context));
21712171
return items;
21722172

21732173
fn gen_test_library_callee<'a, 'b>(callee: &'b Callee<'a>, context: &mut Context<'a>) -> PrintItems {
@@ -2257,7 +2257,7 @@ fn gen_class_expr<'a>(node: &ClassExpr<'a>, context: &mut Context<'a>) -> PrintI
22572257
ClassDeclOrExpr {
22582258
node: node.into(),
22592259
member_node: node.class.into(),
2260-
decorators: &node.class.decorators,
2260+
decorators: node.class.decorators,
22612261
is_class_expr: true,
22622262
is_declare: false,
22632263
is_abstract: node.class.is_abstract(),
@@ -4310,7 +4310,7 @@ fn gen_method_prop<'a>(node: &MethodProp<'a>, context: &mut Context<'a>) -> Prin
43104310
struct ClassOrObjectMethod<'a> {
43114311
node: Node<'a>,
43124312
parameters_range: Option<SourceRange>,
4313-
decorators: Option<&'a Vec<&'a Decorator<'a>>>,
4313+
decorators: Option<&'a [&'a Decorator<'a>]>,
43144314
accessibility: Option<Accessibility>,
43154315
is_static: bool,
43164316
is_async: bool,
@@ -5313,7 +5313,7 @@ fn gen_var_decl<'a>(node: &VarDecl<'a>, context: &mut Context<'a>) -> PrintItems
53135313
VarDeclKind::Var => "var ",
53145314
});
53155315

5316-
items.extend(gen_var_declarators(node.into(), &node.decls, context));
5316+
items.extend(gen_var_declarators(node.into(), node.decls, context));
53175317

53185318
if requires_semi_colon(node, context) {
53195319
items.push_str(";");
@@ -5812,7 +5812,7 @@ fn gen_intersection_type<'a>(node: &TsIntersectionType<'a>, context: &mut Contex
58125812
gen_union_or_intersection_type(
58135813
UnionOrIntersectionType {
58145814
node: node.into(),
5815-
types: &node.types,
5815+
types: node.types,
58165816
is_union: false,
58175817
},
58185818
context,
@@ -6196,7 +6196,7 @@ fn gen_union_type<'a>(node: &TsUnionType<'a>, context: &mut Context<'a>) -> Prin
61966196
gen_union_or_intersection_type(
61976197
UnionOrIntersectionType {
61986198
node: node.into(),
6199-
types: &node.types,
6199+
types: node.types,
62006200
is_union: true,
62016201
},
62026202
context,
@@ -6205,7 +6205,7 @@ fn gen_union_type<'a>(node: &TsUnionType<'a>, context: &mut Context<'a>) -> Prin
62056205

62066206
struct UnionOrIntersectionType<'a, 'b> {
62076207
pub node: Node<'a>,
6208-
pub types: &'b Vec<TsType<'a>>,
6208+
pub types: &'b [TsType<'a>],
62096209
pub is_union: bool,
62106210
}
62116211

src/generation/generate_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ impl<'a> CallOrOptCallExpr<'a> {
405405
}
406406
}
407407

408-
pub fn args(&self) -> &Vec<&'a ExprOrSpread<'a>> {
408+
pub fn args(&self) -> &[&'a ExprOrSpread<'a>] {
409409
match self {
410-
Self::CallExpr(node) => &node.args,
411-
Self::OptCall(node) => &node.args,
410+
Self::CallExpr(node) => node.args,
411+
Self::OptCall(node) => node.args,
412412
}
413413
}
414414

src/generation/swc/flatten_curried_arrows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl<'a> ArrowSignature<'a> {
3030
self.inner.is_async()
3131
}
3232

33-
pub fn params(&self) -> &Vec<Pat<'a>> {
34-
&self.inner.params
33+
pub fn params(&self) -> &[Pat<'a>] {
34+
self.inner.params
3535
}
3636

3737
pub fn type_params(&self) -> Option<&'a TsTypeParamDecl<'a>> {

src/swc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn from_file_path_wasm(path: &Path) -> Option<ModuleSpecifier> {
8585
match component {
8686
std::path::Component::Prefix(prefix) => {
8787
let prefix = prefix.as_os_str().to_string_lossy();
88-
parts.push(percent_encoding::utf8_percent_encode(&prefix.to_string(), percent_encoding::CONTROLS).to_string());
88+
parts.push(percent_encoding::utf8_percent_encode(prefix.as_ref(), percent_encoding::CONTROLS).to_string());
8989
}
9090
std::path::Component::RootDir => {
9191
// ignore

0 commit comments

Comments
 (0)