public RazorUsingDirective(RazorDirectiveSyntax node, AddImportChunkGenerator statement) { Node = node; Statement = statement; }
public override void VisitRazorDirective(RazorDirectiveSyntax node) { var descendantLiterals = node.DescendantNodes(); foreach (var child in descendantLiterals) { if (!(child is CSharpStatementLiteralSyntax literal)) { continue; } var context = literal.GetSpanContext(); if (context == null) { // We can't find a chunk generator. continue; } else if (context.ChunkGenerator is AddTagHelperChunkGenerator addTagHelper) { // Make sure this node exists in the file we're parsing and not in its imports. if (_filePath.Equals(_source.FilePath, StringComparison.Ordinal)) { addTagHelper.Diagnostics.Add( ComponentDiagnosticFactory.Create_UnsupportedTagHelperDirective(node.GetSourceSpan(_source))); } } else if (context.ChunkGenerator is RemoveTagHelperChunkGenerator removeTagHelper) { // Make sure this node exists in the file we're parsing and not in its imports. if (_filePath.Equals(_source.FilePath, StringComparison.Ordinal)) { removeTagHelper.Diagnostics.Add( ComponentDiagnosticFactory.Create_UnsupportedTagHelperDirective(node.GetSourceSpan(_source))); } } else if (context.ChunkGenerator is TagHelperPrefixDirectiveChunkGenerator tagHelperPrefix) { // Make sure this node exists in the file we're parsing and not in its imports. if (_filePath.Equals(_source.FilePath, StringComparison.Ordinal)) { tagHelperPrefix.Diagnostics.Add( ComponentDiagnosticFactory.Create_UnsupportedTagHelperDirective(node.GetSourceSpan(_source))); } } else if (context.ChunkGenerator is AddImportChunkGenerator usingStatement && !usingStatement.IsStatic) { // Get the namespace from the using statement. var @namespace = usingStatement.ParsedNamespace; if (@namespace.Contains('=')) { // We don't support usings with alias. continue; } for (var i = 0; i < _tagHelpers.Count; i++) { var tagHelper = _tagHelpers[i]; if (tagHelper.IsComponentFullyQualifiedNameMatch()) { // We've already added these to our list of matches. continue; } var typeName = tagHelper.GetTypeName(); if (tagHelper.IsChildContentTagHelper()) { // If this is a child content tag helper, we want to add it if it's original type is in scope of the given namespace. // E.g, if the type name is `Test.MyComponent.ChildContent`, we want to add it if `Test.MyComponent` is in this namespace. TrySplitNamespaceAndType(typeName, out typeName, out var _); } if (typeName != null && IsTypeInNamespace(typeName, @namespace)) { // If the type is at the top-level or if the type's namespace matches the using's namespace, add it. Matches.Add(tagHelper); } } } } }
public override void VisitRazorDirective(RazorDirectiveSyntax node) { WriteBlock(node, BlockKindInternal.Directive, base.VisitRazorDirective); }
public override void VisitRazorDirective(RazorDirectiveSyntax node) { var descendantLiterals = node.DescendantNodes(); foreach (var child in descendantLiterals) { if (!(child is CSharpStatementLiteralSyntax literal)) { continue; } var context = literal.GetSpanContext(); if (context == null) { // We can't find a chunk generator. continue; } else if (context.ChunkGenerator is AddTagHelperChunkGenerator addTagHelper) { if (addTagHelper.AssemblyName == null) { // Skip this one, it's an error continue; } if (!AssemblyContainsTagHelpers(addTagHelper.AssemblyName, _tagHelpers)) { // No tag helpers in the assembly. continue; } for (var i = 0; i < _tagHelpers.Count; i++) { var tagHelper = _tagHelpers[i]; if (MatchesDirective(tagHelper, addTagHelper.TypePattern, addTagHelper.AssemblyName)) { Matches.Add(tagHelper); } } } else if (context.ChunkGenerator is RemoveTagHelperChunkGenerator removeTagHelper) { if (removeTagHelper.AssemblyName == null) { // Skip this one, it's an error continue; } if (!AssemblyContainsTagHelpers(removeTagHelper.AssemblyName, _tagHelpers)) { // No tag helpers in the assembly. continue; } for (var i = 0; i < _tagHelpers.Count; i++) { var tagHelper = _tagHelpers[i]; if (MatchesDirective(tagHelper, removeTagHelper.TypePattern, removeTagHelper.AssemblyName)) { Matches.Remove(tagHelper); } } } else if (context.ChunkGenerator is TagHelperPrefixDirectiveChunkGenerator tagHelperPrefix) { if (!string.IsNullOrEmpty(tagHelperPrefix.DirectiveText)) { // We only expect to see a single one of these per file, but that's enforced at another level. _tagHelperPrefix = tagHelperPrefix.DirectiveText; } } } }
public override SyntaxNode VisitRazorDirective(RazorDirectiveSyntax node) { // We don't support directives inside tag helper attributes. Don't rewrite anything inside a directive. // E.g, <p age="@functions { }"> is not supported. return(node); }
public override void VisitRazorDirective(RazorDirectiveSyntax node) { AddSemanticRange(node.Transition, RazorSemanticTokensLegend.RazorTransition); Visit(node.Body); }
public override void VisitRazorDirective(RazorDirectiveSyntax node) { WriteBlock(node, FormattingBlockKind.Directive, base.VisitRazorDirective); }
public override void VisitRazorDirective(RazorDirectiveSyntax node) { AddSemanticRange(node.Transition, SyntaxKind.Transition); base.VisitRazorDirective(node); }