Add support for C# 8 using variable declarations and add more C# 8 coverage.
- When adding additional C# 8 tests found that we didn't fully support this.
- Updated the C# 8.0 test to fully encompass everything C# 8.0.
- Added a feature flag to control using variable declaration errors when not top level.
- Added using variable declaration specific tests.
aspnet/AspNetCoredotnet/aspnetcore-tooling#5092
\n\nCommit migrated from ac08ad3659
This commit is contained in:
parent
6eb9044660
commit
784596aba6
|
|
@ -2001,9 +2001,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
// using Identifier ==> Using Declaration
|
||||
if (!topLevel)
|
||||
{
|
||||
Context.ErrorSink.OnError(
|
||||
RazorDiagnosticFactory.CreateParsing_NamespaceImportAndTypeAliasCannotExistWithinCodeBlock(
|
||||
new SourceSpan(block.Start, block.Name.Length)));
|
||||
// using Variable Declaration
|
||||
|
||||
if (!Context.FeatureFlags.AllowUsingVariableDeclarations)
|
||||
{
|
||||
Context.ErrorSink.OnError(
|
||||
RazorDiagnosticFactory.CreateParsing_NamespaceImportAndTypeAliasCannotExistWithinCodeBlock(
|
||||
new SourceSpan(block.Start, block.Name.Length)));
|
||||
}
|
||||
|
||||
// There are cases when a user will do @using var x = 123; At which point we let C# notify the user
|
||||
// of their error like we do any other invalid expression.
|
||||
if (transition != null)
|
||||
{
|
||||
builder.Add(transition);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var allowHtmlCommentsInTagHelpers = false;
|
||||
var allowComponentFileKind = false;
|
||||
var allowRazorInAllCodeBlocks = false;
|
||||
var allowUsingVariableDeclarations = false;
|
||||
var experimental_AllowConditionalDataDashAttributes = false;
|
||||
|
||||
if (version.CompareTo(RazorLanguageVersion.Version_2_1) >= 0)
|
||||
|
|
@ -25,6 +26,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
// Added in 3.0
|
||||
allowComponentFileKind = true;
|
||||
allowRazorInAllCodeBlocks = true;
|
||||
allowUsingVariableDeclarations = true;
|
||||
}
|
||||
|
||||
if (version.CompareTo(RazorLanguageVersion.Experimental) >= 0)
|
||||
|
|
@ -37,6 +39,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
allowHtmlCommentsInTagHelpers,
|
||||
allowComponentFileKind,
|
||||
allowRazorInAllCodeBlocks,
|
||||
allowUsingVariableDeclarations,
|
||||
experimental_AllowConditionalDataDashAttributes);
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +51,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public abstract bool AllowRazorInAllCodeBlocks { get; }
|
||||
|
||||
public abstract bool AllowUsingVariableDeclarations { get; }
|
||||
|
||||
public abstract bool EXPERIMENTAL_AllowConditionalDataDashAttributes { get; }
|
||||
|
||||
private class DefaultRazorParserFeatureFlags : RazorParserFeatureFlags
|
||||
|
|
@ -57,12 +62,14 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
bool allowHtmlCommentsInTagHelpers,
|
||||
bool allowComponentFileKind,
|
||||
bool allowRazorInAllCodeBlocks,
|
||||
bool allowUsingVariableDeclarations,
|
||||
bool experimental_AllowConditionalDataDashAttributes)
|
||||
{
|
||||
AllowMinimizedBooleanTagHelperAttributes = allowMinimizedBooleanTagHelperAttributes;
|
||||
AllowHtmlCommentsInTagHelpers = allowHtmlCommentsInTagHelpers;
|
||||
AllowComponentFileKind = allowComponentFileKind;
|
||||
AllowRazorInAllCodeBlocks = allowRazorInAllCodeBlocks;
|
||||
AllowUsingVariableDeclarations = allowUsingVariableDeclarations;
|
||||
EXPERIMENTAL_AllowConditionalDataDashAttributes = experimental_AllowConditionalDataDashAttributes;
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +81,8 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
|
||||
public override bool AllowRazorInAllCodeBlocks { get; }
|
||||
|
||||
public override bool AllowUsingVariableDeclarations { get; }
|
||||
|
||||
public override bool EXPERIMENTAL_AllowConditionalDataDashAttributes { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue