@@ -180,6 +180,11 @@ export class RouterParserUtil {
180180 // :(params) => { ... } → :"[Function]"
181181 cleaned = this . replaceBlockArrowFunctions ( cleaned ) ;
182182
183+ // Step 6: Unwrap constructor-wrapped object literals used in route metadata.
184+ // data:newLazyRoutingOptions({preload:true}) -> data:{preload:true}
185+ // This keeps JSON5 parsing resilient for typed route data objects.
186+ cleaned = this . unwrapConstructorWrappedObjectValues ( cleaned ) ;
187+
183188 return cleaned ;
184189 }
185190
@@ -274,6 +279,112 @@ export class RouterParserUtil {
274279 return result ;
275280 }
276281
282+ private unwrapConstructorWrappedObjectValues ( input : string ) : string {
283+ const isIdentifierStart = ( ch : string | undefined ) : boolean =>
284+ ! ! ch && / [ A - Z a - z _ $ ] / . test ( ch ) ;
285+ const isIdentifierPart = ( ch : string | undefined ) : boolean =>
286+ ! ! ch && / [ A - Z a - z 0 - 9 _ $ ] / . test ( ch ) ;
287+
288+ let result = "" ;
289+ let i = 0 ;
290+ let inDouble = false ;
291+ let inSingle = false ;
292+
293+ while ( i < input . length ) {
294+ const ch = input [ i ] ;
295+
296+ if ( ch === '"' && ! inSingle ) {
297+ inDouble = ! inDouble ;
298+ result += ch ;
299+ i ++ ;
300+ continue ;
301+ }
302+ if ( ch === "'" && ! inDouble ) {
303+ inSingle = ! inSingle ;
304+ result += ch ;
305+ i ++ ;
306+ continue ;
307+ }
308+ if ( ch === "\\" && ( inDouble || inSingle ) ) {
309+ result += ch + ( input [ i + 1 ] || "" ) ;
310+ i += 2 ;
311+ continue ;
312+ }
313+
314+ if (
315+ ! inDouble &&
316+ ! inSingle &&
317+ ch === ":" &&
318+ input . slice ( i + 1 , i + 4 ) === "new"
319+ ) {
320+ let nameStart = i + 4 ;
321+ if ( ! isIdentifierStart ( input [ nameStart ] ) ) {
322+ result += ch ;
323+ i ++ ;
324+ continue ;
325+ }
326+
327+ while ( isIdentifierPart ( input [ nameStart ] ) ) {
328+ nameStart ++ ;
329+ }
330+
331+ if ( input [ nameStart ] !== "(" || input [ nameStart + 1 ] !== "{" ) {
332+ result += ch ;
333+ i ++ ;
334+ continue ;
335+ }
336+
337+ let cursor = nameStart + 1 ; // points to '{'
338+ let braceDepth = 1 ;
339+ let objInDouble = false ;
340+ let objInSingle = false ;
341+
342+ cursor ++ ;
343+ while ( cursor < input . length && braceDepth > 0 ) {
344+ const c = input [ cursor ] ;
345+ if ( c === "\\" && ( objInDouble || objInSingle ) ) {
346+ cursor += 2 ;
347+ continue ;
348+ }
349+ if ( c === '"' && ! objInSingle ) {
350+ objInDouble = ! objInDouble ;
351+ cursor ++ ;
352+ continue ;
353+ }
354+ if ( c === "'" && ! objInDouble ) {
355+ objInSingle = ! objInSingle ;
356+ cursor ++ ;
357+ continue ;
358+ }
359+ if ( ! objInDouble && ! objInSingle ) {
360+ if ( c === "{" ) {
361+ braceDepth ++ ;
362+ } else if ( c === "}" ) {
363+ braceDepth -- ;
364+ }
365+ }
366+ cursor ++ ;
367+ }
368+
369+ if ( braceDepth !== 0 || input [ cursor ] !== ")" ) {
370+ result += ch ;
371+ i ++ ;
372+ continue ;
373+ }
374+
375+ const objectLiteral = input . slice ( nameStart + 1 , cursor ) ;
376+ result += ":" + objectLiteral ;
377+ i = cursor + 1 ;
378+ continue ;
379+ }
380+
381+ result += ch ;
382+ i ++ ;
383+ }
384+
385+ return result ;
386+ }
387+
277388 public setRootModule ( module : string ) : void {
278389 this . rootModule = module ;
279390 }
0 commit comments