Skip to content

Commit 2b2f2c1

Browse files
committed
fixed an issue with the currentScript not spotted before
1 parent aeaa193 commit 2b2f2c1

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

docs/index.js

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

docs/index.js.map

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

esm/script-handler.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ const execute = async (currentScript, source, XWorker, isAsync) => {
5555
source,
5656
]);
5757
try {
58-
// temporarily override inherited document.currentScript in a non writable way
59-
// but it deletes it right after to preserve native behavior (as it's sync: no trouble)
60-
defineProperty(document, 'currentScript', {
61-
configurable: true,
62-
get: () => currentScript,
63-
});
6458
registerJSModules(type, module, interpreter, JSModules);
6559
module.registerJSModule(interpreter, 'polyscript', {
6660
XWorker,
@@ -69,10 +63,16 @@ const execute = async (currentScript, source, XWorker, isAsync) => {
6963
workers: workersHandler,
7064
});
7165
dispatch(currentScript, type, 'ready');
72-
const result = module[isAsync ? 'runAsync' : 'run'](interpreter, content);
66+
// temporarily override inherited document.currentScript in a non writable way
67+
// but it deletes it right after to preserve native behavior (as it's sync: no trouble)
68+
defineProperty(document, 'currentScript', {
69+
configurable: true,
70+
get: () => currentScript,
71+
});
7372
const done = dispatch.bind(null, currentScript, type, 'done');
74-
if (isAsync) result.then(done);
75-
else done();
73+
let result = module[isAsync ? 'runAsync' : 'run'](interpreter, content);
74+
if (isAsync) result = await result;
75+
done();
7676
return result;
7777
} finally {
7878
delete document.currentScript;

0 commit comments

Comments
 (0)