Fixed an assumption in ComponentLoweringPass (dotnet/aspnetcore-tooling#226)

\n\nCommit migrated from 87bb138304
This commit is contained in:
Ajay Bhargav Baaskaran 2019-02-20 09:25:12 -08:00 committed by GitHub
parent 54e79153ec
commit ca3e094bee
2 changed files with 26 additions and 20 deletions

View File

@ -304,36 +304,42 @@ namespace Microsoft.AspNetCore.Razor.Language.Components
{
if (attribute.Children[i] is HtmlAttributeValueIntermediateNode htmlValue)
{
attribute.Children[i] = new HtmlContentIntermediateNode()
var newNode = new HtmlContentIntermediateNode()
{
Children =
{
htmlValue.Children.Single(),
},
Source = htmlValue.Source,
};
for (var j = 0; j < htmlValue.Children.Count; j++)
{
newNode.Children.Add(htmlValue.Children[j]);
}
attribute.Children[i] = newNode;
}
else if (attribute.Children[i] is CSharpExpressionAttributeValueIntermediateNode expressionValue)
{
attribute.Children[i] = new CSharpExpressionIntermediateNode()
var newNode = new CSharpExpressionIntermediateNode()
{
Children =
{
expressionValue.Children.Single(),
},
Source = expressionValue.Source,
};
for (var j = 0; j < expressionValue.Children.Count; j++)
{
newNode.Children.Add(expressionValue.Children[j]);
}
attribute.Children[i] = newNode;
}
else if (attribute.Children[i] is CSharpCodeAttributeValueIntermediateNode codeValue)
{
attribute.Children[i] = new CSharpExpressionIntermediateNode()
var newNode = new CSharpExpressionIntermediateNode()
{
Children =
{
codeValue.Children.Single(),
},
Source = codeValue.Source,
};
for (var j = 0; j < codeValue.Children.Count; j++)
{
newNode.Children.Add(codeValue.Children[j]);
}
attribute.Children[i] = newNode;
}
}
}

View File

@ -158,12 +158,12 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
};
}
protected CompileToCSharpResult CompileToCSharp(string cshtmlContent)
protected CompileToCSharpResult CompileToCSharp(string cshtmlContent, bool throwOnFailure=true)
{
return CompileToCSharp(DefaultFileName, cshtmlContent);
return CompileToCSharp(DefaultFileName, cshtmlContent, throwOnFailure);
}
protected CompileToCSharpResult CompileToCSharp(string cshtmlRelativePath, string cshtmlContent)
protected CompileToCSharpResult CompileToCSharp(string cshtmlRelativePath, string cshtmlContent, bool throwOnFailure = true)
{
if (DeclarationOnly && DesignTime)
{
@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
};
// Result of doing 'temp' compilation
var tempAssembly = CompileToAssembly(declaration);
var tempAssembly = CompileToAssembly(declaration, throwOnFailure);
// Add the 'temp' compilation as a metadata reference
var references = BaseCompilation.References.Concat(new[] { tempAssembly.Compilation.ToMetadataReference() }).ToArray();
@ -273,7 +273,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
protected CompileToAssemblyResult CompileToAssembly(CompileToCSharpResult cSharpResult, bool throwOnFailure = true)
{
if (cSharpResult.Diagnostics.Any())
if (cSharpResult.Diagnostics.Any() && throwOnFailure)
{
var diagnosticsLog = string.Join(Environment.NewLine, cSharpResult.Diagnostics.Select(d => d.ToString()).ToArray());
throw new InvalidOperationException($"Aborting compilation to assembly because RazorCompiler returned nonempty diagnostics: {diagnosticsLog}");