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

Added temporary parse error for helper directive #531

Merged
merged 1 commit into from
Sep 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ private void AfterTransition()
}
else
{
if (CurrentSymbol.Content.Equals(SyntaxConstants.CSharp.HelperKeyword))
{
Context.OnError(
CurrentLocation,
RazorResources.FormatParseError_HelperDirectiveNotAvailable(SyntaxConstants.CSharp.HelperKeyword),
CurrentSymbol.Content.Length);
}

Context.CurrentBlock.Type = BlockType.Expression;
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
ImplicitExpression();
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static class CSharp
public static readonly string ElseIfKeyword = "else if";
public static readonly string NamespaceKeyword = "namespace";
public static readonly string ClassKeyword = "class";

// Not supported. Only used for error cases.
public static readonly string HelperKeyword = "helper";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate this from the rest and leave a comment above it stating that it's only for error use-cases.

}
}
}
16 changes: 16 additions & 0 deletions src/Microsoft.AspNet.Razor/Properties/RazorResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.AspNet.Razor/RazorResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,7 @@ Instead, wrap the contents of the block in "{{}}":
<data name="TagHelperParseTreeRewriter_InvalidNestedTag" xml:space="preserve">
<value>The &lt;{0}&gt; tag is not allowed by parent &lt;{1}&gt; tag helper. Only child tag helper(s) targeting tag name(s) '{2}' are allowed.</value>
</data>
<data name="ParseError_HelperDirectiveNotAvailable" xml:space="preserve">
<value>The {0} directive is not supported.</value>
</data>
</root>
15 changes: 15 additions & 0 deletions test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpErrorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public void ParseBlockHandlesQuotesAfterTransition()
length: 1));
}

[Fact]
public void ParseBlockWithHelperDirectiveProducesError()
{
ParseBlockTest("@helper fooHelper { }",
new ExpressionBlock(
Factory.CodeTransition(),
Factory.Code("helper")
.AsImplicitExpression(KeywordSet)
.Accepts(AcceptedCharacters.NonWhiteSpace)),
new RazorError(
RazorResources.FormatParseError_HelperDirectiveNotAvailable(SyntaxConstants.CSharp.HelperKeyword),
new SourceLocation(1, 0, 1),
length: 6));
}

[Fact]
public void ParseBlockCapturesWhitespaceToEndOfLineInInvalidUsingStatementAndTreatsAsFileCode()
{
Expand Down