Skip to content

Commit 6c56faa

Browse files
authored
We avoid prepending a hardline before a LabelDefinition (#456)
1 parent 1b118c0 commit 6c56faa

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/nodes/print-preserving-empty-lines.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ function printPreservingEmptyLines(path, key, options, print) {
1111
const node = childPath.getValue();
1212
const nodeType = node.type;
1313

14-
if (parts.length !== 0) {
14+
if (
15+
// Avoid adding a hardline at the beggining of the document.
16+
parts.length !== 0 &&
17+
// LabelDefinition adds a dedented line so we have to avoid prepending
18+
// a hardline.
19+
nodeType !== 'LabelDefinition'
20+
) {
1521
parts.push(hardline);
1622
}
1723

tests/Assembly/Assembly.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ loop:
117117
a add swap1
118118
n := sub(n, 1)
119119
jump(loop)
120+
120121
loopend:
121122
mstore(0, a)
122123
return(0, 0x20)

tests/Assembly/__snapshots__/jsfmt.spec.js.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ loop:
125125
a add swap1
126126
n := sub(n, 1)
127127
jump(loop)
128+
128129
loopend:
129130
mstore(0, a)
130131
return(0, 0x20)
@@ -322,7 +323,6 @@ contract Assembly {
322323
let n := calldataload(4)
323324
let a := 1
324325
let b := a
325-
326326
loop:
327327
jumpi(loopend, eq(n, 0))
328328
a
@@ -339,19 +339,16 @@ contract Assembly {
339339
assembly {
340340
let x := 8
341341
jump(two)
342-
343342
one:
344343
// Here the stack height is 2 (because we pushed x and 7),
345344
// but the assembler thinks it is 1 because it reads
346345
// from top to bottom.
347346
// Accessing the stack variable x here will lead to errors.
348347
x := 9
349348
jump(three)
350-
351349
two:
352350
7 // push something onto the stack
353351
jump(one)
354-
355352
three:
356353
}
357354
}

tests_config/run_spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ const CURSOR_PLACEHOLDER = '<|>';
1818
const RANGE_START_PLACEHOLDER = '<<<PRETTIER_RANGE_START>>>';
1919
const RANGE_END_PLACEHOLDER = '<<<PRETTIER_RANGE_END>>>';
2020

21-
// TODO: these test files need fix
21+
// Here we add files that will not be the same when formating a second time.
2222
const unstableTests = new Map(
23-
['Assembly/Assembly.sol'].map((fixture) => {
23+
[].map((fixture) => {
2424
const [file, isUnstable = () => true] = Array.isArray(fixture)
2525
? fixture
2626
: [fixture];
2727
return [path.join(__dirname, '../tests/', file), isUnstable];
2828
})
2929
);
3030

31-
const unstableAstTests = new Map();
31+
// Here we add files that will not have the same AST after being formated.
32+
const unstableAstTests = new Map(
33+
[].map((fixture) => {
34+
const [file, isAstUnstable = () => true] = Array.isArray(fixture)
35+
? fixture
36+
: [fixture];
37+
return [path.join(__dirname, '../tests/', file), isAstUnstable];
38+
})
39+
);
3240

3341
const isUnstable = (filename, options) => {
3442
const testFunction = unstableTests.get(filename);

0 commit comments

Comments
 (0)