Skip to content

Commit cf75e5c

Browse files
committed
utils: name_pool
1 parent f6262a7 commit cf75e5c

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/utils/name_pool.cr

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@
1818
# -----------------------------------------------------------------------
1919

2020
module MoonScript
21-
class NamePool(T, B)
22-
@cache = {} of Tuple(B, T) => String
23-
@current = {} of B => String
21+
class NamePool(T, B)
22+
@cache = {} of Tuple(B, T) => String
23+
@current = {} of B => String
2424

25-
def initialize(@initial = 'a'.pred.to_s)
26-
end
25+
def initialize(@initial = 'a'.pred.to_s)
26+
end
2727

28-
def of(subject: T, base: B)
29-
@cache[{base, subject}] ||= next_name(subject, base)
30-
end
28+
def of(subject : T, base : B)
29+
@cache[{base, subject}] ||= next_name(subject, base)
30+
end
3131

32-
def next_name(subject: T:, base: B)
33-
name = @current[base] = (@current[base] ? || @initial).succ
34-
end
35-
end
32+
def next_name(subject : T, base : B)
33+
name = @current[base] = (@current[base]? || @initial).succ
34+
35+
if ["do", "if", "for", "catch", "in"].includes?(name)
36+
next_name(subject, base)
37+
else
38+
name
39+
end
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)