( js: CombinatorCompiler, node: IntersectionNode )
| 1219 | node.tfs ? "transformingNarrowedAfter" : "narrowedAfter" |
| 1220 | |
| 1221 | const writeIntersectionCombinator = ( |
| 1222 | js: CombinatorCompiler, |
| 1223 | node: IntersectionNode |
| 1224 | ): string => { |
| 1225 | const shape = js.shapes && writeShape(js, node) |
| 1226 | if (shape) return shape |
| 1227 | const predicates = node.inner.predicate?.map(predicate => |
| 1228 | writePredicate(js, predicate) |
| 1229 | ) |
| 1230 | const narrowed = |
| 1231 | predicates?.length === 1 ? |
| 1232 | predicates[0] |
| 1233 | : predicates && writeCall("narrowedByEach", `[${predicates.join(", ")}]`) |
| 1234 | const unnarrowed = narrowed && unnarrowedOf(node) |
| 1235 | if (unnarrowed) { |
| 1236 | reachRootsOf(js, unnarrowed) |
| 1237 | return writeCall( |
| 1238 | narrowedAfterOf(unnarrowed), |
| 1239 | readChecker(js, unnarrowed), |
| 1240 | narrowed |
| 1241 | ) |
| 1242 | } |
| 1243 | const refinements = node.preStruct.map(child => writeCheck(js, child)) |
| 1244 | const structure = node.structure && writeStructure(js, node.structure) |
| 1245 | const within = |
| 1246 | structure && narrowed ? |
| 1247 | writeCall( |
| 1248 | narrowedAfterOf(node.structure!), |
| 1249 | !node.structure!.tfs ? structure |
| 1250 | // one that transforms is asked whether it allows data before |
| 1251 | // its narrow reads it: with a ctx where a callback of its reads |
| 1252 | // one, which asked with none would be passed none |
| 1253 | : node.structure!.checksCtx ? writeCall("readingCtx", structure) |
| 1254 | : node.structure!.hasAlias ? writeCall("holdingAlias", structure) |
| 1255 | : structure, |
| 1256 | narrowed |
| 1257 | ) |
| 1258 | : (structure ?? narrowed) |
| 1259 | // props check data is an object, as their basis would |
| 1260 | if ( |
| 1261 | within && |
| 1262 | !refinements.length && |
| 1263 | (!node.basis || |
| 1264 | ((node.structure?.props.length || node.structure?.index) && |
| 1265 | isObjectCheck(node.basis))) |
| 1266 | ) |
| 1267 | return within |
| 1268 | return writeCall( |
| 1269 | "intersection", |
| 1270 | node.basis ? writeCheck(js, node.basis) : "0", |
| 1271 | `[${refinements.join(", ")}]`, |
| 1272 | within, |
| 1273 | node.basis && node.brief !== checkOf(node.basis)!.description ? |
| 1274 | JSON.stringify(node.brief) |
| 1275 | : undefined |
| 1276 | ) |
| 1277 | } |
| 1278 |
no test coverage detected