Repository: dprint/dprint-plugin-typescript (rust)

Issue:
Space removed after method call on number literal
**Describe the bug**

dprint-plugin-typescript version: 0.73.1

**Input Code**

```ts
1+ 2 .toString() +3
```

**Expected Output**

```ts
1 + 2 .toString() + 3
```

or

```ts
1 + 2..toString() + 3
```

or

```ts
1 + (2).toString() + 3
```

**Actual Output**

```ts
1 + 2.toString() + 3;
```

Prettier adds parens; I think that's probably the best thing to do. See also: https://github.com/microsoft/TypeScript/issues/50686

Pull request description:
fix: don't create syntax error with numeric literal as object in member expression
Closes #421

Patch:
diff --git a/src/generation/generate.rs b/src/generation/generate.rs
index a34e0fe..ec864e3 100644
--- a/src/generation/generate.rs
+++ b/src/generation/generate.rs
@@ -7662,7 +7662,13 @@ fn gen_for_member_like_expr_item<'a>(item: &MemberLikeExprItem<'a>, context: &mu
     MemberLikeExprItem::Node(node) => {
       let is_optional = item.is_optional();
       gen_node_with_inner_gen(*node, context, |node_items, _| {
+        // Changing `2 .toString()` to `2.toString()` is a syntax error because `2.` is a numeric
+        // literal, so we surround it in parenthesis `(2).toString()`
+        let is_first_and_number = is_first && node.kind() == NodeKind::Number && !node.text_fast(context.program).contains('.');
         let mut items = PrintItems::new();
+        if is_first_and_number {
+          items.push_str("(");
+        }
         if !is_first {
           if is_optional {
             items.push_str("?.");
@@ -7671,6 +7677,9 @@ fn gen_for_member_like_expr_item<'a>(item: &MemberLikeExprItem<'a>, context: &mu
           }
         }
         items.extend(node_items);
+        if is_first_and_number {
+          items.push_str(")");
+        }
         items
       })
     }


Test patch:
diff --git a/tests/specs/issues/issue0421.txt b/tests/specs/issues/issue0421.txt
new file mode 100644
index 0000000..e7c8003
--- /dev/null
+++ b/tests/specs/issues/issue0421.txt
@@ -0,0 +1,13 @@
+== should add parens for member expr with numeric literal ==
+1+ 2 .toString() +3;
+1+ 2_000 .toString() +3;
+1+ 2..toString() +3;
+1+ 2.1.toString() +3;
+1+ (2).toString() +3;
+
+[expect]
+1 + (2).toString() + 3;
+1 + (2_000).toString() + 3;
+1 + 2..toString() + 3;
+1 + 2.1.toString() + 3;
+1 + (2).toString() + 3;