Skip to content

Commit 7b6a657

Browse files
feat!: use tagged enums in sorbet type definitions (#49)
1 parent 8ab0729 commit 7b6a657

File tree

492 files changed

+5673
-3492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

492 files changed

+5673
-3492
lines changed

Rakefile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,25 @@ multitask(:syntax_tree) do
3535
inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? %w[-i''] : %w[-i]
3636
uuid = SecureRandom.uuid
3737

38-
# `syntax_tree` has trouble with `rbs`'s class aliases
38+
# `syntax_tree` has trouble with `rbs`'s class & module aliases
3939

4040
sed = xargs + %w[sed -E] + inplace + %w[-e]
41-
# annotate class aliases with a unique comment
42-
pre = sed + ["s/class ([^ ]+) = (.+$)/# #{uuid}\\n\\1: \\2/", "--"]
41+
# annotate unprocessable aliases with a unique comment
42+
pre = sed + ["s/(class|module) ([^ ]+) = (.+$)/# \\1 #{uuid}\\n\\2: \\3/", "--"]
4343
fmt = xargs + %w[stree write --plugin=rbs --]
44-
# remove the unique comment and transform class aliases to type aliases
44+
# remove the unique comment and unprocessable aliases to type aliases
4545
subst = <<~SED
46-
s/# #{uuid}//
46+
s/# (class|module) #{uuid}/\\1/
4747
t l1
4848
b
49+
4950
: l1
50-
n
51-
s/([^ :]+): (.+$)/class \\1 = \\2/
51+
N
52+
s/\\n *([^:]+): (.+)$/ \\1 = \\2/
5253
SED
53-
# 1. delete the unique comment
54-
# 2. if deletion happened, branch to label `l1`, else continue
55-
# 3. transform the class alias to a type alias at label `l1`
54+
# for each line:
55+
# 1. try transform the unique comment into `class | module`, if successful, branch to label `l1`.
56+
# 2. at label `l1`, join previously annotated line with `class | module` information.
5657
pst = sed + [subst, "--"]
5758

5859
# transform class aliases to type aliases, which syntax tree has no trouble with

0 commit comments

Comments
 (0)