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

Commit 153ed57

Browse files
committed
[Fixes #472] Added temporary parse error for helper directive
1 parent 4467570 commit 153ed57

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

src/Microsoft.AspNet.Razor/Parser/CSharpCodeParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ private void AfterTransition()
224224
}
225225
else
226226
{
227+
if (CurrentSymbol.Content.Equals(SyntaxConstants.CSharp.HelperKeyword))
228+
{
229+
Context.OnError(
230+
CurrentLocation,
231+
RazorResources.FormatParseError_HelperDirectiveNotAvailable(SyntaxConstants.CSharp.HelperKeyword),
232+
CurrentSymbol.Content.Length);
233+
}
234+
227235
Context.CurrentBlock.Type = BlockType.Expression;
228236
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
229237
ImplicitExpression();

src/Microsoft.AspNet.Razor/Parser/SyntaxConstants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public static class CSharp
2727
public static readonly string ElseIfKeyword = "else if";
2828
public static readonly string NamespaceKeyword = "namespace";
2929
public static readonly string ClassKeyword = "class";
30+
31+
// Not supported. Only used for error cases.
32+
public static readonly string HelperKeyword = "helper";
3033
}
3134
}
3235
}

src/Microsoft.AspNet.Razor/Properties/RazorResources.Designer.cs

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.AspNet.Razor/RazorResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,7 @@ Instead, wrap the contents of the block in "{{}}":
425425
<data name="TagHelperParseTreeRewriter_InvalidNestedTag" xml:space="preserve">
426426
<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>
427427
</data>
428+
<data name="ParseError_HelperDirectiveNotAvailable" xml:space="preserve">
429+
<value>The {0} directive is not supported.</value>
430+
</data>
428431
</root>

test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpErrorTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ public void ParseBlockHandlesQuotesAfterTransition()
2727
length: 1));
2828
}
2929

30+
[Fact]
31+
public void ParseBlockWithHelperDirectiveProducesError()
32+
{
33+
ParseBlockTest("@helper fooHelper { }",
34+
new ExpressionBlock(
35+
Factory.CodeTransition(),
36+
Factory.Code("helper")
37+
.AsImplicitExpression(KeywordSet)
38+
.Accepts(AcceptedCharacters.NonWhiteSpace)),
39+
new RazorError(
40+
RazorResources.FormatParseError_HelperDirectiveNotAvailable(SyntaxConstants.CSharp.HelperKeyword),
41+
new SourceLocation(1, 0, 1),
42+
length: 6));
43+
}
44+
3045
[Fact]
3146
public void ParseBlockCapturesWhitespaceToEndOfLineInInvalidUsingStatementAndTreatsAsFileCode()
3247
{

0 commit comments

Comments
 (0)