最初版本
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import ast
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
text = pathlib.Path(r"F:/AI/guest-cs-stack/flask/chatwoot_proxy.py").read_text(encoding="utf-8")
|
||||
mod = ast.parse(text)
|
||||
found = None
|
||||
for node in ast.walk(mod):
|
||||
if isinstance(node, ast.Constant) and isinstance(node.value, str) and "polishQuickQuestions" in node.value:
|
||||
found = node.value
|
||||
break
|
||||
|
||||
# strip script tags, keep JS
|
||||
js = found
|
||||
js = re.sub(r"</?script[^>]*>", "\n", js, flags=re.I)
|
||||
# remove style blocks if any
|
||||
js = re.sub(r"<style[\s\S]*?</style>", "\n", js, flags=re.I)
|
||||
# remove remaining HTML-ish lines starting with <
|
||||
lines = []
|
||||
for line in js.splitlines():
|
||||
s = line.strip()
|
||||
if s.startswith("<") and not s.startswith("<!"):
|
||||
continue
|
||||
lines.append(line)
|
||||
js = "\n".join(lines)
|
||||
|
||||
with tempfile.NamedTemporaryFile("w", suffix=".js", delete=False, encoding="utf-8") as f:
|
||||
f.write(js)
|
||||
path = f.name
|
||||
|
||||
r = subprocess.run(["node", "--check", path], capture_output=True, text=True)
|
||||
print("return", r.returncode)
|
||||
print(r.stderr[:2000] if r.stderr else "OK")
|
||||
print("wrote", path, "len", len(js))
|
||||
|
||||
# Also locate any /... patterns that look broken: newline inside
|
||||
for m in re.finditer(r"/[^/\n]*\n[^/]*/[gimsuy]*", js):
|
||||
print("MULTILINE REGEX?", repr(m.group(0)[:100]))
|
||||
|
||||
# Find SyntaxError line from node if possible by binary search
|
||||
if r.returncode != 0:
|
||||
err = r.stderr
|
||||
m = re.search(r":(\d+)\n", err)
|
||||
if m:
|
||||
ln = int(m.group(1))
|
||||
all_lines = js.splitlines()
|
||||
start = max(0, ln - 5)
|
||||
end = min(len(all_lines), ln + 5)
|
||||
print("--- around error ---")
|
||||
for i in range(start, end):
|
||||
mark = ">>" if i + 1 == ln else " "
|
||||
print(f"{mark}{i+1}: {all_lines[i]}")
|
||||
Reference in New Issue
Block a user