Skip to content

Commit a737175

Browse files
committed
Don't join multi part literals
1 parent 5d00865 commit a737175

5 files changed

Lines changed: 62 additions & 2 deletions

File tree

src/nodes/HexLiteral.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
const {
2+
doc: {
3+
builders: { join, line }
4+
}
5+
} = require('prettier/standalone');
6+
7+
const { printString } = require('../prettier-comments/common/util');
8+
19
const HexLiteral = {
2-
print: ({ node }) => node.value
10+
print: ({ node, options }) => {
11+
const list = node.parts.map((part) => `hex${printString(part, options)}`);
12+
return join(line, list);
13+
}
314
};
415

516
module.exports = HexLiteral;

src/nodes/StringLiteral.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
const {
2+
doc: {
3+
builders: { join, line }
4+
}
5+
} = require('prettier/standalone');
16
const { printString } = require('../prettier-comments/common/util');
27

38
const StringLiteral = {
4-
print: ({ node, options }) => printString(node.value, options)
9+
print: ({ node, options }) => {
10+
const list = node.parts.map((part) => printString(part, options));
11+
return join(line, list);
12+
}
513
};
614

715
module.exports = StringLiteral;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
contract MultipartStrings {
2+
bytes b1 = hex'beef';
3+
bytes b2 = hex"beef";
4+
bytes b3 = hex"beef" hex"c0ffee";
5+
bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee";
6+
7+
string s1 = "foo";
8+
string s2 = "foo" "bar";
9+
string s3 = "foofoofoofooofoofoofofoooofofoo" "barbarbrabrbarbarbabrabrbabr";
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`MultipartStrings.sol 1`] = `
4+
contract MultipartStrings {
5+
bytes b1 = hex'beef';
6+
bytes b2 = hex"beef";
7+
bytes b3 = hex"beef" hex"c0ffee";
8+
bytes b4 = hex"beeeeeeeeeeeeeeeeeeeeeef" hex"c0000000000ffeeeeeeeeeeeeeeeeeee";
9+
10+
string s1 = "foo";
11+
string s2 = "foo" "bar";
12+
string s3 = "foofoofoofooofoofoofofoooofofoo" "barbarbrabrbarbarbabrabrbabr";
13+
}
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
contract MultipartStrings {
16+
bytes b1 = hex"beef";
17+
bytes b2 = hex"beef";
18+
bytes b3 = hex"beef" hex"c0ffee";
19+
bytes b4 =
20+
hex"beeeeeeeeeeeeeeeeeeeeeef"
21+
hex"c0000000000ffeeeeeeeeeeeeeeeeeee";
22+
23+
string s1 = "foo";
24+
string s2 = "foo" "bar";
25+
string s3 =
26+
"foofoofoofooofoofoofofoooofofoo"
27+
"barbarbrabrbarbarbabrabrbabr";
28+
}
29+
30+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(__dirname);

0 commit comments

Comments
 (0)