Skip to content

Commit bc6eefb

Browse files
authored
Merge pull request #280 from kimdv/kimdv/omit-optional-init-parameters
Omit parameters in init that is optional
2 parents dc23040 + dae0f99 commit bc6eefb

File tree

6 files changed

+252
-269
lines changed

6 files changed

+252
-269
lines changed

Sources/SwiftSyntaxBuilder/Buildables.swift.gyb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,19 @@ extension ${kind}Buildable {
8181
% for node in SYNTAX_NODES:
8282
% if node.is_buildable():
8383
public struct ${node.syntax_kind}: ${node.base_kind}Buildable {
84-
% child_params = []
8584
% for child in node.children:
8685
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token(), child.is_optional)
87-
% child_params.append("%s: %s" % (child.swift_name, param_type))
88-
% end
89-
% for child_param in child_params:
90-
let ${child_param}
86+
let ${"%s: %s" % (child.swift_name, param_type)}
9187
% end
9288

9389
public init(
94-
${',\n '.join(child_params)}
90+
% init_parameters = []
91+
% for child in node.children:
92+
% param_type = syntax_buildable_child_type(child.type_name, child.syntax_kind, child.is_token(), child.is_optional)
93+
% default_value = " = nil" if child.is_optional else ""
94+
% init_parameters.append("%s: %s%s" % (child.swift_name, param_type, default_value))
95+
% end
96+
${',\n '.join(init_parameters)}
9597
) {
9698
% for child in node.children:
9799
self.${child.swift_name} = ${child.swift_name}

0 commit comments

Comments
 (0)