Skip to content

Commit 49fa88d

Browse files
committed
upload ide/test/check_syntax.py
1 parent 9895754 commit 49fa88d

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

ide/test/check_syntax.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 语法检查:用嵌入式 V8 编译三个 JS 文件。
2+
# 若抛出的是 SyntaxError -> 语法错误;若是 ReferenceError/TypeError(缺 document/window/localStorage)
3+
# 则视为「语法正确、仅因无浏览器环境」,计入 OK。
4+
import io
5+
from py_mini_racer import MiniRacer
6+
7+
files = [r"D:\hicode-ide\js\store.js", r"D:\hicode-ide\js\hic.js", r"D:\hicode-ide\js\app.js"]
8+
9+
ok = True
10+
mr = MiniRacer()
11+
# 提供浏览器占位,避免 store.js 顶层立即崩溃(hasLS 已内置 try,但给全些安全)
12+
mr.eval("var window=this; var self=this;")
13+
14+
for path in files:
15+
with io.open(path, "r", encoding="utf-8") as f:
16+
src = f.read()
17+
try:
18+
mr.eval(src)
19+
print("OK ", path)
20+
except Exception as e:
21+
msg = str(e)
22+
if "SyntaxError" in msg:
23+
print("SYNTAX ERR", path, "->", msg[:200]); ok = False
24+
else:
25+
# 运行时环境错误(缺 DOM)视为语法通过
26+
print("OK(env) ", path, "->", msg[:120])
27+
28+
print("RESULT:", "PASS" if ok else "FAIL")
29+
import sys; sys.exit(0 if ok else 1)

0 commit comments

Comments
 (0)