@@ -3,7 +3,6 @@ import { readdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
import { Biome , Distribution } from "@biomejs/js-api" ;
4
4
import { config , createResultFilePath , errorFilePath , finalResultPath , formatterErrorFilePath , resultsDirectory , resumeMode , shouldTakeABreath , startFilePath } from "./config" ;
5
5
import { VirtualTypeScriptEnvironment } from "@typescript/vfs" ;
6
- import ts from "typescript" ;
7
6
import { inspect } from "node:util" ;
8
7
import { join } from "node:path" ;
9
8
@@ -70,8 +69,38 @@ const extractAddress = (line: string) => {
70
69
}
71
70
72
71
const sortMemoryLines = ( memoryLines : string ) => memoryLines . split ( '\n' )
73
- . sort ( ( a , b ) => extractAddress ( a ) - extractAddress ( b ) )
74
- . join ( '\n' ) ;
72
+ . sort ( ( a , b ) => extractAddress ( a ) - extractAddress ( b ) )
73
+ . join ( '\n' ) ;
74
+
75
+ const sortSections = ( data : string ) => {
76
+ // find the lines between `\tmemory: {` and `\t{`
77
+ const memoryLines = data . match ( / \t m e m o r y : { \r ? \n ( .* ?) \r ? \n \t } / s) ;
78
+ if ( memoryLines ) {
79
+ const old = memoryLines [ 1 ] ;
80
+ if ( old . indexOf ( `"111111111` ) !== - 1 ) {
81
+ writeFileSync ( errorFilePath , data , "utf-8" ) ;
82
+ throw new Error ( `found an invalid memory address!` ) ;
83
+ }
84
+ const sorted = sortMemoryLines ( old ) ;
85
+ data = data . replace ( old , sorted )
86
+ }
87
+
88
+ const L1CacheLines = data . match ( / \t L 1 C a c h e : { \r ? \n ( .* ?) \r ? \n \t } / s) ;
89
+ if ( L1CacheLines ) {
90
+ const old = L1CacheLines [ 1 ] ;
91
+ const sorted = sortMemoryLines ( old ) ;
92
+ data = data . replace ( old , sorted )
93
+ }
94
+
95
+ const activeLocalsLines = data . match ( / \t a c t i v e L o c a l s : { \r ? \n ( .* ?) \r ? \n \t } / s) ;
96
+ if ( activeLocalsLines ) {
97
+ const old = activeLocalsLines [ 1 ] ;
98
+ const sorted = old . split ( '\n' ) . sort ( ) . join ( '\n' ) ;
99
+ data = data . replace ( old , sorted )
100
+ }
101
+
102
+ return data ;
103
+ }
75
104
76
105
export const fsWorker = {
77
106
writeFile : (
@@ -95,16 +124,7 @@ export const fsWorker = {
95
124
}
96
125
97
126
if ( kind === 'ts' ) {
98
- // find the lines between `\tmemory: {` and `\t{`
99
- const start = data . indexOf ( '\tmemory: {' ) ;
100
- const end = data . indexOf ( '\t}' , start ) ;
101
- const memoryLines = data . substring ( start , end ) ;
102
- const sortedMemoryLines = sortMemoryLines ( memoryLines ) ;
103
- data = data . replace ( memoryLines , sortedMemoryLines ) ;
104
- if ( memoryLines . indexOf ( `"111111111` ) !== - 1 ) {
105
- writeFileSync ( errorFilePath , data , "utf-8" ) ;
106
- throw new Error ( `found an invalid memory address!` ) ;
107
- }
127
+ data = sortSections ( data ) ;
108
128
}
109
129
110
130
writeFileSync ( filePath , data , "utf-8" ) ;
0 commit comments