Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit 871e82c

Browse files
author
N. Taylor Mullen
committed
Addressed code review comments.
1 parent 25f71e0 commit 871e82c

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ private void RenderRawAttributeValue(string value,
430430
attributeDescriptor,
431431
valueRenderer: (writer) =>
432432
{
433-
// We only want to do the work of generating a line mapping if we're in design time mode.
434433
if (_context.Host.DesignTimeMode)
435434
{
436435
using (new CSharpLineMappingWriter(_writer, documentLocation, value.Length))

src/Microsoft.AspNet.Razor/Generator/TagHelperCodeGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ public override void GenerateStartBlockCode(Block target, CodeGeneratorContext c
6262
attribute.Value.Accept(codeGenerator);
6363

6464
var chunks = codeGenerator.Context.CodeTreeBuilder.CodeTree.Chunks;
65+
var first = chunks.FirstOrDefault();
6566

6667
attributes[attribute.Key] = new ChunkBlock
6768
{
6869
Children = chunks,
69-
Start = chunks.FirstOrDefault()?.Start ?? SourceLocation.Zero
70+
Start = first == null ? SourceLocation.Zero : first.Start
7071
};
7172

7273
// Reset the code tree builder so we can build a new one for the next attribute

src/Microsoft.AspNet.Razor/Parser/TagHelpers/TagHelperBlockBuilder.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,25 @@ private static KeyValuePair<string, SyntaxTreeNode> ParseSpan(
177177
{
178178
var symbol = htmlSymbols[i];
179179

180-
if (name == null && symbol.Type == HtmlSymbolType.Text)
180+
if (afterEquals)
181181
{
182-
name = symbol.Content;
183-
}
184-
else if (afterEquals)
185-
{
186-
// When symbols are accepted into SpanBuilders their locations get altered to abide by the
182+
// When symbols are accepted into SpanBuilders their locations get altered to be offset by the
187183
// parent which is why we need to mark our start location prior to adding the symbol so we know
188184
// the location of the attribute value start within the document.
189185
if (!capturedAttributeValueStart)
190186
{
191187
capturedAttributeValueStart = true;
192188

193-
attributeValueStartLocation += symbol.Start;
189+
attributeValueStartLocation = span.Start + symbol.Start;
194190
}
195191

196192
builder.Accept(symbol);
197193
}
194+
else if (name == null && symbol.Type == HtmlSymbolType.Text)
195+
{
196+
name = symbol.Content;
197+
attributeValueStartLocation = SourceLocation.Advance(span.Start, name);
198+
}
198199
else if (symbol.Type == HtmlSymbolType.Equals)
199200
{
200201
// We've found an '=' symbol, this means that the coming symbols will either be a quote
@@ -205,24 +206,30 @@ private static KeyValuePair<string, SyntaxTreeNode> ParseSpan(
205206
// TODO: Handle malformed tags, if there's an '=' then there MUST be a value.
206207
// https://github.com/aspnet/Razor/issues/104
207208

209+
SourceLocation symbolStartLocation;
210+
208211
// Check for attribute start values, aka single or double quote
209212
if (IsQuote(htmlSymbols[i + 1]))
210213
{
211214
// Move past the attribute start so we can accept the true value.
212215
i++;
216+
symbolStartLocation = htmlSymbols[i + 1].Start;
213217
}
214218
else
215219
{
220+
symbolStartLocation = symbol.Start;
221+
216222
// Set the symbol offset to 0 so we don't attempt to skip an end quote that doesn't exist.
217223
symbolOffset = 0;
218224
}
219225

226+
attributeValueStartLocation = symbolStartLocation + span.Start + SourceLocation.One;
220227
afterEquals = true;
221228
}
222229
}
223230

224-
// After all symbols have been added we need to offset the builders start position. Adding symbols to a
225-
// SpanBuilder alters its position prior to it being occupied.
231+
// After all symbols have been added we need to set the builders start position so we do not indirectly
232+
// modify each symbols Start location.
226233
builder.Start = attributeValueStartLocation;
227234

228235
return CreateMarkupAttribute(name, builder, attributeValueTypes);

src/Microsoft.AspNet.Razor/Text/SourceLocation.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public struct SourceLocation : IEquatable<SourceLocation>, IComparable<SourceLoc
1414
{
1515
public static readonly SourceLocation Undefined = CreateUndefined();
1616
public static readonly SourceLocation Zero = new SourceLocation(0, 0, 0);
17+
public static readonly SourceLocation One = new SourceLocation(1, 0, 1);
1718

1819
private int _absoluteIndex;
1920
private int _lineIndex;

0 commit comments

Comments
 (0)