v2 / vlib / v / gen / js / sourcemap / source_map_generator.v
47 lines · 38 sloc · 802 bytes · c51d30bf5309653c6b573ec815268e69a78ea8cc
Raw
1module sourcemap
2
3struct V3 {
4 SourceMap
5pub:
6 sections []Section @[json: sections]
7}
8
9struct Offset {
10pub mut:
11 line int @[json: line]
12 column int @[json: column]
13}
14
15struct Section {
16pub mut:
17 offset Offset @[json: offset]
18 source_map SourceMap @[json: map]
19}
20
21struct Generator {
22mut:
23 file string
24 // source_root string
25 sections []Section
26}
27
28pub fn generate_empty_map() &Generator {
29 return &Generator{}
30}
31
32pub fn (mut g Generator) add_map(file string, source_root string, sources_content_inline bool, line_offset int,
33 column_offset int) &SourceMap {
34 source_map := new_sourcemap(file, source_root, sources_content_inline)
35
36 offset := Offset{
37 line: line_offset
38 column: column_offset
39 }
40
41 g.sections << Section{
42 offset: offset
43 source_map: source_map
44 }
45
46 return &source_map
47}
48