@@ -276,30 +276,29 @@ export class SwiftSource {
276276 }
277277
278278 /**
279- * If maybeSource is not null or empty, then wrap with start and end, otherwise return an empty
280- * string .
279+ * If maybeSource is not undefined or empty, then wrap with start and end, otherwise return
280+ * undefined .
281281 *
282- * This is just a wrapper for `wrap()` from apollo-codegen-core/lib/utilities/printing.
282+ * This is largely just a wrapper for `wrap()` from apollo-codegen-core/lib/utilities/printing.
283283 */
284284 static wrap (
285285 start : SwiftSource ,
286286 maybeSource ?: SwiftSource ,
287287 end ?: SwiftSource
288- ) : SwiftSource {
289- return new SwiftSource (
290- _wrap (
291- start . source ,
292- maybeSource !== undefined ? maybeSource . source : undefined ,
293- end !== undefined ? end . source : undefined
294- )
288+ ) : SwiftSource | undefined {
289+ const result = _wrap (
290+ start . source ,
291+ maybeSource !== undefined ? maybeSource . source : undefined ,
292+ end !== undefined ? end . source : undefined
295293 ) ;
294+ return result ? new SwiftSource ( result ) : undefined ;
296295 }
297296
298297 /**
299- * Given maybeArray, return an empty string if it is null or empty, otherwise return all items
298+ * Given maybeArray, return undefined if it is undefined or empty, otherwise return all items
300299 * together separated by separator if provided.
301300 *
302- * This is just a wrapper for `join()` from apollo-codegen-core/lib/utilities/printing.
301+ * This is largely just a wrapper for `join()` from apollo-codegen-core/lib/utilities/printing.
303302 *
304303 * @param separator The separator to put between elements. This is typed as `string` with the
305304 * expectation that it's generally something like `', '` but if it contains identifiers it should
@@ -308,8 +307,9 @@ export class SwiftSource {
308307 static join (
309308 maybeArray ?: ( SwiftSource | undefined ) [ ] ,
310309 separator ?: string
311- ) : SwiftSource {
312- return new SwiftSource ( _join ( maybeArray , separator ) ) ;
310+ ) : SwiftSource | undefined {
311+ const result = _join ( maybeArray , separator ) ;
312+ return result ? new SwiftSource ( result ) : undefined ;
313313 }
314314}
315315
@@ -452,9 +452,10 @@ export class SwiftGenerator<Context> extends CodeGenerator<
452452 ) {
453453 this . printNewlineIfNeeded ( ) ;
454454 this . printOnNewline (
455- wrap ( swift `` , new SwiftSource ( _join ( modifiers , " " ) ) , swift ` ` ) . concat (
456- swift `class ${ className } `
457- )
455+ (
456+ wrap ( swift `` , new SwiftSource ( _join ( modifiers , " " ) ) , swift ` ` ) ||
457+ swift ``
458+ ) . concat ( swift `class ${ className } ` )
458459 ) ;
459460 this . print (
460461 wrap (
0 commit comments