public override void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span)
 {
     _builder.Add(new IntermediateToken()
     {
         Content = span.Content,
         Kind    = TokenKind.CSharp,
         Source  = BuildSourceSpanFromNode(span),
     });
 }
Exemplo n.º 2
0
        public void ConstructorTransfersInstanceOfChunkGeneratorFromBlockBuilder()
        {
            // Arrange
            var expected = new ExpressionChunkGenerator();
            var builder  = new BlockBuilder()
            {
                Type           = BlockType.Helper,
                ChunkGenerator = expected
            };

            // Act
            var actual = builder.Build();

            // Assert
            Assert.Same(expected, actual.ChunkGenerator);
        }
            // CSharp expressions are broken up into blocks and spans because Razor allows Razor comments
            // inside an expression.
            // Ex:
            //      @DateTime.@*This is a comment*@Now
            //
            // We need to capture this in the IR so that we can give each piece the correct source mappings
            public override void VisitExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block)
            {
                if (_builder.Current is CSharpExpressionAttributeValueIntermediateNode)
                {
                    VisitDefault(block);
                    return;
                }

                var expressionNode = new CSharpExpressionIntermediateNode();

                _builder.Push(expressionNode);

                VisitDefault(block);

                _builder.Pop();

                if (expressionNode.Children.Count > 0)
                {
                    var sourceRangeStart = expressionNode
                                           .Children
                                           .FirstOrDefault(child => child.Source != null)
                                           ?.Source;

                    if (sourceRangeStart != null)
                    {
                        var contentLength = expressionNode.Children.Sum(child => child.Source?.Length ?? 0);

                        expressionNode.Source = new SourceSpan(
                            sourceRangeStart.Value.FilePath ?? FilePath,
                            sourceRangeStart.Value.AbsoluteIndex,
                            sourceRangeStart.Value.LineIndex,
                            sourceRangeStart.Value.CharacterIndex,
                            contentLength);
                    }
                }
            }
Exemplo n.º 4
0
 public virtual void VisitExpressionSpan(ExpressionChunkGenerator chunkGenerator, Span span)
 {
     VisitDefault(span);
 }
Exemplo n.º 5
0
 public virtual void VisitExpressionBlock(ExpressionChunkGenerator chunkGenerator, Block block)
 {
     VisitDefault(block);
 }