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