MCPcopy Create free account
hub / github.com/Effect-TS/effect / make

Function make

packages/effect/src/internal/pathFilter.ts:229–314  ·  view source on GitHub ↗
(rules: ReadonlyArray<Rule>, defaultExcluded: boolean)

Source from the content-addressed store, hash-verified

227const prunedBelow: Below = { prune: true, reached: false, candidates: [] }
228
229const make = (rules: ReadonlyArray<Rule>, defaultExcluded: boolean): Evaluator => {
230 const compiled = rules.map(compileRule)
231 const excluded = (decision: number): boolean =>
232 decision >= 0 ? !compiled[decision].include : decision === linkBaseline || defaultExcluded
233
234 // Descendants start from `inherited`. An included baseline keeps them, so
235 // the directory must be listed; an excluded one only gives way to a later
236 // inclusion that can match below.
237 const below = (states: ReadonlyArray<unknown>, inherited: number): Below => {
238 if (!excluded(inherited)) {
239 return { prune: false, reached: inherited >= 0, candidates: undefined }
240 }
241 let reached = false
242 let candidates: Array<string> | undefined = []
243 for (let i = Math.max(inherited + 1, 0); i < compiled.length; i++) {
244 const rule = compiled[i]
245 if (!rule.include || !reachable(rule, states[i])) {
246 continue
247 }
248 reached = true
249 const names: ReadonlyArray<string> | undefined = candidates && literals(rule, states[i])
250 candidates = names && candidates!.concat(names.filter((name) => !isUnlisted(name)))
251 }
252 return { prune: !reached, reached, candidates: reached ? candidates : [] }
253 }
254
255 const step = (state: State, name: string, directory: boolean, link: boolean): Visit => {
256 if (state.barrier !== -1) {
257 return { state, decision: state.barrier, excluded: true, ...prunedBelow }
258 }
259 const next = new Array<unknown>(compiled.length)
260 let decision = state.inherited
261 let inherited = state.inherited
262 for (let i = 0; i < compiled.length; i++) {
263 const rule = compiled[i]
264 const value = advance(rule, state.rules[i], name, false)
265 next[i] = value
266 if (accepted(rule, value, directory)) {
267 // A fresh `inherit` hit passes down only if it changes the running
268 // decision, as BuildKit's `MatchesUsingParentResults` does. Here
269 // `decision` is the highest hit below `i`.
270 if (rule.inherit && i > inherited && rule.include === excluded(decision)) {
271 inherited = i
272 }
273 // `i` only grows, but an inherited hit may outrank it
274 if (i > decision) {
275 decision = i
276 }
277 }
278 }
279 const rule = compiled[decision]
280 const isExcluded = excluded(decision)
281 if (isExcluded && rule?.barrier) {
282 return { state: { rules: next, inherited, barrier: decision }, decision, excluded: true, ...prunedBelow }
283 }
284 let children: ReadonlyArray<unknown> = next
285 if (link) {
286 // Inclusions follow the link only through explicit segments, exclusions

Callers 1

evaluatorFunction · 0.70

Calls 3

someMethod · 0.80
belowFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected