Skip to content

Commit b02dd9c

Browse files
authored
fix: swc upgrade - ensure const type params not removed in arrow functions (#517)
1 parent 5b29eaa commit b02dd9c

File tree

5 files changed

+74
-94
lines changed

5 files changed

+74
-94
lines changed

Cargo.lock

Lines changed: 42 additions & 93 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.25.0", features = ["view"] }
29+
deno_ast = { version = "0.26.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"] }

src/swc.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ mod tests {
157157
);
158158
}
159159

160+
#[test]
161+
fn it_should_error_closing_paren_missing() {
162+
// issue 498
163+
run_fatal_diagnostic_test(
164+
"./test.ts",
165+
r#"const foo = <T extends {}>() => {
166+
if (bar() {
167+
console.log(1);
168+
}
169+
};"#,
170+
concat!(
171+
"An arrow function is not allowed here at ./test.ts:1:27\n",
172+
"\n",
173+
" const foo = <T extends {}>() => {\n",
174+
" ~~"
175+
),
176+
);
177+
}
178+
160179
fn run_fatal_diagnostic_test(file_path: &str, text: &str, expected: &str) {
161180
let file_path = PathBuf::from(file_path);
162181
assert_eq!(parse_swc_ast(&file_path, text).err().unwrap().to_string(), expected);

tests/specs/expressions/ArrowFunctionExpression/ArrowFunctionExpression_All.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,9 @@ const someFunc =
263263
c => {
264264
return a + b + c;
265265
};
266+
267+
== should format with const type params ==
268+
const t = <const T extends 5>() => {};
269+
270+
[expect]
271+
const t = <const T extends 5>() => {};

tests/specs/expressions/FunctionExpression/FunctionExpression_All.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ const t = function(testing, this) {};
6969

7070
[expect]
7171
const t = function(testing, this) {};
72+
73+
== should format with const type params ==
74+
const t = function<const T extends 5>() {};
75+
76+
[expect]
77+
const t = function<const T extends 5>() {};

0 commit comments

Comments
 (0)