1- using System . Text . RegularExpressions ;
2- using System . Runtime . CompilerServices ;
3-
41/// <summary>
52/// Splits Polyfill source files by target framework, evaluating conditional compilations.
63/// Unknown symbols (like Feature*) are preserved in the output.
74/// </summary>
85public class Splitter
96{
10- static readonly string SolutionDir = FindSolutionDirectory ( ) ;
11- static readonly string PolyfillDir = Path . Combine ( SolutionDir , "Polyfill" ) ;
12-
13- /// <summary>
14- /// The directory where split files are written.
15- /// </summary>
16- public static readonly string SplitOutputDir = Path . Combine ( SolutionDir , "Split" ) ;
7+ static readonly string PolyfillDir = Path . Combine ( ProjectFiles . SolutionDirectory , "Polyfill" ) ;
178
18- /// <summary>
19- /// Finds the solution directory by navigating up from the source file location.
20- /// Falls back to ProjectFiles.SolutionDirectory if the source file approach fails.
21- /// </summary>
22- static string FindSolutionDirectory ( [ CallerFilePath ] string sourceFilePath = "" )
23- {
24- // Try to find the solution directory from the source file path
25- // The source file is at: src/ApiBuilderTests/Splitter.cs
26- // The solution directory is: src/
27- if ( ! string . IsNullOrEmpty ( sourceFilePath ) )
28- {
29- var dir = Path . GetDirectoryName ( sourceFilePath ) ;
30- if ( dir != null )
31- {
32- var parentDir = Path . GetDirectoryName ( dir ) ;
33- if ( parentDir != null && Directory . Exists ( Path . Combine ( parentDir , "Polyfill" ) ) )
34- {
35- return parentDir ;
36- }
37- }
38- }
39-
40- // Fall back to ProjectFiles.SolutionDirectory
41- return ProjectFiles . SolutionDirectory ;
42- }
9+ public static readonly string SplitOutputDir = Path . Combine ( ProjectFiles . SolutionDirectory , "Split" ) ;
4310
4411 /// <summary>
4512 /// All target frameworks to generate splits for.
@@ -620,9 +587,9 @@ string SimplifyUnary()
620587 return "true" ;
621588 }
622589 // Check if inner starts with ! and simplify double negation
623- if ( inner . StartsWith ( "!" ) )
590+ if ( inner . StartsWith ( '!' ) )
624591 {
625- return inner . Substring ( 1 ) ;
592+ return inner [ 1 .. ] ;
626593 }
627594 return $ "!{ inner } ";
628595 }
@@ -644,7 +611,7 @@ string SimplifyPrimary()
644611 _pos ++ ;
645612 }
646613 // Only keep parens if needed (contains || and was inside an && context)
647- if ( result . Contains ( "||" ) && ! result . StartsWith ( "(" ) )
614+ if ( result . Contains ( "||" ) && ! result . StartsWith ( '(' ) )
648615 {
649616 return $ "({ result } )";
650617 }
0 commit comments