Open cameroncooke opened 8 months ago
Hey @cameroncooke I'm trying to replicate the issue you're facing, tried various ways of defining views in extensions, including in a local .framework bundle - the view is unwrapped with no issues.
Could you share more details on how that view is defined? Or attach a sample project setup that recreates the issue.
I could have just corrected the code of containsPrefixRegex
to make the tests pass, but I'm not 100% sure that's the right place to address the issue.
Usually reflection shows the namespaces of custom types as (unknown context)
, thus a parser, I wonder if you have something peculiar in your setup that made reflection work differently and actually render the namespace like you say (extension in MyModule)
. Maybe you're on a beta Xcode version?
You can also prepare a PR. I would advise adding tests that verify Inspector.typeName(type: MyComponent.self, namespaced: true)
is removing the (extension in MyModule)
part and return MyModule.MyComponent
. Under the hood that method actually calls sanitizingNamespace
, which is the function where the fix should go.
String extension
hasPrefix(regex:wholeMatch:)
doesn't handle reserved RegEx symbols and causes false negatives when checking type prefixes.This is especially true when the type's description includes context information like module name, as an example:
Currently, in my project, I get the error:
This in fact of course is false, the two type strings match, the issue is the injecting of the string and treating it as
regex
.The Regex expression
(extension in MyModule):MyModule.MyComponent
does not have any matches for the literal String(extension in MyModule):MyModule.MyComponent
.The reason for this is:
(
and)
are special characters used to denote the beginning and the end of a capture group..
between the namespace and symbol name is technically also invalid but works because it will match any single character including a literal.
.Reproduction
In my case, the issue was caused because my view type was created within an extension in order to namespace it, i.e:
Regex
Also while investigating this issue the code below seems a little questionable:
Again injecting regex into
String.hasPrefix(_:)
in theremoving(prefix:)
method via theremovingSwiftUINamespace()
method and counting the literal "prefix" characters to return a substring.I did consider opening a pull request and working on a fix but I don't have enough knowledge around why some of this works the way it does to feel confident about changing it.
I did however create three unit tests to exercise the issues:
BaseTypesTests.swift:
The last two tests fail, also the last test is an assumption of what the code is there for.