From c8984f392a4581379d67a2e83b398c29a3bb2ee4 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Fri, 5 May 2017 21:39:11 -0700 Subject: [PATCH] Fix TypeScript regex (#1527) Turns out n.value is NaN for regexes in typescript, go figure. Just moving the two if statements is working to fix the issue. Fixes #1526 --- src/printer.js | 6 +++--- tests/regex/jsfmt.spec.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/printer.js b/src/printer.js index c5104264..45d8cbe6 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1016,12 +1016,12 @@ function genericPrintNoParens(path, options, print, args) { // Babel 6 Literal split case "StringLiteral": case "Literal": - if (typeof n.value === "number") { - return printNumber(n.raw); - } if (n.regex) { return printRegex(n.regex); } + if (typeof n.value === "number") { + return printNumber(n.raw); + } if (typeof n.value !== "string") { return "" + n.value; } diff --git a/tests/regex/jsfmt.spec.js b/tests/regex/jsfmt.spec.js index 1840e9d3..c426c19c 100644 --- a/tests/regex/jsfmt.spec.js +++ b/tests/regex/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, null, ["babylon"]); +run_spec(__dirname, null, ["babylon", "typescript"]);