(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/593master
parent
1ea4ad4e30
commit
f048ad3094
|
@ -63,7 +63,7 @@ function parseWithBabylon(text) {
|
|||
const babylonOptions = {
|
||||
sourceType: "module",
|
||||
allowImportExportEverywhere: false,
|
||||
allowReturnOutsideFunction: false,
|
||||
allowReturnOutsideFunction: true,
|
||||
plugins: [
|
||||
"jsx",
|
||||
"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
|
Loading…
Reference in New Issue