-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinterpreters.js
58 lines (51 loc) · 1.89 KB
/
interpreters.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ⚠️ Part of this file is automatically generated
// The :RUNTIMES comment is a delimiter and no code should be written/changed after
// See rollup/build_interpreters.cjs to know more
/** @type {Map<string, object>} */
export const registry = new Map();
/** @type {Map<string, object>} */
export const configs = new Map();
/** @type {string[]} */
export const selectors = [];
/** @type {string[]} */
export const prefixes = [];
/* c8 ignore start */
export const interpreter = new Proxy(new Map(), {
get(map, id) {
if (!map.has(id)) {
const [type, ...rest] = id.split('@');
const interpreter = registry.get(type);
const url = /^(?:\.?\.?\/|https?:\/\/)/i.test(rest)
? rest.join('@')
: interpreter.module(...rest);
map.set(id, {
url,
module: import(/* webpackIgnore: true */url),
engine: interpreter.engine.bind(interpreter),
});
}
const { url, module, engine } = map.get(id);
return (config, baseURL) =>
module.then((module) => {
configs.set(id, config);
return engine(module, config, url, baseURL);
});
},
});
/* c8 ignore stop */
const register = (interpreter) => {
for (const type of [].concat(interpreter.type)) {
registry.set(type, interpreter);
selectors.push(`script[type="${type}"]`);
prefixes.push(`${type}-`);
}
};
//:RUNTIMES
import dummy from './interpreter/dummy.js';
import micropython from './interpreter/micropython.js';
import pyodide from './interpreter/pyodide.js';
import ruby_wasm_wasi from './interpreter/ruby-wasm-wasi.js';
import wasmoon from './interpreter/wasmoon.js';
import webr from './interpreter/webr.js';
for (const interpreter of [dummy, micropython, pyodide, ruby_wasm_wasi, wasmoon, webr])
register(interpreter);