Skip to content

Commit 2d8713c

Browse files
authored
Add support for extslice (prettier#93)
1 parent c95164c commit 2d8713c

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

src/printer/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,17 @@ function genericPrint(path, options, print) {
895895
);
896896
}
897897

898+
case "ExtSlice": {
899+
return printListLike(
900+
path,
901+
options,
902+
"",
903+
path.map(print, "dims"),
904+
trailingComma,
905+
""
906+
);
907+
}
908+
898909
case "UnaryOp": {
899910
// We don't use a line or escapedLine with Not because wrapping and
900911
// indenting doesn't make sense with a 4-space indent, since the operand
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`list.py 1`] = `
4+
a[-1]
5+
a[-2:]
6+
a[:-2]
7+
a[::-1]
8+
a[1::-1]
9+
a[:-3:-1]
10+
a[-3::-1]
11+
point_coords = coords[i, :]
12+
main(sys.argv[1:])
13+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14+
a[-1]
15+
a[-2:]
16+
a[:-2]
17+
a[::-1]
18+
a[1::-1]
19+
a[:-3:-1]
20+
a[-3::-1]
21+
point_coords = coords[i, :]
22+
main(sys.argv[1:])
23+
24+
`;
25+
26+
exports[`list.py 2`] = `
27+
a[-1]
28+
a[-2:]
29+
a[:-2]
30+
a[::-1]
31+
a[1::-1]
32+
a[:-3:-1]
33+
a[-3::-1]
34+
point_coords = coords[i, :]
35+
main(sys.argv[1:])
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
a[-1]
38+
a[-2:]
39+
a[:-2]
40+
a[::-1]
41+
a[1::-1]
42+
a[:-3:-1]
43+
a[-3::-1]
44+
point_coords = coords[i, :]
45+
main(sys.argv[1:])
46+
47+
`;
48+
49+
exports[`list.py 3`] = `
50+
a[-1]
51+
a[-2:]
52+
a[:-2]
53+
a[::-1]
54+
a[1::-1]
55+
a[:-3:-1]
56+
a[-3::-1]
57+
point_coords = coords[i, :]
58+
main(sys.argv[1:])
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60+
a[-1]
61+
a[-2:]
62+
a[:-2]
63+
a[::-1]
64+
a[1::-1]
65+
a[:-3:-1]
66+
a[-3::-1]
67+
point_coords = coords[i, :]
68+
main(sys.argv[1:])
69+
70+
`;

tests/python_slices/jsfmt.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "none" });
2+
run_spec(__dirname, ["python"], { pythonVersion: "2", trailingComma: "all" });
3+
run_spec(__dirname, ["python"], { pythonVersion: "3" });

tests/python_slices/list.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
a[-1]
2+
a[-2:]
3+
a[:-2]
4+
a[::-1]
5+
a[1::-1]
6+
a[:-3:-1]
7+
a[-3::-1]
8+
point_coords = coords[i, :]
9+
main(sys.argv[1:])

0 commit comments

Comments
 (0)