Remove unneeded chunk data.
Instead lets keep utilizing the Context's state to properly generate a C# file.
This commit is contained in:
parent
47b09a9f31
commit
d85927166b
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
ns = ns.Substring(1);
|
ns = ns.Substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
codeTreeBuilder.AddUsingChunk(ns, target, context);
|
codeTreeBuilder.AddUsingChunk(ns, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
CodeAttributeChunk chunk = codeTreeBuilder.StartChunkBlock<CodeAttributeChunk>(target, context);
|
CodeAttributeChunk chunk = codeTreeBuilder.StartChunkBlock<CodeAttributeChunk>(target);
|
||||||
|
|
||||||
chunk.Attribute = Name;
|
chunk.Attribute = Name;
|
||||||
chunk.Prefix = Prefix;
|
chunk.Prefix = Prefix;
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
public class CSharpCodeVisitor : CodeVisitor<CSharpCodeWriter>
|
public class CSharpCodeVisitor : CodeVisitor<CSharpCodeWriter>
|
||||||
{
|
{
|
||||||
private const string ValueWriterName = "__razor_attribute_value_writer";
|
private const string ValueWriterName = "__razor_attribute_value_writer";
|
||||||
|
private const string TemplateWriterName = "__razor_template_writer";
|
||||||
|
|
||||||
public CSharpCodeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
|
public CSharpCodeVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
|
||||||
: base(writer, context) { }
|
: base(writer, context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Visit(SetLayoutChunk chunk)
|
protected override void Visit(SetLayoutChunk chunk)
|
||||||
{
|
{
|
||||||
|
|
@ -29,11 +30,16 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
Writer.Write(TemplateBlockCodeGenerator.ItemParameterName).Write(" => ")
|
Writer.Write(TemplateBlockCodeGenerator.ItemParameterName).Write(" => ")
|
||||||
.WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName);
|
.WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName);
|
||||||
|
|
||||||
|
string currentTargetWriterName = Context.TargetWriterName;
|
||||||
|
Context.TargetWriterName = TemplateWriterName;
|
||||||
|
|
||||||
using (Writer.BuildLambda(endLine: false, parameterNames: TemplateBlockCodeGenerator.TemplateWriterName))
|
using (Writer.BuildLambda(endLine: false, parameterNames: TemplateBlockCodeGenerator.TemplateWriterName))
|
||||||
{
|
{
|
||||||
Visit((ChunkBlock)chunk);
|
Visit((ChunkBlock)chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context.TargetWriterName = currentTargetWriterName;
|
||||||
|
|
||||||
Writer.WriteEndMethodInvocation(false).WriteLine();
|
Writer.WriteEndMethodInvocation(false).WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,12 +54,12 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(chunk.Url) && !Context.Host.DesignTimeMode)
|
if (!String.IsNullOrEmpty(chunk.Url) && !Context.Host.DesignTimeMode)
|
||||||
{
|
{
|
||||||
if (chunk.RenderingMode == ExpressionRenderingMode.WriteToOutput)
|
if (Context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(chunk.WriterName))
|
if (!String.IsNullOrEmpty(Context.TargetWriterName))
|
||||||
{
|
{
|
||||||
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteLiteralToMethodName)
|
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteLiteralToMethodName)
|
||||||
.Write(chunk.WriterName)
|
.Write(Context.TargetWriterName)
|
||||||
.WriteParameterSeparator();
|
.WriteParameterSeparator();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -66,7 +72,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
.WriteStringLiteral(chunk.Url)
|
.WriteStringLiteral(chunk.Url)
|
||||||
.WriteEndMethodInvocation(endLine: false);
|
.WriteEndMethodInvocation(endLine: false);
|
||||||
|
|
||||||
if (chunk.RenderingMode == ExpressionRenderingMode.WriteToOutput)
|
if (Context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
|
||||||
{
|
{
|
||||||
Writer.WriteEndMethodInvocation();
|
Writer.WriteEndMethodInvocation();
|
||||||
}
|
}
|
||||||
|
|
@ -84,10 +90,10 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(chunk.Text) && !Context.Host.DesignTimeMode)
|
if (!String.IsNullOrEmpty(chunk.Text) && !Context.Host.DesignTimeMode)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(chunk.WriterName))
|
if (!String.IsNullOrEmpty(Context.TargetWriterName))
|
||||||
{
|
{
|
||||||
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteLiteralToMethodName)
|
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteLiteralToMethodName)
|
||||||
.Write(chunk.WriterName)
|
.Write(Context.TargetWriterName)
|
||||||
.WriteParameterSeparator();
|
.WriteParameterSeparator();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -107,7 +113,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
// TODO: Handle instrumentation
|
// TODO: Handle instrumentation
|
||||||
// TODO: Refactor
|
// TODO: Refactor
|
||||||
|
|
||||||
if (!Context.Host.DesignTimeMode && chunk.RenderingMode == ExpressionRenderingMode.InjectCode)
|
if (!Context.Host.DesignTimeMode && Context.ExpressionRenderingMode == ExpressionRenderingMode.InjectCode)
|
||||||
{
|
{
|
||||||
Visit((ChunkBlock)chunk);
|
Visit((ChunkBlock)chunk);
|
||||||
}
|
}
|
||||||
|
|
@ -117,12 +123,12 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
{
|
{
|
||||||
Writer.WriteStartAssignment("__o");
|
Writer.WriteStartAssignment("__o");
|
||||||
}
|
}
|
||||||
else if (chunk.RenderingMode == ExpressionRenderingMode.WriteToOutput)
|
else if (Context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(chunk.WriterName))
|
if (!String.IsNullOrEmpty(Context.TargetWriterName))
|
||||||
{
|
{
|
||||||
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteToMethodName)
|
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteToMethodName)
|
||||||
.Write(chunk.WriterName)
|
.Write(Context.TargetWriterName)
|
||||||
.WriteParameterSeparator();
|
.WriteParameterSeparator();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -137,7 +143,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
{
|
{
|
||||||
Writer.WriteLine(";");
|
Writer.WriteLine(";");
|
||||||
}
|
}
|
||||||
else if (chunk.RenderingMode == ExpressionRenderingMode.WriteToOutput)
|
else if (Context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
|
||||||
{
|
{
|
||||||
Writer.WriteEndMethodInvocation();
|
Writer.WriteEndMethodInvocation();
|
||||||
}
|
}
|
||||||
|
|
@ -170,6 +176,10 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
}
|
}
|
||||||
|
|
||||||
Chunk code = chunk.Children.FirstOrDefault();
|
Chunk code = chunk.Children.FirstOrDefault();
|
||||||
|
ExpressionRenderingMode currentRenderingMode = Context.ExpressionRenderingMode;
|
||||||
|
string currentTargetWriterName = Context.TargetWriterName;
|
||||||
|
|
||||||
|
Context.TargetWriterName = ValueWriterName;
|
||||||
|
|
||||||
Writer.WriteParameterSeparator()
|
Writer.WriteParameterSeparator()
|
||||||
.WriteLine();
|
.WriteLine();
|
||||||
|
|
@ -181,6 +191,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
.WriteParameterSeparator()
|
.WriteParameterSeparator()
|
||||||
.WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" });
|
.WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" });
|
||||||
|
|
||||||
|
Context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;
|
||||||
|
|
||||||
Accept(code);
|
Accept(code);
|
||||||
|
|
||||||
Writer.WriteParameterSeparator()
|
Writer.WriteParameterSeparator()
|
||||||
|
|
@ -211,6 +223,9 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
.WriteBooleanLiteral(false)
|
.WriteBooleanLiteral(false)
|
||||||
.WriteEndMethodInvocation(false);
|
.WriteEndMethodInvocation(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context.TargetWriterName = currentTargetWriterName;
|
||||||
|
Context.ExpressionRenderingMode = currentRenderingMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Visit(LiteralCodeAttributeChunk chunk)
|
protected override void Visit(LiteralCodeAttributeChunk chunk)
|
||||||
|
|
@ -229,8 +244,13 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
{
|
{
|
||||||
Writer.WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" });
|
Writer.WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" });
|
||||||
|
|
||||||
|
ExpressionRenderingMode currentRenderingMode = Context.ExpressionRenderingMode;
|
||||||
|
Context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;
|
||||||
|
|
||||||
Visit((ChunkBlock)chunk);
|
Visit((ChunkBlock)chunk);
|
||||||
|
|
||||||
|
Context.ExpressionRenderingMode = currentRenderingMode;
|
||||||
|
|
||||||
Writer.WriteParameterSeparator()
|
Writer.WriteParameterSeparator()
|
||||||
.Write(chunk.ValueLocation.AbsoluteIndex.ToString(CultureInfo.CurrentCulture))
|
.Write(chunk.ValueLocation.AbsoluteIndex.ToString(CultureInfo.CurrentCulture))
|
||||||
.WriteEndMethodInvocation(false)
|
.WriteEndMethodInvocation(false)
|
||||||
|
|
@ -255,10 +275,10 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
return; // Don't generate anything!
|
return; // Don't generate anything!
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(chunk.WriterName))
|
if (!String.IsNullOrEmpty(Context.TargetWriterName))
|
||||||
{
|
{
|
||||||
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteAttributeToMethodName)
|
Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.WriteAttributeToMethodName)
|
||||||
.Write(chunk.WriterName)
|
.Write(Context.TargetWriterName)
|
||||||
.WriteParameterSeparator();
|
.WriteParameterSeparator();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,14 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
lambdaScope = Writer.BuildLambda(endLine: false, parameterNames: HelperWriterName);
|
lambdaScope = Writer.BuildLambda(endLine: false, parameterNames: HelperWriterName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string currentTargetWriterName = Context.TargetWriterName;
|
||||||
|
Context.TargetWriterName = HelperWriterName;
|
||||||
|
|
||||||
// Generate children code
|
// Generate children code
|
||||||
_codeVisitor.Accept(chunk.Children);
|
_codeVisitor.Accept(chunk.Children);
|
||||||
|
|
||||||
|
Context.TargetWriterName = currentTargetWriterName;
|
||||||
|
|
||||||
if (chunk.HeaderComplete)
|
if (chunk.HeaderComplete)
|
||||||
{
|
{
|
||||||
lambdaScope.Dispose();
|
lambdaScope.Dispose();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
{
|
{
|
||||||
public SourceLocation Start { get; set; }
|
public SourceLocation Start { get; set; }
|
||||||
public SyntaxTreeNode Association { get; set; }
|
public SyntaxTreeNode Association { get; set; }
|
||||||
public string WriterName { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
{
|
{
|
||||||
public class ExpressionBlockChunk : ChunkBlock
|
public class ExpressionBlockChunk : ChunkBlock
|
||||||
{
|
{
|
||||||
public ExpressionRenderingMode RenderingMode { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
public class ExpressionChunk : Chunk
|
public class ExpressionChunk : Chunk
|
||||||
{
|
{
|
||||||
public string Code { get; set; }
|
public string Code { get; set; }
|
||||||
public ExpressionRenderingMode RenderingMode { get; set; }
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,5 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
public class ResolveUrlChunk : Chunk
|
public class ResolveUrlChunk : Chunk
|
||||||
{
|
{
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
public ExpressionRenderingMode RenderingMode { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,12 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
|
|
||||||
public CodeTree CodeTree { get; private set; }
|
public CodeTree CodeTree { get; private set; }
|
||||||
|
|
||||||
public void AddChunk(Chunk chunk, SyntaxTreeNode association, CodeGeneratorContext context, bool topLevel = false)
|
public void AddChunk(Chunk chunk, SyntaxTreeNode association, bool topLevel = false)
|
||||||
{
|
{
|
||||||
_lastChunk = chunk;
|
_lastChunk = chunk;
|
||||||
|
|
||||||
chunk.Start = association.Start;
|
chunk.Start = association.Start;
|
||||||
chunk.Association = association;
|
chunk.Association = association;
|
||||||
chunk.WriterName = context.TargetWriterName;
|
|
||||||
|
|
||||||
// If we're not in the middle of a chunk block
|
// If we're not in the middle of a chunk block
|
||||||
if (_blockChain.Count == 0 || topLevel == true)
|
if (_blockChain.Count == 0 || topLevel == true)
|
||||||
|
|
@ -36,7 +35,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLiteralChunk(string literal, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddLiteralChunk(string literal, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
if (_lastChunk is LiteralChunk)
|
if (_lastChunk is LiteralChunk)
|
||||||
{
|
{
|
||||||
|
|
@ -47,94 +46,92 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler
|
||||||
AddChunk(new LiteralChunk
|
AddChunk(new LiteralChunk
|
||||||
{
|
{
|
||||||
Text = literal,
|
Text = literal,
|
||||||
}, association, context);
|
}, association);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddExpressionChunk(string expression, ExpressionRenderingMode renderingMode, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddExpressionChunk(string expression, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new ExpressionChunk
|
AddChunk(new ExpressionChunk
|
||||||
{
|
{
|
||||||
Code = expression,
|
Code = expression
|
||||||
RenderingMode = renderingMode
|
}, association);
|
||||||
}, association, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddStatementChunk(string code, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddStatementChunk(string code, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new StatementChunk
|
AddChunk(new StatementChunk
|
||||||
{
|
{
|
||||||
Code = code,
|
Code = code,
|
||||||
}, association, context);
|
}, association);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddUsingChunk(string usingNamespace, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddUsingChunk(string usingNamespace, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new UsingChunk
|
AddChunk(new UsingChunk
|
||||||
{
|
{
|
||||||
Namespace = usingNamespace,
|
Namespace = usingNamespace,
|
||||||
}, association, context, topLevel: true);
|
}, association, topLevel: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTypeMemberChunk(string code, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddTypeMemberChunk(string code, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new TypeMemberChunk
|
AddChunk(new TypeMemberChunk
|
||||||
{
|
{
|
||||||
Code = code,
|
Code = code,
|
||||||
}, association, context, topLevel: true);
|
}, association, topLevel: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddLiteralCodeAttributeChunk(string code, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddLiteralCodeAttributeChunk(string code, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new LiteralCodeAttributeChunk
|
AddChunk(new LiteralCodeAttributeChunk
|
||||||
{
|
{
|
||||||
Code = code,
|
Code = code,
|
||||||
}, association, context);
|
}, association);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddResolveUrlChunk(string url, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddResolveUrlChunk(string url, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new ResolveUrlChunk
|
AddChunk(new ResolveUrlChunk
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url
|
||||||
RenderingMode = context.ExpressionRenderingMode
|
}, association);
|
||||||
}, association, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSetLayoutChunk(string layout, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddSetLayoutChunk(string layout, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new SetLayoutChunk
|
AddChunk(new SetLayoutChunk
|
||||||
{
|
{
|
||||||
Layout = layout
|
Layout = layout
|
||||||
}, association, context);
|
}, association);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSetBaseTypeChunk(string typeName, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddSetBaseTypeChunk(string typeName, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new SetBaseTypeChunk
|
AddChunk(new SetBaseTypeChunk
|
||||||
{
|
{
|
||||||
TypeName = typeName.Trim()
|
TypeName = typeName.Trim()
|
||||||
}, association, context, topLevel: true);
|
}, association, topLevel: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSessionStateChunk(string value, SyntaxTreeNode association, CodeGeneratorContext context)
|
public void AddSessionStateChunk(string value, SyntaxTreeNode association)
|
||||||
{
|
{
|
||||||
AddChunk(new SessionStateChunk
|
AddChunk(new SessionStateChunk
|
||||||
{
|
{
|
||||||
Value = value
|
Value = value
|
||||||
}, association, context, topLevel: true);
|
}, association, topLevel: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T StartChunkBlock<T>(SyntaxTreeNode association, CodeGeneratorContext context) where T : ChunkBlock
|
public T StartChunkBlock<T>(SyntaxTreeNode association) where T : ChunkBlock
|
||||||
{
|
{
|
||||||
return StartChunkBlock<T>(association, context, topLevel: false);
|
return StartChunkBlock<T>(association, topLevel: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T StartChunkBlock<T>(SyntaxTreeNode association, CodeGeneratorContext context, bool topLevel) where T : ChunkBlock
|
public T StartChunkBlock<T>(SyntaxTreeNode association, bool topLevel) where T : ChunkBlock
|
||||||
{
|
{
|
||||||
T chunk = (T)Activator.CreateInstance(typeof(T));
|
T chunk = (T)Activator.CreateInstance(typeof(T));
|
||||||
|
|
||||||
AddChunk(chunk, association, context, topLevel);
|
AddChunk(chunk, association, topLevel);
|
||||||
|
|
||||||
_blockChain.Push(chunk);
|
_blockChain.Push(chunk);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
DynamicCodeAttributeChunk chunk = codeTreeBuilder.StartChunkBlock<DynamicCodeAttributeChunk>(target, context);
|
DynamicCodeAttributeChunk chunk = codeTreeBuilder.StartChunkBlock<DynamicCodeAttributeChunk>(target);
|
||||||
chunk.Start = ValueStart;
|
chunk.Start = ValueStart;
|
||||||
chunk.Prefix = Prefix;
|
chunk.Prefix = Prefix;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
ExpressionBlockChunk chunk = codeTreeBuilder.StartChunkBlock<ExpressionBlockChunk>(target, context);
|
ExpressionBlockChunk chunk = codeTreeBuilder.StartChunkBlock<ExpressionBlockChunk>(target);
|
||||||
chunk.RenderingMode = context.ExpressionRenderingMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
|
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
|
||||||
|
|
@ -113,7 +112,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddExpressionChunk(target.Content, context.ExpressionRenderingMode, target, context);
|
codeTreeBuilder.AddExpressionChunk(target.Content, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
HelperChunk chunk = codeTreeBuilder.StartChunkBlock<HelperChunk>(target, context, topLevel: true);
|
HelperChunk chunk = codeTreeBuilder.StartChunkBlock<HelperChunk>(target, topLevel: true);
|
||||||
|
|
||||||
chunk.Signature = Signature;
|
chunk.Signature = Signature;
|
||||||
chunk.Footer = Footer;
|
chunk.Footer = Footer;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiteralCodeAttributeChunk chunk = context.CodeTreeBuilder.StartChunkBlock<LiteralCodeAttributeChunk>(target, context);
|
LiteralCodeAttributeChunk chunk = context.CodeTreeBuilder.StartChunkBlock<LiteralCodeAttributeChunk>(target);
|
||||||
chunk.Prefix = Prefix;
|
chunk.Prefix = Prefix;
|
||||||
chunk.Value = Value;
|
chunk.Value = Value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddLiteralChunk(target.Content, target, context);
|
codeTreeBuilder.AddLiteralChunk(target.Content, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
if (Name == SyntaxConstants.CSharp.SessionStateKeyword)
|
if (Name == SyntaxConstants.CSharp.SessionStateKeyword)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddSessionStateChunk(Value, target, context);
|
codeTreeBuilder.AddSessionStateChunk(Value, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddResolveUrlChunk(target.Content, target, context);
|
codeTreeBuilder.AddResolveUrlChunk(target.Content, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
SectionChunk chunk = codeTreeBuilder.StartChunkBlock<SectionChunk>(target, context);
|
SectionChunk chunk = codeTreeBuilder.StartChunkBlock<SectionChunk>(target);
|
||||||
|
|
||||||
chunk.Name = SectionName;
|
chunk.Name = SectionName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddSetBaseTypeChunk(target.Content, target, context);
|
codeTreeBuilder.AddSetBaseTypeChunk(target.Content, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddSetLayoutChunk(LayoutPath, target, context);
|
codeTreeBuilder.AddSetLayoutChunk(LayoutPath, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddStatementChunk(target.Content, target, context);
|
codeTreeBuilder.AddStatementChunk(target.Content, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
|
|
||||||
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateStartBlockCode(SyntaxTreeNode target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.StartChunkBlock<TemplateChunk>(target, context);
|
codeTreeBuilder.StartChunkBlock<TemplateChunk>(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
|
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Razor.Generator
|
||||||
{
|
{
|
||||||
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
public void GenerateCode(Span target, CodeTreeBuilder codeTreeBuilder, CodeGeneratorContext context)
|
||||||
{
|
{
|
||||||
codeTreeBuilder.AddTypeMemberChunk(target.Content, target, context);
|
codeTreeBuilder.AddTypeMemberChunk(target.Content, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
public override void GenerateCode(Span target, CodeGeneratorContext context)
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ namespace Microsoft.AspNet.Razor.Test.Generator.CodeTree
|
||||||
var language = new CSharpRazorCodeLanguage();
|
var language = new CSharpRazorCodeLanguage();
|
||||||
RazorEngineHost host = new RazorEngineHost(language);
|
RazorEngineHost host = new RazorEngineHost(language);
|
||||||
var context = CodeGeneratorContext.Create(host, "TestClass", "TestNamespace", "Foo.cs", shouldGenerateLinePragmas: false);
|
var context = CodeGeneratorContext.Create(host, "TestClass", "TestNamespace", "Foo.cs", shouldGenerateLinePragmas: false);
|
||||||
context.CodeTreeBuilder.AddUsingChunk("FakeNamespace1", syntaxTreeNode, context);
|
context.CodeTreeBuilder.AddUsingChunk("FakeNamespace1", syntaxTreeNode);
|
||||||
context.CodeTreeBuilder.AddUsingChunk("FakeNamespace2.SubNamespace", syntaxTreeNode, context);
|
context.CodeTreeBuilder.AddUsingChunk("FakeNamespace2.SubNamespace", syntaxTreeNode);
|
||||||
CodeBuilder codeBuilder = language.CreateBuilder(context);
|
CodeBuilder codeBuilder = language.CreateBuilder(context);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,10 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
{
|
{
|
||||||
public static void ValidateResults(string codeTreeCode, string codeDOMCode, IList<LineMapping> codeTreeMappings, IDictionary<int, GeneratedCodeMapping> codeDOMMappings)
|
public static void ValidateResults(string codeTreeCode, string codeDOMCode, IList<LineMapping> codeTreeMappings, IDictionary<int, GeneratedCodeMapping> codeDOMMappings)
|
||||||
{
|
{
|
||||||
Assert.Equal(codeTreeMappings.Count, codeDOMMappings.Values.Count);
|
if (codeDOMMappings != null)
|
||||||
|
{
|
||||||
|
Assert.Equal(codeTreeMappings.Count, codeDOMMappings.Values.Count);
|
||||||
|
}
|
||||||
|
|
||||||
ValidateNamespace(codeTreeCode, codeDOMCode);
|
ValidateNamespace(codeTreeCode, codeDOMCode);
|
||||||
ValidateClass(codeTreeCode, codeDOMCode);
|
ValidateClass(codeTreeCode, codeDOMCode);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
@helper foo(int bar)
|
@{
|
||||||
{
|
var ch = true;
|
||||||
<div>@bar</div>
|
var cls = "bar";
|
||||||
}
|
<a href="Foo" />
|
||||||
|
<p class="@cls" />
|
||||||
@helper foo2(string bar)
|
<p class="foo @cls" />
|
||||||
{
|
<p class="@cls foo" />
|
||||||
<div>@bar</div>
|
<input type="checkbox" checked="@ch" />
|
||||||
|
<input type="checkbox" checked="foo @ch" />
|
||||||
|
<p class="@if (cls != null) { @cls } />
|
||||||
|
<a href="~/Foo" />
|
||||||
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
|
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
|
||||||
}
|
<script src="@Url.Content("~/Scripts/modernizr-2.0.6-development-only.js")" type="text/javascript"></script>
|
||||||
|
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
|
||||||
<span>Hello WOrld</span>
|
}
|
||||||
|
|
||||||
<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
|
|
||||||
Loading…
Reference in New Issue