mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
* Fix #2372 - Allow custom TOML parser * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f769f215b2
commit
ec090922cb
@@ -70,6 +70,7 @@ for (const [TYPE] of TYPES) {
|
|||||||
|
|
||||||
let config,
|
let config,
|
||||||
type,
|
type,
|
||||||
|
parser,
|
||||||
pyElement,
|
pyElement,
|
||||||
pyConfigs = $$(`${TYPE}-config`),
|
pyConfigs = $$(`${TYPE}-config`),
|
||||||
attrConfigs = $$(
|
attrConfigs = $$(
|
||||||
@@ -92,9 +93,11 @@ for (const [TYPE] of TYPES) {
|
|||||||
[pyElement] = pyConfigs;
|
[pyElement] = pyConfigs;
|
||||||
config = pyElement.getAttribute("src") || pyElement.textContent;
|
config = pyElement.getAttribute("src") || pyElement.textContent;
|
||||||
type = pyElement.getAttribute("type");
|
type = pyElement.getAttribute("type");
|
||||||
|
parser = pyElement.getAttribute("config-parser");
|
||||||
} else if (attrConfigs.length) {
|
} else if (attrConfigs.length) {
|
||||||
[pyElement, ...attrConfigs] = attrConfigs;
|
[pyElement, ...attrConfigs] = attrConfigs;
|
||||||
config = pyElement.getAttribute("config");
|
config = pyElement.getAttribute("config");
|
||||||
|
parser = pyElement.getAttribute("config-parser");
|
||||||
// throw an error if dirrent scripts use different configs
|
// throw an error if dirrent scripts use different configs
|
||||||
if (
|
if (
|
||||||
attrConfigs.some((el) => el.getAttribute("config") !== config)
|
attrConfigs.some((el) => el.getAttribute("config") !== config)
|
||||||
@@ -120,9 +123,12 @@ for (const [TYPE] of TYPES) {
|
|||||||
}
|
}
|
||||||
} else if (toml || type === "toml") {
|
} else if (toml || type === "toml") {
|
||||||
try {
|
try {
|
||||||
const { parse } = await import(
|
const module = parser
|
||||||
/* webpackIgnore: true */ "./3rd-party/toml.js"
|
? await import(parser)
|
||||||
);
|
: await import(
|
||||||
|
/* webpackIgnore: true */ "./3rd-party/toml.js"
|
||||||
|
);
|
||||||
|
const parse = module.parse || module.default;
|
||||||
parsed = parse(text);
|
parsed = parse(text);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = syntaxError("TOML", url, e);
|
error = syntaxError("TOML", url, e);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
1
core/tests/javascript/config-parser/file.py
Normal file
1
core/tests/javascript/config-parser/file.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
print("OK")
|
||||||
21
core/tests/javascript/config-parser/index.html
Normal file
21
core/tests/javascript/config-parser/index.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="../../../dist/core.css">
|
||||||
|
<script type="module" src="../../../dist/core.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<py-config config-parser="https://esm.run/basic-toml">
|
||||||
|
[files]
|
||||||
|
'file.py' = ""
|
||||||
|
</py-config>
|
||||||
|
<script type="py">
|
||||||
|
import file
|
||||||
|
from pyscript import document
|
||||||
|
document.documentElement.classList.add("done")
|
||||||
|
document.body.append("OK")
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -2,6 +2,13 @@ import { test, expect } from '@playwright/test';
|
|||||||
|
|
||||||
test.setTimeout(120 * 1000);
|
test.setTimeout(120 * 1000);
|
||||||
|
|
||||||
|
test('config-parser custom TOML', async ({ page }) => {
|
||||||
|
await page.goto('http://localhost:8080/tests/javascript/config-parser/index.html');
|
||||||
|
await page.waitForSelector('html.done');
|
||||||
|
const body = await page.evaluate(() => document.body.innerText);
|
||||||
|
await expect(body.trim()).toBe('OK');
|
||||||
|
});
|
||||||
|
|
||||||
test('MicroPython display', async ({ page }) => {
|
test('MicroPython display', async ({ page }) => {
|
||||||
await page.goto('http://localhost:8080/tests/javascript/mpy.html');
|
await page.goto('http://localhost:8080/tests/javascript/mpy.html');
|
||||||
await page.waitForSelector('html.done.worker');
|
await page.waitForSelector('html.done.worker');
|
||||||
|
|||||||
Reference in New Issue
Block a user