Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Introduce infiniteWidth document #680

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/doc-builders.js
Expand Up @@ -68,6 +68,7 @@ function lineSuffix(contents) {
}

const lineSuffixBoundary = { type: "line-suffix-boundary" };
const infiniteWidth = { type: "infinite-width" };
const breakParent = { type: "break-parent" };
const line = { type: "line" };
const softline = { type: "line", soft: true };
Expand Down Expand Up @@ -104,5 +105,6 @@ module.exports = {
lineSuffixBoundary,
breakParent,
ifBreak,
infiniteWidth,
indent
};
6 changes: 6 additions & 0 deletions src/doc-printer.js
Expand Up @@ -28,6 +28,10 @@ function fits(next, restCommands, width) {
width -= doc.length;
} else {
switch (doc.type) {
case "infinite-width":
width = -1;

break;
case "concat":
for (var i = doc.parts.length - 1; i >= 0; i--) {
cmds.push([ind, mode, doc.parts[i]]);
Expand Down Expand Up @@ -101,6 +105,8 @@ function printDocToString(doc, width, newLine) {
pos += doc.length;
} else {
switch (doc.type) {
case "infinite-width":
break;
case "concat":
for (var i = doc.parts.length - 1; i >= 0; i--) {
cmds.push([ind, mode, doc.parts[i]]);
Expand Down
5 changes: 3 additions & 2 deletions src/printer.js
Expand Up @@ -19,6 +19,7 @@ var conditionalGroup = docBuilders.conditionalGroup;
var ifBreak = docBuilders.ifBreak;
var breakParent = docBuilders.breakParent;
var lineSuffixBoundary = docBuilders.lineSuffixBoundary;
var infiniteWidth = docBuilders.infiniteWidth;

var docUtils = require("./doc-utils");
var willBreak = docUtils.willBreak;
Expand Down Expand Up @@ -711,9 +712,9 @@ function genericPrintNoParens(path, options, print) {
parentIsUnionTypeAnnotation ? 2 : 0,
concat([options.bracketSpacing ? line : softline, rightBrace])
),
shouldBreak ? infiniteWidth : "",
path.call(print, "typeAnnotation")
]),
{ shouldBreak }
])
);
}

Expand Down
138 changes: 138 additions & 0 deletions tests/infinite_width/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,138 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`infinite.js 1`] = `
"function f() {
if (position)
return {name: pair};
else
return {name: pair.substring(0, position), value: pair.substring(position + 1)};
}

function f() {
if (position) return { name: pair };
else return {
name: pair.substring(0, position),
value: pair.substring(position + 1)
};
}

function f() {
if (position)
return { name: pair };
else
return {
name: pair.substring(0, position),
value: pair.substring(position + 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>
);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function f() {
if (position) return { name: pair };
else return {
name: pair.substring(0, position),
value: pair.substring(position + 1)
};
}

function f() {
if (position) return { name: pair };
else return {
name: pair.substring(0, position),
value: pair.substring(position + 1)
};
}

function f() {
if (position) return { name: pair };
else return {
name: pair.substring(0, position),
value: pair.substring(position + 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>
);
}
"
`;
64 changes: 64 additions & 0 deletions tests/infinite_width/infinite.js
@@ -0,0 +1,64 @@
function f() {
if (position)
return {name: pair};
else
return {name: pair.substring(0, position), value: pair.substring(position + 1)};
}

function f() {
if (position) return { name: pair };
else return {
name: pair.substring(0, position),
value: pair.substring(position + 1)
};
}

function f() {
if (position)
return { name: pair };
else
return {
name: pair.substring(0, position),
value: pair.substring(position + 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>
);
}
1 change: 1 addition & 0 deletions tests/infinite_width/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname);
71 changes: 39 additions & 32 deletions tests/method-chain/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -39,18 +39,20 @@ it('should group messages with same created time', () => {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export default store => {
return callApi(endpoint, schema).then(
response => next(
actionWith({
response,
type: successType
})
),
error => next(
actionWith({
type: failureType,
error: error.message || \\"Something bad happened\\"
})
)
response =>
next(
actionWith({
response,
type: successType
})
),
error =>
next(
actionWith({
type: failureType,
error: error.message || \\"Something bad happened\\"
})
)
);
};

Expand Down Expand Up @@ -171,18 +173,21 @@ function f() {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export default function theFunction(action$, store) {
return action$.ofType(THE_ACTION).switchMap(action => Observable.webSocket({
url: THE_URL,
more: stuff(),
evenMore: stuff({
value1: true,
value2: false,
value3: false
})
})
.filter(data => theFilter(data))
.map(({ theType, ...data }) => theMap(theType, data))
.retryWhen(errors => errors));
return action$
.ofType(THE_ACTION)
.switchMap(action =>
Observable.webSocket({
url: THE_URL,
more: stuff(),
evenMore: stuff({
value1: true,
value2: false,
value3: false
})
})
.filter(data => theFilter(data))
.map(({ theType, ...data }) => theMap(theType, data))
.retryWhen(errors => errors));
}

function f() {
Expand Down Expand Up @@ -227,14 +232,16 @@ if (testConfig.ENABLE_ONLINE_TESTS === \\"true\\") {
describe(\\"POST /users/me/pet\\", function() {
it(\\"saves pet\\", function() {
function assert(pet) {
expect(pet).to.have.property(\\"OwnerAddress\\").that.deep.equals({
AddressLine1: \\"Alexanderstrasse\\",
AddressLine2: \\"\\",
PostalCode: \\"10999\\",
Region: \\"Berlin\\",
City: \\"Berlin\\",
Country: \\"DE\\"
});
expect(pet).to.have
.property(\\"OwnerAddress\\")
.that.deep.equals({
AddressLine1: \\"Alexanderstrasse\\",
AddressLine2: \\"\\",
PostalCode: \\"10999\\",
Region: \\"Berlin\\",
City: \\"Berlin\\",
Country: \\"DE\\"
});
}
});
});
Expand Down