From 588c8ce7cda33e4fe58a004cf524bebf7934014d Mon Sep 17 00:00:00 2001 From: James Long Date: Wed, 4 Jan 2017 15:24:10 -0500 Subject: [PATCH] Add `conditionalGroup` to allow manually specifying multiple representations of a document; use it to support expanding last parameter of functions --- src/pp.js | 88 ++++- src/printer.js | 80 +++- src/util.js | 7 + tests/annot/__snapshots__/jsfmt.spec.js.snap | 16 +- .../__snapshots__/jsfmt.spec.js.snap | 14 +- .../arraylib/__snapshots__/jsfmt.spec.js.snap | 67 ++-- tests/async/__snapshots__/jsfmt.spec.js.snap | 8 +- .../__snapshots__/jsfmt.spec.js.snap | 38 +- .../builtins/__snapshots__/jsfmt.spec.js.snap | 24 +- tests/dom/__snapshots__/jsfmt.spec.js.snap | 105 ++--- .../__snapshots__/jsfmt.spec.js.snap | 8 +- tests/fetch/__snapshots__/jsfmt.spec.js.snap | 88 ++--- .../fixpoint/__snapshots__/jsfmt.spec.js.snap | 28 +- .../__snapshots__/jsfmt.spec.js.snap | 27 +- .../buffer/__snapshots__/jsfmt.spec.js.snap | 12 +- .../__snapshots__/jsfmt.spec.js.snap | 90 ++--- .../crypto/__snapshots__/jsfmt.spec.js.snap | 11 +- .../fs/__snapshots__/jsfmt.spec.js.snap | 39 +- .../__snapshots__/jsfmt.spec.js.snap | 27 +- .../__snapshots__/jsfmt.spec.js.snap | 24 +- tests/objmap/__snapshots__/jsfmt.spec.js.snap | 10 +- .../promises/__snapshots__/jsfmt.spec.js.snap | 372 +++++++----------- tests/react/__snapshots__/jsfmt.spec.js.snap | 19 +- .../__snapshots__/jsfmt.spec.js.snap | 23 +- tests/spread/__snapshots__/jsfmt.spec.js.snap | 11 +- tests/super/__snapshots__/jsfmt.spec.js.snap | 10 +- tests/traces/__snapshots__/jsfmt.spec.js.snap | 12 +- .../__snapshots__/jsfmt.spec.js.snap | 12 +- tests/union/__snapshots__/jsfmt.spec.js.snap | 20 +- .../__snapshots__/jsfmt.spec.js.snap | 7 +- 30 files changed, 567 insertions(+), 730 deletions(-) diff --git a/src/pp.js b/src/pp.js index 03d18d912..76d9ab9df 100644 --- a/src/pp.js +++ b/src/pp.js @@ -23,15 +23,27 @@ function indent(n, contents) { return { type: 'indent', contents, n }; } -function group(contents) { +function group(contents, opts) { + opts = opts || {}; assertDoc(contents); - return { type: 'group', contents }; + return { + type: 'group', + contents: contents, + break: !!opts.shouldBreak, + expandedStates: opts.expandedStates + }; } -function multilineGroup(doc) { - assertDoc(doc); - const shouldBreak = hasHardLine(doc); - return { type: 'group', contents: doc, break: shouldBreak }; +function multilineGroup(contents, opts) { + return group(contents, Object.assign(opts || {}, { + shouldBreak: hasHardLine(contents) + })); +} + +function conditionalGroup(states, opts) { + return group(states[0], Object.assign(opts || {}, { + expandedStates: states + })); } function iterDoc(topDoc, func) { @@ -70,10 +82,6 @@ const softline = { type: 'line', soft: true }; const hardline = { type: 'line', hard: true }; const literalline = { type: 'line', hard: true, literal: true }; -function indentedLine(n) { - return { type: 'line', indent: n }; -} - function isEmpty(n) { return typeof n === "string" && n.length === 0; } @@ -183,6 +191,7 @@ function print(w, doc) { // cmds to the array instead of recursively calling `print`. let cmds = [[0, MODE_BREAK, doc]]; let out = []; + let shouldRemeasure = false; while(cmds.length !== 0) { const [ind, mode, doc] = cmds.pop(); @@ -204,16 +213,53 @@ function print(w, doc) { case "group": switch(mode) { case MODE_FLAT: - cmds.push([ind, doc.break ? MODE_BREAK : MODE_FLAT, doc.contents]); - break; + if(!shouldRemeasure) { + cmds.push([ind, doc.break ? MODE_BREAK : MODE_FLAT, doc.contents]); + break; + } + // fallthrough case MODE_BREAK: + shouldRemeasure = false; const next = [ind, MODE_FLAT, doc.contents]; let rem = w - pos; + if(!doc.break && fits(next, cmds, rem)) { cmds.push(next); } else { - cmds.push([ind, MODE_BREAK, doc.contents]); + // Expanded states are a rare case where a document + // can manually provide mutliple representations of + // itself. It provides an array of documents + // going from the least expanded (most flattened) + // representation first to the most expanded. If a + // group has these, we need to manually go through + // these states and find the first one that fits. + if(doc.expandedStates) { + const mostExpanded = doc.expandedStates[doc.expandedStates.length - 1]; + if(doc.break) { + cmds.push([ind, MODE_BREAK, mostExpanded]); + break; + } + else { + for(var i=1; i= doc.expandedStates.length) { + cmds.push([ind, MODE_BREAK, mostExpanded]); + break; + } + else { + const state = doc.expandedStates[i]; + const cmd = [ind, MODE_FLAT, state]; + if(fits(cmd, cmds, rem)) { + cmds.push(cmd); + break; + } + } + } + } + } + else { + cmds.push([ind, MODE_BREAK, doc.contents]); + } } break; } @@ -229,13 +275,13 @@ function print(w, doc) { break; } else { - // We need to switch everything back into - // the breaking mode because this is - // forcing a newline and everything needs - // to be re-measured. - cmds.forEach(cmd => { - cmd[1] = MODE_BREAK; - }); + // This line was forced into the output even if we + // were in flattened mode, so we need to tell the next + // group that no matter what, it needs to remeasure + // because the previous measurement didn't accurately + // capture the entire expression (this is necessary + // for nested groups) + shouldRemeasure = true; } // fallthrough case MODE_BREAK: @@ -268,5 +314,5 @@ function print(w, doc) { module.exports = { fromString, concat, isEmpty, join, line, softline, hardline, literalline, group, multilineGroup, - hasHardLine, indent, print, getFirstString + conditionalGroup, hasHardLine, indent, print, getFirstString }; diff --git a/src/printer.js b/src/printer.js index e41cea470..2bd1f9b88 100644 --- a/src/printer.js +++ b/src/printer.js @@ -15,6 +15,7 @@ var multilineGroup = pp.multilineGroup; var indent = pp.indent; var getFirstString = pp.getFirstString; var hasHardLine = pp.hasHardLine; +var conditionalGroup = pp.conditionalGroup; var normalizeOptions = require("./options").normalize; var types = require("ast-types"); var namedTypes = types.namedTypes; @@ -1175,13 +1176,12 @@ else ); var mostChildren = children.slice(0, -1); - var lastChild = children[children.length - 1]; var closingLines = path.call(print, "closingElement"); return concat( [ openingLines, indent(options.tabWidth, concat(mostChildren)), - lastChild || "", + util.getLast(children) || "", closingLines ] ); @@ -1746,25 +1746,65 @@ function printArgumentsList(path, options, print) { var args; if (printed.length === 0) { - args = ""; - } else - if (printed.length === 1 && getFirstString(printed[0]) === "{") { - // If the only argument is an object, don't force it to be on - // newline and keep the braces on the same line as the parens - args = printed[0]; - } else { - args = concat( - [ - indent( - options.tabWidth, - concat([ softline, join(concat([ ",", line ]), printed) ]) - ), - softline - ] - ); - } + return "()"; + } - return multilineGroup(concat([ "(", args, ")" ])); + const shouldBreak = printed.slice(0, -1).some(hasHardLine); + const lastArg = util.getLast(path.getValue().arguments); + // This is just an optimization; I think we could return the + // conditional group for all function calls, but it's more expensive + // so only do it for specific forms. + const groupLastArg = lastArg.type === "ObjectExpression" || + lastArg.type === "ArrayExpression" || + lastArg.type === "FunctionExpression" || + lastArg.type === "ArrowFunctionExpression"; + + if (groupLastArg) { + return conditionalGroup( + [ + concat([ + "(", + join(concat([ ", " ]), printed), + ")" + ]), + + concat([ + "(", + join(concat([ ",", line ]), printed.slice(0, -1)), + ", ", + group(util.getLast(printed), { shouldBreak: true }), + ")" + ]), + + group( + concat([ + "(", + indent( + options.tabWidth, + concat([ line, join(concat([ ",", line ]), printed) ]) + ), + line, + ")" + ]), + { shouldBreak: true } + ), + ], + shouldBreak + ); + } + + return group( + concat([ + "(", + indent( + options.tabWidth, + concat([ softline, join(concat([ ",", line ]), printed) ]) + ), + softline, + ")" + ]), + shouldBreak + ); } function printFunctionParams(path, print) { diff --git a/src/util.js b/src/util.js index 125fd3f62..0e68d82f4 100644 --- a/src/util.js +++ b/src/util.js @@ -304,3 +304,10 @@ util.isTrailingCommaEnabled = function(options, context) { } return !!trailingComma; }; + +util.getLast = function(arr) { + if(arr.length > 0) { + return arr[arr.length - 1]; + } + return null; +} diff --git a/tests/annot/__snapshots__/jsfmt.spec.js.snap b/tests/annot/__snapshots__/jsfmt.spec.js.snap index 6b0fe0313..a9e7243fc 100644 --- a/tests/annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/annot/__snapshots__/jsfmt.spec.js.snap @@ -102,15 +102,13 @@ function param_anno(n: number): void { function param_anno2( batchRequests: Array<{ method: string; path: string; params: ?Object }> ): void { - batchRequests = batchRequests.map( - request => { - return { - method: request.method, - params: request.params, - relative_url: request.path - }; - } - ); + batchRequests = batchRequests.map(request => { + return { + method: request.method, + params: request.params, + relative_url: request.path + }; + }); } var toz: null = 3; diff --git a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap index 9a6705751..0c5146793 100644 --- a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap @@ -39,15 +39,13 @@ console.log(filteredItems); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ function filterItems(items: Array): Array { - return items.map( - item => { - if (typeof item === \"string\") { - return (item.length > 2 ? item : null); - } else { - return item * 10; - } + return items.map(item => { + if (typeof item === \"string\") { + return (item.length > 2 ? item : null); + } else { + return item * 10; } - ).filter(Boolean); + }).filter(Boolean); } const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]); diff --git a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap index 2407f18e9..47cb14b0f 100644 --- a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap @@ -69,22 +69,18 @@ function from_test() { function foo(x: string) {} var a = [ 0 ]; -var b = a.map( - function(x) { - foo(x); +var b = a.map(function(x) { + foo(x); - return \"\" + x; - } -); + return \"\" + x; +}); var c: number = a[0]; var d: number = b[0]; var e: Array = a.reverse(); var f = [ \"\" ]; -var g: number = f.map( - function() { - return 0; - } -)[0]; +var g: number = f.map(function() { + return 0; +})[0]; var h: Array = [ 1, 2, 3 ]; var i: Array = [ \"a\", \"b\", \"c\" ]; var j: Array = h.concat(i); @@ -94,29 +90,20 @@ var m: Array = h.concat(\"a\", \"b\", \"c\"); var n: Array = h.concat(\"a\", \"b\", \"c\"); function reduce_test() { - [ 0, 1, 2, 3, 4 ].reduce( - function(previousValue, currentValue, index, array) { - return previousValue + currentValue + array[index]; - } - ); + [ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) { + return previousValue + currentValue + array[index]; + }); - [ 0, 1, 2, 3, 4 ].reduce( - function(previousValue, currentValue, index, array) { + [ 0, 1, 2, 3, 4 ].reduce(function(previousValue, currentValue, index, array) { return previousValue + currentValue + array[index]; - }, - 10 - ); + }, 10); - var total = [ 0, 1, 2, 3 ].reduce( - function(a, b) { - return a + b; - } - ); - var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce( - function(a, b) { - return a.concat(b); - } - ); + var total = [ 0, 1, 2, 3 ].reduce(function(a, b) { + return a + b; + }); + var flattened = [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ].reduce(function(a, b) { + return a.concat(b); + }); [ \"\" ].reduce((acc, str) => acc * str.length); @@ -124,18 +111,12 @@ function reduce_test() { } function from_test() { - var a: Array = Array.from( - [ 1, 2, 3 ], - function(val, index) { - return (index % 2 ? \"foo\" : String(val)); - } - ); - var b: Array = Array.from( - [ 1, 2, 3 ], - function(val) { - return String(val); - } - ); + var a: Array = Array.from([ 1, 2, 3 ], function(val, index) { + return (index % 2 ? \"foo\" : String(val)); + }); + var b: Array = Array.from([ 1, 2, 3 ], function(val) { + return String(val); + }); } " `; diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index 9dc530bf9..4e4ae9d5e 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -131,11 +131,9 @@ async function foo() { // am not clear on whether it should. In any case it\'s a strange corner case // that is probably not important to support. class C {} -var P: Promise> = new Promise( - function(resolve, reject) { - resolve(C); - } -); +var P: Promise> = new Promise(function(resolve, reject) { + resolve(C); +}); async function foo() { class Bar extends (await P) {} diff --git a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap index 388610f46..f052dad5f 100644 --- a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap @@ -145,11 +145,9 @@ refuse_return().return(\"string\").then(result => { // error: number | void ~> string declare var gen: AsyncGenerator; -gen.return(0).then( - result => { - (result.value: void); - } -); +gen.return(0).then(result => { + (result.value: void); +}); async function* refuse_return() { try { @@ -159,13 +157,11 @@ async function* refuse_return() { } } -refuse_return().return(\"string\").then( - result => { - if (result.done) { - (result.value: string); - } +refuse_return().return(\"string\").then(result => { + if (result.done) { + (result.value: string); } -); +}); " `; @@ -214,13 +210,11 @@ async function* catch_return() { } async () => { - catch_return().throw(\"\").then( - ({ value }) => { - if (value !== undefined) { - (value: void); - } + catch_return().throw(\"\").then(({ value }) => { + if (value !== undefined) { + (value: void); } - ); + }); }; async function* yield_return() { @@ -234,13 +228,11 @@ async function* yield_return() { } async () => { - yield_return().throw(\"\").then( - ({ value }) => { - if (value !== undefined) { - (value: void); - } + yield_return().throw(\"\").then(({ value }) => { + if (value !== undefined) { + (value: void); } - ); + }); }; " `; diff --git a/tests/builtins/__snapshots__/jsfmt.spec.js.snap b/tests/builtins/__snapshots__/jsfmt.spec.js.snap index f6c1b5b1d..a0044943f 100644 --- a/tests/builtins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/builtins/__snapshots__/jsfmt.spec.js.snap @@ -21,20 +21,16 @@ function g() { // error: string !~> number // error: string !~> number var a = [ \"...\" ]; -var b = a.map( - function(x) { - return 0; - } -); +var b = a.map(function(x) { + return 0; +}); var c: string = b[0]; var array = []; function f() { - array = array.map( - function() { - return \"...\"; - } - ); + array = array.map(function() { + return \"...\"; + }); var x: number = array[0]; } @@ -43,11 +39,9 @@ var Foo = require(\"./genericfoo\"); var foo = new Foo(); function g() { - var foo1 = foo.map( - function() { - return \"...\"; - } - ); + var foo1 = foo.map(function() { + return \"...\"; + }); var x: number = foo1.get(); foo = foo1; diff --git a/tests/dom/__snapshots__/jsfmt.spec.js.snap b/tests/dom/__snapshots__/jsfmt.spec.js.snap index 74eda3ecd..528823972 100644 --- a/tests/dom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dom/__snapshots__/jsfmt.spec.js.snap @@ -447,59 +447,44 @@ let tests = [ // Error: This might be null let tests = [ function() { - document.registerElement( - \"custom-element\", - { - prototype: Object.create( - HTMLElement.prototype, - { - createdCallback: { value: function createdCallback() {} }, - attachedCallback: { value: function attachedCallback() {} }, - detachedCallback: { value: function detachedCallback() {} }, - attributeChangedCallback: { - value: function attributeChangedCallback( - attributeLocalName, - oldAttributeValue, - newAttributeValue, - attributeNamespace - ) {} - } - } - ) - } - ); - }, - function() { - document.registerElement( - \"custom-element\", - { - prototype: Object.assign( - Object.create(HTMLElement.prototype), - { - createdCallback() {}, - attachedCallback() {}, - detachedCallback() {}, - attributeChangedCallback(attributeLocalName, + document.registerElement(\"custom-element\", { + prototype: Object.create(HTMLElement.prototype, { + createdCallback: { value: function createdCallback() {} }, + attachedCallback: { value: function attachedCallback() {} }, + detachedCallback: { value: function detachedCallback() {} }, + attributeChangedCallback: { + value: function attributeChangedCallback( + attributeLocalName, oldAttributeValue, newAttributeValue, - attributeNamespace) {} - } - ) - } - ); + attributeNamespace + ) {} + } + }) + }); }, function() { - document.registerElement( - \"custom-element\", - { - prototype: { - attributeChangedCallback(localName: string, - oldVal: string, - newVal: string, - namespace: string) {} - } + document.registerElement(\"custom-element\", { + prototype: Object.assign(Object.create(HTMLElement.prototype), { + createdCallback() {}, + attachedCallback() {}, + detachedCallback() {}, + attributeChangedCallback(attributeLocalName, + oldAttributeValue, + newAttributeValue, + attributeNamespace) {} + }) + }); + }, + function() { + document.registerElement(\"custom-element\", { + prototype: { + attributeChangedCallback(localName: string, + oldVal: string, + newVal: string, + namespace: string) {} } - ); + }); } ]; " @@ -907,17 +892,13 @@ let tests = [ document.createNodeIterator(document.body, -1, node => \"accept\"); - document.createNodeIterator( - document.body, - -1, - { accept: node => NodeFilter.FILTER_ACCEPT } - ); + document.createNodeIterator(document.body, -1, { + accept: node => NodeFilter.FILTER_ACCEPT + }); - document.createNodeIterator( - document.body, - -1, - { accept: node => \"accept\" } - ); + document.createNodeIterator(document.body, -1, { + accept: node => \"accept\" + }); document.createNodeIterator(document.body, -1, {}); }, @@ -930,11 +911,9 @@ let tests = [ document.createTreeWalker(document.body, -1, node => \"accept\"); - document.createTreeWalker( - document.body, - -1, - { accept: node => NodeFilter.FILTER_ACCEPT } - ); + document.createTreeWalker(document.body, -1, { + accept: node => NodeFilter.FILTER_ACCEPT + }); document.createTreeWalker(document.body, -1, { accept: node => \"accept\" }); diff --git a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap index bd5a7a999..4581773c4 100644 --- a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap @@ -66,11 +66,9 @@ let tests = [ result.baz = false; - (copyProperties(result, { foo: \"a\" }, { bar: 123 }): { - foo: string; - bar: number; - baz: boolean - }); + (copyProperties(result, { foo: \"a\" }, { + bar: 123 + }): { foo: string; bar: number; baz: boolean }); }, function() { const copyProperties = require(\"copyProperties\"); diff --git a/tests/fetch/__snapshots__/jsfmt.spec.js.snap b/tests/fetch/__snapshots__/jsfmt.spec.js.snap index 03815286c..5781bd4d2 100644 --- a/tests/fetch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fetch/__snapshots__/jsfmt.spec.js.snap @@ -203,43 +203,31 @@ const d: Request = new Request(c.clone()); const e: Request = new Request(b, c); const f: Request = new Request({}); const g: Request = new Request(\"http://example.org\", {}); -const h: Request = new Request( - \"http://example.org\", - { - method: \"GET\", - headers: { \"Content-Type\": \"image/jpeg\" }, - mode: \"cors\", - cache: \"default\" - } -); -const i: Request = new Request( - \"http://example.org\", - { - method: \"POST\", - headers: { \"Content-Type\": \"image/jpeg\" }, - body: new URLSearchParams(\"key=value\"), - mode: \"cors\", - cache: \"default\" - } -); -const j: Request = new Request( - \"http://example.org\", - { - method: \"GET\", - headers: \"Content-Type: image/jpeg\", - mode: \"cors\", - cache: \"default\" - } -); -const k: Request = new Request( - \"http://example.org\", - { - method: \"CONNECT\", - headers: { \"Content-Type\": \"image/jpeg\" }, - mode: \"cors\", - cache: \"default\" - } -); +const h: Request = new Request(\"http://example.org\", { + method: \"GET\", + headers: { \"Content-Type\": \"image/jpeg\" }, + mode: \"cors\", + cache: \"default\" +}); +const i: Request = new Request(\"http://example.org\", { + method: \"POST\", + headers: { \"Content-Type\": \"image/jpeg\" }, + body: new URLSearchParams(\"key=value\"), + mode: \"cors\", + cache: \"default\" +}); +const j: Request = new Request(\"http://example.org\", { + method: \"GET\", + headers: \"Content-Type: image/jpeg\", + mode: \"cors\", + cache: \"default\" +}); +const k: Request = new Request(\"http://example.org\", { + method: \"CONNECT\", + headers: { \"Content-Type\": \"image/jpeg\" }, + mode: \"cors\", + cache: \"default\" +}); var l: boolean = h.bodyUsed; h.text().then((t: string) => t); @@ -319,19 +307,19 @@ const b: Response = new Response(new Blob()); const c: Response = new Response(new FormData()); const d: Response = new Response(new FormData(), { status: 404 }); const e: Response = new Response(\"responsebody\", { status: \"404\" }); -const f: Response = new Response( - \"responsebody\", - { status: 404, headers: \"\'Content-Type\': \'image/jpeg\'\" } -); -const g: Response = new Response( - \"responsebody\", - { status: 404, headers: { \"Content-Type\": \"image/jpeg\" } } -); -const h: Response = new Response( - \"responsebody\", - { status: 404, headers: new Headers({ \"Content-Type\": \"image/jpeg\" }) } -); -const i: Response = new Response({ +const f: Response = new Response(\"responsebody\", { + status: 404, + headers: \"\'Content-Type\': \'image/jpeg\'\" +}); +const g: Response = new Response(\"responsebody\", { + status: 404, + headers: { \"Content-Type\": \"image/jpeg\" } +}); +const h: Response = new Response(\"responsebody\", { + status: 404, + headers: new Headers({ \"Content-Type\": \"image/jpeg\" }) +}); +const i: Response = new Response(, { status: 404, headers: new Headers({ \"Content-Type\": \"image/jpeg\" }) }); diff --git a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap index ed69dec03..e1b5fa3ea 100644 --- a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap @@ -45,28 +45,24 @@ function mul(x: number, y: number) { function fix(fold) { var delta = function(delta) { - return fold( - function(x) { - var eta = delta(delta); - return eta(x); - } - ); + return fold(function(x) { + var eta = delta(delta); + return eta(x); + }); }; return delta(delta); } function mk_factorial() { - return fix( - function(factorial) { - return function(n) { - if (eq(n, 1)) { - return 1; - } + return fix(function(factorial) { + return function(n) { + if (eq(n, 1)) { + return 1; + } - return mul(factorial(sub(n, 1)), n); - }; - } - ); + return mul(factorial(sub(n, 1)), n); + }; + }); } var factorial = mk_factorial(); diff --git a/tests/geolocation/__snapshots__/jsfmt.spec.js.snap b/tests/geolocation/__snapshots__/jsfmt.spec.js.snap index 2be6e37cf..1dde54699 100644 --- a/tests/geolocation/__snapshots__/jsfmt.spec.js.snap +++ b/tests/geolocation/__snapshots__/jsfmt.spec.js.snap @@ -22,22 +22,19 @@ geolocation.clearWatch(id); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var geolocation = new Geolocation(); -var id = geolocation.watchPosition( - position => { - var coords: Coordinates = position.coords; - var accuracy: number = coords.accuracy; - }, - e => { - var message: string = e.message; - switch (e.code) { - case e.PERMISSION_DENIED: - case e.POSITION_UNAVAILABLE: - case e.TIMEOUT: - default: - break; - } +var id = geolocation.watchPosition(position => { + var coords: Coordinates = position.coords; + var accuracy: number = coords.accuracy; +}, e => { + var message: string = e.message; + switch (e.code) { + case e.PERMISSION_DENIED: + case e.POSITION_UNAVAILABLE: + case e.TIMEOUT: + default: + break; } -); +}); geolocation.clearWatch(id); " diff --git a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap index c901a4036..e6b90a889 100644 --- a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap @@ -103,18 +103,18 @@ buffer = buffer.fill(\"a\", 0, 0, \"utf8\"); buffer = buffer.fill(\"a\", \"utf8\"); -maybeNum = buffer.find( - (element: number, index: number, array: Uint8Array) => false -); +maybeNum = buffer.find(, (element: number, +index: number, +array: Uint8Array) => false); maybeNum = buffer.find( (element: number, index: number, array: Uint8Array) => false, buffer ); -num = buffer.findIndex( - (element: number, index: number, array: Uint8Array) => false -); +num = buffer.findIndex(, (element: number, +index: number, +array: Uint8Array) => false); num = buffer.findIndex( (element: number, index: number, array: Uint8Array) => false, diff --git a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap index 18536b3e6..c0c564b7d 100644 --- a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap @@ -22,22 +22,15 @@ exec(\'ls\', {maxBuffer: 100}, function(error, stdout, stderr) { // options + callback. var exec = require(\"child_process\").exec; -exec( - \"ls\", - function(error, stdout, stderr) { - console.info(stdout); - } -); +exec(\"ls\", function(error, stdout, stderr) { + console.info(stdout); +}); exec(\"ls\", { timeout: 250 }); -exec( - \"ls\", - { maxBuffer: 100 }, - function(error, stdout, stderr) { - console.info(stdout); - } -); +exec(\"ls\", { maxBuffer: 100 }, function(error, stdout, stderr) { + console.info(stdout); +}); " `; @@ -81,33 +74,21 @@ var execFile = require(\"child_process\").execFile; execFile(\"ls\", [ \"-lh\" ]); -execFile( - \"ls\", - function(error, stdout, stderr) { - console.info(stdout); - } -); +execFile(\"ls\", function(error, stdout, stderr) { + console.info(stdout); +}); execFile(\"wc\", { timeout: 250 }); -execFile( - \"ls\", - [ \"-l\" ], - function(error, stdout, stderr) { - console.info(stdout); - } -); +execFile(\"ls\", [ \"-l\" ], function(error, stdout, stderr) { + console.info(stdout); +}); execFile(\"ls\", [ \"-l\" ], { timeout: 250 }); -execFile( - \"ls\", - [ \"-l\" ], - { timeout: 250 }, - function(error, stdout, stderr) { - console.info(stdout); - } -); +execFile(\"ls\", [ \"-l\" ], { timeout: 250 }, function(error, stdout, stderr) { + console.info(stdout); +}); " `; @@ -185,38 +166,27 @@ var child_process = require(\"child_process\"); var ls = child_process.spawn(\"ls\"); var wc = child_process.spawn(\"wc\", [ \"-l\" ]); -child_process.spawn( - \"echo\", - [ \"-n\", \"\\\"Testing...\\\"\" ], - { env: { TEST: \"foo\" } } -); +child_process.spawn(\"echo\", [ \"-n\", \"\\\"Testing...\\\"\" ], { + env: { TEST: \"foo\" } +}); child_process.spawn(\"echo\", { env: { FOO: 2 } }); -ls.stdout.on( - \"data\", - function(data) { - wc.stdin.write(data); - } -); +ls.stdout.on(\"data\", function(data) { + wc.stdin.write(data); +}); -ls.stderr.on( - \"data\", - function(data) { - console.warn(data); - } -); +ls.stderr.on(\"data\", function(data) { + console.warn(data); +}); -ls.on( - \"close\", - function(code) { - if (code !== 0) { - console.warn(\"\`ls\` exited with code %s\", code); - } - - wc.stdin.end(); +ls.on(\"close\", function(code) { + if (code !== 0) { + console.warn(\"\`ls\` exited with code %s\", code); } -); + + wc.stdin.end(); +}); wc.stdout.pipe(process.stdout); diff --git a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap index 339d99c3f..3b99d34a5 100644 --- a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap @@ -53,14 +53,11 @@ let tests = [ function() { const hmac = crypto.createHmac(\"sha256\", \"a secret\"); - hmac.on( - \"readable\", - () => { - (hmac.read(): ?(string | Buffer)); + hmac.on(\"readable\", () => { + (hmac.read(): ?(string | Buffer)); - (hmac.read(): number); - } - ); + (hmac.read(): number); + }); hmac.write(\"some data to hash\"); diff --git a/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap index 09c25640a..f999e49f6 100644 --- a/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap @@ -41,36 +41,21 @@ fs.readFile(\"file.exp\", {}, (_, data) => { // error var fs = require(\"fs\"); -fs.readFile( - \"file.exp\", - (_, data) => { - (data: Buffer); - } -); +fs.readFile(\"file.exp\", (_, data) => { + (data: Buffer); +}); -fs.readFile( - \"file.exp\", - \"blah\", - (_, data) => { - (data: string); - } -); +fs.readFile(\"file.exp\", \"blah\", (_, data) => { + (data: string); +}); -fs.readFile( - \"file.exp\", - { encoding: \"blah\" }, - (_, data) => { - (data: string); - } -); +fs.readFile(\"file.exp\", { encoding: \"blah\" }, (_, data) => { + (data: string); +}); -fs.readFile( - \"file.exp\", - {}, - (_, data) => { - (data: Buffer); - } -); +fs.readFile(\"file.exp\", {}, (_, data) => { + (data: Buffer); +}); (fs.readFileSync(\"file.exp\"): Buffer); diff --git a/tests/object_api/__snapshots__/jsfmt.spec.js.snap b/tests/object_api/__snapshots__/jsfmt.spec.js.snap index 0cb34ac74..61580b523 100644 --- a/tests/object_api/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_api/__snapshots__/jsfmt.spec.js.snap @@ -57,14 +57,11 @@ module.exports = export_; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ // makes sure this terminates -var export_ = Object.assign( - {}, - { - foo: function(param) { - return param; - } +var export_ = Object.assign({}, { + foo: function(param) { + return param; } -); +}); var decl_export_: { foo: any; bar: any } = Object.assign({}, export_); let anyObj: Object = {}; @@ -192,19 +189,15 @@ var sealed = { one: \"one\", two: \"two\" }; var unsealed = {}; -Object.keys(unsealed).forEach( - k => { - (k: number); - } -); +Object.keys(unsealed).forEach(k => { + (k: number); +}); var dict: { [k: number]: string } = {}; -Object.keys(dict).forEach( - k => { - (k: number); - } -); +Object.keys(dict).forEach(k => { + (k: number); +}); var any: Object = {}; diff --git a/tests/object_assign/__snapshots__/jsfmt.spec.js.snap b/tests/object_assign/__snapshots__/jsfmt.spec.js.snap index 39a29d285..3b78c159f 100644 --- a/tests/object_assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_assign/__snapshots__/jsfmt.spec.js.snap @@ -34,26 +34,18 @@ module.exports = { // Doesn\'t repro if I extend the class myself // Calling Good.foo() in the same file doesn\'t error var EventEmitter = require(\"events\").EventEmitter; -var Bad = Object.assign( - {}, - EventEmitter.prototype, - { - foo: function(): string { - return \"hi\"; - } +var Bad = Object.assign({}, EventEmitter.prototype, { + foo: function(): string { + return \"hi\"; } -); +}); var bad: number = Bad.foo(); class MyEventEmitter extends events$EventEmitter {} -var Good = Object.assign( - {}, - MyEventEmitter.prototype, - { - foo: function(): string { - return \"hi\"; - } +var Good = Object.assign({}, MyEventEmitter.prototype, { + foo: function(): string { + return \"hi\"; } -); +}); var good: number = Good.foo(); module.exports = { Bad: Bad, Good: Good }; diff --git a/tests/objmap/__snapshots__/jsfmt.spec.js.snap b/tests/objmap/__snapshots__/jsfmt.spec.js.snap index 706431ee1..8bb776472 100644 --- a/tests/objmap/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objmap/__snapshots__/jsfmt.spec.js.snap @@ -30,12 +30,10 @@ var o = keyMirror({ FOO: null, BAR: null }); (o.FOO: \"BAR\"); -promiseAllByKey({ foo: Promise.resolve(0), bar: \"bar\" }).then( - o => { - (o.foo: string); +promiseAllByKey({ foo: Promise.resolve(0), bar: \"bar\" }).then(o => { + (o.foo: string); - (o.bar: \"bar\"); - } -); + (o.bar: \"bar\"); +}); " `; diff --git a/tests/promises/__snapshots__/jsfmt.spec.js.snap b/tests/promises/__snapshots__/jsfmt.spec.js.snap index e49f966b6..61874a53f 100644 --- a/tests/promises/__snapshots__/jsfmt.spec.js.snap +++ b/tests/promises/__snapshots__/jsfmt.spec.js.snap @@ -56,23 +56,19 @@ function tes2(val: Map>) { declare var pstr: Promise; declare var pnum: Promise; -Promise.all([ pstr, pnum, true ]).then( - xs => { - let [ a, b, c ] = xs; +Promise.all([ pstr, pnum, true ]).then(xs => { + let [ a, b, c ] = xs; - (a: number); + (a: number); - (b: boolean); + (b: boolean); - (c: string); + (c: string); - xs.forEach( - x => { - (x: void); - } - ); - } -); + xs.forEach(x => { + (x: void); + }); +}); Promise.all(); @@ -428,250 +424,164 @@ Promise.resolve(0) // TODO: resolvedPromise -> catch() -> then():T // TODO // Error: string ~> number -new Promise( - function(resolve, reject) { - resolve(0); - } -).then( - function(num) { - var a: number = num; - var b: string = num; - } -); +new Promise(function(resolve, reject) { + resolve(0); +}).then(function(num) { + var a: number = num; + var b: string = num; +}); -new Promise((resolve, reject) => resolve(0)).then( - function(num) { - var a: number = num; - var b: string = num; - } -); +new Promise((resolve, reject) => resolve(0)).then(function(num) { + var a: number = num; + var b: string = num; +}); -new Promise( - function(resolve, reject) { - resolve( - new Promise( - function(resolve, reject) { +new Promise(function(resolve, reject) { + resolve(new Promise(function(resolve, reject) { + resolve(0); + })); +}).then(function(num) { + var a: number = num; + var b: string = num; +}); + +new Promise(function(resolve, reject) { + resolve(new Promise(function(resolve, reject) { + resolve(new Promise(function(resolve, reject) { resolve(0); - } - ) - ); - } -).then( - function(num) { - var a: number = num; - var b: string = num; - } -); + })); + })); +}).then(function(num) { + var a: number = num; + var b: string = num; +}); -new Promise( - function(resolve, reject) { - resolve( - new Promise( - function(resolve, reject) { - resolve( - new Promise( - function(resolve, reject) { - resolve(0); - } - ) - ); - } - ) - ); +new Promise(function(resolve, reject) { + if (Math.random()) { + resolve(42); + } else { + resolve(\"str\"); } -).then( - function(num) { - var a: number = num; - var b: string = num; +}).then(function(numOrStr) { + if (typeof numOrStr === \"string\") { + var a: string = numOrStr; + } else { + var b: number = numOrStr; } -); -new Promise( - function(resolve, reject) { - if (Math.random()) { - resolve(42); - } else { - resolve(\"str\"); - } - } -).then( - function(numOrStr) { - if (typeof numOrStr === \"string\") { - var a: string = numOrStr; - } else { - var b: number = numOrStr; - } + var c: string = numOrStr; +}); - var c: string = numOrStr; - } -); +new Promise(function(resolve, reject) { + reject(0); +}).catch(function(num) { + var a: number = num; + var b: string = num; +}); -new Promise( - function(resolve, reject) { - reject(0); - } -).catch( - function(num) { - var a: number = num; - var b: string = num; - } -); +new Promise(function(resolve, reject) { + reject(new Promise(function(resolve, reject) { + reject(0); + })); +}).catch(function(num) { + var a: Promise = num; + var b: number = num; +}); -new Promise( - function(resolve, reject) { - reject( - new Promise( - function(resolve, reject) { - reject(0); - } - ) - ); +new Promise(function(resolve, reject) { + if (Math.random()) { + reject(42); + } else { + reject(\"str\"); } -).catch( - function(num) { - var a: Promise = num; - var b: number = num; +}).catch(function(numOrStr) { + if (typeof numOrStr === \"string\") { + var a: string = numOrStr; + } else { + var b: number = numOrStr; } -); -new Promise( - function(resolve, reject) { - if (Math.random()) { - reject(42); - } else { - reject(\"str\"); - } - } -).catch( - function(numOrStr) { - if (typeof numOrStr === \"string\") { - var a: string = numOrStr; - } else { - var b: number = numOrStr; - } + var c: string = numOrStr; +}); - var c: string = numOrStr; - } -); +Promise.resolve(0).then(function(num) { + var a: number = num; + var b: string = num; +}); -Promise.resolve(0).then( - function(num) { - var a: number = num; - var b: string = num; - } -); +Promise.resolve(Promise.resolve(0)).then(function(num) { + var a: number = num; + var b: string = num; +}); -Promise.resolve(Promise.resolve(0)).then( - function(num) { - var a: number = num; - var b: string = num; - } -); +Promise.resolve(Promise.resolve(Promise.resolve(0))).then(function(num) { + var a: number = num; + var b: string = num; +}); -Promise.resolve(Promise.resolve(Promise.resolve(0))).then( - function(num) { - var a: number = num; - var b: string = num; - } -); +Promise.reject(0).catch(function(num) { + var a: number = num; + var b: string = num; +}); -Promise.reject(0).catch( - function(num) { - var a: number = num; - var b: string = num; - } -); +Promise.reject(Promise.resolve(0)).then(function(num) { + var a: Promise = num; + var b: number = num; +}); -Promise.reject(Promise.resolve(0)).then( - function(num) { - var a: Promise = num; - var b: number = num; - } -); +Promise.resolve(0).then(function(num) { + return \"asdf\"; +}).then(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.resolve(0).then( - function(num) { - return \"asdf\"; - } -).then( - function(str) { - var a: string = str; - var b: number = str; - } -); +Promise.resolve(0).then(function(num) { + return Promise.resolve(\"asdf\"); +}).then(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.resolve(0).then( - function(num) { - return Promise.resolve(\"asdf\"); - } -).then( - function(str) { - var a: string = str; - var b: number = str; - } -); +Promise.resolve(0).then(function(num) { + return Promise.resolve(Promise.resolve(\"asdf\")); +}).then(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.resolve(0).then( - function(num) { - return Promise.resolve(Promise.resolve(\"asdf\")); - } -).then( - function(str) { - var a: string = str; - var b: number = str; - } -); +Promise.resolve(0).then(function(num) { + throw \"str\"; +}).catch(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.resolve(0).then( - function(num) { - throw \"str\"; - } -).catch( - function(str) { - var a: string = str; - var b: number = str; - } -); +Promise.reject(0).catch(function(num) { + return \"asdf\"; +}).then(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.reject(0).catch( - function(num) { - return \"asdf\"; - } -).then( - function(str) { - var a: string = str; - var b: number = str; - } -); +Promise.reject(0).catch(function(num) { + return Promise.resolve(\"asdf\"); +}).then(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.reject(0).catch( - function(num) { - return Promise.resolve(\"asdf\"); - } -).then( - function(str) { - var a: string = str; - var b: number = str; - } -); +Promise.reject(0).catch(function(num) { + return Promise.resolve(Promise.resolve(\"asdf\")); +}).then(function(str) { + var a: string = str; + var b: number = str; +}); -Promise.reject(0).catch( - function(num) { - return Promise.resolve(Promise.resolve(\"asdf\")); - } -).then( - function(str) { - var a: string = str; - var b: number = str; - } -); - -Promise.resolve(0).catch(function(err) {}).then( - function(num) { - var a: number = num; - var b: string = num; - } -); +Promise.resolve(0).catch(function(err) {}).then(function(num) { + var a: number = num; + var b: string = num; +}); " `; diff --git a/tests/react/__snapshots__/jsfmt.spec.js.snap b/tests/react/__snapshots__/jsfmt.spec.js.snap index cd21dd5c4..663763869 100644 --- a/tests/react/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react/__snapshots__/jsfmt.spec.js.snap @@ -129,7 +129,7 @@ var blah = ; // error bar, number given string expected /* @flow */ // error bar, number given string expected var React = require(\"react\"); -var Foo = React.createClass({ +var Foo = React.createClass(, { propTypes: { bar: React.PropTypes.string.isRequired } }); var props = { bar: 42 }; @@ -155,7 +155,7 @@ var fail_mistyped_elems = ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var React = require(\"react\"); -var Example = React.createClass({ +var Example = React.createClass(, { propTypes: { arr: React.PropTypes.arrayOf(React.PropTypes.number).isRequired } }); var ok_empty = ; @@ -183,7 +183,7 @@ var fail_mistyped = ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var React = require(\"react\"); -var Example = React.createClass({ +var Example = React.createClass(, { propTypes: { func: React.PropTypes.func.isRequired } }); var ok_void = {}}/>; @@ -275,7 +275,7 @@ var fail_mistyped = ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var React = require(\"react\"); -var Example = React.createClass({ +var Example = React.createClass(, { propTypes: { object: React.PropTypes.object.isRequired } }); var ok_empty = ; @@ -302,7 +302,7 @@ var fail_mistyped_props = ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var React = require(\"react\"); -var Example = React.createClass({ +var Example = React.createClass(, { propTypes: { obj: React.PropTypes.objectOf(React.PropTypes.number).isRequired } @@ -329,7 +329,7 @@ var ex2 = ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var React = require(\"react\"); -var Example = React.createClass({ +var Example = React.createClass(, { propTypes: { literal: React.PropTypes.oneOf([ \"foo\" ]).isRequired } }); var ex1 = ; @@ -366,9 +366,10 @@ var fail_bool = var React = require(\"react\"); var Example = React.createClass({ propTypes: { - prop: React.PropTypes.oneOfType( - [ React.PropTypes.string, React.PropTypes.number ] - ).isRequired + prop: React.PropTypes.oneOfType(, [ + React.PropTypes.string, + React.PropTypes.number + ]).isRequired }, render() { if (typeof this.props.prop === \"string\") { diff --git a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap index 359534ba5..63dcea77b 100644 --- a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap @@ -70,19 +70,16 @@ requireLazy([\'A\']); // Error: No calback expression // Error: No args // Error: Non-stringliteral args // Error: No calback expression -requireLazy( - [ \"A\", \"B\" ], - function(A, B) { - var num1: number = A.numberValueA; - var str1: string = A.stringValueA; - var num2: number = A.stringValueA; - var str2: string = A.numberValueA; - var num3: number = B.numberValueB; - var str3: string = B.stringValueB; - var num4: number = B.stringValueB; - var str4: string = B.numberValueB; - } -); +requireLazy([ \"A\", \"B\" ], function(A, B) { + var num1: number = A.numberValueA; + var str1: string = A.stringValueA; + var num2: number = A.stringValueA; + var str2: string = A.numberValueA; + var num3: number = B.numberValueB; + var str3: string = B.stringValueB; + var num4: number = B.stringValueB; + var str4: string = B.numberValueB; +}); var notA: Object = A; var notB: Object = B; diff --git a/tests/spread/__snapshots__/jsfmt.spec.js.snap b/tests/spread/__snapshots__/jsfmt.spec.js.snap index 50c25b1b7..4cea1ab50 100644 --- a/tests/spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/spread/__snapshots__/jsfmt.spec.js.snap @@ -167,14 +167,11 @@ function test( x: { kind: ?string }, kinds: { [key: string]: string } ): Array<{ kind: ?string }> { - return map( - kinds, - value => { - (value: string); + return map(kinds, value => { + (value: string); - return { ...x, kind: value }; - } - ); + return { ...x, kind: value }; + }); } " `; diff --git a/tests/super/__snapshots__/jsfmt.spec.js.snap b/tests/super/__snapshots__/jsfmt.spec.js.snap index 40f05d18e..5e0d5e71e 100644 --- a/tests/super/__snapshots__/jsfmt.spec.js.snap +++ b/tests/super/__snapshots__/jsfmt.spec.js.snap @@ -280,12 +280,10 @@ class K_ { } class K extends K_ { constructor() { - super( - () => { - if (_this) - _this.foo(); - } - ); + super(() => { + if (_this) + _this.foo(); + }); var _this = this; diff --git a/tests/traces/__snapshots__/jsfmt.spec.js.snap b/tests/traces/__snapshots__/jsfmt.spec.js.snap index aae29dc03..6ea04f734 100644 --- a/tests/traces/__snapshots__/jsfmt.spec.js.snap +++ b/tests/traces/__snapshots__/jsfmt.spec.js.snap @@ -46,11 +46,9 @@ function f2(xlam) { g2(xlam); } -f2( - function(x) { - return x * x; - } -); +f2(function(x) { + return x * x; +}); function g3(ylam: (s: string) => number) {} @@ -89,10 +87,10 @@ function f(b): React.Element<*> { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var React = require(\"react\"); -var A = React.createClass({ +var A = React.createClass(, { propTypes: { foo: React.PropTypes.string.isRequired } }); -var B = React.createClass({ +var B = React.createClass(, { propTypes: { bar: React.PropTypes.string.isRequired } }); diff --git a/tests/undefined/__snapshots__/jsfmt.spec.js.snap b/tests/undefined/__snapshots__/jsfmt.spec.js.snap index d354760d2..788f07b23 100644 --- a/tests/undefined/__snapshots__/jsfmt.spec.js.snap +++ b/tests/undefined/__snapshots__/jsfmt.spec.js.snap @@ -15,15 +15,13 @@ foo(); // OK to leave out arg, same as resolve(undefined) // simpler repro to show that too few args are fine when expecting void function doSomethingAsync(): Promise { - return new Promise( - (resolve, reject) => { - resolve(); + return new Promise((resolve, reject) => { + resolve(); - var anotherVoidPromise: Promise = Promise.resolve(); + var anotherVoidPromise: Promise = Promise.resolve(); - resolve(anotherVoidPromise); - } - ); + resolve(anotherVoidPromise); + }); } function foo(x: void) {} diff --git a/tests/union/__snapshots__/jsfmt.spec.js.snap b/tests/union/__snapshots__/jsfmt.spec.js.snap index a90fecc29..37189a751 100644 --- a/tests/union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union/__snapshots__/jsfmt.spec.js.snap @@ -84,19 +84,13 @@ exports[`test issue-198.js 1`] = ` }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // This should fail because str is string, not number -var p = new Promise( - function(resolve, reject) { - resolve(5); - } -).then( - function(num) { - return num.toFixed(); - } -).then( - function(str) { - return str.toFixed(); - } -); +var p = new Promise(function(resolve, reject) { + resolve(5); +}).then(function(num) { + return num.toFixed(); +}).then(function(str) { + return str.toFixed(); +}); " `; diff --git a/tests/union_new/__snapshots__/jsfmt.spec.js.snap b/tests/union_new/__snapshots__/jsfmt.spec.js.snap index 982cb3c90..4a0be04b5 100644 --- a/tests/union_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union_new/__snapshots__/jsfmt.spec.js.snap @@ -1461,12 +1461,9 @@ exports[`test test20.js 1`] = ` // Array#reduce [ 0, 1 ].reduce((x, y, i) => y); -[ \"a\", \"b\" ].reduce( - (regex, representation, index) => { +[ \"a\", \"b\" ].reduce((regex, representation, index) => { return regex + ((index ? \"|\" : \"\")) + \"(\" + representation + \")\"; - }, - \"\" -); + }, \"\"); [ \"\" ].reduce((acc, str) => acc * str.length); "