(Babylon) Allow return outside function (#1608)

This makes it easier to format code snippets including a `return`
statement, without having to format the entire function. For example,
given the following code:

```js
function f() {
    return someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD
}
```

a developer could select the line containing `return`, then use
prettier to format the code to:

```js
function f() {
return (
  someVeryLongStringA &&
  someVeryLongStringB &&
  someVeryLongStringC &&
  someVeryLongStringD
);
}
```

which can then be reindented by the editor.

---

Related to https://github.com/prettier/prettier/issues/593
This commit is contained in:
Joseph Frazier authored and Christopher Chedeau committed 2017-05-14 14:45:33 -07:00
1 parent 1ea4ad4e30
commit f048ad3094
4 files changed
+16 -1

No files matched your search

+1 -1
View File
@@ -63,7 +63,7 @@ function parseWithBabylon(text) {
const babylonOptions = { const babylonOptions = {
sourceType: "module", sourceType: "module",
allowImportExportEverywhere: false, allowImportExportEverywhere: false,
allowReturnOutsideFunction: false, allowReturnOutsideFunction: true,
plugins: [ plugins: [
"jsx", "jsx",
"flow", "flow",
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`return-outside-function.js 1`] = `
return someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
return (
someVeryLongStringA &&
someVeryLongStringB &&
someVeryLongStringC &&
someVeryLongStringD
);
`;
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "babylon" }, ["typescript"]);
@@ -0,0 +1 @@
return someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD