Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow internal-only namespaces in @import directive #1765

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Framework/Framework/Compilation/CompiledAssemblyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ private HashSet<string> GetAllNamespaces()
foreach (var a in GetAllAssemblies())
{
string? lastNs = null; // namespaces come in batches, usually, so no need to hash it everytime when a quick compare says it's the same as last time
foreach (var type in a.ExportedTypes)
foreach (var type in a.GetLoadableTypes())
{
var ns = type.Namespace;
if (ns is null || lastNs == ns)
continue;
result.Add(ns);
result.Add(ns);
lastNs = ns;
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
using System;
using System.Collections.Generic;

namespace DotVVM.Framework.Tests.Runtime.ControlTree.TestInternalOnlyNamespace
{
class InternalClass { }
}

namespace DotVVM.Framework.Tests.Runtime.ControlTree
{
[TestClass]
Expand Down Expand Up @@ -70,6 +75,46 @@ @viewModel object
Assert.AreEqual(typeof(List<int>).FullName, importDirective.Type.FullName);
}

[TestMethod]
public void ResolvedTree_ImportDirective_NamespaceDoesNotExist()
{
var root = ParseSource(@"
@viewModel object
@import This.Namespace.Does.Not.Exist
");
var importDirective = EnsureSingleResolvedImportDirective(root);

Assert.IsTrue(importDirective.HasError);
Assert.AreEqual("This.Namespace.Does.Not.Exist is unknown type or namespace.", importDirective.DothtmlNode.NodeErrors.Single());
}
[TestMethod]
public void ResolvedTree_ImportDirective_NamespaceDoesNotExist_Alias()
{
var root = ParseSource(@"
@viewModel object
@import testns = This.Namespace.Does.Not.Exist
");
var importDirective = EnsureSingleResolvedImportDirective(root);

Assert.IsTrue(importDirective.HasError);
Assert.AreEqual("This.Namespace.Does.Not.Exist is unknown type or namespace.", importDirective.DothtmlNode.NodeErrors.Single());
}

[TestMethod]
public void ResolvedTree_ImportDirective_InternalNamespace()
{
var root = ParseSource(@"
@viewModel object
@import DotVVM.Framework.Tests.Runtime.ControlTree.TestInternalOnlyNamespace
");
var importDirective = EnsureSingleResolvedImportDirective(root);

Assert.IsFalse(importDirective.HasError, message: importDirective.DothtmlNode.NodeErrors.SingleOrDefault());
Assert.IsNull(importDirective.Type);
Assert.IsTrue(importDirective.IsNamespace);
}


private static ResolvedImportDirective EnsureSingleResolvedImportDirective(ResolvedTreeRoot root) =>
root.Directives["import"]
.Single()
Expand Down
Loading