aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver/src/resolvers/fallthrough_resolver.ts
blob: 338f334f4155b6e1d5e0f4893c143943d46e3a19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import * as _ from 'lodash';

import { ContractSource } from '../types';

import { Resolver } from './resolver';

export class FallthroughResolver extends Resolver {
    private readonly _resolvers: Resolver[] = [];
    public appendResolver(resolver: Resolver): void {
        this._resolvers.push(resolver);
    }
    public resolveIfExists(importPath: string): ContractSource | undefined {
        for (const resolver of this._resolvers) {
            const contractSourceIfExists = resolver.resolveIfExists(importPath);
            if (!_.isUndefined(contractSourceIfExists)) {
                return contractSourceIfExists;
            }
        }
        return undefined;
    }
}