diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs index 960cc7cf04..e29710acd1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/CSharpCodeParser.cs @@ -54,7 +54,6 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy private Dictionary _directiveParsers = new Dictionary(StringComparer.Ordinal); private Dictionary> _keywordParsers = new Dictionary>(); - private HashSet _seenDirectives = new HashSet(StringComparer.Ordinal); public CSharpCodeParser(ParserContext context) : this(directives: Enumerable.Empty(), 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; diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/ParserContext.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/ParserContext.cs index 897504a300..1207616604 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/ParserContext.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/ParserContext.cs @@ -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(StringComparer.Ordinal); } public SyntaxTreeBuilder Builder { get; } public ErrorSink ErrorSink { get; set; } + public HashSet SeenDirectives { get; } + public ITextDocument Source { get; } public RazorSourceDocument SourceDocument { get; }