Skip to content

Commit f2686fd

Browse files
authored
feat: upgrade for TypeScript 5.0 (except decorators) (#505)
1 parent 05ed0c9 commit f2686fd

File tree

9 files changed

+121
-24
lines changed

9 files changed

+121
-24
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
steps:
3030
- uses: actions/checkout@v2
31-
- uses: dtolnay/rust-toolchain@stable
31+
- uses: dsherret/rust-toolchain-file@v1
3232
- name: Install wasm32 target
3333
if: matrix.config.kind == 'test_release'
3434
run: rustup target add wasm32-unknown-unknown

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
token: ${{ secrets.GH_DPRINTBOT_PAT }}
2626

2727
- uses: denoland/setup-deno@v1
28-
- uses: dtolnay/rust-toolchain@stable
28+
- uses: dsherret/rust-toolchain-file@v1
2929

3030
- name: Bump version and tag
3131
env:

Cargo.lock

Lines changed: 51 additions & 16 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.24.0", features = ["view"] }
29+
deno_ast = { version = "0.25.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/generation/generate.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn gen_node_with_inner_gen<'a>(node: Node<'a>, context: &mut Context<'a>, inner_
144144
Node::Constructor(node) => gen_constructor(node, context),
145145
Node::Decorator(node) => gen_decorator(node, context),
146146
Node::TsParamProp(node) => gen_parameter_prop(node, context),
147+
Node::AutoAccessor(node) => gen_auto_accessor(node, context),
147148
Node::PrivateMethod(node) => gen_private_method(node, context),
148149
Node::PrivateName(node) => gen_private_name(node, context),
149150
Node::PrivateProp(node) => gen_private_prop(node, context),
@@ -456,6 +457,29 @@ fn gen_class_method<'a>(node: &'a ClassMethod, context: &mut Context<'a>) -> Pri
456457
)
457458
}
458459

