Move seen directives to the parser context.
- The context is guaranteed to be re-created per-parse, it should own the seen directives. #1376
This commit is contained in:
parent
7a04e35da5
commit
6bbcbc1261
|
|
@ -54,7 +54,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
||||||
private Dictionary<string, Action> _directiveParsers = new Dictionary<string, Action>(StringComparer.Ordinal);
|
private Dictionary<string, Action> _directiveParsers = new Dictionary<string, Action>(StringComparer.Ordinal);
|
||||||
private Dictionary<CSharpKeyword, Action<bool>> _keywordParsers = new Dictionary<CSharpKeyword, Action<bool>>();
|
private Dictionary<CSharpKeyword, Action<bool>> _keywordParsers = new Dictionary<CSharpKeyword, Action<bool>>();
|
||||||
private HashSet<string> _seenDirectives = new HashSet<string>(StringComparer.Ordinal);
|
|
||||||
|
|
||||||
public CSharpCodeParser(ParserContext context)
|
public CSharpCodeParser(ParserContext context)
|
||||||
: this(directives: Enumerable.Empty<DirectiveDescriptor>(), context: context)
|
: this(directives: Enumerable.Empty<DirectiveDescriptor>(), context: context)
|
||||||
|
|
@ -95,7 +94,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
_directiveParsers.Add(directive, () =>
|
_directiveParsers.Add(directive, () =>
|
||||||
{
|
{
|
||||||
handler();
|
handler();
|
||||||
_seenDirectives.Add(directive);
|
Context.SeenDirectives.Add(directive);
|
||||||
});
|
});
|
||||||
|
|
||||||
Keywords.Add(directive);
|
Keywords.Add(directive);
|
||||||
|
|
@ -1781,7 +1780,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
{
|
{
|
||||||
if (descriptor.Usage == DirectiveUsage.FileScopedSinglyOccurring)
|
if (descriptor.Usage == DirectiveUsage.FileScopedSinglyOccurring)
|
||||||
{
|
{
|
||||||
if (_seenDirectives.Contains(descriptor.Directive))
|
if (Context.SeenDirectives.Contains(descriptor.Directive))
|
||||||
{
|
{
|
||||||
UsageError(Resources.FormatDuplicateDirective(descriptor.Directive));
|
UsageError(Resources.FormatDuplicateDirective(descriptor.Directive));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
|
|
@ -25,12 +26,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
ParseOnlyLeadingDirectives = options.ParseOnlyLeadingDirectives;
|
ParseOnlyLeadingDirectives = options.ParseOnlyLeadingDirectives;
|
||||||
Builder = new SyntaxTreeBuilder();
|
Builder = new SyntaxTreeBuilder();
|
||||||
ErrorSink = new ErrorSink();
|
ErrorSink = new ErrorSink();
|
||||||
|
SeenDirectives = new HashSet<string>(StringComparer.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SyntaxTreeBuilder Builder { get; }
|
public SyntaxTreeBuilder Builder { get; }
|
||||||
|
|
||||||
public ErrorSink ErrorSink { get; set; }
|
public ErrorSink ErrorSink { get; set; }
|
||||||
|
|
||||||
|
public HashSet<string> SeenDirectives { get; }
|
||||||
|
|
||||||
public ITextDocument Source { get; }
|
public ITextDocument Source { get; }
|
||||||
|
|
||||||
public RazorSourceDocument SourceDocument { get; }
|
public RazorSourceDocument SourceDocument { get; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue