Repository: prettier/plugin-pug (ts)

Issue:
Bug: Spaces are not maintained between interpolations
### Plugin Version

^2.5.0

### Prettier Version

^2.8.8

### Which frameworks are affected?

- [ ] none
- [ ] vue
- [ ] angular
- [ ] svelte

### Node Version

16.13/0

### Which operating systems have you used?

- [X] Linux
- [ ] macOS
- [ ] Windows

### Prettier config

```json
{
	"useTabs": true,
	"tabWidth": 4,
	"semi": false,
	"singleQuote": true
}
```


### Input

```pug
li #[b #{ key }:] #{ value }
li #{ key } #{ value }
li #[b #{ key }:] #[i= value]

li #[b #{ key }: ]#{ value }
li #[b #{ key }: ]#[i= value]
```


### Output or Error

```pug
li #[b #{ key }:]#{ value }
li #{ key }#{ value }
li #[b #{ key }:]#[i= value]

li #[b #{ key }:]#{ value }
li #[b #{ key }:]#[i= value]
```


### Expected Output

```pug
li #[b #{ key }:] #{ value }
li #{ key } #{ value }
li #[b #{ key }:] #[i= value]

li #[b #{ key }: ]#{ value }
li #[b #{ key }: ]#[i= value]
```


### Additional Context

Currently enforcing the space with a literal `&nbsp;` so it's not breaking, but it is a bit of a pain and ugly. I don't mind so much the collapsing inside of the interpolation though

Pull request description:
Handle whitespace in interpolations
closes #447 

Patch:
diff --git a/src/printer.ts b/src/printer.ts
index 3816c48..8973774 100644
--- a/src/printer.ts
+++ b/src/printer.ts
@@ -1553,8 +1553,10 @@ export class PugPrinter {
           break;
         case 'interpolated-code':
         case 'end-pug-interpolation':
-          if (/^ .+$/.test(val)) {
+          if (/^ .+$/.test(val) || val === ' ') {
             result += ' ';
+          } else if (/^.+ $/.test(val)) {
+            needsTrailingWhitespace = true;
           }
           break;
       }


Test patch:
diff --git a/tests/issues/issue-447/formatted.pug b/tests/issues/issue-447/formatted.pug
new file mode 100644
index 0000000..05301a4
--- /dev/null
+++ b/tests/issues/issue-447/formatted.pug
@@ -0,0 +1,20 @@
+li #[b #{ key }:] #{ value }
+li #{ key } #{ value }
+li #[b #{ key }:] #[i= value]
+
+li #[b #{ key }: ]#{ value }
+li #[b #{ key }: ]#[i= value]
+
+li #[b #{ key } :]#{ value }
+li #[b #{ key } :]#[i= value]
+
+div
+  li #[b #{ key }:] #{ value }
+  li #{ key } #{ value }
+  li #[b #{ key }:] #[i= value]
+
+  li #[b #{ key }: ]#{ value }
+  li #[b #{ key }: ]#[i= value]
+
+  li #[b #{ key } :]#{ value }
+  li #[b #{ key } :]#[i= value]
diff --git a/tests/issues/issue-447/issue-447.test.ts b/tests/issues/issue-447/issue-447.test.ts
new file mode 100644
index 0000000..0a832a5
--- /dev/null
+++ b/tests/issues/issue-447/issue-447.test.ts
@@ -0,0 +1,9 @@
+import { compareFiles } from 'tests/common';
+import { describe, expect, it } from 'vitest';
+
+describe('Issues', () => {
+  it('should handle whitespace in interpolations', () => {
+    const { expected, actual } = compareFiles(__dirname);
+    expect(actual).toBe(expected);
+  });
+});
diff --git a/tests/issues/issue-447/unformatted.pug b/tests/issues/issue-447/unformatted.pug
new file mode 100644
index 0000000..05301a4
--- /dev/null
+++ b/tests/issues/issue-447/unformatted.pug
@@ -0,0 +1,20 @@
+li #[b #{ key }:] #{ value }
+li #{ key } #{ value }
+li #[b #{ key }:] #[i= value]
+
+li #[b #{ key }: ]#{ value }
+li #[b #{ key }: ]#[i= value]
+
+li #[b #{ key } :]#{ value }
+li #[b #{ key } :]#[i= value]
+
+div
+  li #[b #{ key }:] #{ value }
+  li #{ key } #{ value }
+  li #[b #{ key }:] #[i= value]
+
+  li #[b #{ key }: ]#{ value }
+  li #[b #{ key }: ]#[i= value]
+
+  li #[b #{ key } :]#{ value }
+  li #[b #{ key } :]#[i= value]