Skip to content

Commit ece0cff

Browse files
authored
fix: handle override keyword for auto accessors (#597)
1 parent 46f10fd commit ece0cff

File tree

9 files changed

+63
-58
lines changed

9 files changed

+63
-58
lines changed

Cargo.lock

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

dprint.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"**/target"
1313
],
1414
"plugins": [
15-
"https://plugins.dprint.dev/typescript-0.86.1.wasm",
16-
"https://plugins.dprint.dev/json-0.17.4.wasm",
17-
"https://plugins.dprint.dev/markdown-0.15.3.wasm",
15+
"https://plugins.dprint.dev/typescript-0.88.7.wasm",
16+
"https://plugins.dprint.dev/json-0.19.1.wasm",
17+
"https://plugins.dprint.dev/markdown-0.16.3.wasm",
1818
"https://plugins.dprint.dev/toml-0.5.4.wasm",
19-
"https://plugins.dprint.dev/exec-0.4.3.json@42343548b8022c99b1d750be6b894fe6b6c7ee25f72ae9f9082226dd2e515072"
19+
"https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
2020
]
2121
}

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.74.0"
2+
channel = "1.75.0"
33
components = ["clippy"]

src/generation/generate.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,12 @@ fn gen_auto_accessor<'a>(node: &AutoAccessor<'a>, context: &mut Context<'a>) ->
472472
accessibility: node.accessibility(),
473473
is_abstract: false,
474474
is_optional: false,
475-
is_override: false,
475+
// todo: https://github.com/swc-project/swc/issues/8344
476+
is_override: node
477+
.tokens_fast(context.program)
478+
.iter()
479+
.take_while(|t| t.start() < node.key.start())
480+
.any(|t| t.span.text_fast(context.program) == "override"),
476481
readonly: false,
477482
// todo: https://github.com/swc-project/swc/issues/8344
478483
definite: node.type_ann.is_some() && node.key.next_token_fast(context.program).is_some_and(|t| t.token == Token::Bang),
@@ -635,9 +640,6 @@ fn gen_class_prop_common<'a, 'b>(node: GenClassPropCommon<'a, 'b>, context: &mut
635640
if node.is_static {
636641
items.push_str("static ");
637642
}
638-
if node.is_auto_accessor {
639-
items.push_str("accessor ");
640-
}
641643
if node.is_abstract {
642644
items.push_str("abstract ");
643645
}
@@ -647,6 +649,9 @@ fn gen_class_prop_common<'a, 'b>(node: GenClassPropCommon<'a, 'b>, context: &mut
647649
if node.readonly {
648650
items.push_str("readonly ");
649651
}
652+
if node.is_auto_accessor {
653+
items.push_str("accessor ");
654+
}
650655
items.extend(if node.computed {
651656
let inner_key_node = match node.key {
652657
Node::ComputedPropName(prop) => prop.expr.as_node(),

src/utils/char_iterator.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
use std::iter::Peekable;
22
use std::str::Chars;
33

4-
pub trait IteratorCharExt: Iterator<Item = char> {
5-
fn peek(&mut self) -> Option<&char>;
4+
pub struct IteratorCharExt<'a>(Peekable<Chars<'a>>);
65

7-
fn check_text(&mut self, text: &str) -> bool {
6+
impl<'a> IteratorCharExt<'a> {
7+
pub fn new(chars: Peekable<Chars<'a>>) -> Self {
8+
Self(chars)
9+
}
10+
11+
pub fn next(&mut self) -> Option<char> {
12+
self.0.next()
13+
}
14+
15+
pub fn peek(&mut self) -> Option<&char> {
16+
self.0.peek()
17+
}
18+
19+
pub fn check_text(&mut self, text: &str) -> bool {
820
for text_ch in text.chars() {
921
match self.peek() {
1022
Some(ch) if *ch == text_ch => self.next(),
@@ -14,19 +26,19 @@ pub trait IteratorCharExt: Iterator<Item = char> {
1426
true
1527
}
1628

17-
fn skip_whitespace(&mut self) {
29+
pub fn skip_whitespace(&mut self) {
1830
self.skip_while(char::is_whitespace);
1931
}
2032

21-
fn skip_spaces(&mut self) {
33+
pub fn skip_spaces(&mut self) {
2234
self.skip_while(|c| c == ' ');
2335
}
2436

25-
fn skip_all_until_new_line(&mut self) {
37+
pub fn skip_all_until_new_line(&mut self) {
2638
self.skip_while(|c| c != '\n');
2739
}
2840

29-
fn skip_while<P: Fn(char) -> bool>(&mut self, predicate: P) {
41+
pub fn skip_while<P: Fn(char) -> bool>(&mut self, predicate: P) {
3042
while let Some(ch) = self.peek() {
3143
if !predicate(*ch) {
3244
break;
@@ -35,9 +47,3 @@ pub trait IteratorCharExt: Iterator<Item = char> {
3547
}
3648
}
3749
}
38-
39-
impl<'a> IteratorCharExt for Peekable<Chars<'a>> {
40-
fn peek(&mut self) -> Option<&char> {
41-
self.peek()
42-
}
43-
}

src/utils/file_text_has_ignore_comment.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use crate::utils::char_iterator::IteratorCharExt;
22
use std::iter::Iterator;
3-
use std::iter::Peekable;
4-
use std::str::Chars;
53

64
pub fn file_text_has_ignore_comment(file_text: &str, ignore_text: &str) -> bool {
7-
let mut chars = file_text.chars().peekable();
5+
let mut chars = IteratorCharExt::new(file_text.chars().peekable());
86

97
// skip over the shebang
108
if file_text.starts_with("#!") {
@@ -35,7 +33,7 @@ pub fn file_text_has_ignore_comment(file_text: &str, ignore_text: &str) -> bool
3533
}
3634
return false;
3735

38-
fn check_single_line_comment(chars: &mut Peekable<Chars>, ignore_text: &str) -> bool {
36+
fn check_single_line_comment(chars: &mut IteratorCharExt, ignore_text: &str) -> bool {
3937
chars.skip_spaces(); // only spaces, not whitespace
4038
if chars.check_text(ignore_text) {
4139
return true;
@@ -44,7 +42,7 @@ pub fn file_text_has_ignore_comment(file_text: &str, ignore_text: &str) -> bool
4442
false
4543
}
4644

47-
fn check_multi_line_comment(chars: &mut Peekable<Chars>, ignore_text: &str) -> bool {
45+
fn check_multi_line_comment(chars: &mut IteratorCharExt, ignore_text: &str) -> bool {
4846
chars.skip_whitespace();
4947
if chars.check_text(ignore_text) {
5048
return true;

src/utils/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod stack;
55
mod string_utils;
66
mod vec_map;
77

8-
pub use char_iterator::*;
98
pub use file_text_has_ignore_comment::*;
109
pub use is_prefix_semi_colon_insertion_char::*;
1110
pub use stack::*;

tests/specs/declarations/class/auto_accessor/AutoAccessor_All.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Person {
77
private accessor test3 : string;
88
accessor #test = 2;
99
accessor here!: string;
10+
override accessor test4: string;
1011

1112
constructor(name: string) {
1213
this.name = name;
@@ -21,6 +22,7 @@ class Person {
2122
private accessor test3: string;
2223
accessor #test = 2;
2324
accessor here!: string;
25+
override accessor test4: string;
2426

2527
constructor(name: string) {
2628
this.name = name;

0 commit comments

Comments
 (0)