@@ -90,11 +90,16 @@ function extractRootObjects(code: string) {
9090 const colonIdx = code . indexOf ( ':' , i )
9191 if ( colonIdx === - 1 ) break
9292
93- // backtrack to find the key (simple word characters)
93+ // --- find key ---
94+ // walk backwards from colon to find start of key
9495 let keyEnd = colonIdx - 1
9596 while ( keyEnd >= 0 && / \s / . test ( code [ keyEnd ] ) ) keyEnd --
97+
9698 let keyStart = keyEnd
97- while ( keyStart >= 0 && / \w / . test ( code [ keyStart ] ) ) keyStart --
99+ // keep going back until we hit a delimiter (whitespace, brace, semicolon, comma, or start of file)
100+ while ( keyStart >= 0 && ! / [ \s { } ; , \n ] / . test ( code [ keyStart ] ) ) {
101+ keyStart --
102+ }
98103
99104 // find the opening brace after colon
100105 const braceIdx = code . indexOf ( '{' , colonIdx )
@@ -321,14 +326,12 @@ export const fromTypes =
321326 )
322327 )
323328
324- const routesString = extractRootObjects (
325- instance . replace ( matchStatus , '"$1":' )
326- )
327-
328329 const routes : AdditionalReference = { }
329330
330331 // Treaty is a collection of { ... } & { ... } & { ... }
331- for ( const route of routesString ) {
332+ for ( const route of extractRootObjects (
333+ instance . slice ( 2 ) . replace ( matchStatus , '"$1":' )
334+ ) ) {
332335 let schema = TypeBox ( route . replaceAll ( / r e a d o n l y / g, '' ) )
333336 if ( schema . type !== 'object' ) continue
334337
0 commit comments