From bdaac57a2be7c2660776531f74e15e83ab28c74d Mon Sep 17 00:00:00 2001 From: Rudro Samanta Date: Wed, 17 May 2023 22:24:20 -0700 Subject: [PATCH 1/2] Ignore internal properties in components - Fixes #458 (see bug for details) --- .../Tasks/PluginizedASTDeclarationParserTask.swift | 8 ++++++-- .../Parsing/Tasks/DeclarationsParserTask.swift | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Generator/Sources/NeedleFramework/Parsing/Pluginized/Tasks/PluginizedASTDeclarationParserTask.swift b/Generator/Sources/NeedleFramework/Parsing/Pluginized/Tasks/PluginizedASTDeclarationParserTask.swift index 3c3aef0..67fa639 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 233c788..3c138d0 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) } From f1fbc782700c10543a9394b3b588ebf59a876c96 Mon Sep 17 00:00:00 2001 From: Rudro Samanta Date: Wed, 16 Aug 2023 13:01:08 -0700 Subject: [PATCH 2/2] Fix tests --- .../Fixtures/ComponentSample.swift | 22 +++++++++---------- ...uginizedDependencyGraphExporterTests.swift | 2 +- .../Sources/LoggedIn/LoggedInComponent.swift | 2 +- .../Sources/Root/RootComponent.swift | 4 ++-- .../TicTacToeCore/Root/RootComponent.swift | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift b/Generator/Tests/NeedleFrameworkTests/Fixtures/ComponentSample.swift index 1d14e5c..dc1f88f 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 e7ecedb..c741b6b 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 4ddccdd..257f014 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 e5ab9c9..e228141 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 e5ab9c9..e228141 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() } }