(mod: any)
| 8 | * If a TDZ error happens, retry several microtasks and finally one macrotask tick. |
| 9 | */ |
| 10 | export async function safeReadDefault(mod: any): Promise<any | null> { |
| 11 | const isTdz = (err: any) => /before initialization|TDZ/i.test(String(err?.message || err || '')); |
| 12 | // Attempt immediate read |
| 13 | try { |
| 14 | return mod?.default ?? mod ?? null; |
| 15 | } catch (e) { |
| 16 | if (!isTdz(e)) throw e; |
| 17 | } |
| 18 | // A few microtask retries |
| 19 | for (let i = 0; i < 4; i++) { |
| 20 | await Promise.resolve(); |
| 21 | try { |
| 22 | return mod?.default ?? mod ?? null; |
| 23 | } catch (e) { |
| 24 | if (!isTdz(e)) throw e; |
| 25 | } |
| 26 | } |
| 27 | // One macrotask tick (allow dependent modules to finish evaluating) |
| 28 | await new Promise<void>((r) => setTimeout(r, 0)); |
| 29 | try { |
| 30 | return mod?.default ?? mod ?? null; |
| 31 | } catch (e) { |
| 32 | if (!isTdz(e)) throw e; |
| 33 | } |
| 34 | // Final microtask after macrotask |
| 35 | await Promise.resolve(); |
| 36 | try { |
| 37 | return mod?.default ?? mod ?? null; |
| 38 | } catch (e) { |
| 39 | throw e; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Resolve NativeScript core classes/Application from the vendor realm or globalThis. |
| 44 | export function getCore(name: 'Application' | 'Frame' | 'Page' | 'Label'): any { |
no test coverage detected