mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Defaulting to async for top-level await (#2134)
This commit is contained in:
committed by
GitHub
parent
fafdf74007
commit
0d0ea96435
597
pyscript.core/package-lock.json
generated
597
pyscript.core/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pyscript/core",
|
"name": "@pyscript/core",
|
||||||
"version": "0.5.2",
|
"version": "0.5.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "PyScript",
|
"description": "PyScript",
|
||||||
"module": "./index.js",
|
"module": "./index.js",
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ungap/with-resolvers": "^0.1.0",
|
"@ungap/with-resolvers": "^0.1.0",
|
||||||
"basic-devtools": "^0.1.6",
|
"basic-devtools": "^0.1.6",
|
||||||
"polyscript": "^0.14.5",
|
"polyscript": "^0.15.0",
|
||||||
"sticky-module": "^0.1.1",
|
"sticky-module": "^0.1.1",
|
||||||
"to-json-callback": "^0.1.1",
|
"to-json-callback": "^0.1.1",
|
||||||
"type-checked-collections": "^0.1.7"
|
"type-checked-collections": "^0.1.7"
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
"@codemirror/lang-python": "^6.1.6",
|
"@codemirror/lang-python": "^6.1.6",
|
||||||
"@codemirror/language": "^6.10.2",
|
"@codemirror/language": "^6.10.2",
|
||||||
"@codemirror/state": "^6.4.1",
|
"@codemirror/state": "^6.4.1",
|
||||||
"@codemirror/view": "^6.29.1",
|
"@codemirror/view": "^6.30.0",
|
||||||
"@playwright/test": "^1.45.3",
|
"@playwright/test": "^1.45.3",
|
||||||
"@rollup/plugin-commonjs": "^26.0.1",
|
"@rollup/plugin-commonjs": "^26.0.1",
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||||
|
|||||||
BIN
pyscript.core/pyscript-core-0.5.3-rc1.tgz
Normal file
BIN
pyscript.core/pyscript-core-0.5.3-rc1.tgz
Normal file
Binary file not shown.
@@ -12,6 +12,7 @@ import {
|
|||||||
define,
|
define,
|
||||||
defineProperty,
|
defineProperty,
|
||||||
dispatch,
|
dispatch,
|
||||||
|
isSync,
|
||||||
queryTarget,
|
queryTarget,
|
||||||
unescape,
|
unescape,
|
||||||
whenDefined,
|
whenDefined,
|
||||||
@@ -202,15 +203,13 @@ for (const [TYPE, interpreter] of TYPES) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isScript(element)) {
|
if (isScript(element)) {
|
||||||
const {
|
const isAsync = !isSync(element);
|
||||||
attributes: { async: isAsync, target },
|
const target = element.getAttribute("target");
|
||||||
} = element;
|
const show = target
|
||||||
const hasTarget = !!target?.value;
|
? queryTarget(element, target)
|
||||||
const show = hasTarget
|
|
||||||
? queryTarget(element, target.value)
|
|
||||||
: document.createElement("script-py");
|
: document.createElement("script-py");
|
||||||
|
|
||||||
if (!hasTarget) {
|
if (!target) {
|
||||||
const { head, body } = document;
|
const { head, body } = document;
|
||||||
if (head.contains(element)) body.append(show);
|
if (head.contains(element)) body.append(show);
|
||||||
else element.after(show);
|
else element.after(show);
|
||||||
@@ -331,7 +330,7 @@ for (const [TYPE, interpreter] of TYPES) {
|
|||||||
async connectedCallback() {
|
async connectedCallback() {
|
||||||
if (!this.executed) {
|
if (!this.executed) {
|
||||||
this.executed = true;
|
this.executed = true;
|
||||||
const isAsync = this.hasAttribute("async");
|
const isAsync = !isSync(this);
|
||||||
const { io, run, runAsync } = await this._wrap
|
const { io, run, runAsync } = await this._wrap
|
||||||
.promise;
|
.promise;
|
||||||
this.srcCode = await fetchSource(
|
this.srcCode = await fetchSource(
|
||||||
|
|||||||
@@ -5,11 +5,17 @@
|
|||||||
<script type="module" src="../dist/core.js"></script>
|
<script type="module" src="../dist/core.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<py-script async>
|
<py-script>
|
||||||
import asyncio
|
import asyncio
|
||||||
print('foo')
|
print('py-script sleep')
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
print('bar')
|
print('py-script done')
|
||||||
</py-script>
|
</py-script>
|
||||||
|
<script type="py">
|
||||||
|
import asyncio
|
||||||
|
print('script-py sleep')
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
print('script-py done')
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -48,12 +48,12 @@
|
|||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="mpy" worker>
|
<script type="mpy" async="false" worker>
|
||||||
from pyscript import document
|
from pyscript import document
|
||||||
print("actual code in worker")
|
print("actual code in worker")
|
||||||
document.documentElement.classList.add('worker')
|
document.documentElement.classList.add('worker')
|
||||||
</script>
|
</script>
|
||||||
<script type="mpy">
|
<script type="mpy" async="false">
|
||||||
print("actual code in main")
|
print("actual code in main")
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class TestBasic(PyScriptTest):
|
|||||||
def test_input_exception(self):
|
def test_input_exception(self):
|
||||||
self.pyscript_run(
|
self.pyscript_run(
|
||||||
"""
|
"""
|
||||||
<script type="py">
|
<script type="py" async="false">
|
||||||
input("what's your name?")
|
input("what's your name?")
|
||||||
</script>
|
</script>
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ class TestDisplay(PyScriptTest):
|
|||||||
def test_consecutive_display(self):
|
def test_consecutive_display(self):
|
||||||
self.pyscript_run(
|
self.pyscript_run(
|
||||||
"""
|
"""
|
||||||
<script type="py">
|
<script type="py" async="false">
|
||||||
from pyscript import display
|
from pyscript import display
|
||||||
display('hello 1')
|
display('hello 1')
|
||||||
</script>
|
</script>
|
||||||
<p>hello 2</p>
|
<p>hello 2</p>
|
||||||
<script type="py">
|
<script type="py" async="false">
|
||||||
from pyscript import display
|
from pyscript import display
|
||||||
display('hello 3')
|
display('hello 3')
|
||||||
</script>
|
</script>
|
||||||
@@ -177,16 +177,16 @@ class TestDisplay(PyScriptTest):
|
|||||||
def test_consecutive_display_target(self):
|
def test_consecutive_display_target(self):
|
||||||
self.pyscript_run(
|
self.pyscript_run(
|
||||||
"""
|
"""
|
||||||
<script type="py" id="first">
|
<script type="py" id="first" async="false">
|
||||||
from pyscript import display
|
from pyscript import display
|
||||||
display('hello 1')
|
display('hello 1')
|
||||||
</script>
|
</script>
|
||||||
<p>hello in between 1 and 2</p>
|
<p>hello in between 1 and 2</p>
|
||||||
<script type="py" id="second">
|
<script type="py" id="second" async="false">
|
||||||
from pyscript import display
|
from pyscript import display
|
||||||
display('hello 2', target="second")
|
display('hello 2', target="second")
|
||||||
</script>
|
</script>
|
||||||
<script type="py" id="third">
|
<script type="py" id="third" async="false">
|
||||||
from pyscript import display
|
from pyscript import display
|
||||||
display('hello 3')
|
display('hello 3')
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user