forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-sources.mjs
More file actions
43 lines (42 loc) · 1.22 KB
/
Copy pathstring-sources.mjs
File metadata and controls
43 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const SOURCES = {
__proto__: null,
'test:Array': ['1', '2'], // both `1,2` and `12` are valid ESM
'test:ArrayBuffer': new ArrayBuffer(0),
'test:BigInt64Array': new BigInt64Array(0),
'test:BigUint64Array': new BigUint64Array(0),
'test:Float32Array': new Float32Array(0),
'test:Float64Array': new Float64Array(0),
'test:Int8Array': new Int8Array(0),
'test:Int16Array': new Int16Array(0),
'test:Int32Array': new Int32Array(0),
'test:null': null,
'test:Object': {},
'test:SharedArrayBuffer': new SharedArrayBuffer(0),
'test:string': '',
'test:String': new String(''),
'test:Uint8Array': new Uint8Array(0),
'test:Uint8ClampedArray': new Uint8ClampedArray(0),
'test:Uint16Array': new Uint16Array(0),
'test:Uint32Array': new Uint32Array(0),
'test:undefined': undefined,
}
export function resolve(specifier, context, next) {
if (specifier.startsWith('test:')) {
return {
importAttributes: context.importAttributes,
shortCircuit: true,
url: specifier,
};
}
return next(specifier);
}
export function load(href, context, next) {
if (href.startsWith('test:')) {
return {
format: 'module',
shortCircuit: true,
source: SOURCES[href],
};
}
return next(href);
}