Only allow same-line arrow-less body for explicit nodes (#966)
In practice, trying to allow calls to be inlined is causing a lot of code to look very weird and unstable as seen by the four issues this is fixing. It also requires us to add a conditional group and do hackery around it. Fixes #959 Fixes #760 Fixes #615 Fixes #625
This commit is contained in:
1 parent
9ef8c709bb
commit
d39facc022
5 files changed
+253
-49
No files matched your search
+7
-14
@@ -341,25 +341,18 @@ function genericPrintNoParens(path, options, print) {
|
|||||||
n.body.type === "ArrayExpression" ||
|
n.body.type === "ArrayExpression" ||
|
||||||
n.body.type === "ObjectExpression" ||
|
n.body.type === "ObjectExpression" ||
|
||||||
n.body.type === "JSXElement" ||
|
n.body.type === "JSXElement" ||
|
||||||
n.body.type === "BlockStatement"
|
n.body.type === "BlockStatement" ||
|
||||||
|
n.body.type === "TaggedTemplateExpression" ||
|
||||||
|
n.body.type === "TemplateElement"
|
||||||
) {
|
) {
|
||||||
return group(collapsed);
|
return group(collapsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// These nested groups are a little wonky, but because
|
|
||||||
// `conditionalGroup` suppresses break propagation, we want to
|
|
||||||
// re-propagate it. We still want to allow the printer to choose
|
|
||||||
// the more collapsed version, but still break parents if there
|
|
||||||
// are any hard breaks in the content.
|
|
||||||
return group(
|
return group(
|
||||||
conditionalGroup([
|
concat([
|
||||||
collapsed,
|
concat(parts),
|
||||||
concat([
|
group(indent(options.tabWidth, concat([line, body])))
|
||||||
concat(parts),
|
])
|
||||||
group(indent(options.tabWidth, concat([line, body])))
|
|
||||||
])
|
|
||||||
]),
|
|
||||||
{ shouldBreak: willBreak(body) }
|
|
||||||
);
|
);
|
||||||
case "MethodDefinition":
|
case "MethodDefinition":
|
||||||
if (n.static) {
|
if (n.static) {
|
||||||
|
|||||||
@@ -71,6 +71,145 @@ a = () => ({} = this);
|
|||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`call.js 1`] = `
|
||||||
|
"Seq(typeDef.interface.groups).forEach(group =>
|
||||||
|
Seq(group.members).forEach((member, memberName) =>
|
||||||
|
markdownDoc(
|
||||||
|
member.doc,
|
||||||
|
{ typePath: typePath.concat(memberName.slice(1)),
|
||||||
|
signatures: member.signatures }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const promiseFromCallback = fn =>
|
||||||
|
new Promise((resolve, reject) =>
|
||||||
|
fn((err, result) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
return resolve(result);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
runtimeAgent.getProperties(
|
||||||
|
objectId,
|
||||||
|
false, // ownProperties
|
||||||
|
false, // accessorPropertiesOnly
|
||||||
|
false, // generatePreview
|
||||||
|
(error, properties, internalProperties) => {
|
||||||
|
return 1
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={(e) => this.setState({progress: Math.round(100 * e.nativeEvent.loaded / e.nativeEvent.total)})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total,
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total,
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Seq(typeDef.interface.groups).forEach(group =>
|
||||||
|
Seq(group.members).forEach((member, memberName) =>
|
||||||
|
markdownDoc(member.doc, {
|
||||||
|
typePath: typePath.concat(memberName.slice(1)),
|
||||||
|
signatures: member.signatures
|
||||||
|
})));
|
||||||
|
|
||||||
|
const promiseFromCallback = fn =>
|
||||||
|
new Promise((resolve, reject) =>
|
||||||
|
fn((err, result) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
return resolve(result);
|
||||||
|
}));
|
||||||
|
|
||||||
|
runtimeAgent.getProperties(
|
||||||
|
objectId,
|
||||||
|
false, // ownProperties
|
||||||
|
false, // accessorPropertiesOnly
|
||||||
|
false, // generatePreview
|
||||||
|
(error, properties, internalProperties) => {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`long-call-no-args.js 1`] = `
|
exports[`long-call-no-args.js 1`] = `
|
||||||
"veryLongCall(VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG_CONSTANT, () => {})
|
"veryLongCall(VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_VERY_LONG_CONSTANT, () => {})
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
Seq(typeDef.interface.groups).forEach(group =>
|
||||||
|
Seq(group.members).forEach((member, memberName) =>
|
||||||
|
markdownDoc(
|
||||||
|
member.doc,
|
||||||
|
{ typePath: typePath.concat(memberName.slice(1)),
|
||||||
|
signatures: member.signatures }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
const promiseFromCallback = fn =>
|
||||||
|
new Promise((resolve, reject) =>
|
||||||
|
fn((err, result) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
return resolve(result);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
runtimeAgent.getProperties(
|
||||||
|
objectId,
|
||||||
|
false, // ownProperties
|
||||||
|
false, // accessorPropertiesOnly
|
||||||
|
false, // generatePreview
|
||||||
|
(error, properties, internalProperties) => {
|
||||||
|
return 1
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={(e) => this.setState({progress: Math.round(100 * e.nativeEvent.loaded / e.nativeEvent.total)})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total,
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
onProgress={e =>
|
||||||
|
this.setState({
|
||||||
|
progress: Math.round(
|
||||||
|
100 * e.nativeEvent.loaded / e.nativeEvent.total,
|
||||||
|
),
|
||||||
|
})}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -656,12 +656,13 @@ export type BuckWebSocketMessage =
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Missing one level of indentation because of the comment
|
// Missing one level of indentation because of the comment
|
||||||
const rootEpic = (actions, store) => combineEpics(...epics)(actions, store)
|
const rootEpic = (actions, store) =>
|
||||||
// Log errors and continue.
|
combineEpics(...epics)(actions, store)
|
||||||
.catch((err, stream) => {
|
// Log errors and continue.
|
||||||
getLogger().error(err);
|
.catch((err, stream) => {
|
||||||
return stream;
|
getLogger().error(err);
|
||||||
});
|
return stream;
|
||||||
|
});
|
||||||
|
|
||||||
// Two extra levels of indentation because of the comment
|
// Two extra levels of indentation because of the comment
|
||||||
export type AsyncExecuteOptions = child_process$execFileOpts & {
|
export type AsyncExecuteOptions = child_process$execFileOpts & {
|
||||||
@@ -881,12 +882,13 @@ export type BuckWebSocketMessage =
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Missing one level of indentation because of the comment
|
// Missing one level of indentation because of the comment
|
||||||
const rootEpic = (actions, store) => combineEpics(...epics)(actions, store)
|
const rootEpic = (actions, store) =>
|
||||||
// Log errors and continue.
|
combineEpics(...epics)(actions, store)
|
||||||
.catch((err, stream) => {
|
// Log errors and continue.
|
||||||
getLogger().error(err);
|
.catch((err, stream) => {
|
||||||
return stream;
|
getLogger().error(err);
|
||||||
});
|
return stream;
|
||||||
|
});
|
||||||
|
|
||||||
// Two extra levels of indentation because of the comment
|
// Two extra levels of indentation because of the comment
|
||||||
export type AsyncExecuteOptions = child_process$execFileOpts & {
|
export type AsyncExecuteOptions = child_process$execFileOpts & {
|
||||||
|
|||||||
@@ -39,18 +39,20 @@ it('should group messages with same created time', () => {
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
export default store => {
|
export default store => {
|
||||||
return callApi(endpoint, schema).then(
|
return callApi(endpoint, schema).then(
|
||||||
response => next(
|
response =>
|
||||||
actionWith({
|
next(
|
||||||
response,
|
actionWith({
|
||||||
type: successType
|
response,
|
||||||
})
|
type: successType
|
||||||
),
|
})
|
||||||
error => next(
|
),
|
||||||
actionWith({
|
error =>
|
||||||
type: failureType,
|
next(
|
||||||
error: error.message || \\"Something bad happened\\"
|
actionWith({
|
||||||
})
|
type: failureType,
|
||||||
)
|
error: error.message || \\"Something bad happened\\"
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -173,18 +175,19 @@ function f() {
|
|||||||
}
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
export default function theFunction(action$, store) {
|
export default function theFunction(action$, store) {
|
||||||
return action$.ofType(THE_ACTION).switchMap(action => Observable.webSocket({
|
return action$.ofType(THE_ACTION).switchMap(action =>
|
||||||
url: THE_URL,
|
Observable.webSocket({
|
||||||
more: stuff(),
|
url: THE_URL,
|
||||||
evenMore: stuff({
|
more: stuff(),
|
||||||
value1: true,
|
evenMore: stuff({
|
||||||
value2: false,
|
value1: true,
|
||||||
value3: false
|
value2: false,
|
||||||
|
value3: false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
.filter(data => theFilter(data))
|
||||||
.filter(data => theFilter(data))
|
.map(({ theType, ...data }) => theMap(theType, data))
|
||||||
.map(({ theType, ...data }) => theMap(theType, data))
|
.retryWhen(errors => errors));
|
||||||
.retryWhen(errors => errors));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
|
|||||||
Reference in new issue
Block a user