8000 Defaulting to async for top-level await (#2134) · shgopher/pyscript@0d0ea96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d0ea96

Browse files
Defaulting to async for top-level await (pyscript#2134)
1 parent fafdf74 commit 0d0ea96

File tree

8 files changed

+37
-609
lines changed

8 files changed

+37
-609
lines changed

pyscript.core/package-lock.json

Lines changed: 10 additions & 587 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyscript.core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"@ungap/with-resolvers": "^0.1.0",
4646
"basic-devtools": "^0.1.6",
47-
"polyscript": "^0.14.5",
47+
"polyscript": "^0.15.0",
4848
"sticky-module": "^0.1.1",
4949
"to-json-callback": "^0.1.1",
5050
"type-checked-collections": "^0.1.7"
@@ -54,7 +54,7 @@
5454
"@codemirror/lang-python": "^6.1.6",
5555
"@codemirror/language": "^6.10.2",
5656
"@codemirror/state": "^6.4.1",
57-
"@codemirror/view": "^6.29.1",
57+
"@codemirror/view": "^6.30.0",
5858
"@playwright/test": "^1.45.3",
5959
"@rollup/plugin-commonjs": "^26.0.1",
6060
"@rollup/plugin-node-resolve": "^15.2.3",
2.38 MB
Binary file not shown.

pyscript.core/src/core.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
define,
1313
defineProperty,
1414
dispatch,
15+
isSync,
1516
queryTarget,
1617
unescape,
1718
whenDefined,
@@ -202,15 +203,13 @@ for (const [TYPE, interpreter] of TYPES) {
202203
}
203204

204205
if (isScript(element)) {
205-
const {
206-
attributes: { async: isAsync, target },
207-
} = element;
208-
const hasTarget = !!target?.value;
209-
const show = hasTarget
210-
? queryTarget(element, target.value)
206+
const isAsync = !isSync(element);
207+
const target = element.getAttribute("target");
208+
const show = target
209+
? queryTarget(element, target)
211210
: document.createElement("script-py");
212211

213-
if (!hasTarget) {
212+
if (!target) {
214213
const { head, body } = document;
215214
if (head.contains(element)) body.append(show);
216215
else element.after(show);
@@ -331,7 +330,7 @@ for (const [TYPE, interpreter] of TYPES) {
331330
async connectedCallback() {
332331
if (!this.executed) {
333332
this.executed = true;
334-
const isAsync = this.hasAttribute("async");
333+
const isAsync = !isSync(this);
335334
const { io, run, runAsync } = await this._wrap
336335
.promise;
337336
this.srcCode = await fetchSource(

pyscript.core/test/async.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
<script type="module" src="../dist/core.js"></script>
66
</head>
77
<body>
8-
<py-script async>
8+
<py-script>
99
import asyncio
10-
print('foo')
10+
print('py-script sleep')
1111
await asyncio.sleep(1)
12-
print('bar')
12+
print('py-script done')
1313
</py-script>
14+
<script type="py">
15+
import asyncio
16+
print('script-py sleep')
17+
await asyncio.sleep(1)
18+
print('script-py done')
19+
</script>
1420
</body>
1521
</html>

pyscript.core/test/hooks.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
</script>
4949
</head>
5050
<body>
51-
<script type="mpy" worker>
51+
<script type="mpy" async="false" worker>
5252
from pyscript import document
5353
print("actual code in worker")
5454
document.documentElement.classList.add('worker')
5555
</script>
56-
<script type="mpy">
56+
<script type="mpy" async="false">
5757
print("actual code in main")
5858
</script>
5959
</body>

pyscript.core/tests/integration/test_01_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_print(self):
9797
def test_input_exception(self):
9898
self.pyscript_run(
9999
"""
100-
<script type="py">
100+
<script type="py" async="false">
101101
input("what's your name?")
102102
</script>
103103
"""

pyscript.core/tests/integration/test_02_display.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ def test_simple_display(self):
4343
def test_consecutive_display(self):
4444
self.pyscript_run(
4545
"""
46-
<script type="py">
46+
<script type="py" async="false">
4747
from pyscript import display
4848
display('hello 1')
4949
</script>
5050
<p>hello 2</p>
51-
<script type="py">
51+
<script type="py" async="false">
5252
from pyscript import display
5353
display('hello 3')
5454
</script>
@@ -177,16 +177,16 @@ def test_target_script_py(self):
177177
def test_consecutive_display_target(self):
178178
self.pyscript_run(
179179
"""
180-
<script type="py" id="first">
180+
<script type="py" id="first" async="false">
181181
from pyscript import display
182182
display('hello 1')
183183
</script>
184184
<p>hello in between 1 and 2</p>
185-
<script type="py" id="second">
185+
<script type="py" id="second" async="false">
186186
from pyscript import display
187187
display('hello 2', target="second")
188188
</script>
189-
<script type="py" id="third">
189+
<script type="py" id="third" async="false">
190190
from pyscript import display
191191
display('hello 3')
192192
</script>

0 commit comments

Comments
 (0)
0