Skip to content

Commit 65f4a66

Browse files
committed
printing undefined as empty string so most of the Ternary operators could be removed.
1 parent f851b8e commit 65f4a66

42 files changed

Lines changed: 130 additions & 129 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/slang-nodes/AddressType.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { getNodeMetadata } from '../slang-utils/metadata.js';
3+
import { joinExisting } from '../slang-utils/join-existing.js';
34

45
import type * as ast from '@nomicfoundation/slang/ast';
56
import type { Doc } from 'prettier';
@@ -24,6 +25,6 @@ export class AddressType implements SlangNode {
2425
}
2526

2627
print(): Doc {
27-
return ['address', this.payableKeyword ? ' payable' : ''];
28+
return joinExisting(' ', ['address', this.payableKeyword]);
2829
}
2930
}

src/slang-nodes/ArrayTypeName.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ export class ArrayTypeName implements SlangNode {
3939
}
4040

4141
print(path: AstPath<ArrayTypeName>, print: PrintFunction): Doc {
42-
return [
43-
path.call(print, 'operand'),
44-
'[',
45-
this.index ? path.call(print, 'index') : '',
46-
']'
47-
];
42+
return [path.call(print, 'operand'), '[', path.call(print, 'index'), ']'];
4843
}
4944
}

src/slang-nodes/AssemblyStatement.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
3+
import { joinExisting } from '../slang-utils/join-existing.js';
34
import { StringLiteral } from './StringLiteral.js';
45
import { AssemblyFlagsDeclaration } from './AssemblyFlagsDeclaration.js';
56
import { YulBlock } from './YulBlock.js';
@@ -48,11 +49,11 @@ export class AssemblyStatement implements SlangNode {
4849
}
4950

5051
print(path: AstPath<AssemblyStatement>, print: PrintFunction): Doc {
51-
return [
52-
'assembly ',
53-
this.label ? [path.call(print, 'label'), ' '] : '',
54-
this.flags ? [path.call(print, 'flags'), ' '] : '',
52+
return joinExisting(' ', [
53+
'assembly',
54+
path.call(print, 'label'),
55+
path.call(print, 'flags'),
5556
path.call(print, 'body')
56-
];
57+
]);
5758
}
5859
}

src/slang-nodes/CatchClause.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ export class CatchClause implements SlangNode {
4141
}
4242

4343
print(path: AstPath<CatchClause>, print: PrintFunction): Doc {
44-
return [
45-
'catch ',
46-
this.error ? path.call(print, 'error') : '',
47-
path.call(print, 'body')
48-
];
44+
return ['catch ', path.call(print, 'error'), path.call(print, 'body')];
4945
}
5046
}

src/slang-nodes/CatchClauseError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class CatchClauseError implements SlangNode {
4949

5050
print(path: AstPath<CatchClauseError>, print: PrintFunction): Doc {
5151
return [
52-
this.name ? path.call(print, 'name') : '',
52+
path.call(print, 'name'),
5353
group(path.call(print, 'parameters')),
5454
' '
5555
];

src/slang-nodes/DecimalNumberExpression.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
3+
import { joinExisting } from '../slang-utils/join-existing.js';
34
import { NumberUnit } from './NumberUnit.js';
45

56
import type * as ast from '@nomicfoundation/slang/ast';
@@ -33,6 +34,6 @@ export class DecimalNumberExpression implements SlangNode {
3334
}
3435

3536
print(path: AstPath<DecimalNumberExpression>, print: PrintFunction): Doc {
36-
return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : ''];
37+
return joinExisting(' ', [this.literal, path.call(print, 'unit')]);
3738
}
3839
}

src/slang-nodes/ErrorParameter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
3+
import { joinExisting } from '../slang-utils/join-existing.js';
34
import { TypeName } from './TypeName.js';
45
import { Identifier } from './Identifier.js';
56

@@ -39,9 +40,9 @@ export class ErrorParameter implements SlangNode {
3940
}
4041

4142
print(path: AstPath<ErrorParameter>, print: PrintFunction): Doc {
42-
return [
43+
return joinExisting(' ', [
4344
path.call(print, 'typeName'),
44-
this.name ? [' ', path.call(print, 'name')] : ''
45-
];
45+
path.call(print, 'name')
46+
]);
4647
}
4748
}

src/slang-nodes/EventParameter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
3+
import { joinExisting } from '../slang-utils/join-existing.js';
34
import { TypeName } from './TypeName.js';
45
import { Identifier } from './Identifier.js';
56

@@ -42,10 +43,10 @@ export class EventParameter implements SlangNode {
4243
}
4344

4445
print(path: AstPath<EventParameter>, print: PrintFunction): Doc {
45-
return [
46+
return joinExisting(' ', [
4647
path.call(print, 'typeName'),
47-
this.indexedKeyword ? ' indexed' : '',
48-
this.name ? [' ', path.call(print, 'name')] : ''
49-
];
48+
this.indexedKeyword,
49+
path.call(print, 'name')
50+
]);
5051
}
5152
}

src/slang-nodes/ForStatement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { doc } from 'prettier';
21
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
2+
import { doc } from 'prettier';
33
import { printSeparatedList } from '../slang-printers/print-separated-list.js';
44
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
55
import { ForStatementInitialization } from './ForStatementInitialization.js';
@@ -68,7 +68,7 @@ export class ForStatement implements SlangNode {
6868
print(path: AstPath<ForStatement>, print: PrintFunction): Doc {
6969
const initialization = path.call(print, 'initialization');
7070
const condition = path.call(print, 'condition');
71-
const iterator = this.iterator ? path.call(print, 'iterator') : '';
71+
const iterator = path.call(print, 'iterator');
7272

7373
return [
7474
'for (',

src/slang-nodes/HexNumberExpression.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/kinds/index.js';
22
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
3+
import { joinExisting } from '../slang-utils/join-existing.js';
34
import { NumberUnit } from './NumberUnit.js';
45

56
import type * as ast from '@nomicfoundation/slang/ast';
@@ -33,6 +34,6 @@ export class HexNumberExpression implements SlangNode {
3334
}
3435

3536
print(path: AstPath<HexNumberExpression>, print: PrintFunction): Doc {
36-
return [this.literal, this.unit ? [' ', path.call(print, 'unit')] : ''];
37+
return joinExisting(' ', [this.literal, path.call(print, 'unit')]);
3738
}
3839
}

0 commit comments

Comments
 (0)