Skip to content

Commit 9c2cec6

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

10 files changed

+115
-106
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.

docs/zip-gl8b5xR3.js renamed to docs/zip-C10rja2G.js

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

docs/zip-C10rja2G.js.map

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

docs/zip-gl8b5xR3.js.map

-1
This file was deleted.

esm/custom.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import '@ungap/with-resolvers';
22
import { $$ } from 'basic-devtools';
33

4-
import { JSModules, assign, create, createOverload, createResolved, dedent, defineProperty, nodeInfo, registerJSModules } from './utils.js';
4+
import { JSModules, isSync, assign, create, createOverload, createResolved, dedent, defineProperty, nodeInfo, registerJSModules } from './utils.js';
55
import { getDetails } from './script-handler.js';
66
import { registry as defaultRegistry, prefixes, configs } from './interpreters.js';
77
import { getRuntimeID } from './loader.js';
@@ -69,7 +69,7 @@ export const handleCustomType = async (node) => {
6969
type: runtime,
7070
custom: type,
7171
config: node.getAttribute('config') || config || {},
72-
async: node.getAttribute('async') !== 'false',
72+
async: !isSync(node),
7373
serviceWorker: node.getAttribute('service-worker'),
7474
});
7575
defineProperty(node, 'xworker', { value: xworker });

esm/script-handler.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import $xworker from './worker/class.js';
66
import workerURL from './worker/url.js';
77
import { getRuntime, getRuntimeID } from './loader.js';
88
import { registry } from './interpreters.js';
9-
import { JSModules, all, dispatch, resolve, defineProperty, nodeInfo, registerJSModules } from './utils.js';
9+
import { JSModules, isSync, all, dispatch, resolve, defineProperty, nodeInfo, registerJSModules } from './utils.js';
1010

1111
const getRoot = (script) => {
1212
let parent = script;
@@ -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;
@@ -125,7 +125,6 @@ export const handle = async (script) => {
125125
// and/or source code with different config or interpreter
126126
const {
127127
attributes: {
128-
async: asyncAttribute,
129128
config,
130129
env,
131130
name: wn,
@@ -138,7 +137,7 @@ export const handle = async (script) => {
138137
} = script;
139138

140139
/* c8 ignore start */
141-
const isAsync = asyncAttribute?.value !== 'false';
140+
const isAsync = !isSync(script);
142141

143142
const versionValue = version?.value;
144143
const name = getRuntimeID(type, versionValue);

esm/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export const importCSS = href => new Promise((onload, onerror) => {
124124
});
125125

126126
export const isCSS = source => /\.css$/i.test(new URL(source).pathname);
127+
128+
export const isSync = element =>
129+
/^(?:false|0|no)$/i.test(element.getAttribute('async'));
130+
127131
/* c8 ignore stop */
128132

129133
export {

package-lock.json

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

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
"@playwright/test": "^1.45.3",
4343
"@rollup/plugin-node-resolve": "^15.2.3",
4444
"@rollup/plugin-terser": "^0.4.4",
45-
"@zip.js/zip.js": "^2.7.47",
45+
"@zip.js/zip.js": "^2.7.48",
4646
"c8": "^10.1.2",
4747
"chokidar": "^3.6.0",
4848
"eslint": "^9.8.0",
4949
"linkedom": "^0.18.4",
50-
"rollup": "^4.19.1",
50+
"rollup": "^4.19.2",
5151
"static-handler": "^0.4.3",
5252
"typescript": "^5.5.4"
5353
},
@@ -78,14 +78,14 @@
7878
"@webreflection/idb-map": "^0.3.1",
7979
"basic-devtools": "^0.1.6",
8080
"codedent": "^0.1.2",
81-
"coincident": "^2.0.1",
82-
"gc-hook": "^0.3.1",
81+
"coincident": "^2.0.5",
82+
"gc-hook": "^0.4.1",
8383
"html-escaper": "^3.0.3",
8484
"proxy-target": "^3.0.2",
8585
"sticky-module": "^0.1.1",
8686
"to-json-callback": "^0.1.1"
8787
},
8888
"worker": {
89-
"blob": "sha256-TcNhn9gQ+KzsuVdb4meFvtbYIbGO2LqYd62IMVpt9UM="
89+
"blob": "sha256-daao4AY1C1yVgnZJI/0/Oz4VbjaD4MfpJGh+wR8sICk="
9090
}
9191
}

0 commit comments

Comments
 (0)