Skip to content

Commit 13eb97b

Browse files
authored
feat: support const type parameters (#491)
1 parent 94891a3 commit 13eb97b

File tree

9 files changed

+192
-170
lines changed

9 files changed

+192
-170
lines changed

Cargo.lock

Lines changed: 173 additions & 159 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.23.2", features = ["view"] }
29+
deno_ast = { version = "0.24.0", features = ["view"] }
3030
dprint-core = { version = "0.60.0", features = ["formatting"] }
3131
rustc-hash = "1.1.0"
3232
serde = { version = "1.0.144", features = ["derive"] }

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.66.0"
2+
channel = "1.67.0"
33
components = ["clippy"]

src/generation/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> Context<'a> {
170170
pub fn assert_text(&self, range: SourceRange, expected_text: &str) {
171171
let actual_text = range.text_fast(self.program);
172172
if actual_text != expected_text {
173-
panic!("Debug Panic Expected text `{}`, but found `{}`", expected_text, actual_text)
173+
panic!("Debug Panic Expected text `{expected_text}`, but found `{actual_text}`")
174174
}
175175
}
176176
}

src/generation/generate.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,6 +5830,9 @@ fn gen_type_ann<'a>(node: &'a TsTypeAnn, context: &mut Context<'a>) -> PrintItem
58305830
fn gen_type_param<'a>(node: &'a TsTypeParam, context: &mut Context<'a>) -> PrintItems {
58315831
let mut items = PrintItems::new();
58325832

5833+
if node.is_const() {
5834+
items.push_str("const ");
5835+
}
58335836
if node.is_in() {
58345837
items.push_str("in ");
58355838
}
@@ -8856,7 +8859,7 @@ fn gen_assignment_like_with_token<'a>(expr: Node<'a>, op: &'static str, op_token
88568859
if op == ":" {
88578860
items.push_str(op)
88588861
} else {
8859-
items.push_string(format!(" {}", op))
8862+
items.push_string(format!(" {op}"))
88608863
}
88618864

88628865
let op_end = op_token
@@ -9131,11 +9134,11 @@ fn gen_surrounded_by_tokens<'a>(
91319134
}
91329135

91339136
#[cfg(debug_assertions)]
9134-
fn assert_has_op<'a>(op: &str, op_token: Option<&TokenAndSpan>, context: &mut Context<'a>) {
9137+
fn assert_has_op(op: &str, op_token: Option<&TokenAndSpan>, context: &mut Context) {
91359138
if let Some(op_token) = op_token {
91369139
context.assert_text(SourceRange::new(op_token.start(), op_token.end()), op);
91379140
} else {
9138-
panic!("Debug panic! Expected to have op token: {}", op);
9141+
panic!("Debug panic! Expected to have op token: {op}");
91399142
}
91409143
}
91419144

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(clippy::if_same_then_else)]
55
#![allow(clippy::vec_init_then_push)]
66
#![allow(clippy::type_complexity)]
7+
#![allow(clippy::needless_lifetimes)] // todo: enable this in the future
78
#![deny(clippy::disallowed_methods)]
89
#![deny(clippy::disallowed_types)]
910

src/swc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn ensure_no_specific_syntax_errors(parsed_source: &ParsedSource) -> Result<
8888
if !final_message.is_empty() {
8989
final_message.push_str("\n\n");
9090
}
91-
final_message.push_str(&format!("{}", diagnostic));
91+
final_message.push_str(&format!("{diagnostic}"));
9292
}
9393
bail!("{}", final_message)
9494
}

tests/specs/types/TypeParameter/TypeParameter_All.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
~~ lineWidth: 40 ~~
22
== should put type parameters on multiple lines when they extend beyond the line width ==
3-
class Test<T, TestingThisOut extends number> {
3+
class Test<T, const U, TestingThisOut extends number> {
44
}
55

66
[expect]
77
class Test<
88
T,
9+
const U,
910
TestingThisOut extends number,
1011
> {
1112
}

tests/test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ fn test_performance() {
3939
#[test]
4040
fn test_specs() {
4141
//debug_here!();
42-
let mut global_config = GlobalConfiguration::default();
43-
global_config.indent_width = Some(4); // for the tests only because a higher indent width increases the likelihood of problems
42+
let mut global_config = GlobalConfiguration {
43+
// for the tests only because a higher indent width increases the likelihood of problems
44+
indent_width: Some(4),
45+
..Default::default()
46+
};
4447

4548
run_specs(
4649
&PathBuf::from("./tests/specs"),
@@ -50,7 +53,7 @@ fn test_specs() {
5053
format_twice: true,
5154
},
5255
{
53-
let global_config = global_config.clone();
56+
let global_config = global_config;
5457
move |file_name, file_text, spec_config| {
5558
let config_result = resolve_config(parse_config_key_map(spec_config), &global_config);
5659
ensure_no_diagnostics(&config_result.diagnostics);

0 commit comments

Comments
 (0)