Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
be78d2f
Clean up CodeTarget infrastructure
DustinCampbell Sep 24, 2025
464497b
Clean up DocumentWriter
DustinCampbell Sep 24, 2025
147a418
Pass CancellationToken to DocumentWriter
DustinCampbell Sep 24, 2025
49d4950
Thread CancellationToken through DefaultRazorTagHelperRewritePhase
DustinCampbell Sep 24, 2025
05fa9ca
Thread CancellationToken through DefaultRazorTagHelperContextDiscover…
DustinCampbell Sep 24, 2025
1d52b9f
Thread CancellationToken through DefaultRazorSyntaxTreePhase
DustinCampbell Sep 24, 2025
d653712
Pass ImmutableArray to CSharpCodeParser rather than IEnumerable
DustinCampbell Sep 24, 2025
12c5082
Don't use ImmutableHashSet and ImmutableDictionary in CSharpCodeParser
DustinCampbell Sep 24, 2025
621258e
Clean up and improve TokenizerBackedParser and HtmlMarkupParser a bit
DustinCampbell Sep 24, 2025
190770f
Thread CancellationToken through DefaultRazorParsingPhase
DustinCampbell Sep 24, 2025
1ca30a1
Pass CancellationToken into all passes
DustinCampbell Sep 25, 2025
d28200e
Compiler phases call ThrowIfCancellationRequested in-between passes
DustinCampbell Sep 25, 2025
b7be199
RazorSourceGenerator should pass CancellationToken to compiler phases
DustinCampbell Sep 25, 2025
d90acc5
CR feedback and setting optimal capacities in CSharpCodeParser
DustinCampbell Sep 26, 2025
0a4e035
CR Feedback: Move CancellationToken checks outside of fast loops
DustinCampbell Sep 26, 2025
d55ee7a
Move DocumentWrite.WriteDocument into DefaultRazorCSharpLoweringPhase
DustinCampbell Sep 26, 2025
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System;
using Xunit;

Expand All @@ -15,10 +13,9 @@ public void CreateDefault_CreatesDefaultCodeTarget()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.Default;

// Act
var target = CodeTarget.CreateDefault(codeDocument, options);
var target = CodeTarget.CreateDefault(codeDocument);

// Assert
Assert.IsType<DefaultCodeTarget>(target);
Expand All @@ -32,10 +29,9 @@ public void CreateDefault_CallsDelegate()
Action<CodeTargetBuilder> @delegate = (b) => { wasCalled = true; };

var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.Default;

// Act
CodeTarget.CreateDefault(codeDocument, options, @delegate);
CodeTarget.CreateDefault(codeDocument, @delegate);

// Assert
Assert.True(wasCalled);
Expand All @@ -46,10 +42,9 @@ public void CreateDefault_AllowsNullDelegate()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.Default;

// Act
CodeTarget.CreateDefault(codeDocument, options, configure: null);
CodeTarget.CreateDefault(codeDocument, configure: null);

// Assert (does not throw)
}
Expand All @@ -59,10 +54,9 @@ public void CreateEmpty_AllowsNullDelegate()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.Default;

// Act
CodeTarget.CreateDefault(codeDocument, options, configure: null);
CodeTarget.CreateDefault(codeDocument, configure: null);

// Assert (does not throw)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using Xunit;

namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration;
Expand All @@ -14,19 +12,18 @@ public void Build_CreatesDefaultCodeTarget()
{
// Arrange
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var options = RazorCodeGenerationOptions.Default;

var builder = new DefaultCodeTargetBuilder(codeDocument, options);
var builder = new DefaultCodeTargetBuilder(codeDocument);

var extensions = new ICodeTargetExtension[]
{
new MyExtension1(),
new MyExtension2(),
new MyExtension1(),
new MyExtension2(),
};

for (var i = 0; i < extensions.Length; i++)
foreach (var extension in extensions)
{
builder.TargetExtensions.Add(extensions[i]);
builder.TargetExtensions.Add(extension);
}

// Act
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System.Linq;
using System.Collections.Immutable;
using Xunit;

namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration;

public class DefaultCodeTargetTest
{
[Fact]
public void Constructor_CreatesDefensiveCopy()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;

var extensions = new ICodeTargetExtension[]
{
new MyExtension2(),
new MyExtension1(),
};

// Act
var target = new DefaultCodeTarget(options, extensions);

// Assert
Assert.NotSame(extensions, target);
}

[Fact]
public void CreateWriter_DesignTime_CreatesDesignTimeNodeWriter()
{
// Arrange
var options = RazorCodeGenerationOptions.DesignTimeDefault;
var target = new DefaultCodeTarget(options, Enumerable.Empty<ICodeTargetExtension>());
var codeDocument = RazorCodeDocument.Create(
TestRazorSourceDocument.Create(),
codeGenerationOptions: RazorCodeGenerationOptions.DesignTimeDefault);
var target = new DefaultCodeTarget(codeDocument, extensions: []);

// Act
var writer = target.CreateNodeWriter();
Expand All @@ -47,8 +28,8 @@ public void CreateWriter_DesignTime_CreatesDesignTimeNodeWriter()
public void CreateWriter_Runtime_CreatesRuntimeNodeWriter()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;
var target = new DefaultCodeTarget(options, Enumerable.Empty<ICodeTargetExtension>());
var codeDocument = TestRazorCodeDocument.CreateEmpty();
var target = new DefaultCodeTarget(codeDocument, extensions: []);

// Act
var writer = target.CreateNodeWriter();
Expand All @@ -61,15 +42,14 @@ public void CreateWriter_Runtime_CreatesRuntimeNodeWriter()
public void HasExtension_ReturnsTrue_WhenExtensionFound()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;
var codeDocument = TestRazorCodeDocument.CreateEmpty();

var extensions = new ICodeTargetExtension[]
{
new MyExtension2(),
new MyExtension1(),
};
ImmutableArray<ICodeTargetExtension> extensions = [
new MyExtension2(),
new MyExtension1()
];

var target = new DefaultCodeTarget(options, extensions);
var target = new DefaultCodeTarget(codeDocument, extensions);

// Act
var result = target.HasExtension<MyExtension1>();
Expand All @@ -82,15 +62,14 @@ public void HasExtension_ReturnsTrue_WhenExtensionFound()
public void HasExtension_ReturnsFalse_WhenExtensionNotFound()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;
var codeDocument = TestRazorCodeDocument.CreateEmpty();

var extensions = new ICodeTargetExtension[]
{
new MyExtension2(),
new MyExtension2(),
};
ImmutableArray<ICodeTargetExtension> extensions = [
new MyExtension2(),
new MyExtension2()
];

var target = new DefaultCodeTarget(options, extensions);
var target = new DefaultCodeTarget(codeDocument, extensions);

// Act
var result = target.HasExtension<MyExtension1>();
Expand All @@ -103,15 +82,14 @@ public void HasExtension_ReturnsFalse_WhenExtensionNotFound()
public void GetExtension_ReturnsExtension_WhenExtensionFound()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;
var codeDocument = TestRazorCodeDocument.CreateEmpty();

var extensions = new ICodeTargetExtension[]
{
new MyExtension2(),
new MyExtension1(),
};
ImmutableArray<ICodeTargetExtension> extensions = [
new MyExtension2(),
new MyExtension1()
];

var target = new DefaultCodeTarget(options, extensions);
var target = new DefaultCodeTarget(codeDocument, extensions);

// Act
var result = target.GetExtension<MyExtension1>();
Expand All @@ -124,17 +102,16 @@ public void GetExtension_ReturnsExtension_WhenExtensionFound()
public void GetExtension_ReturnsFirstMatch_WhenExtensionFound()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;
var codeDocument = TestRazorCodeDocument.CreateEmpty();

var extensions = new ICodeTargetExtension[]
{
new MyExtension2(),
new MyExtension1(),
new MyExtension2(),
new MyExtension1(),
};
ImmutableArray<ICodeTargetExtension> extensions = [
new MyExtension2(),
new MyExtension1(),
new MyExtension2(),
new MyExtension1()
];

var target = new DefaultCodeTarget(options, extensions);
var target = new DefaultCodeTarget(codeDocument, extensions);

// Act
var result = target.GetExtension<MyExtension1>();
Expand All @@ -148,15 +125,14 @@ public void GetExtension_ReturnsFirstMatch_WhenExtensionFound()
public void GetExtension_ReturnsNull_WhenExtensionNotFound()
{
// Arrange
var options = RazorCodeGenerationOptions.Default;
var codeDocument = TestRazorCodeDocument.CreateEmpty();

var extensions = new ICodeTargetExtension[]
{
new MyExtension2(),
new MyExtension2(),
};
ImmutableArray<ICodeTargetExtension> extensions = [
new MyExtension2(),
new MyExtension2()
];

var target = new DefaultCodeTarget(options, extensions);
var target = new DefaultCodeTarget(codeDocument, extensions);

// Act
var result = target.GetExtension<MyExtension1>();
Expand Down
Loading