UNPKG

691 BPlain TextView Raw
1import {errorMessage, isFunction, loadResources} from './utils';
2
3import type {Loader, LoaderCallback} from '.';
4
5/* eslint-disable no-invalid-this */
6const loader: Loader = function (source) {
7 this.cacheable();
8
9 const callback = this.async();
10
11 if (!isFunction<LoaderCallback>(callback)) {
12 throw new Error(errorMessage.syncCompilation);
13 }
14
15 /* istanbul ignore if: not possible to test */
16 if (typeof source !== 'string') {
17 throw new Error(errorMessage.impossible);
18 }
19
20 /* eslint-disable-next-line @typescript-eslint/no-floating-promises */
21 loadResources(this, source, callback);
22};
23/* eslint-enable no-invalid-this */
24
25export default loader;