Skip to content

Commit

Permalink
Fix bug with holes in array literals (#7911)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Mar 31, 2020
1 parent bd31256 commit 18bf01e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
16 changes: 16 additions & 0 deletions changelog_unreleased/javascript/pr-7911.md
@@ -0,0 +1,16 @@
#### Fix bug with holes in array literals ([#7911](https://github.com/prettier/prettier/pull/7911) by [@bakkot](https://github.com/bakkot))

<!-- prettier-ignore -->
```jsx
// Input
new Test()
.test()
.test([, 0])
.test();

// Prettier stable
[error] in.js: TypeError: Cannot read property 'type' of null

// Prettier master
new Test().test().test([, 0]).test();
```
2 changes: 1 addition & 1 deletion src/language-js/utils.js
Expand Up @@ -958,7 +958,7 @@ function isSimpleCallArgument(node, depth) {
);
}
if (node.type === "ArrayExpression") {
return node.elements.every(isChildSimple);
return node.elements.every((x) => x == null || isChildSimple(x));
}
if (
node.type === "CallExpression" ||
Expand Down
17 changes: 17 additions & 0 deletions tests/arrays/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -18,6 +18,23 @@ const b =
================================================================================
`;

exports[`holes-in-args.js 1`] = `
====================================options=====================================
parsers: ["flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
new Test()
.test()
.test([, 0])
.test();
=====================================output=====================================
new Test().test().test([, 0]).test();
================================================================================
`;

exports[`last.js 1`] = `
====================================options=====================================
parsers: ["flow", "typescript"]
Expand Down
4 changes: 4 additions & 0 deletions tests/arrays/holes-in-args.js
@@ -0,0 +1,4 @@
new Test()
.test()
.test([, 0])
.test();

0 comments on commit 18bf01e

Please sign in to comment.