Skip to content

Commit 9a6d58b

Browse files
committed
fix: #30 - declare should not be removed on class properties.
1 parent 1a7ff21 commit 9a6d58b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parsing/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ fn parse_class_prop<'a>(node: &'a ClassProp, context: &mut Context<'a>) -> Print
409409
is_static: node.is_static,
410410
decorators: &node.decorators,
411411
computed: node.computed,
412+
is_declare: node.declare,
412413
accessibility: &node.accessibility,
413414
is_abstract: node.is_abstract,
414415
is_optional: node.is_optional,
@@ -469,6 +470,7 @@ fn parse_private_prop<'a>(node: &'a PrivateProp, context: &mut Context<'a>) -> P
469470
is_static: node.is_static,
470471
decorators: &node.decorators,
471472
computed: node.computed,
473+
is_declare: false,
472474
accessibility: &node.accessibility,
473475
is_abstract: node.is_abstract,
474476
is_optional: node.is_optional,
@@ -484,6 +486,7 @@ struct ParseClassPropCommon<'a> {
484486
pub is_static: bool,
485487
pub decorators: &'a Vec<Decorator>,
486488
pub computed: bool,
489+
pub is_declare: bool,
487490
pub accessibility: &'a Option<Accessibility>,
488491
pub is_abstract: bool,
489492
pub is_optional: bool,
@@ -494,6 +497,7 @@ struct ParseClassPropCommon<'a> {
494497
fn parse_class_prop_common<'a>(node: ParseClassPropCommon<'a>, context: &mut Context<'a>) -> PrintItems {
495498
let mut items = PrintItems::new();
496499
items.extend(parse_decorators(node.decorators, false, context));
500+
if node.is_declare { items.push_str("declare "); }
497501
if let Some(accessibility) = node.accessibility {
498502
items.push_str(&format!("{} ", accessibility_to_str(accessibility)));
499503
}

tests/specs/issues/issue0030.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
== should keep declare public ==
2+
class Test {
3+
declare public type: string;
4+
declare other: string;
5+
}
6+
7+
[expect]
8+
class Test {
9+
declare public type: string;
10+
declare other: string;
11+
}

0 commit comments

Comments
 (0)