[Fixes #50] Removed unnecessary whitespaces before text tag
This commit is contained in:
parent
c680d6b953
commit
4d80c96f9c
|
|
@ -388,14 +388,14 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any;
|
Span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any;
|
||||||
|
|
||||||
// Accept whitespace but always keep the last whitespace node so we can put it back if necessary
|
// Accept whitespace but always keep the last whitespace node so we can put it back if necessary
|
||||||
var lastWs = AcceptWhiteSpaceInLines();
|
var lastWhitespace = AcceptWhiteSpaceInLines();
|
||||||
Debug.Assert(lastWs == null || (lastWs.Start.AbsoluteIndex + lastWs.Content.Length == CurrentLocation.AbsoluteIndex));
|
Debug.Assert(lastWhitespace == null || (lastWhitespace.Start.AbsoluteIndex + lastWhitespace.Content.Length == CurrentLocation.AbsoluteIndex));
|
||||||
|
|
||||||
if (EndOfFile)
|
if (EndOfFile)
|
||||||
{
|
{
|
||||||
if (lastWs != null)
|
if (lastWhitespace != null)
|
||||||
{
|
{
|
||||||
Accept(lastWs);
|
Accept(lastWhitespace);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -411,16 +411,23 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
if (Context.DesignTimeMode || !isMarkup)
|
if (Context.DesignTimeMode || !isMarkup)
|
||||||
{
|
{
|
||||||
// CODE owns whitespace, MARKUP owns it ONLY in DesignTimeMode.
|
// CODE owns whitespace, MARKUP owns it ONLY in DesignTimeMode.
|
||||||
if (lastWs != null)
|
if (lastWhitespace != null)
|
||||||
{
|
{
|
||||||
Accept(lastWs);
|
Accept(lastWhitespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
var nextSymbol = Lookahead(1);
|
||||||
|
|
||||||
// MARKUP owns whitespace EXCEPT in DesignTimeMode.
|
// MARKUP owns whitespace EXCEPT in DesignTimeMode.
|
||||||
PutCurrentBack();
|
PutCurrentBack();
|
||||||
PutBack(lastWs);
|
|
||||||
|
// Don't putback the whitespace if it precedes a '<text>' tag.
|
||||||
|
if (nextSymbol != null && !nextSymbol.Content.Equals(SyntaxConstants.TextTagName))
|
||||||
|
{
|
||||||
|
PutBack(lastWhitespace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMarkup)
|
if (isMarkup)
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
[InlineData("ConditionalAttributes")]
|
[InlineData("ConditionalAttributes")]
|
||||||
[InlineData("ResolveUrl")]
|
[InlineData("ResolveUrl")]
|
||||||
[InlineData("Await")]
|
[InlineData("Await")]
|
||||||
|
[InlineData("CodeBlockWithTextElement")]
|
||||||
public void CSharpCodeGeneratorCorrectlyGeneratesRunTimeCode(string testType)
|
public void CSharpCodeGeneratorCorrectlyGeneratesRunTimeCode(string testType)
|
||||||
{
|
{
|
||||||
RunTest(testType);
|
RunTest(testType);
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
onResults(results);
|
onResults(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Verify code against baseline
|
// Verify code against baseline
|
||||||
Assert.Equal(expectedOutput, textOutput);
|
Assert.Equal(expectedOutput, textOutput);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
.AsStatement()
|
.AsStatement()
|
||||||
.AutoCompleteWith("}"),
|
.AutoCompleteWith("}"),
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
Factory.Markup(" "),
|
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
Factory.MarkupTransition("<text").Accepts(AcceptedCharacters.Any)),
|
Factory.MarkupTransition("<text").Accepts(AcceptedCharacters.Any)),
|
||||||
Factory.Markup(Environment.NewLine + " ").Accepts(AcceptedCharacters.None),
|
Factory.Markup(Environment.NewLine + " ").Accepts(AcceptedCharacters.None),
|
||||||
|
|
|
||||||
|
|
@ -578,7 +578,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
new StatementBlock(
|
new StatementBlock(
|
||||||
Factory.Code("if (i > 0) {").AsStatement(),
|
Factory.Code("if (i > 0) {").AsStatement(),
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
Factory.Markup(" "),
|
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
Factory.MarkupTransition("<text>").Accepts(AcceptedCharacters.None)),
|
Factory.MarkupTransition("<text>").Accepts(AcceptedCharacters.None)),
|
||||||
Factory.Markup(";").Accepts(AcceptedCharacters.None),
|
Factory.Markup(";").Accepts(AcceptedCharacters.None),
|
||||||
|
|
@ -599,7 +598,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
.AsStatement()
|
.AsStatement()
|
||||||
.AutoCompleteWith(autoCompleteString: null),
|
.AutoCompleteWith(autoCompleteString: null),
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
Factory.Markup(" "),
|
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
Factory.MarkupTransition("<text>").Accepts(AcceptedCharacters.None)),
|
Factory.MarkupTransition("<text>").Accepts(AcceptedCharacters.None)),
|
||||||
Factory.Markup(";").Accepts(AcceptedCharacters.None),
|
Factory.Markup(";").Accepts(AcceptedCharacters.None),
|
||||||
|
|
@ -639,7 +637,6 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
),
|
),
|
||||||
Factory.Code($" }}{Environment.NewLine} foreach (var p in Enumerable.Range(1, 10)) {{{Environment.NewLine}").AsStatement(),
|
Factory.Code($" }}{Environment.NewLine} foreach (var p in Enumerable.Range(1, 10)) {{{Environment.NewLine}").AsStatement(),
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
Factory.Markup(" "),
|
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
Factory.MarkupTransition("<text>").Accepts(AcceptedCharacters.None)),
|
Factory.MarkupTransition("<text>").Accepts(AcceptedCharacters.None)),
|
||||||
Factory.Markup("The number is ").Accepts(AcceptedCharacters.None),
|
Factory.Markup("The number is ").Accepts(AcceptedCharacters.None),
|
||||||
|
|
|
||||||
|
|
@ -4386,7 +4386,6 @@ namespace Microsoft.AspNet.Razor.Test.TagHelpers
|
||||||
factory.CodeTransition(),
|
factory.CodeTransition(),
|
||||||
factory.Code("do { var foo = bar;").AsStatement(),
|
factory.Code("do { var foo = bar;").AsStatement(),
|
||||||
new MarkupBlock(
|
new MarkupBlock(
|
||||||
factory.Markup(" "),
|
|
||||||
new MarkupTagBlock(
|
new MarkupTagBlock(
|
||||||
factory.MarkupTransition("<text>")),
|
factory.MarkupTransition("<text>")),
|
||||||
factory.Markup("Foo").Accepts(AcceptedCharacters.None),
|
factory.Markup("Foo").Accepts(AcceptedCharacters.None),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
#pragma checksum "CodeBlockWithTextElement.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "740b5af27dd6c6ff0e88b39a02d4bf1a38fcdc0b"
|
||||||
|
namespace TestOutput
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
public class CodeBlockWithTextElement
|
||||||
|
{
|
||||||
|
#line hidden
|
||||||
|
public CodeBlockWithTextElement()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable 1998
|
||||||
|
public override async Task ExecuteAsync()
|
||||||
|
{
|
||||||
|
#line 1 "CodeBlockWithTextElement.cshtml"
|
||||||
|
|
||||||
|
var a = 1;
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
Instrumentation.BeginContext(26, 1, false);
|
||||||
|
#line 2 "CodeBlockWithTextElement.cshtml"
|
||||||
|
Write(a);
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
Instrumentation.BeginContext(34, 2, true);
|
||||||
|
WriteLiteral("\r\n");
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
#line 3 "CodeBlockWithTextElement.cshtml"
|
||||||
|
var b = 1;
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
Instrumentation.BeginContext(60, 1, false);
|
||||||
|
#line 3 "CodeBlockWithTextElement.cshtml"
|
||||||
|
Write(b);
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
Instrumentation.BeginContext(68, 2, true);
|
||||||
|
WriteLiteral("\r\n");
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
#line 4 "CodeBlockWithTextElement.cshtml"
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
Instrumentation.BeginContext(71, 2, true);
|
||||||
|
WriteLiteral("\r\n");
|
||||||
|
Instrumentation.EndContext();
|
||||||
|
}
|
||||||
|
#pragma warning restore 1998
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -160,14 +160,14 @@ if(true) {
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
WriteLiteral(" checkbox ");
|
WriteLiteral("checkbox ");
|
||||||
#line 18 "ComplexTagHelpers.cshtml"
|
#line 18 "ComplexTagHelpers.cshtml"
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
WriteLiteral(" anything ");
|
WriteLiteral("anything ");
|
||||||
#line 18 "ComplexTagHelpers.cshtml"
|
#line 18 "ComplexTagHelpers.cshtml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,11 @@ WriteTo(__razor_attribute_value_writer, link);
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
Instrumentation.BeginContext(77, 3, true);
|
Instrumentation.BeginContext(84, 2, true);
|
||||||
WriteLiteralTo(__razor_attribute_value_writer, " # ");
|
WriteLiteralTo(__razor_attribute_value_writer, "# ");
|
||||||
Instrumentation.EndContext();
|
Instrumentation.EndContext();
|
||||||
#line 2 "InlineBlocks.cshtml"
|
#line 2 "InlineBlocks.cshtml"
|
||||||
}
|
}
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ namespace TestOutput
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
Instrumentation.BeginContext(211, 16, true);
|
Instrumentation.BeginContext(221, 12, true);
|
||||||
WriteLiteral(" \r\n <a");
|
WriteLiteral("\r\n <a");
|
||||||
Instrumentation.EndContext();
|
Instrumentation.EndContext();
|
||||||
WriteAttribute("href", Tuple.Create(" href=\"", 233), Tuple.Create("\"", 245), Tuple.Create(Tuple.Create("", 240), Tuple.Create<System.Object, System.Int32>(Href("~/Foo"), 240), false));
|
WriteAttribute("href", Tuple.Create(" href=\"", 233), Tuple.Create("\"", 245), Tuple.Create(Tuple.Create("", 240), Tuple.Create<System.Object, System.Int32>(Href("~/Foo"), 240), false));
|
||||||
Instrumentation.BeginContext(246, 20, true);
|
Instrumentation.BeginContext(246, 20, true);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
@{
|
||||||
|
var a = 1; <text>@a</text>
|
||||||
|
var b = 1; <text>@b</text>
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue