Skip to content

Commit a8c525d

Browse files
committed
Make interpreters code async by default
1 parent 98813a8 commit a8c525d

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

docs/index.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.js.map

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/custom.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const handleCustomType = async (node) => {
6969
type: runtime,
7070
custom: type,
7171
config: node.getAttribute('config') || config || {},
72-
async: node.hasAttribute('async'),
72+
async: node.getAttribute('async') !== 'false',
7373
serviceWorker: node.getAttribute('service-worker'),
7474
});
7575
defineProperty(node, 'xworker', { value: xworker });

esm/script-handler.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const handle = async (script) => {
125125
// and/or source code with different config or interpreter
126126
const {
127127
attributes: {
128-
async: isAsync,
128+
async: asyncAttribute,
129129
config,
130130
env,
131131
name: wn,
@@ -137,19 +137,21 @@ export const handle = async (script) => {
137137
type,
138138
} = script;
139139

140+
/* c8 ignore start */
141+
const isAsync = asyncAttribute?.value !== 'false';
142+
140143
const versionValue = version?.value;
141144
const name = getRuntimeID(type, versionValue);
142145
let configValue = getValue(config, '|');
143146
const id = getValue(env, '') || `${name}${configValue}`;
144147
configValue = configValue.slice(1);
145148

146-
/* c8 ignore start */
147149
const url = workerURL(script);
148150
if (url) {
149151
const XWorker = $xworker(type, versionValue);
150152
const xworker = new XWorker(url, {
151153
...nodeInfo(script, type),
152-
async: !!isAsync,
154+
async: isAsync,
153155
config: configValue,
154156
serviceWorker: sw?.value,
155157
});
@@ -176,7 +178,7 @@ export const handle = async (script) => {
176178
// start fetching external resources ASAP
177179
const source = src ? fetch(src).text() : script.textContent;
178180
details.queue = details.queue.then(() =>
179-
execute(script, source, details.XWorker, !!isAsync),
181+
execute(script, source, details.XWorker, isAsync),
180182
);
181183
}
182184
};

test/mocked/micropython.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const loadMicroPython = () => ({
1919
python.target = document.currentScript.target;
2020
}
2121
},
22+
runPythonAsync(content) {
23+
return this.runPython(content);
24+
},
2225
globals: {
2326
set(name, value) {
2427
globalThis[name] = value;

test/mocked/pyodide.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const loadPyodide = () => ({
2626
}
2727
python.target = document.currentScript.target;
2828
},
29+
runPythonAsync(content) {
30+
return this.runPython(content);
31+
},
2932
globals: {
3033
set(name, value) {
3134
globalThis[name] = value;

0 commit comments

Comments
 (0)