Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,19 @@ function genericPrint(path, options, print) {
return node.value;
case 'AssemblySwitch':
doc = join(hardline, path.map(print, 'cases'));
return concat(['switch ', path.call(print, 'expression'), hardline, doc]);
return concat([
'switch ',
path.call(print, 'expression'),
indent(hardline),
indent(doc)
]);
case 'AssemblyCase':
if (node.default) {
doc = concat(['default']);
} else {
doc = concat(['case ', path.call(print, 'value')]);
}
return join(' ', [doc, '{}']);
return join(' ', [doc, path.call(print, 'block')]);
case 'AssemblyLocalDefinition':
return join(' ', [
'let',
Expand Down
12 changes: 12 additions & 0 deletions tests/Assembly/Assembly.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ contract Assembly {
}
}
}

function caseAssembly() {
assembly {
switch value
case 0 {
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
}
case 1 {
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
}
}
}
}
24 changes: 24 additions & 0 deletions tests/Assembly/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ contract Assembly {
}
}
}

function caseAssembly() {
assembly {
switch value
case 0 {
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
}
case 1 {
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
}
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
contract Assembly {
Expand All @@ -20,6 +32,18 @@ contract Assembly {
}
}
}

function caseAssembly() {
assembly {
switch value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm, shall we have 2 spaces to indent the "case" inside the switch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean that the cases should be more indented than the switch? Yeah, I agree with that, and that's what prettier does in javascript.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! thanks so much

case 0 {
mstore(0, 0x0000000000000000000000000000000000000000000000000000000000000000)
}
case 1 {
mstore(0, 0x1111111111111111111111111111111111111111111111111111111111111111)
}
}
}
}

`;