Skip to content

Commit 309bcc6

Browse files
committed
feat: Support TypeScript 4.3
1 parent f40c8f0 commit 309bcc6

File tree

7 files changed

+61
-30
lines changed

7 files changed

+61
-30
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-typescript"
33
description = "TypeScript and JavaScript code formatter."
44
keywords = ["formatting", "formatter", "typescript", "javascript"]
5-
version = "0.43.0"
5+
version = "0.44.0"
66
authors = ["David Sherret <[email protected]>"]
77
edition = "2018"
88
license = "MIT"
@@ -26,9 +26,9 @@ wasm = ["serde_json", "dprint-core/wasm"]
2626
[dependencies]
2727
dprint-core = { version = "0.35.3", features = ["formatting"] }
2828
fnv = "1.0.7"
29-
swc_common = "0.10.13"
30-
swc_ecmascript = { version = "0.29.1", features = ["parser"] }
31-
swc_ast_view = { version = "0.13.1", package = "dprint-swc-ecma-ast-view" }
29+
swc_common = "0.10.14"
30+
swc_ecmascript = { version = "0.31.0", features = ["parser"] }
31+
swc_ast_view = { version = "0.15.0", package = "dprint-swc-ecma-ast-view" }
3232
serde = { version = "1.0.118", features = ["derive"] }
3333
serde_json = { version = "1.0", optional = true }
3434

