diff --git a/Changelog.md b/Changelog.md index 647227cf..0c49ecc4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #130 by @mattt. - Fixed file and directory unexpected permissions. #146 by @niw. +- Fixed declarations for properties without explicit type annotations. + #150 by @mattt. ## [1.0.0-beta.3] - 2020-05-19 diff --git a/Sources/SwiftDoc/SourceFile.swift b/Sources/SwiftDoc/SourceFile.swift index 8c54a183..ebf49d44 100644 --- a/Sources/SwiftDoc/SourceFile.swift +++ b/Sources/SwiftDoc/SourceFile.swift @@ -58,7 +58,6 @@ public struct SourceFile: Hashable, Codable { func symbol(_ node: Node, api: API) -> Symbol? { guard let documentation = try? Documentation.parse(node.documentation) else { return nil } let sourceLocation = sourceLocationConverter.location(for: node.position) - return Symbol(api: api, context: context, declaration: "\(api)", documentation: documentation, sourceLocation: sourceLocation) } @@ -184,8 +183,16 @@ public struct SourceFile: Hashable, Codable { } override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind { - let variables = node.bindings.compactMap { binding in - Variable(binding.withInitializer(nil)) + let variables = node.bindings.compactMap { binding -> Variable? in + // Omit initializer expression if closure or function call + // to ensure reasonable declaration code blocks. + if let value = binding.initializer?.value, + value.is(ClosureExprSyntax.self) || value.is(FunctionCallExprSyntax.self) + { + return Variable(binding.withInitializer(nil)) + } else { + return Variable(binding) + } } for variable in variables {