summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2019-10-13 04:55:05 +0900
committerRyan Dahl <ry@tinyclouds.org>2019-10-12 12:55:05 -0700
commit5f5583cf19349d19f717f65312558588825ad7b8 (patch)
treec27a00e8405a68d9800f4f021dcb531a6fd30ad6
parent4b7204babe4716af107786f8794072b9496d2daf (diff)
fix: [prettier] deno fmt should format jsx/tsx files (#3118)
-rwxr-xr-xstd/prettier/main.ts4
-rw-r--r--std/prettier/main_test.ts12
-rw-r--r--std/prettier/testdata/3.jsx2
-rw-r--r--std/prettier/testdata/4.tsx3
4 files changed, 16 insertions, 5 deletions
diff --git a/std/prettier/main.ts b/std/prettier/main.ts
index bd9238be2..2937a9751 100755
--- a/std/prettier/main.ts
+++ b/std/prettier/main.ts
@@ -191,9 +191,9 @@ async function formatFile(
* Selects the right prettier parser for the given path.
*/
function selectParser(path: string): ParserLabel | null {
- if (/\.ts$/.test(path)) {
+ if (/\.tsx?$/.test(path)) {
return "typescript";
- } else if (/\.js$/.test(path)) {
+ } else if (/\.jsx?$/.test(path)) {
return "babel";
} else if (/\.json$/.test(path)) {
return "json";
diff --git a/std/prettier/main_test.ts b/std/prettier/main_test.ts
index 56d031b64..65a963c02 100644
--- a/std/prettier/main_test.ts
+++ b/std/prettier/main_test.ts
@@ -26,8 +26,9 @@ const cmd = [
"--allow-run",
"--allow-write",
"--allow-read",
- "prettier/main.ts"
+ "./prettier/main.ts"
];
+
const testdata = join("prettier", "testdata");
function normalizeOutput(output: string): string {
@@ -51,7 +52,9 @@ test(async function testPrettierCheckAndFormatFiles(): Promise<void> {
const files = [
join(tempDir, "0.ts"),
join(tempDir, "1.js"),
- join(tempDir, "2.ts")
+ join(tempDir, "2.ts"),
+ join(tempDir, "3.jsx"),
+ join(tempDir, "4.tsx")
];
let p = await run([...cmd, "--check", ...files]);
@@ -63,7 +66,10 @@ test(async function testPrettierCheckAndFormatFiles(): Promise<void> {
assertEquals(
normalizeOutput(p.stdout),
normalizeOutput(`Formatting ${tempDir}/0.ts
-Formatting ${tempDir}/1.js`)
+Formatting ${tempDir}/1.js
+Formatting ${tempDir}/3.jsx
+Formatting ${tempDir}/4.tsx
+`)
);
p = await run([...cmd, "--check", ...files]);
diff --git a/std/prettier/testdata/3.jsx b/std/prettier/testdata/3.jsx
new file mode 100644
index 000000000..d58db9e7b
--- /dev/null
+++ b/std/prettier/testdata/3.jsx
@@ -0,0 +1,2 @@
+<div>
+</div>
diff --git a/std/prettier/testdata/4.tsx b/std/prettier/testdata/4.tsx
new file mode 100644
index 000000000..88d34f7fa
--- /dev/null
+++ b/std/prettier/testdata/4.tsx
@@ -0,0 +1,3 @@
+<div>
+</div>
+