Skip to content

Commit f7dbedf

Browse files
authored
Merge pull request #393 from prettier-solidity/multi-part-literals
Don't join multi-part literals
2 parents 33368a1 + a737175 commit f7dbedf

7 files changed

Lines changed: 66 additions & 6 deletions

File tree

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"jest-watch-typeahead": "^0.6.0"
7272
},
7373
"dependencies": {
74-
"@solidity-parser/parser": "^0.9.0",
74+
"@solidity-parser/parser": "^0.9.1",
7575
"dir-to-object": "^2.0.0",
7676
"emoji-regex": "^9.0.0",
7777
"escape-string-regexp": "^4.0.0",

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)