Skip to content

Commit

Permalink
RazorProjectEngine: Do not allow nullable file kind
Browse files Browse the repository at this point in the history
It turns out that nothing calls these APIs with a null file kind, so let's not annotate it that way.
  • Loading branch information
DustinCampbell committed Dec 26, 2024
1 parent 1c6fb18 commit 5dea634
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ public RazorCodeDocument Process(RazorProjectItem projectItem)

public RazorCodeDocument Process(
RazorSourceDocument source,
string? fileKind,
string fileKind,
ImmutableArray<RazorSourceDocument> importSources,
IReadOnlyList<TagHelperDescriptor> tagHelpers)
IReadOnlyList<TagHelperDescriptor>? tagHelpers)
{
ArgHelper.ThrowIfNull(source);
ArgHelper.ThrowIfNull(fileKind);

var codeDocument = CreateCodeDocumentCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: null);
ProcessCore(codeDocument);
Expand All @@ -80,6 +81,7 @@ public RazorCodeDocument ProcessDeclarationOnly(
IReadOnlyList<TagHelperDescriptor> tagHelpers)
{
ArgHelper.ThrowIfNull(source);
ArgHelper.ThrowIfNull(fileKind);

var codeDocument = CreateCodeDocumentCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: (builder) =>
{
Expand All @@ -101,11 +103,12 @@ public RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem)

public RazorCodeDocument ProcessDesignTime(
RazorSourceDocument source,
string? fileKind,
string fileKind,
ImmutableArray<RazorSourceDocument> importSources,
IReadOnlyList<TagHelperDescriptor>? tagHelpers)
{
ArgHelper.ThrowIfNull(source);
ArgHelper.ThrowIfNull(fileKind);

var codeDocument = CreateCodeDocumentDesignTimeCore(source, fileKind, importSources, tagHelpers, configureParser: null, configureCodeGeneration: null);
ProcessCore(codeDocument);
Expand All @@ -130,12 +133,14 @@ private protected RazorCodeDocument CreateCodeDocumentCore(
}

var importSourceDocuments = GetImportSourceDocuments(importItems.DrainToImmutable());
return CreateCodeDocumentCore(sourceDocument, projectItem.FileKind, importSourceDocuments, tagHelpers: null, configureParser, configureCodeGeneration, cssScope: projectItem.CssScope);

return CreateCodeDocumentCore(
sourceDocument, projectItem.FileKind, importSourceDocuments, tagHelpers: null, configureParser, configureCodeGeneration, cssScope: projectItem.CssScope);
}

internal RazorCodeDocument CreateCodeDocumentCore(
RazorSourceDocument sourceDocument,
string? fileKind = null,
string fileKind,
ImmutableArray<RazorSourceDocument> importSourceDocuments = default,
IReadOnlyList<TagHelperDescriptor>? tagHelpers = null,
Action<RazorParserOptionsBuilder>? configureParser = null,
Expand All @@ -156,12 +161,9 @@ internal RazorCodeDocument CreateCodeDocumentCore(
});

var codeDocument = RazorCodeDocument.Create(sourceDocument, importSourceDocuments, parserOptions, codeGenerationOptions);
codeDocument.SetTagHelpers(tagHelpers);

if (fileKind != null)
{
codeDocument.SetFileKind(fileKind);
}
codeDocument.SetTagHelpers(tagHelpers);
codeDocument.SetFileKind(fileKind);

if (cssScope != null)
{
Expand Down Expand Up @@ -194,7 +196,7 @@ private protected RazorCodeDocument CreateCodeDocumentDesignTimeCore(

private RazorCodeDocument CreateCodeDocumentDesignTimeCore(
RazorSourceDocument sourceDocument,
string? fileKind,
string fileKind,
ImmutableArray<RazorSourceDocument> importSourceDocuments,
IReadOnlyList<TagHelperDescriptor>? tagHelpers,
Action<RazorParserOptionsBuilder>? configureParser,
Expand All @@ -214,12 +216,9 @@ private RazorCodeDocument CreateCodeDocumentDesignTimeCore(
});

var codeDocument = RazorCodeDocument.Create(sourceDocument, importSourceDocuments, parserOptions, codeGenerationOptions);
codeDocument.SetTagHelpers(tagHelpers);

if (fileKind != null)
{
codeDocument.SetFileKind(fileKind);
}
codeDocument.SetTagHelpers(tagHelpers);
codeDocument.SetFileKind(fileKind);

return codeDocument;
}
Expand Down

0 comments on commit 5dea634

Please sign in to comment.