Repository: jlongster/prettier
Pull request #257 (2017-01-17 02:19:01)

Preserve the way numbers were written
The goal of the pretty printer is to make sure that the indentation is correct, not to dictate how numbers should be written :)


Patch:
diff --git a/src/fast-path.js b/src/fast-path.js
index cc195dc92..94b2fcf44 100644
--- a/src/fast-path.js
+++ b/src/fast-path.js
@@ -374,6 +374,7 @@ FPp.needsParens = function(assumeExpressionContext) {
 
       switch (parent.type) {
         case "MemberExpression":
+        case "TaggedTemplateExpression":
         case "UnaryExpression":
           return true;
 
diff --git a/src/printer.js b/src/printer.js
index 0bdd19e99..1cf403c1d 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -690,12 +690,15 @@ function genericPrintNoParens(path, options, print) {
     "RegExpLiteral":
       return fromString(n.extra.raw);
     // Babel 6 Literal split
-    case "BooleanLiteral":
-    // Babel 6 Literal split
     case "NumericLiteral":
+      return n.extra.raw;
+    // Babel 6 Literal split
+    case "BooleanLiteral":
     // Babel 6 Literal split
     case "StringLiteral":
     case "Literal":
+      if (typeof n.value === "number")
+        return n.raw;
       if (typeof n.value !== "string")
         return fromString(n.value, options);
 


Test patch:
diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap
index 3e6449a4b..9e447683e 100644
--- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap
@@ -30,6 +30,7 @@ exports[`test arrow_function_expression.js 1`] = `
 typeof (() => {});
 export default (() => {})();
 (() => {})()\`\`;
+(() => {})\`\`;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 (a => {
 }).length;
@@ -39,6 +40,8 @@ export default (() => {
 })()
 (() => {
 })()\`\`;
+(() => {
+})\`\`;
 "
 `;
 
diff --git a/tests/arrows/arrow_function_expression.js b/tests/arrows/arrow_function_expression.js
index f0309346f..dac425060 100644
--- a/tests/arrows/arrow_function_expression.js
+++ b/tests/arrows/arrow_function_expression.js
@@ -2,3 +2,4 @@
 typeof (() => {});
 export default (() => {})();
 (() => {})()``;
+(() => {})``;
diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap
index a776342cc..cb2af2b51 100644
--- a/tests/function/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/function/__snapshots__/jsfmt.spec.js.snap
@@ -356,6 +356,7 @@ exports[`test function_expression.js 1`] = `
 typeof (function() {});
 export default (function() {})();
 (function() {})()\`\`;
+(function() {})\`\`;
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 (function() {
 }).length;
@@ -365,6 +366,8 @@ export default (function() {
 })()
 (function() {
 })()\`\`;
+(function() {
+})\`\`;
 "
 `;
 
diff --git a/tests/function/function_expression.js b/tests/function/function_expression.js
index 786e8bdb5..93c6da8ec 100644
--- a/tests/function/function_expression.js
+++ b/tests/function/function_expression.js
@@ -2,3 +2,4 @@
 typeof (function() {});
 export default (function() {})();
 (function() {})()``;
+(function() {})``;
diff --git a/tests/module_use_strict/__snapshots__/jsfmt.spec.js.snap b/tests/module_use_strict/__snapshots__/jsfmt.spec.js.snap
index ea7d880b6..6e98314fe 100644
--- a/tests/module_use_strict/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/module_use_strict/__snapshots__/jsfmt.spec.js.snap
@@ -5,6 +5,6 @@ exports[`test test.js 1`] = `
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // @flow
 
-(1: number);
+(01: number);
 "
 `;
diff --git a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap
index 91cb232c5..85d6f7cf5 100644
--- a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap
@@ -116,8 +116,8 @@ num = buffer.indexOf(3);
 num = buffer.indexOf(3, 4);
 
 // static methods
-buffer = Buffer.from([ 98, 117, 102, 102, 101, 114 ]);
-const typedArray = new Uint8Array([ 52 ]);
+buffer = Buffer.from([ 0x62, 0x75, 0x66, 0x66, 0x65, 0x72 ]);
+const typedArray = new Uint8Array([ 0x34 ]);
 buffer = Buffer.from(
   typedArray.buffer,
   typedArray.byteOffset,
@@ -131,7 +131,7 @@ buffer = Buffer.from(\"foo\", \"utf8\");
 // flow doesn\'t support a subclass hiding a superclass member, so this checks out as
 // ok, even though it is not correct.
 buffer = Buffer.from(
-  [ 98, 117, 102, 102, 101, 114 ],
+  [ 0x62, 0x75, 0x66, 0x66, 0x65, 0x72 ],
   (a: number) => a + 1,
   {}
 ); // should error but doesn\'t
diff --git a/tests/unicode/__snapshots__/jsfmt.spec.js.snap b/tests/unicode/__snapshots__/jsfmt.spec.js.snap
index 7c143e019..5e9d38546 100644
--- a/tests/unicode/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/unicode/__snapshots__/jsfmt.spec.js.snap
@@ -43,7 +43,7 @@ function utf16Length(str, pos) {
  * @return {boolean}      Whether code-unit is in a surrogate (hi/low) range
  */
 function inSurrogateRange(codeUnit) {
-  return 55296 <= codeUnit && codeUnit <= 57343;
+  return 0xD800 <= codeUnit && codeUnit <= 0xDFFF;
 }
 
 /**