src/parsing/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ fn parse_class_method<'a>(node: &'a ClassMethod, context: &mut Context<'a>) -> P
425425
kind: node.method_kind().into(),
426426
is_generator: node.function.is_generator(),
427427
is_optional: node.is_optional(),
428+
is_override: node.is_override(),
428429
key: node.key.into(),
429430
type_params: node.function.type_params.map(|x| x.into()),
430431
params: node.function.params.iter().map(|&x| x.into()).collect(),
@@ -445,6 +446,7 @@ fn parse_private_method<'a>(node: &'a PrivateMethod, context: &mut Context<'a>)
445446
kind: node.method_kind().into(),
446447
is_generator: node.function.is_generator(),
447448
is_optional: node.is_optional(),
449+
is_override: node.is_override(),
448450
key: node.key.into(),
449451
type_params: node.function.type_params.map(|x| x.into()),
450452
params: node.function.params.iter().map(|&x| x.into()).collect(),
@@ -465,6 +467,7 @@ fn parse_class_prop<'a>(node: &'a ClassProp, context: &mut Context<'a>) -> Print
465467
accessibility: node.accessibility(),
466468
is_abstract: node.is_abstract(),
467469
is_optional: node.is_optional(),
470+
is_override: node.is_override(),
468471
readonly: node.readonly(),
469472
definite: node.definite(),
470473
}, context)
@@ -482,6 +485,7 @@ fn parse_constructor<'a>(node: &'a Constructor, context: &mut Context<'a>) -> Pr
482485
kind: ClassOrObjectMethodKind::Constructor,
483486
is_generator: false,
484487
is_optional: node.is_optional(),
488+
is_override: false,
485489
key: node.key.into(),
486490
type_params: None,
487491
params: node.params.iter().map(|x| x.into()).collect(),
@@ -527,6 +531,7 @@ fn parse_private_prop<'a>(node: &'a PrivateProp, context: &mut Context<'a>) -> P
527531
accessibility: node.accessibility(),
528532
is_abstract: node.is_abstract(),
529533
is_optional: node.is_optional(),
534+
is_override: node.is_override(),
530535
readonly: node.readonly(),
531536
definite: node.definite(),
532537
}, context)
@@ -543,6 +548,7 @@ struct ParseClassPropCommon<'a> {
543548
pub accessibility: Option<Accessibility>,
544549
pub is_abstract: bool,
545550
pub is_optional: bool,
551+
pub is_override: bool,
546552
pub readonly: bool,
547553
pub definite: bool,
548554
}
@@ -556,6 +562,7 @@ fn parse_class_prop_common<'a>(node: ParseClassPropCommon<'a>, context: &mut Con
556562
}
557563
if node.is_static { items.push_str("static "); }
558564
if node.is_abstract { items.push_str("abstract "); }
565+
if node.is_override { items.push_str("override "); }
559566
if node.readonly { items.push_str("readonly "); }
560567
let key_span = node.key.span();
561568
items.extend(if node.computed {
@@ -1941,6 +1948,7 @@ fn parse_getter_prop<'a>(node: &'a GetterProp, context: &mut Context<'a>) -> Pri
19411948
kind: ClassOrObjectMethodKind::Getter,
19421949
is_generator: false,
19431950
is_optional: false,
1951+
is_override: false,
19441952
key: node.key.into(),
19451953
type_params: None,
19461954
params: Vec::new(),
@@ -2068,6 +2076,7 @@ fn parse_setter_prop<'a>(node: &'a SetterProp, context: &mut Context<'a>) -> Pri
20682076
kind: ClassOrObjectMethodKind::Setter,
20692077
is_generator: false,
20702078
is_optional: false,
2079+
is_override: false,
20712080
key: node.key.into(),
20722081
type_params: None,
20732082
params: vec![node.param.into()],
@@ -2384,6 +2393,7 @@ fn parse_construct_signature_decl<'a>(node: &'a TsConstructSignatureDecl, contex
23842393
fn parse_index_signature<'a>(node: &'a TsIndexSignature, context: &mut Context<'a>) -> PrintItems {
23852394
let mut items = PrintItems::new();
23862395

2396+
if node.is_static() { items.push_str("static "); }
23872397
if node.readonly() { items.push_str("readonly "); }
23882398

23892399
let param: Node<'a> = node.params.iter().next().expect("Expected the index signature to have one parameter.").into();
@@ -3025,6 +3035,7 @@ fn parse_method_prop<'a>(node: &'a MethodProp, context: &mut Context<'a>) -> Pri
30253035
is_static: false,
30263036
is_async: node.function.is_async(),
30273037
is_abstract: false,
3038+
is_override: false,
30283039
kind: ClassOrObjectMethodKind::Method,
30293040
is_generator: node.function.is_generator(),
30303041
is_optional: false,
@@ -3047,6 +3058,7 @@ struct ClassOrObjectMethod<'a> {
30473058
kind: ClassOrObjectMethodKind,
30483059
is_generator: bool,
30493060
is_optional: bool,
3061+
is_override: bool,
30503062
key: Node<'a>,
30513063
type_params: Option<Node<'a>>,
30523064
params: Vec<Node<'a>>,
@@ -3085,6 +3097,7 @@ fn parse_class_or_object_method<'a>(node: ClassOrObjectMethod<'a>, context: &mut
30853097
}
30863098
if node.is_static { items.push_str("static "); }
30873099
if node.is_abstract { items.push_str("abstract "); }
3100+
if node.is_override { items.push_str("override "); }
30883101
if node.is_async { items.push_str("async "); }
30893102

30903103
match node.kind {

tests/specs/declarations/class/method/ClassMethod_All.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
~~ lineWidth: 50 ~~
22
== should format different kinds of class methods ==
3-
abstract class Test {
3+
abstract class Test extends Base {
44
constructor() {
55
super(5, 4);
66
}
77

88
@dec
9-
public static async method1(): string {
9+
public static override async method1(): 2 {
1010
// test
1111
}
1212

@@ -46,13 +46,13 @@ abstract class Test {
4646
}
4747

4848
[expect]
49-
abstract class Test {
49+
abstract class Test extends Base {
5050
constructor() {
5151
super(5, 4);
5252
}
5353

5454
@dec
55-
public static async method1(): string {
55+
public static override async method1(): 2 {
5656
// test
5757
}
5858

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
~~ lineWidth: 50 ~~
22
== should format private methods ==
3-
abstract class Test {
3+
abstract class Test extends Base {
44
#method1( arg : string ) : test {
55
return 5 ;
66
}
77

88
#method2?() {
99
}
10+
11+
override async #method3() {
12+
}
1013
}
1114

1215
[expect]
13-
abstract class Test {
16+
abstract class Test extends Base {
1417
#method1(arg: string): test {
1518
return 5;
1619
}
1720

1821
#method2?() {
1922
}
23+
24+
override async #method3() {
25+
}
2026
}

tests/specs/declarations/class/private_property/PrivateProperty_All.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
~~ lineWidth: 40 ~~
22
== should format ==
3-
class Test {
3+
class Test extends Base {
44
#p1;
55
#p2 : string;
66
#p3 = 4;
77
#p4 ? : string;
8+
override #p5;
89

910
constructor() {
1011
this.#p1 = "test";
1112
}
1213
}
1314

1415
[expect]
15-
class Test {
16+
class Test extends Base {
1617
#p1;
1718
#p2: string;
1819
#p3 = 4;
1920
#p4?: string;
21+
override #p5;
2022

2123
constructor() {
2224
this.#p1 = "test";

tests/specs/declarations/class/property/ClassProperty_All.txt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
~~ lineWidth: 50 ~~
22
== should format different kinds of class properties ==
3-
abstract class Test {
4-
public static readonly prop1: string;
3+
abstract class Test extends Base {
4+
public static readonly prop1: 2;
55
protected abstract readonly prop2: number;
6-
prop3! : string;
7-
prop4?: string;
8-
prop5 ;
9-
"prop6" : string;
10-
7 : number;
11-
["8"] : number;
12-
prop9 : number = 5;
6+
public override readonly prop3: 2;
7+
prop4! : string;
8+
prop5?: string;
9+
prop6 ;
10+
"prop7" : string;
11+
8 : number;
12+
["9"] : number;
13+
prop10 : number = 5;
1314
someVeryLongProperty: string | number | stringg | number;
1415
@dec
1516
readonly propReadonly = 3;
1617
}
1718

1819
[expect]
19-
abstract class Test {
20-
public static readonly prop1: string;
20+
abstract class Test extends Base {
21+
public static readonly prop1: 2;
2122
protected abstract readonly prop2: number;
22-
prop3!: string;
23-
prop4?: string;
24-
prop5;
25-
"prop6": string;
26-
7: number;
27-
["8"]: number;
28-
prop9: number = 5;
23+
public override readonly prop3: 2;
24+
prop4!: string;
25+
prop5?: string;
26+
prop6;
27+
"prop7": string;
28+
8: number;
29+
["9"]: number;
30+
prop10: number = 5;
2931
someVeryLongProperty:
3032
| string
3133
| number

tests/specs/declarations/interface/indexSignature/IndexSignature_All.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ interface T {
66
readonly [index]: string;
77
}
88

9+
class Test {
10+
static readonly [index]: number;
11+
}
12+
913
[expect]
1014
interface T {
1115
[index: number]: string;
@@ -15,3 +19,7 @@ interface T {
1519
| boolean;
1620
readonly [index]: string;
1721
}
22+
23+
class Test {
24+
static readonly [index]: number;
25+
}

0 commit comments

Comments
 (0)