460+
fn gen_auto_accessor<'a>(node: &'a AutoAccessor, context: &mut Context<'a>) -> PrintItems {
461+
gen_class_prop_common(
462+
GenClassPropCommon {
463+
original: node.into(),
464+
key: node.key.into(),
465+
value: &node.value,
466+
type_ann: &node.type_ann,
467+
is_static: node.is_static(),
468+
decorators: &node.decorators,
469+
computed: false,
470+
is_auto_accessor: true,
471+
is_declare: false,
472+
accessibility: node.accessibility(),
473+
is_abstract: false,
474+
is_optional: false,
475+
is_override: false,
476+
readonly: false,
477+
definite: false,
478+
},
479+
context,
480+
)
481+
}
482+
459483
fn gen_private_method<'a>(node: &'a PrivateMethod, context: &mut Context<'a>) -> PrintItems {
460484
gen_class_or_object_method(
461485
ClassOrObjectMethod {
@@ -490,6 +514,7 @@ fn gen_class_prop<'a>(node: &'a ClassProp, context: &mut Context<'a>) -> PrintIt
490514
is_static: node.is_static(),
491515
decorators: &node.decorators,
492516
computed: matches!(node.key, PropName::Computed(_)),
517+
is_auto_accessor: false,
493518
is_declare: node.declare(),
494519
accessibility: node.accessibility(),
495520
is_abstract: node.is_abstract(),
@@ -566,6 +591,7 @@ fn gen_private_prop<'a>(node: &'a PrivateProp, context: &mut Context<'a>) -> Pri
566591
is_static: node.is_static(),
567592
decorators: &node.decorators,
568593
computed: false,
594+
is_auto_accessor: false,
569595
is_declare: false,
570596
accessibility: node.accessibility(),
571597
is_abstract: false,
@@ -588,6 +614,7 @@ struct GenClassPropCommon<'a> {
588614
pub computed: bool,
589615
pub is_declare: bool,
590616
pub accessibility: Option<Accessibility>,
617+
pub is_auto_accessor: bool,
591618
pub is_abstract: bool,
592619
pub is_optional: bool,
593620
pub is_override: bool,
@@ -607,6 +634,9 @@ fn gen_class_prop_common<'a>(node: GenClassPropCommon<'a>, context: &mut Context
607634
if node.is_static {
608635
items.push_str("static ");
609636
}
637+
if node.is_auto_accessor {
638+
items.push_str("accessor ");
639+
}
610640
if node.is_abstract {
611641
items.push_str("abstract ");
612642
}
@@ -4390,7 +4420,11 @@ fn gen_do_while_stmt<'a>(node: &'a DoWhileStmt, context: &mut Context<'a>) -> Pr
43904420

43914421
fn gen_export_all<'a>(node: &'a ExportAll, context: &mut Context<'a>) -> PrintItems {
43924422
let mut items = PrintItems::new();
4393-
items.push_str("export * from ");
4423+
if node.type_only() {
4424+
items.push_str("export type * from ");
4425+
} else {
4426+
items.push_str("export * from ");
4427+
}
43944428
items.extend(gen_node(node.src.into(), context));
43954429

43964430
if let Some(asserts) = node.asserts {
@@ -4723,7 +4757,7 @@ fn gen_for_of_stmt<'a>(node: &'a ForOfStmt, context: &mut Context<'a>) -> PrintI
47234757
if context.config.for_of_statement_space_after_for_keyword {
47244758
items.push_str(" ");
47254759
}
4726-
if node.await_token().is_some() {
4760+
if node.is_await() {
47274761
// todo: generate comments around await token range
47284762
items.push_str("await ");
47294763
}

src/swc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn parse_inner(file_path: &Path, text_info: SourceTextInfo) -> Result<ParsedSour
3434
}
3535

3636
fn parse_inner_no_diagnostic_check(file_path: &Path, text_info: SourceTextInfo) -> Result<ParsedSource> {
37-
let media_type: deno_ast::MediaType = file_path.into();
37+
let media_type = deno_ast::MediaType::from_path(file_path);
3838
let mut syntax = deno_ast::get_syntax(media_type);
3939
if let Syntax::Es(es) = &mut syntax {
4040
// support decorators in js
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
~~ lineWidth: 50 ~~
2+
== should format auto accessors ==
3+
class Person {
4+
accessor name: string;
5+
static accessor test: string;
6+
public static accessor test2 : string;
7+
private accessor test3 : string;
8+
accessor #test = 2;
9+
10+
constructor(name: string) {
11+
this.name = name;
12+
}
13+
}
14+
15+
[expect]
16+
class Person {
17+
accessor name: string;
18+
static accessor test: string;
19+
public static accessor test2: string;
20+
private accessor test3: string;
21+
accessor #test = 2;
22+
23+
constructor(name: string) {
24+
this.name = name;
25+
}
26+
}

tests/specs/declarations/export/ExportAllDeclaration_All.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
~~ lineWidth: 50 ~~
22
== should format ==
33
export * from "test" ;
4+
export type * from "test" ;
45

56
[expect]
67
export * from "test";
8+
export type * from "test";
79

810
== should format assertions ==
911
export * from "a" assert {type: "json"};

tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn test_performance() {
3939
#[test]
4040
fn test_specs() {
4141
//debug_here!();
42-
let mut global_config = GlobalConfiguration {
42+
let global_config = GlobalConfiguration {
4343
// for the tests only because a higher indent width increases the likelihood of problems
4444
indent_width: Some(4),
4545
..Default::default()
@@ -53,7 +53,7 @@ fn test_specs() {
5353
format_twice: true,
5454
},
5555
{
56-
let global_config = global_config;
56+
let global_config = global_config.clone();
5757
move |file_name, file_text, spec_config| {
5858
let config_result = resolve_config(parse_config_key_map(spec_config), &global_config);
5959
ensure_no_diagnostics(&config_result.diagnostics);

0 commit comments

Comments
 (0)