+ }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument, verifyLinePragmas: false);
+ CompileToAssembly(generated,
+ // x:\dir\subdir\Test\TestComponent.cshtml(7,1): error CS1028: Unexpected preprocessor directive
+ // #endif
+ Diagnostic(ErrorCode.ERR_UnexpectedDirective, "#endif").WithLocation(7, 1));
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_01()
+ {
+ var generated = CompileToCSharp("""
+ @{ #if true }
+ @{ #endif }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated,
+ // x:\dir\subdir\Test\TestComponent.cshtml(1,13): error CS1025: Single-line comment or end-of-line expected
+ // #if true }
+ Diagnostic(ErrorCode.ERR_EndOfPPLineExpected, "}").WithLocation(1, 13),
+ // x:\dir\subdir\Test\TestComponent.cshtml(2,11): error CS1025: Single-line comment or end-of-line expected
+ // #endif }
+ Diagnostic(ErrorCode.ERR_EndOfPPLineExpected, "}").WithLocation(2, 11));
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_02()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ /* test */ #if true
+ }
+ @{
+ /* test */ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated,
+ // x:\dir\subdir\Test\TestComponent.cshtml(2,12): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
+ // /* test */ #if true
+ Diagnostic(ErrorCode.ERR_BadDirectivePlacement, "#").WithLocation(2, 12),
+ // x:\dir\subdir\Test\TestComponent.cshtml(5,12): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
+ // /* test */ #endif
+ Diagnostic(ErrorCode.ERR_BadDirectivePlacement, "#").WithLocation(5, 12));
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_03()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #pragma warning disable 219
+ var x = 1; #if true
+ }
+ @{
+ var y = 2; #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated,
+ // x:\dir\subdir\Test\TestComponent.cshtml(3,12): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
+ // var x = 1; #if true
+ Diagnostic(ErrorCode.ERR_BadDirectivePlacement, "#").WithLocation(3, 12),
+ // x:\dir\subdir\Test\TestComponent.cshtml(6,12): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
+ // var y = 2; #endif
+ Diagnostic(ErrorCode.ERR_BadDirectivePlacement, "#").WithLocation(6, 12));
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_04()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ var x = #if true;
+ }
+ @{
+ x #endif;
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated,
+ // x:\dir\subdir\Test\TestComponent.cshtml(2,9): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
+ // var x = #if true;
+ Diagnostic(ErrorCode.ERR_BadDirectivePlacement, "#").WithLocation(2, 9),
+ // x:\dir\subdir\Test\TestComponent.cshtml(2,17): error CS1025: Single-line comment or end-of-line expected
+ // var x = #if true;
+ Diagnostic(ErrorCode.ERR_EndOfPPLineExpected, ";").WithLocation(2, 17),
+ // x:\dir\subdir\Test\TestComponent.cshtml(5,1): error CS0841: Cannot use local variable 'x' before it is declared
+ // x #endif;
+ Diagnostic(ErrorCode.ERR_VariableUsedBeforeDeclaration, "x").WithArguments("x").WithLocation(5, 1),
+ // x:\dir\subdir\Test\TestComponent.cshtml(5,2): error CS1002: ; expected
+ // x #endif;
+ Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(5, 2),
+ // x:\dir\subdir\Test\TestComponent.cshtml(5,3): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line
+ // x #endif;
+ Diagnostic(ErrorCode.ERR_BadDirectivePlacement, "#").WithLocation(5, 3),
+ // x:\dir\subdir\Test\TestComponent.cshtml(5,9): error CS1025: Single-line comment or end-of-line expected
+ // x #endif;
+ Diagnostic(ErrorCode.ERR_EndOfPPLineExpected, ";").WithLocation(5, 9));
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_05()
+ {
+ var generated = CompileToCSharp("""
+ @{
+
#if true
+ }
+ @{
+
#endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument, verifyLinePragmas: false);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_06()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if true
+ }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_07()
+ {
+ // This test uses tabs as the leading whitespace
+ var generated = CompileToCSharp("""
+ @{
+ #if true
+ }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_08()
+ {
+ // vertical tab
+ var generated = CompileToCSharp($$"""
+ @{
+ {{'\v'}}#if true
+ }
+ @{
+ {{'\v'}}#endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_09()
+ {
+ // Form feed
+ var generated = CompileToCSharp($$"""
+ @{
+ {{'\f'}}#if true
+ }
+ @{
+ {{'\f'}}#endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_10()
+ {
+ // NBSP
+ var generated = CompileToCSharp($$"""
+ @{
+ {{'\u00A0'}}#if true
+ }
+ @{
+ {{'\u00A0'}}#endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void StartOfLine_11()
+ {
+ // ZWNBSP
+ var generated = CompileToCSharp($$"""
+ @{
+ {{'\uFEFF'}}#if true
+ }
+ @{
+ {{'\uFEFF'}}#endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_01()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{ #endif }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ var expectedDiagnostic = DesignTime ?
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(14,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(14, 1),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10)
+ }
+ :
+ new[]
+ {
+
+ // x:\dir\subdir\Test\TestComponent.cshtml(15,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(15, 1),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10)
+ };
+
+ CompileToAssembly(generated, expectedDiagnostic);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_02()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{ Test #endif }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ var expectedDiagnostics = DesignTime ?
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(14,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(14, 1),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10)
+ }
+ :
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(15,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(15, 1),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10)
+ };
+
+ CompileToAssembly(generated, expectedDiagnostics);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_03()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{
+ /* test */ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ var expectedDiagnostics = DesignTime ?
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(16,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(16, 1),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10)
+ }
+ :
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(17,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(17, 1),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10)
+ };
+
+ CompileToAssembly(generated, expectedDiagnostics);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_04()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{
+ /* test */ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ var expectedDiagnostics = DesignTime ?
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(16,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(16, 1),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10)
+ }
+ :
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(17,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(17, 1),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10)
+ };
+
+ CompileToAssembly(generated, expectedDiagnostics);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_05()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{
+
#endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ var expectedDiagnostics = DesignTime ?
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(16,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(16, 1),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10),
+ // (26,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(26, 10)
+ }
+ :
+ new[]
+ {
+ // x:\dir\subdir\Test\TestComponent.cshtml(17,1): error CS1027: #endif directive expected
+ //
+ Diagnostic(ErrorCode.ERR_EndifDirectiveExpected, "").WithLocation(17, 1),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10),
+ // (19,10): error CS1513: } expected
+ // {
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(19, 10)
+ };
+
+ CompileToAssembly(generated, expectedDiagnostics);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_06()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{ #else }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_07()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{ Test #else }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_08()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{
+ /* test */ #else
+ }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_09()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{
+ /* test */ #else
+ }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+ CompileToAssembly(generated);
+ }
+
+ [IntegrationTestFact]
+ public void MisplacedEndingDirective_10()
+ {
+ var generated = CompileToCSharp("""
+ @{
+ #if false
+ }
+ @{
+
#else
+ }
+ @{
+ #endif
+ }
+ """);
+
+ AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
+ AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
+
+ CompileToAssembly(generated);
+ }
+}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpBlockTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpBlockTest.cs
index e1fa97a2bcf..d858ef1df4e 100644
--- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpBlockTest.cs
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpBlockTest.cs
@@ -906,6 +906,20 @@ public void EscapedIdentifiers_13()
""");
}
+ [Fact]
+ public void Usings()
+ {
+ ParseDocumentTest("""
+ {
+ @using global::System
+ @using global::System.Collections.Generic
+ @using global::System.Linq
+ @using global::System.Threading.Tasks
+ @using global::Microsoft.AspNetCore.Components
+ }
+ """);
+ }
+
private void RunRazorCommentBetweenClausesTest(string preComment, string postComment, AcceptedCharactersInternal acceptedCharacters = AcceptedCharactersInternal.Any)
{
ParseDocumentTest(preComment + "@* Foo *@ @* Bar *@" + postComment);
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpPreprocessorTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpPreprocessorTest.cs
new file mode 100644
index 00000000000..8653c45f23b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpPreprocessorTest.cs
@@ -0,0 +1,365 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Collections.Immutable;
+using Microsoft.CodeAnalysis.CSharp;
+using Xunit;
+
+namespace Microsoft.AspNetCore.Razor.Language.Legacy;
+
+public class CSharpPreprocessorTest() : ParserTestBase(layer: TestProject.Layer.Compiler)
+{
+ [Fact]
+ public void Pragmas()
+ {
+ ParseDocumentTest("""
+ @{
+ #pragma warning disable 123
+ #pragma warning restore 123
+ #pragma checksum "file.cs" "{00000000-0000-0000-0000-000000000000}" "1234"
+ }
+ """);
+ }
+
+ [Fact]
+ public void NullableDirectives()
+ {
+ ParseDocumentTest("""
+ @{
+ #nullable enable
+ #nullable disable
+ #nullable restore
+ #nullable enable annotations
+ #nullable disable annotations
+ #nullable restore annotations
+ #nullable enable warnings
+ #nullable disable warnings
+ #nullable restore warnings
+ }
+ """);
+ }
+
+ [Fact]
+ public void DefineThenIfDef()
+ {
+ ParseDocumentTest("""
+ @{
+ #define SYMBOL
+ #if SYMBOL
+ #undef SYMBOL
+ #if SYMBOL
+ var x = 1;
+ #endif
+ #else
+ var x = 1;
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void ErrorWarningLine()
+ {
+ ParseDocumentTest("""
+ @{
+ #line 1 "file.cs"
+ #error This is an error
+ #line default
+ #warning This is a warning
+ #line hidden
+ #line (1, 1) - (5, 60) 10 "partial-class.cs"
+ }
+ """);
+ }
+
+ [Fact]
+ public void Regions()
+ {
+ ParseDocumentTest("""
+ @{
+ #region MyRegion }
+ #endregion
+ }
+ """);
+ }
+
+ [Fact]
+ public void SimpleIfDef_01()
+ {
+ ParseDocumentTest("""
+ @{
+ #if true
+ var x = 1;
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void SimpleIfDef_02()
+ {
+ ParseDocumentTest("""
+ @{
+ #if true
+
Some text
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfDefFromParseOptions_Symbol()
+ {
+ IfDefFromParseOptions("SYMBOL");
+ }
+
+ [Fact]
+ public void IfDefFromParseOptions_Symbol2()
+ {
+ IfDefFromParseOptions("SYMBOL2");
+ }
+
+ [Fact]
+ public void IfDefFromParseOptions_None()
+ {
+ IfDefFromParseOptions(null);
+ }
+
+ private void IfDefFromParseOptions(string? directive)
+ {
+ var parseOptions = CSharpParseOptions.Default;
+
+ if (directive != null)
+ {
+ parseOptions = parseOptions.WithPreprocessorSymbols(ImmutableArray.Create(directive));
+ }
+
+ ParseDocumentTest("""
+ @{
+ #if SYMBOL
+ var x = 1;
+ #elif SYMBOL2
+ var x = 2;
+ #else
+ var x = 3;
+ #endif
+ }
+ """, parseOptions);
+ }
+
+ [Fact]
+ public void IfDefAcrossMultipleBlocks()
+ {
+ ParseDocumentTest("""
+ @{
+ #if false
+ var x = 1;
+ }
+
+
+
+ @{
+ var y = 2;
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfDefDisabledSectionUnbalanced()
+ {
+ ParseDocumentTest("""
+ @{
+ #if false
+ void M() {
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfDefNotOnNewline_01()
+ {
+ ParseDocumentTest("""
+ @{ #if false }
+
+ @{
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfDefNotOnNewline_02()
+ {
+ ParseDocumentTest("""
+ @{#if false }
+
+ @{
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void ElIfNotOnNewline()
+ {
+ ParseDocumentTest("""
+ @{
+ #if true
+ }
+
+ @{ #elif false }
+
+ @{
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void ElseNotOnNewline()
+ {
+ ParseDocumentTest("""
+ @{
+ #if true
+ }
+
+ @{ #else }
+
+ @{
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void EndIfNotOnNewline()
+ {
+ ParseDocumentTest("""
+ @{
+ #if false
+ }
+
+ @{ #endif }
+ """);
+ }
+
+ [Fact]
+ public void UsingStatementResults()
+ {
+ ParseDocumentTest("""
+ @using (var test = blah)
+ #if true
+ {
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfStatementAfterIf()
+ {
+ ParseDocumentTest("""
+ @if (true)
+ #if true
+ {
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfStatementAfterIfBlock()
+ {
+ ParseDocumentTest("""
+ @if (true)
+ {
+ #if true
+ }
+ #endif
+ """);
+ }
+
+ [Fact]
+ public void IfStatementAfterIfBeforeElseIf()
+ {
+ ParseDocumentTest("""
+ @if (true)
+ {
+ }
+ #if true
+ else if (false)
+ #endif
+ {
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfStatementAfterElseIf()
+ {
+ ParseDocumentTest("""
+ @if (true)
+ {
+ }
+ else if (false)
+ #if true
+ {
+ #endif
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfStatementAfterElseIfBeforeElse()
+ {
+ ParseDocumentTest("""
+ @if (true)
+ {
+ }
+ else if (false)
+ {
+ }
+ #if true
+ else
+ #endif
+ {
+ }
+ """);
+ }
+
+ [Fact]
+ public void IfStatementAfterElse()
+ {
+ ParseDocumentTest("""
+ @if (true)
+ {
+ }
+ else if (false)
+ {
+ }
+ else
+ #if true
+ {
+ #endif
+ }
+ """);
+ }
+}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpTokenizerOperatorsTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpTokenizerOperatorsTest.cs
index 05120b41887..677119d077b 100644
--- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpTokenizerOperatorsTest.cs
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Legacy/CSharpTokenizerOperatorsTest.cs
@@ -287,11 +287,4 @@ public void RightShift_Is_Not_Specially_Recognized()
SyntaxFactory.Token(SyntaxKind.GreaterThan, ">"),
SyntaxFactory.Token(SyntaxKind.GreaterThan, ">"));
}
-
- // PROTOTYPE: Re-enable
- // [Fact]
- // public void Hash_Is_Recognized()
- // {
- // TestSingleToken("#", SyntaxKind.Hash);
- // }
}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorDiagnosticDescriptorTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorDiagnosticDescriptorTest.cs
index 23d6e2f4b75..d57ad2cc813 100644
--- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorDiagnosticDescriptorTest.cs
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorDiagnosticDescriptorTest.cs
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
+using System.Collections.Generic;
+using System.Linq;
using Xunit;
namespace Microsoft.AspNetCore.Razor.Language;
@@ -74,4 +77,30 @@ public void RazorDiagnosticDescriptor_HashCodesNotEqual()
// Assert
Assert.False(result);
}
+
+ [Fact]
+ public void NoDuplicateDiagnosticIds()
+ {
+ var ids = new HashSet
(StringComparer.Ordinal);
+ var factoryType = typeof(RazorDiagnosticFactory);
+
+ addAllDescriptors(ids, factoryType, typeof(AspNetCore.Razor.Language.RazorDiagnosticDescriptor));
+ addAllDescriptors(ids, factoryType, typeof(CodeAnalysis.Razor.RazorDiagnosticFactory));
+ addAllDescriptors(ids, factoryType, typeof(AspNetCore.Razor.Language.Components.ComponentDiagnosticFactory));
+ addAllDescriptors(ids, factoryType, typeof(AspNetCore.Mvc.Razor.Extensions.RazorExtensionsDiagnosticFactory));
+
+ static void addAllDescriptors(HashSet ids, Type factoryType, Type diagnosticDescriptorType)
+ {
+ foreach (var field in factoryType.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).Where(f => f.FieldType == diagnosticDescriptorType))
+ {
+ var descriptor = (RazorDiagnosticDescriptor)field.GetValue(null)!;
+ if (ids.Contains(descriptor.Id))
+ {
+ Assert.Fail($"Duplicate diagnostic id '{descriptor.Id}' found.");
+ }
+
+ ids.Add(descriptor.Id);
+ }
+ }
+ }
}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.codegen.cs
new file mode 100644
index 00000000000..405ead4942a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+
+
+#nullable restore
+#line 6 "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..39bfbdef6f6
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.diagnostics.txt
@@ -0,0 +1,4 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+x:\dir\subdir\Test\TestComponent.razor(2,5): Error RZ9980: Unclosed tag 'div' with no matching end tag.
+x:\dir\subdir\Test\TestComponent.razor(2,6): Error RZ1025: The "div" element was not closed. All elements must be either self-closing or have a matching end tag.
+x:\dir\subdir\Test\TestComponent.razor(4,5): Error RZ9980: Unclosed tag 'div' with no matching end tag.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.ir.txt
new file mode 100644
index 00000000000..1c33749dbb5
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.ir.txt
@@ -0,0 +1,28 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [6] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [6] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ MarkupElement - (8:1,4 [44] x:\dir\subdir\Test\TestComponent.razor) - div
+ HtmlContent - (13:1,9 [16] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (13:1,9 [16] x:\dir\subdir\Test\TestComponent.razor) - Html - \n#if true\n
+ MarkupElement - (29:3,4 [23] x:\dir\subdir\Test\TestComponent.razor) - div
+ HtmlContent - (34:3,9 [5] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (34:3,9 [5] x:\dir\subdir\Test\TestComponent.razor) - Html - \n}\n
+ CSharpCode - (41:5,2 [10] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (41:5,2 [10] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
+ CSharpCode - (52:7,1 [0] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (52:7,1 [0] x:\dir\subdir\Test\TestComponent.razor) - CSharp -
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.mappings.txt
new file mode 100644
index 00000000000..98f3dd79d12
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/AfterTag/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [6] x:\dir\subdir\Test\TestComponent.razor)
+|
+ |
+Generated Location: (917:26,2 [6] )
+|
+ |
+
+Source Location: (41:5,2 [10] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (996:30,2 [10] )
+|
+#endif
+|
+
+Source Location: (52:7,1 [0] x:\dir\subdir\Test\TestComponent.razor)
+||
+Generated Location: (1057:36,1 [0] )
+||
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.codegen.cs
new file mode 100644
index 00000000000..15bb25bb7cc
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.codegen.cs
@@ -0,0 +1,40 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#define SomeSymbol
+#undef SomeSymbol
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..81e184a8cb9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(2,1): Error RZ1042: '#define' and '#undef' cannot be used in razor markup.
+x:\dir\subdir\Test\TestComponent.razor(3,1): Error RZ1042: '#define' and '#undef' cannot be used in razor markup.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.ir.txt
new file mode 100644
index 00000000000..beaf2a3c125
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [41] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [41] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#define SomeSymbol\n#undef SomeSymbol\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.mappings.txt
new file mode 100644
index 00000000000..6260a12aa65
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.mappings.txt
@@ -0,0 +1,11 @@
+Source Location: (2:0,2 [41] x:\dir\subdir\Test\TestComponent.razor)
+|
+#define SomeSymbol
+#undef SomeSymbol
+|
+Generated Location: (986:28,2 [41] )
+|
+#define SomeSymbol
+#undef SomeSymbol
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..ea917289677
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.codegen.cs
@@ -0,0 +1,41 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+ Some text
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..843d40d0fe9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [43] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [43] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n Some text
\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..0e191edb0d4
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/DisabledText_01/TestComponent.mappings.txt
@@ -0,0 +1,13 @@
+Source Location: (2:0,2 [43] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+ Some text
+#endif
+|
+Generated Location: (986:28,2 [43] )
+|
+#if false
+ Some text
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.codegen.cs
new file mode 100644
index 00000000000..c9504c2833d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.ir.txt
new file mode 100644
index 00000000000..4f53dbddb70
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#pragma warning disable 219 // variable declared but not used\n#if true\n var x = 1;\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.mappings.txt
new file mode 100644
index 00000000000..6af2997bec9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [99] x:\dir\subdir\Test\TestComponent.razor)
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+Generated Location: (986:28,2 [99] )
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..2a21d32d6c3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.codegen.cs
@@ -0,0 +1,41 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ #endif }
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..3e562b47dce
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(4,4): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..d5521d4f438
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [27] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [27] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ #endif }
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..f437cfc9844
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.mappings.txt
@@ -0,0 +1,11 @@
+Source Location: (2:0,2 [27] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ #endif }|
+Generated Location: (986:28,2 [27] )
+|
+#if false
+}
+@{ #endif }|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.codegen.cs
new file mode 100644
index 00000000000..44ecb3e9fe8
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.codegen.cs
@@ -0,0 +1,41 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ Test #endif }
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..795fd53013a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(4,9): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.ir.txt
new file mode 100644
index 00000000000..9880e71b4f4
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [32] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [32] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ Test #endif }
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.mappings.txt
new file mode 100644
index 00000000000..08e68598ca3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.mappings.txt
@@ -0,0 +1,11 @@
+Source Location: (2:0,2 [32] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ Test #endif }|
+Generated Location: (986:28,2 [32] )
+|
+#if false
+}
+@{ Test #endif }|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.codegen.cs
new file mode 100644
index 00000000000..5d1b22dc58a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.codegen.cs
@@ -0,0 +1,43 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #endif
+}
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..9ec9ceea358
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.ir.txt
new file mode 100644
index 00000000000..27d684786c3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #endif\n}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.mappings.txt
new file mode 100644
index 00000000000..0ce431c3ca2
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+Generated Location: (986:28,2 [40] )
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.codegen.cs
new file mode 100644
index 00000000000..5d1b22dc58a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.codegen.cs
@@ -0,0 +1,43 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #endif
+}
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..9ec9ceea358
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.ir.txt
new file mode 100644
index 00000000000..27d684786c3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #endif\n}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.mappings.txt
new file mode 100644
index 00000000000..0ce431c3ca2
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+Generated Location: (986:28,2 [40] )
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.codegen.cs
new file mode 100644
index 00000000000..715d0e79901
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.codegen.cs
@@ -0,0 +1,43 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+#endif
+}
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..8cace6a0b73
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(5,6): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.ir.txt
new file mode 100644
index 00000000000..1bce84ebbe6
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n#endif
\n}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.mappings.txt
new file mode 100644
index 00000000000..1cc3d69178b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+#endif
+}|
+Generated Location: (986:28,2 [40] )
+|
+#if false
+}
+@{
+#endif
+}|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.codegen.cs
new file mode 100644
index 00000000000..8c67dbe862d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.codegen.cs
@@ -0,0 +1,43 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ #else }
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..e769081ec2d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(4,4): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.ir.txt
new file mode 100644
index 00000000000..caa3f6f9b40
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ #else }\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.mappings.txt
new file mode 100644
index 00000000000..0758141e7fb
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.mappings.txt
@@ -0,0 +1,17 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ #else }
+@{
+#endif
+|
+Generated Location: (986:28,2 [40] )
+|
+#if false
+}
+@{ #else }
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.codegen.cs
new file mode 100644
index 00000000000..88b92bb4700
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.codegen.cs
@@ -0,0 +1,43 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ Test #else }
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..9db7a3b206f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(4,9): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.ir.txt
new file mode 100644
index 00000000000..363ef118761
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ Test #else }\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.mappings.txt
new file mode 100644
index 00000000000..b8a607a0208
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.mappings.txt
@@ -0,0 +1,17 @@
+Source Location: (2:0,2 [45] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ Test #else }
+@{
+#endif
+|
+Generated Location: (986:28,2 [45] )
+|
+#if false
+}
+@{ Test #else }
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.codegen.cs
new file mode 100644
index 00000000000..197093fcb6d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.codegen.cs
@@ -0,0 +1,45 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..d07194cdc17
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.ir.txt
new file mode 100644
index 00000000000..5feff7e6515
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #else\n}\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.mappings.txt
new file mode 100644
index 00000000000..16ffa33a721
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+Generated Location: (986:28,2 [53] )
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.codegen.cs
new file mode 100644
index 00000000000..197093fcb6d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.codegen.cs
@@ -0,0 +1,45 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..d07194cdc17
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.ir.txt
new file mode 100644
index 00000000000..5feff7e6515
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #else\n}\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.mappings.txt
new file mode 100644
index 00000000000..16ffa33a721
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+Generated Location: (986:28,2 [53] )
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.codegen.cs
new file mode 100644
index 00000000000..b2e6def9652
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.codegen.cs
@@ -0,0 +1,45 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+#else
+}
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..bf174dea560
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(5,6): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.ir.txt
new file mode 100644
index 00000000000..067b646a506
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n#else
\n}\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.mappings.txt
new file mode 100644
index 00000000000..798ba23bd06
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+#else
+}
+@{
+#endif
+|
+Generated Location: (986:28,2 [53] )
+|
+#if false
+}
+@{
+#else
+}
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..ec7ffa458df
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.codegen.cs
@@ -0,0 +1,48 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if SomeSymbol
+
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 3 "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..7f8a293ae41
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.ir.txt
@@ -0,0 +1,23 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [22] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [22] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if SomeSymbol\n
+ MarkupElement - (24:2,4 [16] x:\dir\subdir\Test\TestComponent.razor) - p
+ HtmlContent - (27:2,7 [9] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (27:2,7 [9] x:\dir\subdir\Test\TestComponent.razor) - Html - Some text
+ CSharpCode - (40:2,20 [10] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (40:2,20 [10] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..5ebdaa2d252
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [22] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if SomeSymbol
+ |
+Generated Location: (986:28,2 [22] )
+|
+#if SomeSymbol
+ |
+
+Source Location: (40:2,20 [10] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (1149:37,20 [10] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.codegen.cs
new file mode 100644
index 00000000000..8f48a7307e1
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.codegen.cs
@@ -0,0 +1,41 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if !SomeSymbol
+ Some text
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.ir.txt
new file mode 100644
index 00000000000..d470dcea5a0
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [49] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [49] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if !SomeSymbol\n Some text
\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.mappings.txt
new file mode 100644
index 00000000000..272a4fa2199
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.mappings.txt
@@ -0,0 +1,13 @@
+Source Location: (2:0,2 [49] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if !SomeSymbol
+ Some text
+#endif
+|
+Generated Location: (986:28,2 [49] )
+|
+#if !SomeSymbol
+ Some text
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.codegen.cs
new file mode 100644
index 00000000000..6298cd47cd3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
+
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.ir.txt
new file mode 100644
index 00000000000..28c85a2cf76
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.ir.txt
@@ -0,0 +1,18 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.cshtml)
+ LazyIntermediateToken - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n#pragma warning disable 219 // variable declared but not used\n#if true\n var x = 1;\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.mappings.txt
new file mode 100644
index 00000000000..bfb65e81c94
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [99] x:\dir\subdir\Test\TestComponent.cshtml)
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+Generated Location: (987:28,2 [99] )
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..b217c3d0b0f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.codegen.cs
@@ -0,0 +1,45 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+ #if true }
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 2 "x:\dir\subdir\Test\TestComponent.razor"
+ #endif }
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..ade23f6812a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.diagnostics.txt
@@ -0,0 +1,5 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+x:\dir\subdir\Test\TestComponent.razor(1,4): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(2,2): Error RZ1010: Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.
+x:\dir\subdir\Test\TestComponent.razor(2,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+x:\dir\subdir\Test\TestComponent.razor(2,4): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..8fed836a353
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - #if true }\n
+ CSharpCode - (17:1,2 [9] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (17:1,2 [9] x:\dir\subdir\Test\TestComponent.razor) - CSharp - #endif }
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..7838fb06523
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.mappings.txt
@@ -0,0 +1,12 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+| #if true }
+|
+Generated Location: (986:28,2 [13] )
+| #if true }
+|
+
+Source Location: (17:1,2 [9] x:\dir\subdir\Test\TestComponent.razor)
+| #endif }|
+Generated Location: (1120:35,2 [9] )
+| #endif }|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.codegen.cs
new file mode 100644
index 00000000000..edb7b50d9e3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+/* test */ #if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+/* test */ #endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..dcc476581b2
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(2,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(5,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.ir.txt
new file mode 100644
index 00000000000..1d84332d429
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [23] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [23] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n/* test */ #if true\n
+ CSharpCode - (30:3,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (30:3,2 [21] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n/* test */ #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.mappings.txt
new file mode 100644
index 00000000000..1c39848192d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [23] x:\dir\subdir\Test\TestComponent.razor)
+|
+/* test */ #if true
+|
+Generated Location: (986:28,2 [23] )
+|
+/* test */ #if true
+|
+
+Source Location: (30:3,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+|
+/* test */ #endif
+|
+Generated Location: (1130:36,2 [21] )
+|
+/* test */ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.codegen.cs
new file mode 100644
index 00000000000..a03adf625fc
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.codegen.cs
@@ -0,0 +1,48 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#pragma warning disable 219
+var x = 1; #if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 5 "x:\dir\subdir\Test\TestComponent.razor"
+
+var y = 2; #endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..6de12f462d9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(3,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(6,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.ir.txt
new file mode 100644
index 00000000000..f204c8c132d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [52] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [52] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#pragma warning disable 219\nvar x = 1; #if true\n
+ CSharpCode - (59:4,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (59:4,2 [21] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \nvar y = 2; #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.mappings.txt
new file mode 100644
index 00000000000..c14b49d007d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.mappings.txt
@@ -0,0 +1,20 @@
+Source Location: (2:0,2 [52] x:\dir\subdir\Test\TestComponent.razor)
+|
+#pragma warning disable 219
+var x = 1; #if true
+|
+Generated Location: (986:28,2 [52] )
+|
+#pragma warning disable 219
+var x = 1; #if true
+|
+
+Source Location: (59:4,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+|
+var y = 2; #endif
+|
+Generated Location: (1159:37,2 [21] )
+|
+var y = 2; #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.codegen.cs
new file mode 100644
index 00000000000..49dca9ea6d1
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+var x = #if true;
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+x #endif;
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..a09c47e3599
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(2,9): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(5,3): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.ir.txt
new file mode 100644
index 00000000000..910d6a080f9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [21] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \nvar x = #if true;\n
+ CSharpCode - (28:3,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (28:3,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \nx #endif;\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.mappings.txt
new file mode 100644
index 00000000000..8391296cbf0
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+|
+var x = #if true;
+|
+Generated Location: (986:28,2 [21] )
+|
+var x = #if true;
+|
+
+Source Location: (28:3,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+x #endif;
+|
+Generated Location: (1128:36,2 [13] )
+|
+x #endif;
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.codegen.cs
new file mode 100644
index 00000000000..42c6a1923df
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.codegen.cs
@@ -0,0 +1,39 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+
+
+
+
+
+
+
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.ir.txt
new file mode 100644
index 00000000000..ffff14e63e4
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.ir.txt
@@ -0,0 +1,30 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ MarkupElement - (4:1,0 [19] x:\dir\subdir\Test\TestComponent.razor) - div
+ HtmlContent - (9:1,5 [8] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (9:1,5 [8] x:\dir\subdir\Test\TestComponent.razor) - Html - #if true
+ CSharpCode - (23:1,19 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (23:1,19 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ CSharpCode - (30:3,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (30:3,2 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ MarkupElement - (32:4,0 [17] x:\dir\subdir\Test\TestComponent.razor) - div
+ HtmlContent - (37:4,5 [6] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (37:4,5 [6] x:\dir\subdir\Test\TestComponent.razor) - Html - #endif
+ CSharpCode - (49:4,17 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (49:4,17 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.mappings.txt
new file mode 100644
index 00000000000..183e10af207
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.mappings.txt
@@ -0,0 +1,28 @@
+Source Location: (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+|
+|
+Generated Location: (917:26,2 [2] )
+|
+|
+
+Source Location: (23:1,19 [2] x:\dir\subdir\Test\TestComponent.razor)
+|
+|
+Generated Location: (940:28,19 [2] )
+|
+|
+
+Source Location: (30:3,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+|
+|
+Generated Location: (946:30,2 [2] )
+|
+|
+
+Source Location: (49:4,17 [2] x:\dir\subdir\Test\TestComponent.razor)
+|
+|
+Generated Location: (967:32,17 [2] )
+|
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.codegen.cs
new file mode 100644
index 00000000000..94fc45e7c01
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+ #if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+ #endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.ir.txt
new file mode 100644
index 00000000000..1d780c999d9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [16] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [16] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #if true\n
+ CSharpCode - (23:3,2 [14] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (23:3,2 [14] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.mappings.txt
new file mode 100644
index 00000000000..ce6ca81474b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [16] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #if true
+|
+Generated Location: (986:28,2 [16] )
+|
+ #if true
+|
+
+Source Location: (23:3,2 [14] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #endif
+|
+Generated Location: (1123:36,2 [14] )
+|
+ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.codegen.cs
new file mode 100644
index 00000000000..80d4fbdda4f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+ #if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+ #endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.ir.txt
new file mode 100644
index 00000000000..98194fc9a04
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.mappings.txt
new file mode 100644
index 00000000000..29c562ba298
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #if true
+|
+Generated Location: (986:28,2 [13] )
+|
+ #if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #endif
+|
+Generated Location: (1120:36,2 [11] )
+|
+ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.codegen.cs
new file mode 100644
index 00000000000..72ed1bdfbd0
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.ir.txt
new file mode 100644
index 00000000000..8244fbe10c0
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.mappings.txt
new file mode 100644
index 00000000000..ce5560674bc
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if true
+|
+Generated Location: (986:28,2 [13] )
+|
+#if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (1120:36,2 [11] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.codegen.cs
new file mode 100644
index 00000000000..7e0ebf2640f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.ir.txt
new file mode 100644
index 00000000000..0eaeefd504f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.mappings.txt
new file mode 100644
index 00000000000..592b6e8123b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if true
+|
+Generated Location: (986:28,2 [13] )
+|
+#if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (1120:36,2 [11] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.codegen.cs
new file mode 100644
index 00000000000..d83115e7e7e
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+ #if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+ #endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.ir.txt
new file mode 100644
index 00000000000..d72229e802f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.mappings.txt
new file mode 100644
index 00000000000..517205df2d8
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #if true
+|
+Generated Location: (986:28,2 [13] )
+|
+ #if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #endif
+|
+Generated Location: (1120:36,2 [11] )
+|
+ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.codegen.cs
new file mode 100644
index 00000000000..daaada0827c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.codegen.cs
@@ -0,0 +1,47 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 219
+ private void __RazorDirectiveTokenHelpers__() {
+ }
+ #pragma warning restore 219
+ #pragma warning disable 0414
+ private static object __o = null;
+ #pragma warning restore 0414
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line 1 "x:\dir\subdir\Test\TestComponent.razor"
+
+#if true
+
+#line default
+#line hidden
+#nullable disable
+#nullable restore
+#line 4 "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.ir.txt
new file mode 100644
index 00000000000..d0b53f8a00b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.ir.txt
@@ -0,0 +1,20 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [20] ) - global::System
+ UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [25] ) - global::System.Linq
+ UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ DesignTimeDirective -
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning disable 0414
+ CSharpCode -
+ IntermediateToken - - CSharp - private static object __o = null;
+ CSharpCode -
+ IntermediateToken - - CSharp - #pragma warning restore 0414
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.mappings.txt
new file mode 100644
index 00000000000..af59ae9a61b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if true
+|
+Generated Location: (986:28,2 [13] )
+|
+#if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (1120:36,2 [11] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.codegen.cs
new file mode 100644
index 00000000000..9613e830339
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.codegen.cs
@@ -0,0 +1,39 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+ __builder.OpenElement(0, "div");
+ __builder.AddMarkupContent(1, "\r\n#if true\r\n ");
+ __builder.OpenElement(2, "div");
+ __builder.AddMarkupContent(3, "\r\n}\r\n");
+#nullable restore
+#line (6,3)-(8,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ __builder.CloseElement();
+ __builder.CloseElement();
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..39bfbdef6f6
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.diagnostics.txt
@@ -0,0 +1,4 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+x:\dir\subdir\Test\TestComponent.razor(2,5): Error RZ9980: Unclosed tag 'div' with no matching end tag.
+x:\dir\subdir\Test\TestComponent.razor(2,6): Error RZ1025: The "div" element was not closed. All elements must be either self-closing or have a matching end tag.
+x:\dir\subdir\Test\TestComponent.razor(4,5): Error RZ9980: Unclosed tag 'div' with no matching end tag.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.ir.txt
new file mode 100644
index 00000000000..186b30ac122
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.ir.txt
@@ -0,0 +1,21 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ MarkupElement - (8:1,4 [44] x:\dir\subdir\Test\TestComponent.razor) - div
+ HtmlContent - (13:1,9 [16] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (13:1,9 [16] x:\dir\subdir\Test\TestComponent.razor) - Html - \n#if true\n
+ MarkupElement - (29:3,4 [23] x:\dir\subdir\Test\TestComponent.razor) - div
+ HtmlContent - (34:3,9 [5] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (34:3,9 [5] x:\dir\subdir\Test\TestComponent.razor) - Html - \n}\n
+ CSharpCode - (41:5,2 [10] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (41:5,2 [10] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
+ CSharpCode - (52:7,1 [0] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (52:7,1 [0] x:\dir\subdir\Test\TestComponent.razor) - CSharp -
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.mappings.txt
new file mode 100644
index 00000000000..01c3cd890a1
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/AfterTag/TestComponent.mappings.txt
@@ -0,0 +1,9 @@
+Source Location: (41:5,2 [10] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (950:25,0 [10] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.codegen.cs
new file mode 100644
index 00000000000..6a97aed820c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.codegen.cs
@@ -0,0 +1,34 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(4,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#define SomeSymbol
+#undef SomeSymbol
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..81e184a8cb9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(2,1): Error RZ1042: '#define' and '#undef' cannot be used in razor markup.
+x:\dir\subdir\Test\TestComponent.razor(3,1): Error RZ1042: '#define' and '#undef' cannot be used in razor markup.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.ir.txt
new file mode 100644
index 00000000000..1462fdf0a9c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [41] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [41] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#define SomeSymbol\n#undef SomeSymbol\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.mappings.txt
new file mode 100644
index 00000000000..0854d1e069e
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DefineAndUndef/TestComponent.mappings.txt
@@ -0,0 +1,11 @@
+Source Location: (2:0,2 [41] x:\dir\subdir\Test\TestComponent.razor)
+|
+#define SomeSymbol
+#undef SomeSymbol
+|
+Generated Location: (733:21,0 [41] )
+|
+#define SomeSymbol
+#undef SomeSymbol
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..5568a7f490d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.codegen.cs
@@ -0,0 +1,35 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(5,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+ Some text
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..1ecf1ca0ae7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [43] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [43] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n Some text
\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..ffbabab12a7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/DisabledText_01/TestComponent.mappings.txt
@@ -0,0 +1,13 @@
+Source Location: (2:0,2 [43] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+ Some text
+#endif
+|
+Generated Location: (733:21,0 [43] )
+|
+#if false
+ Some text
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.codegen.cs
new file mode 100644
index 00000000000..50ddb6130fd
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.codegen.cs
@@ -0,0 +1,36 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.ir.txt
new file mode 100644
index 00000000000..f6b185b6770
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#pragma warning disable 219 // variable declared but not used\n#if true\n var x = 1;\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.mappings.txt
new file mode 100644
index 00000000000..489aba5e808
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/IfDefAndPragma/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [99] x:\dir\subdir\Test\TestComponent.razor)
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+Generated Location: (733:21,0 [99] )
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..2cf10985bc2
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.codegen.cs
@@ -0,0 +1,35 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(4,12) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ #endif }
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..3e562b47dce
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(4,4): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..7eae833c8a7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [27] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [27] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ #endif }
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..43cc84b0f22
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_01/TestComponent.mappings.txt
@@ -0,0 +1,11 @@
+Source Location: (2:0,2 [27] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ #endif }|
+Generated Location: (734:21,0 [27] )
+|
+#if false
+}
+@{ #endif }|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.codegen.cs
new file mode 100644
index 00000000000..ac2513aaaf9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.codegen.cs
@@ -0,0 +1,35 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(4,17) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ Test #endif }
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..795fd53013a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(4,9): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.ir.txt
new file mode 100644
index 00000000000..e2ad2dfaa46
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [32] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [32] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ Test #endif }
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.mappings.txt
new file mode 100644
index 00000000000..b7de6df6b30
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_02/TestComponent.mappings.txt
@@ -0,0 +1,11 @@
+Source Location: (2:0,2 [32] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ Test #endif }|
+Generated Location: (734:21,0 [32] )
+|
+#if false
+}
+@{ Test #endif }|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.codegen.cs
new file mode 100644
index 00000000000..6b7ca7766df
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.codegen.cs
@@ -0,0 +1,37 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(6,2) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #endif
+}
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..9ec9ceea358
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.ir.txt
new file mode 100644
index 00000000000..31c3f899f5c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #endif\n}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.mappings.txt
new file mode 100644
index 00000000000..f36f5d6f500
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_03/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+Generated Location: (733:21,0 [40] )
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.codegen.cs
new file mode 100644
index 00000000000..6b7ca7766df
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.codegen.cs
@@ -0,0 +1,37 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(6,2) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #endif
+}
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..9ec9ceea358
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.ir.txt
new file mode 100644
index 00000000000..31c3f899f5c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #endif\n}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.mappings.txt
new file mode 100644
index 00000000000..f36f5d6f500
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_04/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+Generated Location: (733:21,0 [40] )
+|
+#if false
+}
+@{
+/* test */ #endif
+}|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.codegen.cs
new file mode 100644
index 00000000000..eb224d3fd6e
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.codegen.cs
@@ -0,0 +1,37 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(6,2) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+#endif
+}
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..8cace6a0b73
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+(5,6): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.ir.txt
new file mode 100644
index 00000000000..6be3cef0d86
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n#endif
\n}
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.mappings.txt
new file mode 100644
index 00000000000..a52ce5c7e6f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_05/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+#endif
+}|
+Generated Location: (733:21,0 [40] )
+|
+#if false
+}
+@{
+#endif
+}|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.codegen.cs
new file mode 100644
index 00000000000..834e98a511f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.codegen.cs
@@ -0,0 +1,37 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(7,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ #else }
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..e769081ec2d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(4,4): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.ir.txt
new file mode 100644
index 00000000000..316a30d5518
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ #else }\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.mappings.txt
new file mode 100644
index 00000000000..b72da18fca7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_06/TestComponent.mappings.txt
@@ -0,0 +1,17 @@
+Source Location: (2:0,2 [40] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ #else }
+@{
+#endif
+|
+Generated Location: (733:21,0 [40] )
+|
+#if false
+}
+@{ #else }
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.codegen.cs
new file mode 100644
index 00000000000..014a01a24a7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.codegen.cs
@@ -0,0 +1,37 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(7,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{ Test #else }
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..9db7a3b206f
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(4,9): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.ir.txt
new file mode 100644
index 00000000000..90e8d9a6750
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{ Test #else }\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.mappings.txt
new file mode 100644
index 00000000000..3a5b52af815
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_07/TestComponent.mappings.txt
@@ -0,0 +1,17 @@
+Source Location: (2:0,2 [45] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{ Test #else }
+@{
+#endif
+|
+Generated Location: (733:21,0 [45] )
+|
+#if false
+}
+@{ Test #else }
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.codegen.cs
new file mode 100644
index 00000000000..e7c8942510b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.codegen.cs
@@ -0,0 +1,39 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(9,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..d07194cdc17
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.ir.txt
new file mode 100644
index 00000000000..b9ef95c30f1
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #else\n}\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.mappings.txt
new file mode 100644
index 00000000000..65438e0a422
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_08/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+Generated Location: (733:21,0 [53] )
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.codegen.cs
new file mode 100644
index 00000000000..e7c8942510b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.codegen.cs
@@ -0,0 +1,39 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(9,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..d07194cdc17
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(5,12): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.ir.txt
new file mode 100644
index 00000000000..b9ef95c30f1
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n/* test */ #else\n}\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.mappings.txt
new file mode 100644
index 00000000000..65438e0a422
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_09/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+Generated Location: (733:21,0 [53] )
+|
+#if false
+}
+@{
+/* test */ #else
+}
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.codegen.cs
new file mode 100644
index 00000000000..b2926415380
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.codegen.cs
@@ -0,0 +1,39 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(9,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if false
+}
+@{
+#else
+}
+@{
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..bf174dea560
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.diagnostics.txt
@@ -0,0 +1 @@
+(5,6): Warning RZ1044: Possible C# preprocessor directive is misplaced. C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.ir.txt
new file mode 100644
index 00000000000..91895f6af8a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if false\n}\n@{\n#else
\n}\n@{\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.mappings.txt
new file mode 100644
index 00000000000..b8bdbffc560
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/MisplacedEndingDirective_10/TestComponent.mappings.txt
@@ -0,0 +1,21 @@
+Source Location: (2:0,2 [53] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if false
+}
+@{
+#else
+}
+@{
+#endif
+|
+Generated Location: (733:21,0 [53] )
+|
+#if false
+}
+@{
+#else
+}
+@{
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..e4fcc29928b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if SomeSymbol
+
+#line default
+#line hidden
+#nullable disable
+
+ __builder.AddMarkupContent(0, "Some text
");
+#nullable restore
+#line (4,1)-(5,1) "x:\dir\subdir\Test\TestComponent.razor"
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..0d148ccbb3b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.ir.txt
@@ -0,0 +1,14 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [18] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [18] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if SomeSymbol\n
+ MarkupBlock - - Some text
+ CSharpCode - (42:3,0 [8] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (42:3,0 [8] x:\dir\subdir\Test\TestComponent.razor) - CSharp - #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..d46ad129417
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_01/TestComponent.mappings.txt
@@ -0,0 +1,16 @@
+Source Location: (2:0,2 [18] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if SomeSymbol
+|
+Generated Location: (733:21,0 [18] )
+|
+#if SomeSymbol
+|
+
+Source Location: (42:3,0 [8] x:\dir\subdir\Test\TestComponent.razor)
+|#endif
+|
+Generated Location: (946:31,0 [8] )
+|#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.codegen.cs
new file mode 100644
index 00000000000..c9ba698b168
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.codegen.cs
@@ -0,0 +1,35 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(5,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if !SomeSymbol
+ Some text
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.ir.txt
new file mode 100644
index 00000000000..075038c3ac4
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [49] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [49] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if !SomeSymbol\n Some text
\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.mappings.txt
new file mode 100644
index 00000000000..39078215500
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/PassParseOptionsThrough_02/TestComponent.mappings.txt
@@ -0,0 +1,13 @@
+Source Location: (2:0,2 [49] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if !SomeSymbol
+ Some text
+#endif
+|
+Generated Location: (733:21,0 [49] )
+|
+#if !SomeSymbol
+ Some text
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.codegen.cs
new file mode 100644
index 00000000000..20d5f19ac3b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.codegen.cs
@@ -0,0 +1,36 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(6,1) "x:\dir\subdir\Test\TestComponent.cshtml"
+
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.ir.txt
new file mode 100644
index 00000000000..e2d04e8a6c6
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.ir.txt
@@ -0,0 +1,11 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.cshtml)
+ LazyIntermediateToken - (2:0,2 [99] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n#pragma warning disable 219 // variable declared but not used\n#if true\n var x = 1;\n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.mappings.txt
new file mode 100644
index 00000000000..a241e826801
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/SimpleIfDef/TestComponent.mappings.txt
@@ -0,0 +1,15 @@
+Source Location: (2:0,2 [99] x:\dir\subdir\Test\TestComponent.cshtml)
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+Generated Location: (734:21,0 [99] )
+|
+#pragma warning disable 219 // variable declared but not used
+#if true
+ var x = 1;
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.codegen.cs
new file mode 100644
index 00000000000..9652333b2e7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.codegen.cs
@@ -0,0 +1,40 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(2,1) "x:\dir\subdir\Test\TestComponent.razor"
+ #if true }
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (2,3)-(2,12) "x:\dir\subdir\Test\TestComponent.razor"
+ #endif }
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..ade23f6812a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.diagnostics.txt
@@ -0,0 +1,5 @@
+x:\dir\subdir\Test\TestComponent.razor(1,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+x:\dir\subdir\Test\TestComponent.razor(1,4): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(2,2): Error RZ1010: Unexpected "{" after "@" character. Once inside the body of a code block (@if {}, @{}, etc.) you do not need to use "@{" to switch to code.
+x:\dir\subdir\Test\TestComponent.razor(2,2): Error RZ1006: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
+x:\dir\subdir\Test\TestComponent.razor(2,4): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.ir.txt
new file mode 100644
index 00000000000..bce548ad9f9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - #if true }\n
+ CSharpCode - (17:1,2 [9] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (17:1,2 [9] x:\dir\subdir\Test\TestComponent.razor) - CSharp - #endif }
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.mappings.txt
new file mode 100644
index 00000000000..161c58ca33b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_01/TestComponent.mappings.txt
@@ -0,0 +1,12 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+| #if true }
+|
+Generated Location: (733:21,0 [13] )
+| #if true }
+|
+
+Source Location: (17:1,2 [9] x:\dir\subdir\Test\TestComponent.razor)
+| #endif }|
+Generated Location: (878:29,0 [9] )
+| #endif }|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.codegen.cs
new file mode 100644
index 00000000000..def2f0c3863
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+/* test */ #if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+/* test */ #endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..dcc476581b2
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(2,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(5,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.ir.txt
new file mode 100644
index 00000000000..3c9fcaeedc0
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [23] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [23] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n/* test */ #if true\n
+ CSharpCode - (30:3,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (30:3,2 [21] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n/* test */ #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.mappings.txt
new file mode 100644
index 00000000000..1824c4f5964
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_02/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [23] x:\dir\subdir\Test\TestComponent.razor)
+|
+/* test */ #if true
+|
+Generated Location: (733:21,0 [23] )
+|
+/* test */ #if true
+|
+
+Source Location: (30:3,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+|
+/* test */ #endif
+|
+Generated Location: (887:30,0 [21] )
+|
+/* test */ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.codegen.cs
new file mode 100644
index 00000000000..2053d765d2d
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.codegen.cs
@@ -0,0 +1,43 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(4,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#pragma warning disable 219
+var x = 1; #if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (5,3)-(7,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+var y = 2; #endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..6de12f462d9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(3,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(6,12): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.ir.txt
new file mode 100644
index 00000000000..f1937989b55
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [52] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [52] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#pragma warning disable 219\nvar x = 1; #if true\n
+ CSharpCode - (59:4,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (59:4,2 [21] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \nvar y = 2; #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.mappings.txt
new file mode 100644
index 00000000000..a866c00ca44
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_03/TestComponent.mappings.txt
@@ -0,0 +1,20 @@
+Source Location: (2:0,2 [52] x:\dir\subdir\Test\TestComponent.razor)
+|
+#pragma warning disable 219
+var x = 1; #if true
+|
+Generated Location: (733:21,0 [52] )
+|
+#pragma warning disable 219
+var x = 1; #if true
+|
+
+Source Location: (59:4,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+|
+var y = 2; #endif
+|
+Generated Location: (916:31,0 [21] )
+|
+var y = 2; #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.codegen.cs
new file mode 100644
index 00000000000..39097fea388
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+var x = #if true;
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+x #endif;
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.diagnostics.txt
new file mode 100644
index 00000000000..a09c47e3599
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.diagnostics.txt
@@ -0,0 +1,2 @@
+x:\dir\subdir\Test\TestComponent.razor(2,9): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
+x:\dir\subdir\Test\TestComponent.razor(5,3): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.ir.txt
new file mode 100644
index 00000000000..91597324ca3
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [21] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \nvar x = #if true;\n
+ CSharpCode - (28:3,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (28:3,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \nx #endif;\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.mappings.txt
new file mode 100644
index 00000000000..ba6d1d7c4a6
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_04/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [21] x:\dir\subdir\Test\TestComponent.razor)
+|
+var x = #if true;
+|
+Generated Location: (733:21,0 [21] )
+|
+var x = #if true;
+|
+
+Source Location: (28:3,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+x #endif;
+|
+Generated Location: (885:30,0 [13] )
+|
+x #endif;
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.codegen.cs
new file mode 100644
index 00000000000..817ee0b2819
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.codegen.cs
@@ -0,0 +1,26 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+ __builder.AddMarkupContent(0, "#if true
");
+ __builder.AddMarkupContent(1, "#endif
");
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.ir.txt
new file mode 100644
index 00000000000..ca778d3c2a6
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_05/TestComponent.ir.txt
@@ -0,0 +1,19 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ MarkupBlock - - #if true
+ CSharpCode - (25:2,0 [0] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (25:2,0 [0] x:\dir\subdir\Test\TestComponent.razor) - CSharp -
+ CSharpCode - (30:3,2 [2] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (30:3,2 [2] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n
+ MarkupBlock - - #endif
+ CSharpCode - (51:5,0 [0] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (51:5,0 [0] x:\dir\subdir\Test\TestComponent.razor) - CSharp -
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.codegen.cs
new file mode 100644
index 00000000000..348f0fbd367
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+ #if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+ #endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.ir.txt
new file mode 100644
index 00000000000..8eb6874d305
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [16] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [16] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #if true\n
+ CSharpCode - (23:3,2 [14] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (23:3,2 [14] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.mappings.txt
new file mode 100644
index 00000000000..c7c3889d0dd
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_06/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [16] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #if true
+|
+Generated Location: (733:21,0 [16] )
+|
+ #if true
+|
+
+Source Location: (23:3,2 [14] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #endif
+|
+Generated Location: (880:30,0 [14] )
+|
+ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.codegen.cs
new file mode 100644
index 00000000000..644109899ab
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+ #if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+ #endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.ir.txt
new file mode 100644
index 00000000000..9c602d9198a
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.mappings.txt
new file mode 100644
index 00000000000..75ae62ff45b
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_07/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #if true
+|
+Generated Location: (733:21,0 [13] )
+|
+ #if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #endif
+|
+Generated Location: (877:30,0 [11] )
+|
+ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.codegen.cs
new file mode 100644
index 00000000000..d24b5e3ed3c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.ir.txt
new file mode 100644
index 00000000000..b18b7c73b1c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.mappings.txt
new file mode 100644
index 00000000000..c146d0ee00e
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_08/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if true
+|
+Generated Location: (733:21,0 [13] )
+|
+#if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (877:30,0 [11] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.codegen.cs
new file mode 100644
index 00000000000..86e70a81f85
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.ir.txt
new file mode 100644
index 00000000000..9335b08dd84
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.mappings.txt
new file mode 100644
index 00000000000..737b2e28fa0
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_09/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if true
+|
+Generated Location: (733:21,0 [13] )
+|
+#if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (877:30,0 [11] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.codegen.cs
new file mode 100644
index 00000000000..8830d18b6a7
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+ #if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+ #endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.ir.txt
new file mode 100644
index 00000000000..b3f7754173e
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n #endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.mappings.txt
new file mode 100644
index 00000000000..deb6998c322
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_10/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #if true
+|
+Generated Location: (733:21,0 [13] )
+|
+ #if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+ #endif
+|
+Generated Location: (877:30,0 [11] )
+|
+ #endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.codegen.cs
new file mode 100644
index 00000000000..a9c77e6b364
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.codegen.cs
@@ -0,0 +1,42 @@
+//
+#pragma warning disable 1591
+namespace Test
+{
+ #line default
+ using global::System;
+ using global::System.Collections.Generic;
+ using global::System.Linq;
+ using global::System.Threading.Tasks;
+ using global::Microsoft.AspNetCore.Components;
+ #line default
+ #line hidden
+ #nullable restore
+ public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
+ #nullable disable
+ {
+ #pragma warning disable 1998
+ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
+ {
+#nullable restore
+#line (1,3)-(3,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#if true
+
+#line default
+#line hidden
+#nullable disable
+
+#nullable restore
+#line (4,3)-(6,1) "x:\dir\subdir\Test\TestComponent.razor"
+
+#endif
+
+#line default
+#line hidden
+#nullable disable
+
+ }
+ #pragma warning restore 1998
+ }
+}
+#pragma warning restore 1591
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.ir.txt
new file mode 100644
index 00000000000..c50aed42b07
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.ir.txt
@@ -0,0 +1,13 @@
+Document -
+ NamespaceDeclaration - - Test
+ UsingDirective - (3:1,1 [22] ) - global::System
+ UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
+ UsingDirective - (69:3,1 [27] ) - global::System.Linq
+ UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
+ UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
+ ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
+ MethodDeclaration - - protected override - void - BuildRenderTree
+ CSharpCode - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#if true\n
+ CSharpCode - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+ LazyIntermediateToken - (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor) - CSharp - \n#endif\n
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.mappings.txt
new file mode 100644
index 00000000000..594291e5e53
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimePreprocessorDirectiveTest/StartOfLine_11/TestComponent.mappings.txt
@@ -0,0 +1,18 @@
+Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.razor)
+|
+#if true
+|
+Generated Location: (733:21,0 [13] )
+|
+#if true
+|
+
+Source Location: (20:3,2 [11] x:\dir\subdir\Test\TestComponent.razor)
+|
+#endif
+|
+Generated Location: (877:30,0 [11] )
+|
+#endif
+|
+
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpBlockTest/Usings.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpBlockTest/Usings.cspans.txt
new file mode 100644
index 00000000000..99a22954242
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpBlockTest/Usings.cspans.txt
@@ -0,0 +1,16 @@
+Markup span at (0:0,0 [3] ) - Parent: Markup block at (0:0,0 [185] )
+Transition span at (3:1,0 [1] ) - Parent: Directive block at (3:1,0 [23] )
+Code span at (4:1,1 [22] ) - Parent: Directive block at (3:1,0 [23] )
+Markup span at (26:2,0 [0] ) - Parent: Markup block at (0:0,0 [185] )
+Transition span at (26:2,0 [1] ) - Parent: Directive block at (26:2,0 [43] )
+Code span at (27:2,1 [42] ) - Parent: Directive block at (26:2,0 [43] )
+Markup span at (69:3,0 [0] ) - Parent: Markup block at (0:0,0 [185] )
+Transition span at (69:3,0 [1] ) - Parent: Directive block at (69:3,0 [28] )
+Code span at (70:3,1 [27] ) - Parent: Directive block at (69:3,0 [28] )
+Markup span at (97:4,0 [0] ) - Parent: Markup block at (0:0,0 [185] )
+Transition span at (97:4,0 [1] ) - Parent: Directive block at (97:4,0 [39] )
+Code span at (98:4,1 [38] ) - Parent: Directive block at (97:4,0 [39] )
+Markup span at (136:5,0 [0] ) - Parent: Markup block at (0:0,0 [185] )
+Transition span at (136:5,0 [1] ) - Parent: Directive block at (136:5,0 [48] )
+Code span at (137:5,1 [47] ) - Parent: Directive block at (136:5,0 [48] )
+Markup span at (184:6,0 [1] ) - Parent: Markup block at (0:0,0 [185] )
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpBlockTest/Usings.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpBlockTest/Usings.stree.txt
new file mode 100644
index 00000000000..447016add4e
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpBlockTest/Usings.stree.txt
@@ -0,0 +1,90 @@
+RazorDocument - [0..185)::185 - [{LF@using global::SystemLF@using global::System.Collections.GenericLF@using global::System.LinqLF@using global::System.Threading.TasksLF@using global::Microsoft.AspNetCore.ComponentsLF}]
+ MarkupBlock - [0..185)::185
+ MarkupTextLiteral - [0..3)::3 - [{LF] - Gen
+ Text;[{];
+ NewLine;[LF];
+ CSharpCodeBlock - [3..26)::23
+ RazorDirective - [3..26)::23
+ CSharpTransition - [3..4)::1 - Gen
+ Transition;[@];
+ RazorDirectiveBody - [4..26)::22
+ CSharpStatementLiteral - [4..26)::22 - [using global::SystemLF] - Gen
+ Keyword;[using];
+ Whitespace;[ ];
+ Keyword;[global];
+ DoubleColon;[::];
+ Identifier;[System];
+ NewLine;[LF];
+ MarkupTextLiteral - [26..26)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [26..69)::43
+ RazorDirective - [26..69)::43
+ CSharpTransition - [26..27)::1 - Gen
+ Transition;[@];
+ RazorDirectiveBody - [27..69)::42
+ CSharpStatementLiteral - [27..69)::42 - [using global::System.Collections.GenericLF] - Gen
+ Keyword;[using];
+ Whitespace;[ ];
+ Keyword;[global];
+ DoubleColon;[::];
+ Identifier;[System];
+ Dot;[.];
+ Identifier;[Collections];
+ Dot;[.];
+ Identifier;[Generic];
+ NewLine;[LF];
+ MarkupTextLiteral - [69..69)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [69..97)::28
+ RazorDirective - [69..97)::28
+ CSharpTransition - [69..70)::1 - Gen
+ Transition;[@];
+ RazorDirectiveBody - [70..97)::27
+ CSharpStatementLiteral - [70..97)::27 - [using global::System.LinqLF] - Gen
+ Keyword;[using];
+ Whitespace;[ ];
+ Keyword;[global];
+ DoubleColon;[::];
+ Identifier;[System];
+ Dot;[.];
+ Identifier;[Linq];
+ NewLine;[LF];
+ MarkupTextLiteral - [97..97)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [97..136)::39
+ RazorDirective - [97..136)::39
+ CSharpTransition - [97..98)::1 - Gen
+ Transition;[@];
+ RazorDirectiveBody - [98..136)::38
+ CSharpStatementLiteral - [98..136)::38 - [using global::System.Threading.TasksLF] - Gen
+ Keyword;[using];
+ Whitespace;[ ];
+ Keyword;[global];
+ DoubleColon;[::];
+ Identifier;[System];
+ Dot;[.];
+ Identifier;[Threading];
+ Dot;[.];
+ Identifier;[Tasks];
+ NewLine;[LF];
+ MarkupTextLiteral - [136..136)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [136..184)::48
+ RazorDirective - [136..184)::48
+ CSharpTransition - [136..137)::1 - Gen
+ Transition;[@];
+ RazorDirectiveBody - [137..184)::47
+ CSharpStatementLiteral - [137..184)::47 - [using global::Microsoft.AspNetCore.ComponentsLF] - Gen
+ Keyword;[using];
+ Whitespace;[ ];
+ Keyword;[global];
+ DoubleColon;[::];
+ Identifier;[Microsoft];
+ Dot;[.];
+ Identifier;[AspNetCore];
+ Dot;[.];
+ Identifier;[Components];
+ NewLine;[LF];
+ MarkupTextLiteral - [184..185)::1 - [}] - Gen
+ Text;[}];
+ EndOfFile;[];
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.cspans.txt
new file mode 100644
index 00000000000..efde9d0ccc4
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.cspans.txt
@@ -0,0 +1,6 @@
+Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [115] )
+Transition span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [115] )
+MetaCode span at (1:0,1 [1] ) - Parent: Statement block at (0:0,0 [115] )
+Code span at (2:0,2 [112] ) - Parent: Statement block at (0:0,0 [115] )
+MetaCode span at (114:10,0 [1] ) - Parent: Statement block at (0:0,0 [115] )
+Markup span at (115:10,1 [0] ) - Parent: Markup block at (0:0,0 [115] )
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.diag.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.diag.txt
new file mode 100644
index 00000000000..5b5e80a91b9
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.diag.txt
@@ -0,0 +1,2 @@
+(2,1): Error RZ1042: '#define' and '#undef' cannot be used in razor markup.
+(4,1): Error RZ1042: '#define' and '#undef' cannot be used in razor markup.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.stree.txt
new file mode 100644
index 00000000000..b929d9f69d5
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/DefineThenIfDef.stree.txt
@@ -0,0 +1,28 @@
+RazorDocument - [0..115)::115 - [@{LF#define SYMBOLLF#if SYMBOLLF#undef SYMBOLLF#if SYMBOLLF var x = 1;LF#endifLF#elseLF var x = 1;LF#endifLF}]
+ MarkupBlock - [0..115)::115
+ MarkupTextLiteral - [0..0)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [0..115)::115
+ CSharpStatement - [0..115)::115
+ CSharpTransition - [0..1)::1 - Gen
+ Transition;[@];
+ CSharpStatementBody - [1..115)::114
+ RazorMetaCode - [1..2)::1 - Gen
+ LeftBrace;[{];
+ CSharpCodeBlock - [2..114)::112
+ CSharpStatementLiteral - [2..114)::112 - [LF#define SYMBOLLF#if SYMBOLLF#undef SYMBOLLF#if SYMBOLLF var x = 1;LF#endifLF#elseLF var x = 1;LF#endifLF] - Gen
+ NewLine;[LF];
+ CSharpDirective;[#define SYMBOLLF];RZ1042(4:1,0 [16] )
+ CSharpDirective;[#if SYMBOLLF];
+ CSharpDirective;[#undef SYMBOLLF];RZ1042(32:3,0 [15] )
+ CSharpDirective;[#if SYMBOLLF];
+ CSharpDisabledText;[ var x = 1;LF];
+ CSharpDirective;[#endifLF];
+ CSharpDirective;[#elseLF];
+ CSharpDisabledText;[ var x = 1;LF];
+ CSharpDirective;[#endifLF];
+ RazorMetaCode - [114..115)::1 - Gen
+ RightBrace;[}];
+ MarkupTextLiteral - [115..115)::0 - [] - Gen
+ Marker;[];
+ EndOfFile;[];
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.cspans.txt
new file mode 100644
index 00000000000..13049e42f47
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.cspans.txt
@@ -0,0 +1,19 @@
+Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [119] )
+Transition span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [15] )
+MetaCode span at (1:0,1 [1] ) - Parent: Statement block at (0:0,0 [15] )
+Code span at (2:0,2 [12] ) - Parent: Statement block at (0:0,0 [15] )
+MetaCode span at (14:2,0 [1] ) - Parent: Statement block at (0:0,0 [15] )
+Markup span at (15:2,1 [2] ) - Parent: Markup block at (0:0,0 [119] )
+Markup span at (17:3,0 [5] ) - Parent: Tag block at (17:3,0 [5] )
+Markup span at (22:3,5 [6] ) - Parent: Markup block at (0:0,0 [119] )
+Markup span at (28:4,4 [3] ) - Parent: Tag block at (28:4,4 [3] )
+Markup span at (31:4,7 [7] ) - Parent: Markup block at (0:0,0 [119] )
+Markup span at (38:4,14 [4] ) - Parent: Tag block at (38:4,14 [4] )
+Markup span at (42:4,18 [2] ) - Parent: Markup block at (0:0,0 [119] )
+Markup span at (44:5,0 [6] ) - Parent: Tag block at (44:5,0 [6] )
+Markup span at (50:5,6 [2] ) - Parent: Markup block at (0:0,0 [119] )
+Transition span at (52:6,0 [1] ) - Parent: Statement block at (52:6,0 [67] )
+MetaCode span at (53:6,1 [1] ) - Parent: Statement block at (52:6,0 [67] )
+Code span at (54:6,2 [64] ) - Parent: Statement block at (52:6,0 [67] )
+MetaCode span at (118:12,0 [1] ) - Parent: Statement block at (52:6,0 [67] )
+Markup span at (119:12,1 [0] ) - Parent: Markup block at (0:0,0 [119] )
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.diag.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.diag.txt
new file mode 100644
index 00000000000..b9fdc01f017
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.diag.txt
@@ -0,0 +1 @@
+(7,4): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.stree.txt
new file mode 100644
index 00000000000..a7741d6001c
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElIfNotOnNewline.stree.txt
@@ -0,0 +1,66 @@
+RazorDocument - [0..119)::119 - [@{LF#if trueLF}LFLF@{ #elif false }LFLF@{LF#endifLF}]
+ MarkupBlock - [0..119)::119
+ MarkupTextLiteral - [0..0)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [0..15)::15
+ CSharpStatement - [0..15)::15
+ CSharpTransition - [0..1)::1 - Gen
+ Transition;[@];
+ CSharpStatementBody - [1..15)::14
+ RazorMetaCode - [1..2)::1 - Gen
+ LeftBrace;[{];
+ CSharpCodeBlock - [2..14)::12
+ CSharpStatementLiteral - [2..14)::12 - [LF#if trueLF] - Gen
+ NewLine;[LF];
+ CSharpDirective;[#if trueLF];
+ RazorMetaCode - [14..15)::1 - Gen
+ RightBrace;[}];
+ MarkupEphemeralTextLiteral - [15..17)::2 - [LF] - Gen
+ NewLine;[LF];
+ MarkupElement - [17..50)::33
+ MarkupStartTag - [17..22)::5 - [] - Gen
+ OpenAngle;[<];
+ Text;[div];
+ CloseAngle;[>];
+ MarkupTextLiteral - [22..28)::6 - [LF ] - Gen
+ NewLine;[LF];
+ Whitespace;[ ];
+ MarkupElement - [28..42)::14
+ MarkupStartTag - [28..31)::3 - [] - Gen
+ OpenAngle;[<];
+ Text;[p];
+ CloseAngle;[>];
+ MarkupTextLiteral - [31..38)::7 - [Content] - Gen
+ Text;[Content];
+ MarkupEndTag - [38..42)::4 - [
] - Gen
+ OpenAngle;[<];
+ ForwardSlash;[/];
+ Text;[p];
+ CloseAngle;[>];
+ MarkupTextLiteral - [42..44)::2 - [LF] - Gen
+ NewLine;[LF];
+ MarkupEndTag - [44..50)::6 - [ ] - Gen
+ OpenAngle;[<];
+ ForwardSlash;[/];
+ Text;[div];
+ CloseAngle;[>];
+ MarkupTextLiteral - [50..52)::2 - [LF] - Gen
+ NewLine;[LF];
+ CSharpCodeBlock - [52..119)::67
+ CSharpStatement - [52..119)::67
+ CSharpTransition - [52..53)::1 - Gen
+ Transition;[@];
+ CSharpStatementBody - [53..119)::66
+ RazorMetaCode - [53..54)::1 - Gen
+ LeftBrace;[{];
+ CSharpCodeBlock - [54..118)::64
+ CSharpStatementLiteral - [54..118)::64 - [ #elif false }LFLF@{LF#endifLF] - Gen
+ Whitespace;[ ];
+ CSharpDirective;[#elif false }LF];RZ1043(55:6,3 [15] )
+ CSharpDisabledText;[LF@{LF];
+ CSharpDirective;[#endifLF];
+ RazorMetaCode - [118..119)::1 - Gen
+ RightBrace;[}];
+ MarkupTextLiteral - [119..119)::0 - [] - Gen
+ Marker;[];
+ EndOfFile;[];
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.cspans.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.cspans.txt
new file mode 100644
index 00000000000..4fe5d939370
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.cspans.txt
@@ -0,0 +1,19 @@
+Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [113] )
+Transition span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [15] )
+MetaCode span at (1:0,1 [1] ) - Parent: Statement block at (0:0,0 [15] )
+Code span at (2:0,2 [12] ) - Parent: Statement block at (0:0,0 [15] )
+MetaCode span at (14:2,0 [1] ) - Parent: Statement block at (0:0,0 [15] )
+Markup span at (15:2,1 [2] ) - Parent: Markup block at (0:0,0 [113] )
+Markup span at (17:3,0 [5] ) - Parent: Tag block at (17:3,0 [5] )
+Markup span at (22:3,5 [6] ) - Parent: Markup block at (0:0,0 [113] )
+Markup span at (28:4,4 [3] ) - Parent: Tag block at (28:4,4 [3] )
+Markup span at (31:4,7 [7] ) - Parent: Markup block at (0:0,0 [113] )
+Markup span at (38:4,14 [4] ) - Parent: Tag block at (38:4,14 [4] )
+Markup span at (42:4,18 [2] ) - Parent: Markup block at (0:0,0 [113] )
+Markup span at (44:5,0 [6] ) - Parent: Tag block at (44:5,0 [6] )
+Markup span at (50:5,6 [2] ) - Parent: Markup block at (0:0,0 [113] )
+Transition span at (52:6,0 [1] ) - Parent: Statement block at (52:6,0 [61] )
+MetaCode span at (53:6,1 [1] ) - Parent: Statement block at (52:6,0 [61] )
+Code span at (54:6,2 [58] ) - Parent: Statement block at (52:6,0 [61] )
+MetaCode span at (112:12,0 [1] ) - Parent: Statement block at (52:6,0 [61] )
+Markup span at (113:12,1 [0] ) - Parent: Markup block at (0:0,0 [113] )
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.diag.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.diag.txt
new file mode 100644
index 00000000000..b9fdc01f017
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.diag.txt
@@ -0,0 +1 @@
+(7,4): Error RZ1043: C# preprocessor directives must be at the start of the line, except for whitespace.
diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.stree.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.stree.txt
new file mode 100644
index 00000000000..86f86073ad4
--- /dev/null
+++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/ParserTests/CSharpPreprocessorTest/ElseNotOnNewline.stree.txt
@@ -0,0 +1,66 @@
+RazorDocument - [0..113)::113 - [@{LF#if trueLF}LFLF@{ #else }LFLF@{LF#endifLF}]
+ MarkupBlock - [0..113)::113
+ MarkupTextLiteral - [0..0)::0 - [] - Gen
+ Marker;[];
+ CSharpCodeBlock - [0..15)::15
+ CSharpStatement - [0..15)::15
+ CSharpTransition - [0..1)::1 - Gen
+ Transition;[@];
+ CSharpStatementBody - [1..15)::14
+ RazorMetaCode - [1..2)::1 - Gen
+ LeftBrace;[{];
+ CSharpCodeBlock - [2..14)::12
+ CSharpStatementLiteral - [2..14)::12 - [LF#if trueLF] - Gen
+ NewLine;[LF];
+ CSharpDirective;[#if trueLF];
+ RazorMetaCode - [14..15)::1 - Gen