(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
master
Joseph Frazier 2017-05-14 17:45:33 -04:00 committed by Christopher Chedeau
parent 1ea4ad4e30
commit f048ad3094
4 changed files with 16 additions and 1 deletions

View File

@ -63,7 +63,7 @@ function parseWithBabylon(text) {
const babylonOptions = {
sourceType: "module",
allowImportExportEverywhere: false,
allowReturnOutsideFunction: false,
allowReturnOutsideFunction: true,
plugins: [
"jsx",
"flow",

View File

@ -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
);
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "babylon" }, ["typescript"]);

View File

@ -0,0 +1 @@
return someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD