( def: unknown, ctx: BaseParseContext )
| 76 | const parseCacheSizes = new WeakMap<BaseScope, number>() |
| 77 | |
| 78 | export const parseInnerDefinition = ( |
| 79 | def: unknown, |
| 80 | ctx: BaseParseContext |
| 81 | ): InnerParseResult => { |
| 82 | if (typeof def === "string") { |
| 83 | if (ctx.args && Object.keys(ctx.args).some(k => def.includes(k))) { |
| 84 | // we can only rely on the cache if there are no contextual |
| 85 | // resolutions like "this" or generic args |
| 86 | return parseString(def, ctx) |
| 87 | } |
| 88 | let scopeCache = parseCache.get(ctx.$) |
| 89 | if (!scopeCache) { |
| 90 | scopeCache = Object.create(null) as Record<string, InnerParseResult> |
| 91 | parseCache.set(ctx.$, scopeCache) |
| 92 | } |
| 93 | if (scopeCache[def]) { |
| 94 | $ark.reached?.cached(scopeCache, def) |
| 95 | return scopeCache[def] |
| 96 | } |
| 97 | const mark = $ark.reached?.mark() |
| 98 | const result = parseString(def, ctx) |
| 99 | const node = isArray(result) ? result[0] : result |
| 100 | if (!inProgress.definitions || !node.hasAlias) { |
| 101 | scopeCache = parseCache.get(ctx.$) ?? scopeCache |
| 102 | if (!(def in scopeCache)) { |
| 103 | const size = (parseCacheSizes.get(ctx.$) ?? 0) + 1 |
| 104 | if (size > maxCachedDefs) { |
| 105 | scopeCache = Object.create(null) as Record<string, InnerParseResult> |
| 106 | parseCache.set(ctx.$, scopeCache) |
| 107 | parseCacheSizes.set(ctx.$, 1) |
| 108 | } else parseCacheSizes.set(ctx.$, size) |
| 109 | } |
| 110 | scopeCache[def] = result |
| 111 | $ark.reached?.store(mark, scopeCache, def) |
| 112 | } |
| 113 | return result |
| 114 | } |
| 115 | return hasDomain(def, "object") ? |
| 116 | parseObject(def, ctx) |
| 117 | : throwParseError(writeBadDefinitionTypeMessage(domainOf(def))) |
| 118 | } |
| 119 | |
| 120 | export const parseObject = (def: object, ctx: BaseParseContext): BaseRoot => { |
| 121 | const objectKind = objectKindOf(def) |
no test coverage detected