-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmaps.py
41 lines (30 loc) · 887 Bytes
/
maps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pathlib import Path
from pyjsx.source_maps.source_maps import convert_mappings, generate_source_map
from pyjsx.transpiler import Parser
# source = """\
# <p {...rest}>
# <h1>Title</h1>
# <h2>Subtitle</h2>
# {foo}
# </p>"""
# source = """\
# <p>
# lorem ipsum
# <b>blah</b>
# blah
# {foo}
# </p>"""
source = Path("main.px").read_text("utf-8")
p = Parser(source)
ast = p.parse()
# tr = Transpiler(ast)
# tr.transpile()
transpiled, source_map = ast.transpile()
for m in source_map:
print(m, source[m.original_offset :])
# print(source_map)
source_map = convert_mappings(source_map, source, transpiled, name="main.px")
generated = generate_source_map(source_map, sources=["main.px"], sources_content=[source], file="main.px")
print(transpiled)
Path("main.px.map").write_text(generated, "utf-8")
Path("main.py").write_text(transpiled, "utf-8")