[Fixes #472] Added temporary parse error for helper directive
This commit is contained in:
parent
44675701cb
commit
153ed57d66
|
|
@ -224,6 +224,14 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
}
|
}
|
||||||
else
|
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.Type = BlockType.Expression;
|
||||||
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
Context.CurrentBlock.ChunkGenerator = new ExpressionChunkGenerator();
|
||||||
ImplicitExpression();
|
ImplicitExpression();
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,9 @@ namespace Microsoft.AspNet.Razor.Parser
|
||||||
public static readonly string ElseIfKeyword = "else if";
|
public static readonly string ElseIfKeyword = "else if";
|
||||||
public static readonly string NamespaceKeyword = "namespace";
|
public static readonly string NamespaceKeyword = "namespace";
|
||||||
public static readonly string ClassKeyword = "class";
|
public static readonly string ClassKeyword = "class";
|
||||||
|
|
||||||
|
// Not supported. Only used for error cases.
|
||||||
|
public static readonly string HelperKeyword = "helper";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1546,6 +1546,22 @@ namespace Microsoft.AspNet.Razor
|
||||||
return string.Format(CultureInfo.CurrentCulture, GetString("TagHelperParseTreeRewriter_InvalidNestedTag"), p0, p1, p2);
|
return string.Format(CultureInfo.CurrentCulture, GetString("TagHelperParseTreeRewriter_InvalidNestedTag"), p0, p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The {0} directive is not supported.
|
||||||
|
/// </summary>
|
||||||
|
internal static string ParseError_HelperDirectiveNotAvailable
|
||||||
|
{
|
||||||
|
get { return GetString("ParseError_HelperDirectiveNotAvailable"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The {0} directive is not supported.
|
||||||
|
/// </summary>
|
||||||
|
internal static string FormatParseError_HelperDirectiveNotAvailable(object p0)
|
||||||
|
{
|
||||||
|
return string.Format(CultureInfo.CurrentCulture, GetString("ParseError_HelperDirectiveNotAvailable"), p0);
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetString(string name, params string[] formatterNames)
|
private static string GetString(string name, params string[] formatterNames)
|
||||||
{
|
{
|
||||||
var value = _resourceManager.GetString(name);
|
var value = _resourceManager.GetString(name);
|
||||||
|
|
|
||||||
|
|
@ -425,4 +425,7 @@ Instead, wrap the contents of the block in "{{}}":
|
||||||
<data name="TagHelperParseTreeRewriter_InvalidNestedTag" xml:space="preserve">
|
<data name="TagHelperParseTreeRewriter_InvalidNestedTag" xml:space="preserve">
|
||||||
<value>The <{0}> tag is not allowed by parent <{1}> tag helper. Only child tag helper(s) targeting tag name(s) '{2}' are allowed.</value>
|
<value>The <{0}> tag is not allowed by parent <{1}> tag helper. Only child tag helper(s) targeting tag name(s) '{2}' are allowed.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ParseError_HelperDirectiveNotAvailable" xml:space="preserve">
|
||||||
|
<value>The {0} directive is not supported.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -27,6 +27,21 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp
|
||||||
length: 1));
|
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]
|
[Fact]
|
||||||
public void ParseBlockCapturesWhitespaceToEndOfLineInInvalidUsingStatementAndTreatsAsFileCode()
|
public void ParseBlockCapturesWhitespaceToEndOfLineInInvalidUsingStatementAndTreatsAsFileCode()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue