Mutate the doc.parts array when printing fill (#3273)

master
Lucas Duailibe 2017-11-16 09:55:55 -02:00 committed by GitHub
parent 66d9b266e8
commit 8e5c335bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -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,