Skip to content

Commit

Permalink
feat: remove all regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Denny09310 committed Jul 16, 2024
1 parent c91b1f6 commit e763e42
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 67 deletions.
54 changes: 0 additions & 54 deletions src/Blazor.SourceGenerators/Expressions/SharedRegex.cs

This file was deleted.

25 changes: 14 additions & 11 deletions src/Blazor.SourceGenerators/Extensions/AttributeSyntaxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("\"", "");
}
2 changes: 0 additions & 2 deletions src/Blazor.SourceGenerators/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
21 changes: 21 additions & 0 deletions src/Blazor.SourceGenerators/TypeScript/Types/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit e763e42

Please sign in to comment.