Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bf8e3b1

Browse files
committed
Ensure the pin is before the expressions
1 parent 1cae7ec commit bf8e3b1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/syntax_tree.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,12 +2407,14 @@ def to_json(*opts)
24072407
# :call-seq:
24082408
# on_begin: (untyped bodystmt) -> Begin | PinnedBegin
24092409
def on_begin(bodystmt)
2410-
if beginning = find_token(Op, "^", consume: false)
2411-
tokens.delete(beginning)
2410+
pin = find_token(Op, "^", consume: false)
2411+
2412+
if pin && pin.location.start_char < bodystmt.location.start_char
2413+
tokens.delete(pin)
24122414
find_token(LParen)
24132415

2414-
ending = find_token(RParen)
2415-
location = beginning.location.to(ending.location)
2416+
rparen = find_token(RParen)
2417+
location = pin.location.to(rparen.location)
24162418

24172419
PinnedBegin.new(statement: bodystmt, location: location)
24182420
else
@@ -13087,7 +13089,9 @@ def to_json(*opts)
1308713089
# :call-seq:
1308813090
# on_var_ref: ((Const | CVar | GVar | Ident | IVar | Kw) value) -> VarRef
1308913091
def on_var_ref(value)
13090-
if pin = find_token(Op, "^", consume: false)
13092+
pin = find_token(Op, "^", consume: false)
13093+
13094+
if pin && pin.location.start_char == value.location.start_char - 1
1309113095
tokens.delete(pin)
1309213096
PinnedVarRef.new(value: value, location: pin.location.to(value.location))
1309313097
else

0 commit comments

Comments
 (0)