Skip to content

Commit debb5e5

Browse files
committed
Split x-strings into lines to map each line back to original source line
1 parent 6def562 commit debb5e5

File tree

5 files changed

+1922
-1880
lines changed

5 files changed

+1922
-1880
lines changed

lib/opal/fragment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def to_code
2222
end
2323
end
2424

25+
# debug:
26+
# alias code to_code
27+
2528
# inspect the contents of this fragment, f("fooo")
2629
def inspect
2730
"f(#{@code.inspect})"

lib/opal/nodes/literal.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,27 @@ def compile
5151
end
5252
end
5353

54+
module XStringLineSplitter
55+
def compile_split_lines(value, sexp)
56+
idx = 0
57+
value.each_line do |line|
58+
if idx == 0
59+
push line
60+
else
61+
line_sexp = s()
62+
line_sexp.loc = [sexp.line + idx, 0]
63+
frag = Fragment.new(line, line_sexp)
64+
push frag
65+
end
66+
67+
idx += 1
68+
end
69+
end
70+
end
71+
5472
class XStringNode < Base
73+
include XStringLineSplitter
74+
5575
handle :xstr
5676

5777
children :value
@@ -61,11 +81,16 @@ def needs_semicolon?
6181
end
6282

6383
def compile
64-
push value.to_s
84+
compile_split_lines(value.to_s, @sexp)
85+
6586
push ';' if needs_semicolon?
6687

6788
wrap '(', ')' if recv?
6889
end
90+
91+
def start_line
92+
@sexp.line
93+
end
6994
end
7095

7196
class DynamicStringNode < Base

lib/opal/parser.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,16 @@ def new_yield(args)
558558
s(:yield, *args)
559559
end
560560

561-
def new_xstr(str)
561+
def new_xstr(start_t, str, end_t)
562562
return s(:xstr, '') unless str
563563
case str.type
564564
when :str then str.type = :xstr
565565
when :dstr then str.type = :dxstr
566566
when :evstr then str = s(:dxstr, '', str)
567567
end
568568

569+
str.loc = source(start_t)
570+
569571
str
570572
end
571573

0 commit comments

Comments
 (0)