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

Mutate the doc.parts array when printing fill #3273

Merged
merged 2 commits into from
Nov 16, 2017
Merged
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
12 changes: 9 additions & 3 deletions src/doc-printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,16 @@ function printDocToString(doc, options) {
break;
}

const remaining = parts.slice(2);
const remainingCmd = [ind, mode, fill(remaining)];
// At this point we've handled the first pair (context, separator)
// and will create a new fill doc for the rest of the content.
// Ideally we wouldn't mutate the array here but coping all the
// elements to a new array would make this algorithm quadratic,
// which is unusable for large arrays (e.g. large texts in JSX).
parts.splice(0, 2);
const remainingCmd = [ind, mode, fill(parts)];

const secondContent = parts[0];

const secondContent = parts[2];
const firstAndSecondContentFlatCmd = [
ind,
MODE_FLAT,
Expand Down