(script, type, interpreter)
| 256 | }; |
| 257 | |
| 258 | const init = async (script, type, interpreter) => { |
| 259 | const [ |
| 260 | { basicSetup, EditorView }, |
| 261 | { Compartment }, |
| 262 | { python }, |
| 263 | { indentUnit }, |
| 264 | { keymap }, |
| 265 | { defaultKeymap, indentWithTab }, |
| 266 | ] = await Promise.all([ |
| 267 | codemirror.core, |
| 268 | codemirror.state, |
| 269 | codemirror.python, |
| 270 | codemirror.language, |
| 271 | codemirror.view, |
| 272 | codemirror.commands, |
| 273 | ]); |
| 274 | |
| 275 | let isSetup = script.hasAttribute("setup"); |
| 276 | const hasConfig = script.hasAttribute("config"); |
| 277 | const serviceWorker = script.getAttribute("service-worker"); |
| 278 | const env = `${interpreter}-${script.getAttribute("env") || getID(type)}`; |
| 279 | |
| 280 | // allow specifying custom run and stop buttons through dataset attributes |
| 281 | const { dataset } = script; |
| 282 | if (dataset.run) RUN_BUTTON = dataset.run; |
| 283 | if (dataset.stop) STOP_BUTTON = dataset.stop; |
| 284 | |
| 285 | // helps preventing too lazy ServiceWorker initialization on button run |
| 286 | if (serviceWorker) { |
| 287 | new XWorker("data:application/javascript,postMessage(0)", { |
| 288 | type: "dummy", |
| 289 | serviceWorker, |
| 290 | }).onmessage = ({ target }) => target.terminate(); |
| 291 | } |
| 292 | |
| 293 | // allow bootstrap with same env for repeated editor creation |
| 294 | // only if `env-override` is explicitly set as attribute |
| 295 | if (hasConfig && configs.has(env)) { |
| 296 | if (script.hasAttribute("env-override")) { |
| 297 | // in this case we need to bootstrap the env again |
| 298 | // because otherwise each env would leak |
| 299 | envs.delete(env); |
| 300 | } else { |
| 301 | throw new SyntaxError( |
| 302 | configs.get(env) |
| 303 | ? `duplicated config for env: ${env}` |
| 304 | : `unable to add a config to the env: ${env}`, |
| 305 | ); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | configs.set(env, hasConfig); |
| 310 | |
| 311 | let source = script.textContent; |
| 312 | |
| 313 | // verify the src points to a valid file that can be parsed |
| 314 | const { src } = script; |
| 315 | if (src) { |
no test coverage detected