Repository: prettier/prettier (JavaScript)

Issue:
Prettier removes trailing comma of generic arrow function in Markdown tsx codeblock
**Prettier 2.4.1**
[Playground link](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEADdACGBnAHgHSkimxizlIwF4MAeAFQBoA+ACgDcBDAGwFc4kGegEpqzDMAC+AbkLpUhEIxAQADjACW0bMlCcATvogB3AAoGEOlD2OcAnjuUAjfZzABrODADKnALZwADIaUHDIAGY82HDOrh5e3qpuIQDmyDD6-Mpwfk5wACb5BYGcUCm8nClwAGIQ+n6cMJplyCCcvDAQSiAAFjB+3ADqPRrw2ElgcN6Woxrso3atYNiOICHR+jCmrikNEVExIABWeN6p3HAAirwQ8Pvc0cpJ+hutDfru+SZQ3ar6ITBBhp8jAesgABwABieRmig1cqlafwocH07DCygAjjd4Ns1FY2tgALShAoFbr6ODYjSU7aVPZISIPQ7RPwadKZFnnK44sKMg7KGCcJxAkFgpAAJkFrg03FSAGEIH4GSAKABWbq8aL0YVWJmPEDsfgASSgRVg3jA-3UAEEzd4YHYLvdopJJEA)
<!-- prettier-ignore -->
```sh
--parser markdown
```

**Input:**
<!-- prettier-ignore -->
````markdown
``` tsx
const test = <T,>(value: T) => {};
```

````

**Output:**
<!-- prettier-ignore -->
````markdown
```tsx
const test = <T>(value: T) => {};
```

````

**Expected behavior:**
Prettier should not remove the trailing comma because this results in invalid code. Expected output is:

<!-- prettier-ignore -->
````markdown
```tsx
const test = <T,>(value: T) => {};
```

````

Prettier handles trailing commas correctly in `.tsx` files. It does it by checking if the file name ends with `.tsx`. As this is false in markdown files (`.md` instead) it removes the comma. See https://github.com/prettier/prettier/blob/main/src/language-js/print/type-parameters.js#L54-L64




Hints:

Patch:
diff --git a/src/language-markdown/embed.js b/src/language-markdown/embed.js
--- a/src/language-markdown/embed.js
+++ b/src/language-markdown/embed.js
@@ -21,9 +21,13 @@ function embed(path, print, textToDoc, options) {
       const style = styleUnit.repeat(
         Math.max(3, getMaxContinuousCount(node.value, styleUnit) + 1)
       );
+      const newOptions = { parser };
+      if (node.lang === "tsx") {
+        newOptions.filepath = "dummy.tsx";
+      }
       const doc = textToDoc(
         getFencedCodeBlockValue(node, options.originalText),
-        { parser },
+        newOptions,
         { stripTrailingHardline: true }
       );
       return markAsRoot([


Test patch:
diff --git a/tests/format/markdown/code/__snapshots__/jsfmt.spec.js.snap b/tests/format/markdown/code/__snapshots__/jsfmt.spec.js.snap
--- a/tests/format/markdown/code/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/format/markdown/code/__snapshots__/jsfmt.spec.js.snap
@@ -290,3 +290,22 @@ hello world
 
 ================================================================================
 `;
+
+exports[`tsx-trailing-comma.md - {"proseWrap":"always"} format 1`] = `
+====================================options=====================================
+parsers: ["markdown"]
+printWidth: 80
+proseWrap: "always"
+                                                                                | printWidth
+=====================================input======================================
+\`\`\`tsx
+const test = <T,>(value: T) => {};
+\`\`\`
+
+=====================================output=====================================
+\`\`\`tsx
+const test = <T,>(value: T) => {};
+\`\`\`
+
+================================================================================
+`;
diff --git a/tests/format/markdown/code/tsx-trailing-comma.md b/tests/format/markdown/code/tsx-trailing-comma.md
new file mode 100644
--- /dev/null
+++ b/tests/format/markdown/code/tsx-trailing-comma.md
@@ -0,0 +1,3 @@
+```tsx
+const test = <T,>(value: T) => {};
+```