diff --git a/src/Blazor.SourceGenerators/Expressions/SharedRegex.cs b/src/Blazor.SourceGenerators/Expressions/SharedRegex.cs deleted file mode 100644 index 17597af7..00000000 --- a/src/Blazor.SourceGenerators/Expressions/SharedRegex.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) David Pine. All rights reserved. -// Licensed under the MIT License. - -namespace Blazor.SourceGenerators.Expressions; - -internal static class SharedRegex -{ - // See: https://regex101.com/r/GV3DiG/1 - public static readonly Regex InterfaceRegex = - new("^(?'declaration'interface.*?{.*?})$", - RegexOptions.Singleline | RegexOptions.Multiline); - - public static readonly Regex InterfaceTypeNameRegex = - new("(?:interface )(?'TypeName'\\S+)"); - - public static readonly Regex ExtendsTypeNameRegex = - new("(?:extends )(?'TypeName'\\S+)"); - - public static readonly Regex TypeRegex = - new("^(?'type'type.*?)$", - RegexOptions.Singleline | RegexOptions.Multiline); - - public static readonly Regex TypeNameRegex = - new("(?:type )(?'TypeName'\\S+)"); - - /// - /// Given a string value of "clearWatch(watchId: number): void;", the - /// following capture groups would be present: - /// - /// MethodName: "clearWatch" - /// Parameters: "(watchId: number)" - /// ReturnType: ": void;" - /// - /// - public static readonly Regex TypeScriptMethodRegex = - new(@"^(?'MethodName'\S+(?=\())(?'Parameters'.*\))(?'ReturnType'\:.*)$", RegexOptions.Multiline); - - /// - /// Given a string value of "(position: GeolocationPosition): void;", the - /// following capture groups would be present: - /// - /// Parameters: "(position: GeolocationPosition" - /// ReturnType: ": void;" - /// - /// - public static readonly Regex TypeScriptCallbackRegex = - new(@"^(?'Parameters'\(.*\))(?'ReturnType'\:.*)$", RegexOptions.Multiline); - - public static readonly Regex TypeScriptPropertyRegex = - new(@"^(?'Name'.*)\:(?:.{1})(?'Type'.*)\;$", RegexOptions.Multiline); - - public static readonly Regex ArrayValuesRegex = - new(@"\[(?'Values'[^[\]]*)\]", RegexOptions.Multiline); -} diff --git a/src/Blazor.SourceGenerators/Extensions/AttributeSyntaxExtensions.cs b/src/Blazor.SourceGenerators/Extensions/AttributeSyntaxExtensions.cs index b0a71e41..453d887b 100644 --- a/src/Blazor.SourceGenerators/Extensions/AttributeSyntaxExtensions.cs +++ b/src/Blazor.SourceGenerators/Extensions/AttributeSyntaxExtensions.cs @@ -62,33 +62,36 @@ internal static GeneratorOptions GetGeneratorOptions( static string[]? ParseArray(string args) { + // Remove unwanted parts of the string var replacedArgs = args .Replace("new[]", "") .Replace("new []", "") .Replace("new string[]", "") .Replace("new string []", "") .Replace("{", "[") - .Replace("}", "]"); + .Replace("}", "]") + .Trim(); - var values = SharedRegex.ArrayValuesRegex - .GetMatchGroupValue(replacedArgs, "Values"); + // Find the first '[' and the last ']' to extract the array contents + var startIndex = replacedArgs.IndexOf('[') + 1; + var endIndex = replacedArgs.LastIndexOf(']'); - if (values is not null) + // Check if the brackets are correctly positioned + if (startIndex > 0 && endIndex > startIndex) { - var trimmed = values.Trim(); - var descriptors = trimmed.Split(','); + var values = replacedArgs.Substring(startIndex, endIndex - startIndex); + + // Split the values by commas + var descriptors = values.Split(','); return descriptors - .Select(descriptor => - { - descriptor = RemoveQuotes(descriptor).Trim(); - return descriptor; - }) + .Select(descriptor => RemoveQuotes(descriptor).Trim()) .ToArray(); } return default; } + private static string RemoveQuotes(string value) => value.Replace("\"", ""); } \ No newline at end of file diff --git a/src/Blazor.SourceGenerators/GlobalUsings.cs b/src/Blazor.SourceGenerators/GlobalUsings.cs index 3d2461b0..7326d40f 100644 --- a/src/Blazor.SourceGenerators/GlobalUsings.cs +++ b/src/Blazor.SourceGenerators/GlobalUsings.cs @@ -8,7 +8,6 @@ global using System.Text.RegularExpressions; global using Blazor.SourceGenerators.CSharp; global using Blazor.SourceGenerators.Diagnostics; -global using Blazor.SourceGenerators.Expressions; global using Blazor.SourceGenerators.Extensions; global using Blazor.SourceGenerators.JavaScript; global using Blazor.SourceGenerators.Parsers; @@ -18,5 +17,4 @@ global using Microsoft.CodeAnalysis.CSharp; global using Microsoft.CodeAnalysis.CSharp.Syntax; global using Microsoft.CodeAnalysis.Text; -global using static Blazor.SourceGenerators.Expressions.SharedRegex; global using static Blazor.SourceGenerators.Source.SourceCode; diff --git a/src/Blazor.SourceGenerators/TypeScript/Types/Enums.cs b/src/Blazor.SourceGenerators/TypeScript/Types/Enums.cs index 52ba5364..b4f82eff 100644 --- a/src/Blazor.SourceGenerators/TypeScript/Types/Enums.cs +++ b/src/Blazor.SourceGenerators/TypeScript/Types/Enums.cs @@ -7,6 +7,10 @@ #nullable disable namespace Blazor.SourceGenerators.TypeScript.Types; +#pragma warning disable S2344 // Enumeration type names should not have "Flags" or "Enum" suffixes +#pragma warning disable S4663 // Comments should not be empty +#pragma warning disable S125 // Sections of code should not be commented out + [Flags] public enum NodeFlags { @@ -45,6 +49,8 @@ public enum NodeFlags TypeExcludesFlags = YieldContext | AwaitContext } +#pragma warning disable CA1069 // I valori di enumerazione non devono essere duplicati + public enum TypeScriptSyntaxKind { Unknown, @@ -442,6 +448,8 @@ public enum TypeScriptSyntaxKind LastJsDocTagNode = JsDocLiteralType } +#pragma warning restore CA1069 // I valori di enumerazione non devono essere duplicati + public enum CharacterCode { NullCharacter = 0, @@ -809,6 +817,8 @@ public enum TypeReferenceSerializationKind ObjectType // The TypeReferenceNode resolves to any other type. } +#pragma warning disable CA1069 // I valori di enumerazione non devono essere duplicati + public enum SymbolFlags { None = 0, @@ -898,6 +908,8 @@ public enum SymbolFlags Classifiable = Class | Enum | TypeAlias | Interface | TypeParameter | Module } +#pragma warning restore CA1069 // I valori di enumerazione non devono essere duplicati + public enum CheckFlags { Instantiated = 1 << 0, // Instantiated symbol @@ -1160,6 +1172,8 @@ public enum Extension LastTypeScriptExtension = Dts } +#pragma warning disable CA1069 // I valori di enumerazione non devono essere duplicati + public enum TransformFlags { None = 0, @@ -1257,6 +1271,8 @@ public enum TransformFlags Es2015FunctionSyntaxMask = ContainsCapturedLexicalThis | ContainsDefaultValueAssignments } +#pragma warning restore CA1069 // I valori di enumerazione non devono essere duplicati + public enum EmitFlags { SingleLine = 1 << 0, // The contents of this node should be emitted on a single line. @@ -1339,3 +1355,8 @@ public enum EmitHint IdentifierName, // Emitting an IdentifierName Unspecified // Emitting an otherwise unspecified node } + + +#pragma warning restore S125 // Sections of code should not be commented out +#pragma warning restore S4663 // Comments should not be empty +#pragma warning restore S2344 // Enumeration type names should not have "Flags" or "Enum" suffixes \ No newline at end of file