From 008c09463b3ff9893b259b6287566a7392bf3a52 Mon Sep 17 00:00:00 2001 From: Rudro Samanta Date: Wed, 16 Aug 2023 15:22:41 -0700 Subject: [PATCH] Ignore internal properties in components (#459) * Ignore internal properties in components - Fixes #458 (see bug for details) * Fix tests --- .../PluginizedASTDeclarationParserTask.swift | 8 +++++-- .../Tasks/DeclarationsParserTask.swift | 5 +++-- .../Fixtures/ComponentSample.swift | 22 +++++++++---------- ...uginizedDependencyGraphExporterTests.swift | 2 +- .../Sources/LoggedIn/LoggedInComponent.swift | 2 +- .../Sources/Root/RootComponent.swift | 4 ++-- .../TicTacToeCore/Root/RootComponent.swift | 4 ++-- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Generator/Sources/NeedleFramework/Parsing/Pluginized/Tasks/PluginizedASTDeclarationParserTask.swift b/Generator/Sources/NeedleFramework/Parsing/Pluginized/Tasks/PluginizedASTDeclarationParserTask.swift index 3c3aef04..67fa6390 100644 --- a/Generator/Sources/NeedleFramework/Parsing/Pluginized/Tasks/PluginizedASTDeclarationParserTask.swift +++ b/Generator/Sources/NeedleFramework/Parsing/Pluginized/Tasks/PluginizedASTDeclarationParserTask.swift @@ -106,24 +106,28 @@ private final class PluginizedVisitor: BaseVisitor { override func visitPost(_ node: ClassDeclSyntax) { let componentName = node.typeName if componentName == currentPluginizedComponentName { + // Internal properties cannot be seen by the needle generated code, so leave them out + let filteredProperties = propertiesDict[componentName, default: []].filter { property in !property.isInternal } let component = ASTComponent(name: componentName, dependencyProtocolName: currentPluginExtensionGenerics.dependencyProtocolName, isRoot: node.isRoot, sourceHash: sourceHash, filePath: filePath, - properties: propertiesDict[componentName, default: []], + properties: filteredProperties, expressionCallTypeNames: Array(componentToCallExprs[componentName, default: []]).sorted()) let pluginizedComponent = PluginizedASTComponent(data: component, pluginExtensionType: currentPluginExtensionGenerics.pluginExtensionName, nonCoreComponentType: currentPluginExtensionGenerics.nonCoreComponentName) pluginizedComponents.append(pluginizedComponent) } else if componentName == currentNonCoreComponentName { + // Internal properties cannot be seen by the needle generated code, so leave them out + let filteredProperties = propertiesDict[componentName, default: []].filter { property in !property.isInternal } let component = ASTComponent(name: componentName, dependencyProtocolName: currentDependencyProtocol ?? "", isRoot: false, sourceHash: sourceHash, filePath: filePath, - properties: propertiesDict[componentName, default: []], + properties: filteredProperties, expressionCallTypeNames: Array(componentToCallExprs[componentName, default: []]).sorted()) nonCoreComponents.append(component) } diff --git a/Generator/Sources/NeedleFramework/Parsing/Tasks/DeclarationsParserTask.swift b/Generator/Sources/NeedleFramework/Parsing/Tasks/DeclarationsParserTask.swift index 233c7888..3c138d00 100644 --- a/Generator/Sources/NeedleFramework/Parsing/Tasks/DeclarationsParserTask.swift +++ b/Generator/Sources/NeedleFramework/Parsing/Tasks/DeclarationsParserTask.swift @@ -97,13 +97,14 @@ private final class Visitor: BaseVisitor { let componentName = node.typeName if componentName == currentEntityNode?.typeName { let dependencyProtocolName = node.isRoot ? emptyDependency.name : (currentDependencyProtocol ?? "") - + // Internal properties cannot be seen by the needle generated code, so leave them out + let filteredProperties = propertiesDict[componentName, default: []].filter { property in !property.isInternal } let component = ASTComponent(name: componentName, dependencyProtocolName: dependencyProtocolName, isRoot: node.isRoot, sourceHash: sourceHash, filePath: filePath, - properties: propertiesDict[componentName, default: []], + properties: filteredProperties, expressionCallTypeNames: Array(componentToCallExprs[componentName, default: []]).sorted()) components.append(component) } diff --git a/Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift b/Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift index 1d14e5cc..dc1f88f8 100644 --- a/Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift +++ b/Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift @@ -17,19 +17,19 @@ class MyComponent: NeedleFoundation.Component< MyDependency > { - let stream: Stream = Stream() + public let stream: Stream = Stream() - var donut: Donut { + public var donut: Donut { return Donut() } - var sweetsBasket: Basket { + public var sweetsBasket: Basket { return shared { Basket(dependency.candy, self.donut) } } - var myChildComponent: MyChildComponent { + public var myChildComponent: MyChildComponent { return MyChildComponent(parent: self) } @@ -44,10 +44,10 @@ protocol SomeNonCoreDependency: Dependency { } class SomeNonCoreComponent: NeedleFoundation.NonCoreComponent< SomeNonCoreDependency > { - var newNonCoreObject: NonCoreObject? { + public var newNonCoreObject: NonCoreObject? { return NonCoreObject() } - var sharedNonCoreObject: SharedObject { + public var sharedNonCoreObject: SharedObject { return shared { return SharedObject() } @@ -55,7 +55,7 @@ class SomeNonCoreComponent: NeedleFoundation.NonCoreComponent< SomeNonCoreDep } class MyRComp: BootstrapComponent { - var rootObj: Obj { + public var rootObj: Obj { return shared { Obj() } @@ -63,17 +63,17 @@ class MyRComp: BootstrapComponent { } class My2Component: Component { - var book: Book { + public var book: Book { return shared { Book() } } - var maybeWallet: Wallet? { + public var maybeWallet: Wallet? { return Wallet() } - var myStore: MyStorage { + public var myStore: MyStorage { return MyStorage() } @@ -98,7 +98,7 @@ class SomePluginizedComp: PluginizedComponent< ADependency, BExtension, SomeNonCoreComponent >, Stuff { - var tv: Tv { + public var tv: Tv { return LGOLEDTv() } } diff --git a/Generator/Tests/NeedleFrameworkTests/Generating/Pluginized/PluginizedDependencyGraphExporterTests.swift b/Generator/Tests/NeedleFrameworkTests/Generating/Pluginized/PluginizedDependencyGraphExporterTests.swift index e7ecedb8..c741b6b6 100644 --- a/Generator/Tests/NeedleFrameworkTests/Generating/Pluginized/PluginizedDependencyGraphExporterTests.swift +++ b/Generator/Tests/NeedleFrameworkTests/Generating/Pluginized/PluginizedDependencyGraphExporterTests.swift @@ -49,7 +49,7 @@ class PluginizedDependencyGraphExporterTests: AbstractPluginizedGeneratorTests { XCTAssertTrue(generated.contains("import UIKit")) XCTAssertTrue(generated.contains("import ScoreSheet")) XCTAssertTrue(generated.contains("import TicTacToeIntegrations")) - XCTAssertTrue(generated.contains("private let needleDependenciesHash : String? = \"4b585865bab35437b0cbc60e9d74b1b1\"")) + XCTAssertTrue(generated.contains("private let needleDependenciesHash : String? = \"86deb40d0ec1c9fc9fd5e5e8fc17a167\"")) XCTAssertTrue(generated.contains("// MARK: - Registration")) XCTAssertTrue(generated.contains(""" registerProviderFactory(\"^->RootComponent->LoggedOutComponent\", factory1434ff4463106e5c4f1bb3a8f24c1d289f2c0f2e) diff --git a/Sample/MVC/TicTacToe/Sources/LoggedIn/LoggedInComponent.swift b/Sample/MVC/TicTacToe/Sources/LoggedIn/LoggedInComponent.swift index 4ddccdd5..257f0140 100644 --- a/Sample/MVC/TicTacToe/Sources/LoggedIn/LoggedInComponent.swift +++ b/Sample/MVC/TicTacToe/Sources/LoggedIn/LoggedInComponent.swift @@ -19,7 +19,7 @@ import UIKit class LoggedInComponent: Component, LoggedInBuilder { - var scoreStream: ScoreStream { + public var scoreStream: ScoreStream { return mutableScoreStream } diff --git a/Sample/MVC/TicTacToe/Sources/Root/RootComponent.swift b/Sample/MVC/TicTacToe/Sources/Root/RootComponent.swift index e5ab9c9c..e2281413 100644 --- a/Sample/MVC/TicTacToe/Sources/Root/RootComponent.swift +++ b/Sample/MVC/TicTacToe/Sources/Root/RootComponent.swift @@ -19,11 +19,11 @@ import UIKit class RootComponent: BootstrapComponent { - var playersStream: PlayersStream { + public var playersStream: PlayersStream { return mutablePlayersStream } - var mutablePlayersStream: MutablePlayersStream { + public var mutablePlayersStream: MutablePlayersStream { return shared { PlayersStreamImpl() } } diff --git a/Sample/Pluginized/TicTacToe/TicTacToeCore/Root/RootComponent.swift b/Sample/Pluginized/TicTacToe/TicTacToeCore/Root/RootComponent.swift index e5ab9c9c..e2281413 100644 --- a/Sample/Pluginized/TicTacToe/TicTacToeCore/Root/RootComponent.swift +++ b/Sample/Pluginized/TicTacToe/TicTacToeCore/Root/RootComponent.swift @@ -19,11 +19,11 @@ import UIKit class RootComponent: BootstrapComponent { - var playersStream: PlayersStream { + public var playersStream: PlayersStream { return mutablePlayersStream } - var mutablePlayersStream: MutablePlayersStream { + public var mutablePlayersStream: MutablePlayersStream { return shared { PlayersStreamImpl() } }