rbi 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ab48b069bf534228e48c5c76caeb71daca4dd905a00cbdbfdd0ce7ce9374987
4
- data.tar.gz: f301b0ce6eff170542931c88095d78ff60ffd5e20720eb04461bdbb3eeb98a8d
3
+ metadata.gz: 5cc6303b86c0b3b1292e099fc6e9ff2c93c60bb037fafcfe2590604a0ed478c2
4
+ data.tar.gz: 2236bb45edc75082c3f9ad930550e9a004f25303a58249ceb1880149b5cb1f37
5
5
  SHA512:
6
- metadata.gz: d2f844f5e4d6ec819125d1b91bd40e9af9821f32a4ca76036ccabe5beac985dc566d0cc8d9946ed1488c78115d3a64d798833d13256d829c686df1668353e314
7
- data.tar.gz: a1bb0eabd7e81e3563e20bfb35eb0bf2044d152c0019ed78018327d6b60c4897b89a94f4fd741f077e7cb5186a82fbd7cf3c08b3340d2f1caa913b2d773adddc
6
+ metadata.gz: 701247c0c71ea9535baaed16e813a741595a79e020c9bce294fafc291e71eac90f84cca974a68860aed8509986d159290481b5a1c83cab64d030fd683c55ea67
7
+ data.tar.gz: e8fdf27c22593876dd7e0c08098ee77927d851ca636bfc816c137667d85bd1314a38eca69b1f14fd1b12d7940eb5ee5dfe3b21415a3c23fbe2eb05d08d3c4c7d
data/Gemfile CHANGED
@@ -9,8 +9,8 @@ group(:development, :test) do
9
9
  gem("byebug")
10
10
  gem("minitest")
11
11
  gem("minitest-reporters")
12
- gem("rake", "~> 13.0")
13
- gem("rubocop", "~> 1.56", require: false)
12
+ gem("rake", "~> 13.1")
13
+ gem("rubocop", "~> 1.57", require: false)
14
14
  gem("rubocop-shopify", require: false)
15
15
  gem("rubocop-sorbet", require: false)
16
16
  gem("sorbet", ">= 0.5.9204", require: false)
data/lib/rbi/loc.rb CHANGED
@@ -8,14 +8,14 @@ module RBI
8
8
  class << self
9
9
  extend T::Sig
10
10
 
11
- sig { params(file: String, yarp_location: YARP::Location).returns(Loc) }
12
- def from_yarp(file, yarp_location)
11
+ sig { params(file: String, prism_location: Prism::Location).returns(Loc) }
12
+ def from_prism(file, prism_location)
13
13
  new(
14
14
  file: file,
15
- begin_line: yarp_location.start_line,
16
- end_line: yarp_location.end_line,
17
- begin_column: yarp_location.start_column,
18
- end_column: yarp_location.end_column,
15
+ begin_line: prism_location.start_line,
16
+ end_line: prism_location.end_line,
17
+ begin_column: prism_location.start_column,
18
+ end_column: prism_location.end_column,
19
19
  )
20
20
  end
21
21
  end
data/lib/rbi/parser.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "yarp"
4
+ require "prism"
5
5
 
6
6
  module RBI
7
7
  class ParseError < StandardError
@@ -93,7 +93,7 @@ module RBI
93
93
 
94
94
  sig { params(source: String, file: String).returns(Tree) }
95
95
  def parse(source, file:)
96
- result = YARP.parse(source)
96
+ result = Prism.parse(source)
97
97
  unless result.success?
98
98
  message = result.errors.map { |e| "#{e.message}." }.join(" ")
99
99
  error = result.errors.first
@@ -104,14 +104,12 @@ module RBI
104
104
  visitor = TreeBuilder.new(source, comments: result.comments, file: file)
105
105
  visitor.visit(result.value)
106
106
  visitor.tree
107
- rescue YARP::ParseError => e
108
- raise ParseError.new(e.message, Loc.from_yarp(file, e.location))
109
107
  rescue ParseError => e
110
108
  raise e
111
109
  rescue => e
112
110
  last_node = visitor&.last_node
113
111
  last_location = if last_node
114
- Loc.from_yarp(file, last_node.location)
112
+ Loc.from_prism(file, last_node.location)
115
113
  else
116
114
  Loc.new(file: file)
117
115
  end
@@ -121,7 +119,7 @@ module RBI
121
119
  raise exception
122
120
  end
123
121
 
124
- class Visitor < YARP::Visitor
122
+ class Visitor < Prism::Visitor
125
123
  extend T::Sig
126
124
 
127
125
  sig { params(source: String, file: String).void }
@@ -134,19 +132,19 @@ module RBI
134
132
 
135
133
  private
136
134
 
137
- sig { params(node: YARP::Node).returns(Loc) }
135
+ sig { params(node: Prism::Node).returns(Loc) }
138
136
  def node_loc(node)
139
- Loc.from_yarp(@file, node.location)
137
+ Loc.from_prism(@file, node.location)
140
138
  end
141
139
 
142
- sig { params(node: T.nilable(YARP::Node)).returns(T.nilable(String)) }
140
+ sig { params(node: T.nilable(Prism::Node)).returns(T.nilable(String)) }
143
141
  def node_string(node)
144
142
  return unless node
145
143
 
146
144
  node.slice
147
145
  end
148
146
 
149
- sig { params(node: YARP::Node).returns(String) }
147
+ sig { params(node: Prism::Node).returns(String) }
150
148
  def node_string!(node)
151
149
  T.must(node_string(node))
152
150
  end
@@ -158,32 +156,25 @@ module RBI
158
156
  sig { returns(Tree) }
159
157
  attr_reader :tree
160
158
 
161
- sig { returns(T.nilable(YARP::Node)) }
159
+ sig { returns(T.nilable(Prism::Node)) }
162
160
  attr_reader :last_node
163
161
 
164
- sig { params(source: String, comments: T::Array[YARP::Comment], file: String).void }
162
+ sig { params(source: String, comments: T::Array[Prism::Comment], file: String).void }
165
163
  def initialize(source, comments:, file:)
166
164
  super(source, file: file)
167
165
 
168
- @comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer, YARP::Comment])
166
+ @comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer, Prism::Comment])
169
167
  @tree = T.let(Tree.new, Tree)
170
168
 
171
169
  @scopes_stack = T.let([@tree], T::Array[Tree])
172
- @last_node = T.let(nil, T.nilable(YARP::Node))
170
+ @last_node = T.let(nil, T.nilable(Prism::Node))
173
171
  @last_sigs = T.let([], T::Array[RBI::Sig])
174
172
  @last_sigs_comments = T.let([], T::Array[Comment])
175
173
  end
176
174
 
177
- sig { override.params(node: T.nilable(YARP::Node)).void }
178
- def visit(node)
179
- return unless node
180
-
181
- @last_node = node
182
- super
183
- end
184
-
185
- sig { override.params(node: YARP::ClassNode).void }
175
+ sig { override.params(node: Prism::ClassNode).void }
186
176
  def visit_class_node(node)
177
+ @last_node = node
187
178
  scope = Class.new(
188
179
  node_string!(node.constant_path),
189
180
  superclass_name: node_string(node.superclass),
@@ -196,19 +187,24 @@ module RBI
196
187
  visit(node.body)
197
188
  collect_dangling_comments(node)
198
189
  @scopes_stack.pop
190
+ @last_node = nil
199
191
  end
200
192
 
201
- sig { override.params(node: YARP::ConstantWriteNode).void }
193
+ sig { override.params(node: Prism::ConstantWriteNode).void }
202
194
  def visit_constant_write_node(node)
195
+ @last_node = node
203
196
  visit_constant_assign(node)
197
+ @last_node = nil
204
198
  end
205
199
 
206
- sig { override.params(node: YARP::ConstantPathWriteNode).void }
200
+ sig { override.params(node: Prism::ConstantPathWriteNode).void }
207
201
  def visit_constant_path_write_node(node)
202
+ @last_node = node
208
203
  visit_constant_assign(node)
204
+ @last_node = nil
209
205
  end
210
206
 
211
- sig { params(node: T.any(YARP::ConstantWriteNode, YARP::ConstantPathWriteNode)).void }
207
+ sig { params(node: T.any(Prism::ConstantWriteNode, Prism::ConstantPathWriteNode)).void }
212
208
  def visit_constant_assign(node)
213
209
  struct = parse_struct(node)
214
210
 
@@ -217,9 +213,9 @@ module RBI
217
213
  elsif type_variable_definition?(node.value)
218
214
  TypeMember.new(
219
215
  case node
220
- when YARP::ConstantWriteNode
216
+ when Prism::ConstantWriteNode
221
217
  node.name.to_s
222
- when YARP::ConstantPathWriteNode
218
+ when Prism::ConstantPathWriteNode
223
219
  node_string!(node.target)
224
220
  end,
225
221
  node_string!(node.value),
@@ -229,9 +225,9 @@ module RBI
229
225
  else
230
226
  Const.new(
231
227
  case node
232
- when YARP::ConstantWriteNode
228
+ when Prism::ConstantWriteNode
233
229
  node.name.to_s
234
- when YARP::ConstantPathWriteNode
230
+ when Prism::ConstantPathWriteNode
235
231
  node_string!(node.target)
236
232
  end,
237
233
  node_string!(node.value),
@@ -241,8 +237,9 @@ module RBI
241
237
  end
242
238
  end
243
239
 
244
- sig { override.params(node: YARP::DefNode).void }
240
+ sig { override.params(node: Prism::DefNode).void }
245
241
  def visit_def_node(node)
242
+ @last_node = node
246
243
  current_scope << Method.new(
247
244
  node.name.to_s,
248
245
  params: parse_params(node.parameters),
@@ -251,10 +248,12 @@ module RBI
251
248
  comments: current_sigs_comments + node_comments(node),
252
249
  is_singleton: !!node.receiver,
253
250
  )
251
+ @last_node = nil
254
252
  end
255
253
 
256
- sig { override.params(node: YARP::ModuleNode).void }
254
+ sig { override.params(node: Prism::ModuleNode).void }
257
255
  def visit_module_node(node)
256
+ @last_node = node
258
257
  scope = Module.new(
259
258
  node_string!(node.constant_path),
260
259
  loc: node_loc(node),
@@ -266,19 +265,23 @@ module RBI
266
265
  visit(node.body)
267
266
  collect_dangling_comments(node)
268
267
  @scopes_stack.pop
268
+ @last_node = nil
269
269
  end
270
270
 
271
- sig { override.params(node: YARP::ProgramNode).void }
271
+ sig { override.params(node: Prism::ProgramNode).void }
272
272
  def visit_program_node(node)
273
+ @last_node = node
273
274
  super
274
275
 
275
276
  collect_orphan_comments
276
277
  separate_header_comments
277
278
  set_root_tree_loc
279
+ @last_node = nil
278
280
  end
279
281
 
280
- sig { override.params(node: YARP::SingletonClassNode).void }
282
+ sig { override.params(node: Prism::SingletonClassNode).void }
281
283
  def visit_singleton_class_node(node)
284
+ @last_node = node
282
285
  scope = SingletonClass.new(
283
286
  loc: node_loc(node),
284
287
  comments: node_comments(node),
@@ -289,11 +292,13 @@ module RBI
289
292
  visit(node.body)
290
293
  collect_dangling_comments(node)
291
294
  @scopes_stack.pop
295
+ @last_node = nil
292
296
  end
293
297
 
294
- sig { params(node: YARP::CallNode).void }
298
+ sig { params(node: Prism::CallNode).void }
295
299
  def visit_call_node(node)
296
- message = node.name
300
+ @last_node = node
301
+ message = node.name.to_s
297
302
  case message
298
303
  when "abstract!", "sealed!", "interface!"
299
304
  current_scope << Helper.new(
@@ -303,7 +308,11 @@ module RBI
303
308
  )
304
309
  when "attr_reader"
305
310
  args = node.arguments
306
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
311
+
312
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
313
+ @last_node = nil
314
+ return
315
+ end
307
316
 
308
317
  current_scope << AttrReader.new(
309
318
  *T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
@@ -313,7 +322,11 @@ module RBI
313
322
  )
314
323
  when "attr_writer"
315
324
  args = node.arguments
316
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
325
+
326
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
327
+ @last_node = nil
328
+ return
329
+ end
317
330
 
318
331
  current_scope << AttrWriter.new(
319
332
  *T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
@@ -323,7 +336,11 @@ module RBI
323
336
  )
324
337
  when "attr_accessor"
325
338
  args = node.arguments
326
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
339
+
340
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
341
+ @last_node = nil
342
+ return
343
+ end
327
344
 
328
345
  current_scope << AttrAccessor.new(
329
346
  *T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
@@ -333,19 +350,31 @@ module RBI
333
350
  )
334
351
  when "enums"
335
352
  block = node.block
336
- return unless block.is_a?(YARP::BlockNode)
353
+
354
+ unless block.is_a?(Prism::BlockNode)
355
+ @last_node = nil
356
+ return
357
+ end
337
358
 
338
359
  body = block.body
339
- return unless body.is_a?(YARP::StatementsNode)
360
+
361
+ unless body.is_a?(Prism::StatementsNode)
362
+ @last_node = nil
363
+ return
364
+ end
340
365
 
341
366
  current_scope << TEnumBlock.new(
342
- body.body.map { |stmt| T.cast(stmt, YARP::ConstantWriteNode).name.to_s },
367
+ body.body.map { |stmt| T.cast(stmt, Prism::ConstantWriteNode).name.to_s },
343
368
  loc: node_loc(node),
344
369
  comments: node_comments(node),
345
370
  )
346
371
  when "extend"
347
372
  args = node.arguments
348
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
373
+
374
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
375
+ @last_node = nil
376
+ return
377
+ end
349
378
 
350
379
  current_scope << Extend.new(
351
380
  *T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
@@ -354,7 +383,11 @@ module RBI
354
383
  )
355
384
  when "include"
356
385
  args = node.arguments
357
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
386
+
387
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
388
+ @last_node = nil
389
+ return
390
+ end
358
391
 
359
392
  current_scope << Include.new(
360
393
  *T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
@@ -363,7 +396,11 @@ module RBI
363
396
  )
364
397
  when "mixes_in_class_methods"
365
398
  args = node.arguments
366
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
399
+
400
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
401
+ @last_node = nil
402
+ return
403
+ end
367
404
 
368
405
  current_scope << MixesInClassMethods.new(
369
406
  *T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
@@ -372,12 +409,12 @@ module RBI
372
409
  )
373
410
  when "private", "protected", "public"
374
411
  args = node.arguments
375
- if args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
412
+ if args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
376
413
  visit(node.arguments)
377
414
  last_node = @scopes_stack.last&.nodes&.last
378
415
  case last_node
379
416
  when Method, Attr
380
- last_node.visibility = parse_visibility(node.name, node)
417
+ last_node.visibility = parse_visibility(node.name.to_s, node)
381
418
  else
382
419
  raise ParseError.new(
383
420
  "Unexpected token `#{node.message}` before `#{last_node&.string&.strip}`",
@@ -385,16 +422,24 @@ module RBI
385
422
  )
386
423
  end
387
424
  else
388
- current_scope << parse_visibility(node.name, node)
425
+ current_scope << parse_visibility(node.name.to_s, node)
389
426
  end
390
427
  when "prop", "const"
391
428
  parse_tstruct_field(node)
392
429
  when "requires_ancestor"
393
430
  block = node.block
394
- return unless block.is_a?(YARP::BlockNode)
431
+
432
+ unless block.is_a?(Prism::BlockNode)
433
+ @last_node = nil
434
+ return
435
+ end
395
436
 
396
437
  body = block.body
397
- return unless body.is_a?(YARP::StatementsNode)
438
+
439
+ unless body.is_a?(Prism::StatementsNode)
440
+ @last_node = nil
441
+ return
442
+ end
398
443
 
399
444
  current_scope << RequiresAncestor.new(
400
445
  node_string!(body),
@@ -411,12 +456,14 @@ module RBI
411
456
  comments: node_comments(node),
412
457
  )
413
458
  end
459
+
460
+ @last_node = nil
414
461
  end
415
462
 
416
463
  private
417
464
 
418
465
  # Collect all the remaining comments within a node
419
- sig { params(node: YARP::Node).void }
466
+ sig { params(node: Prism::Node).void }
420
467
  def collect_dangling_comments(node)
421
468
  first_line = node.location.start_line
422
469
  last_line = node.location.end_line
@@ -449,7 +496,7 @@ module RBI
449
496
 
450
497
  # Preserve blank lines in comments
451
498
  if last_line && line > last_line + 1
452
- recv << BlankLine.new(loc: Loc.from_yarp(@file, comment.location))
499
+ recv << BlankLine.new(loc: Loc.from_prism(@file, comment.location))
453
500
  end
454
501
 
455
502
  recv << parse_comment(comment)
@@ -476,7 +523,7 @@ module RBI
476
523
  comments
477
524
  end
478
525
 
479
- sig { params(node: YARP::Node).returns(T::Array[Comment]) }
526
+ sig { params(node: Prism::Node).returns(T::Array[Comment]) }
480
527
  def node_comments(node)
481
528
  comments = []
482
529
 
@@ -494,21 +541,21 @@ module RBI
494
541
  comments
495
542
  end
496
543
 
497
- sig { params(node: YARP::Comment).returns(Comment) }
544
+ sig { params(node: Prism::Comment).returns(Comment) }
498
545
  def parse_comment(node)
499
- Comment.new(node.location.slice.gsub(/^# ?/, "").rstrip, loc: Loc.from_yarp(@file, node.location))
546
+ Comment.new(node.location.slice.gsub(/^# ?/, "").rstrip, loc: Loc.from_prism(@file, node.location))
500
547
  end
501
548
 
502
- sig { params(node: T.nilable(YARP::Node)).returns(T::Array[Arg]) }
549
+ sig { params(node: T.nilable(Prism::Node)).returns(T::Array[Arg]) }
503
550
  def parse_send_args(node)
504
551
  args = T.let([], T::Array[Arg])
505
- return args unless node.is_a?(YARP::ArgumentsNode)
552
+ return args unless node.is_a?(Prism::ArgumentsNode)
506
553
 
507
554
  node.arguments.each do |arg|
508
555
  case arg
509
- when YARP::KeywordHashNode
556
+ when Prism::KeywordHashNode
510
557
  arg.elements.each do |assoc|
511
- next unless assoc.is_a?(YARP::AssocNode)
558
+ next unless assoc.is_a?(Prism::AssocNode)
512
559
 
513
560
  args << KwArg.new(
514
561
  node_string!(assoc.key).delete_suffix(":"),
@@ -523,13 +570,13 @@ module RBI
523
570
  args
524
571
  end
525
572
 
526
- sig { params(node: T.nilable(YARP::Node)).returns(T::Array[Param]) }
573
+ sig { params(node: T.nilable(Prism::Node)).returns(T::Array[Param]) }
527
574
  def parse_params(node)
528
575
  params = []
529
- return params unless node.is_a?(YARP::ParametersNode)
576
+ return params unless node.is_a?(Prism::ParametersNode)
530
577
 
531
578
  node.requireds.each do |param|
532
- next unless param.is_a?(YARP::RequiredParameterNode)
579
+ next unless param.is_a?(Prism::RequiredParameterNode)
533
580
 
534
581
  params << ReqParam.new(
535
582
  param.name.to_s,
@@ -539,7 +586,7 @@ module RBI
539
586
  end
540
587
 
541
588
  node.optionals.each do |param|
542
- next unless param.is_a?(YARP::OptionalParameterNode)
589
+ next unless param.is_a?(Prism::OptionalParameterNode)
543
590
 
544
591
  params << OptParam.new(
545
592
  param.name.to_s,
@@ -550,7 +597,7 @@ module RBI
550
597
  end
551
598
 
552
599
  rest = node.rest
553
- if rest.is_a?(YARP::RestParameterNode)
600
+ if rest.is_a?(Prism::RestParameterNode)
554
601
  params << RestParam.new(
555
602
  rest.name&.to_s || "*args",
556
603
  loc: node_loc(rest),
@@ -559,7 +606,7 @@ module RBI
559
606
  end
560
607
 
561
608
  node.keywords.each do |param|
562
- next unless param.is_a?(YARP::KeywordParameterNode)
609
+ next unless param.is_a?(Prism::KeywordParameterNode)
563
610
 
564
611
  value = param.value
565
612
  params << if value
@@ -579,7 +626,7 @@ module RBI
579
626
  end
580
627
 
581
628
  rest_kw = node.keyword_rest
582
- if rest_kw.is_a?(YARP::KeywordRestParameterNode)
629
+ if rest_kw.is_a?(Prism::KeywordRestParameterNode)
583
630
  params << KwRestParam.new(
584
631
  rest_kw.name&.to_s || "**kwargs",
585
632
  loc: node_loc(rest_kw),
@@ -588,7 +635,7 @@ module RBI
588
635
  end
589
636
 
590
637
  block = node.block
591
- if block.is_a?(YARP::BlockParameterNode)
638
+ if block.is_a?(Prism::BlockParameterNode)
592
639
  params << BlockParam.new(
593
640
  block.name&.to_s || "&block",
594
641
  loc: node_loc(block),
@@ -599,7 +646,7 @@ module RBI
599
646
  params
600
647
  end
601
648
 
602
- sig { params(node: YARP::CallNode).returns(Sig) }
649
+ sig { params(node: Prism::CallNode).returns(Sig) }
603
650
  def parse_sig(node)
604
651
  @last_sigs_comments = node_comments(node)
605
652
 
@@ -609,10 +656,10 @@ module RBI
609
656
  builder.current
610
657
  end
611
658
 
612
- sig { params(node: T.any(YARP::ConstantWriteNode, YARP::ConstantPathWriteNode)).returns(T.nilable(Struct)) }
659
+ sig { params(node: T.any(Prism::ConstantWriteNode, Prism::ConstantPathWriteNode)).returns(T.nilable(Struct)) }
613
660
  def parse_struct(node)
614
661
  send = node.value
615
- return unless send.is_a?(YARP::CallNode)
662
+ return unless send.is_a?(Prism::CallNode)
616
663
  return unless send.message == "new"
617
664
 
618
665
  recv = send.receiver
@@ -623,14 +670,14 @@ module RBI
623
670
  keyword_init = T.let(false, T::Boolean)
624
671
 
625
672
  args = send.arguments
626
- if args.is_a?(YARP::ArgumentsNode)
673
+ if args.is_a?(Prism::ArgumentsNode)
627
674
  args.arguments.each do |arg|
628
675
  case arg
629
- when YARP::SymbolNode
676
+ when Prism::SymbolNode
630
677
  members << arg.value
631
- when YARP::KeywordHashNode
678
+ when Prism::KeywordHashNode
632
679
  arg.elements.each do |assoc|
633
- next unless assoc.is_a?(YARP::AssocNode)
680
+ next unless assoc.is_a?(Prism::AssocNode)
634
681
 
635
682
  key = node_string!(assoc.key)
636
683
  val = node_string(assoc.value)
@@ -644,9 +691,9 @@ module RBI
644
691
  end
645
692
 
646
693
  name = case node
647
- when YARP::ConstantWriteNode
694
+ when Prism::ConstantWriteNode
648
695
  node.name.to_s
649
- when YARP::ConstantPathWriteNode
696
+ when Prism::ConstantPathWriteNode
650
697
  node_string!(node.target)
651
698
  end
652
699
 
@@ -659,10 +706,10 @@ module RBI
659
706
  struct
660
707
  end
661
708
 
662
- sig { params(send: YARP::CallNode).void }
709
+ sig { params(send: Prism::CallNode).void }
663
710
  def parse_tstruct_field(send)
664
711
  args = send.arguments
665
- return unless args.is_a?(YARP::ArgumentsNode)
712
+ return unless args.is_a?(Prism::ArgumentsNode)
666
713
 
667
714
  name_arg, type_arg, *rest = args.arguments
668
715
  return unless name_arg
@@ -675,10 +722,10 @@ module RBI
675
722
  default_value = T.let(nil, T.nilable(String))
676
723
 
677
724
  rest&.each do |arg|
678
- next unless arg.is_a?(YARP::KeywordHashNode)
725
+ next unless arg.is_a?(Prism::KeywordHashNode)
679
726
 
680
727
  arg.elements.each do |assoc|
681
- next unless assoc.is_a?(YARP::AssocNode)
728
+ next unless assoc.is_a?(Prism::AssocNode)
682
729
 
683
730
  if node_string(assoc.key) == "default:"
684
731
  default_value = node_string(assoc.value)
@@ -696,7 +743,7 @@ module RBI
696
743
  end
697
744
  end
698
745
 
699
- sig { params(name: String, node: YARP::Node).returns(Visibility) }
746
+ sig { params(name: String, node: Prism::Node).returns(Visibility) }
700
747
  def parse_visibility(name, node)
701
748
  case name
702
749
  when "public"
@@ -734,9 +781,9 @@ module RBI
734
781
  )
735
782
  end
736
783
 
737
- sig { params(node: T.nilable(YARP::Node)).returns(T::Boolean) }
784
+ sig { params(node: T.nilable(Prism::Node)).returns(T::Boolean) }
738
785
  def type_variable_definition?(node)
739
- return false unless node.is_a?(YARP::CallNode)
786
+ return false unless node.is_a?(Prism::CallNode)
740
787
  return false unless node.block
741
788
 
742
789
  node.message == "type_member" || node.message == "type_template"
@@ -756,12 +803,12 @@ module RBI
756
803
  @current = T.let(Sig.new, Sig)
757
804
  end
758
805
 
759
- sig { override.params(node: YARP::CallNode).void }
806
+ sig { override.params(node: Prism::CallNode).void }
760
807
  def visit_call_node(node)
761
808
  case node.message
762
809
  when "sig"
763
810
  args = node.arguments
764
- if args.is_a?(YARP::ArgumentsNode)
811
+ if args.is_a?(Prism::ArgumentsNode)
765
812
  args.arguments.each do |arg|
766
813
  @current.is_final = node_string(arg) == ":final"
767
814
  end
@@ -770,7 +817,7 @@ module RBI
770
817
  @current.is_abstract = true
771
818
  when "checked"
772
819
  args = node.arguments
773
- if args.is_a?(YARP::ArgumentsNode)
820
+ if args.is_a?(Prism::ArgumentsNode)
774
821
  arg = node_string(args.arguments.first)
775
822
  @current.checked = arg&.delete_prefix(":")&.to_sym
776
823
  end
@@ -782,13 +829,13 @@ module RBI
782
829
  visit(node.arguments)
783
830
  when "returns"
784
831
  args = node.arguments
785
- if args.is_a?(YARP::ArgumentsNode)
832
+ if args.is_a?(Prism::ArgumentsNode)
786
833
  first = args.arguments.first
787
834
  @current.return_type = node_string!(first) if first
788
835
  end
789
836
  when "type_parameters"
790
837
  args = node.arguments
791
- if args.is_a?(YARP::ArgumentsNode)
838
+ if args.is_a?(Prism::ArgumentsNode)
792
839
  args.arguments.each do |arg|
793
840
  @current.type_params << node_string!(arg).delete_prefix(":")
794
841
  end
@@ -801,7 +848,7 @@ module RBI
801
848
  visit(node.block)
802
849
  end
803
850
 
804
- sig { override.params(node: YARP::AssocNode).void }
851
+ sig { override.params(node: Prism::AssocNode).void }
805
852
  def visit_assoc_node(node)
806
853
  @current.params << SigParam.new(
807
854
  node_string!(node.key).delete_suffix(":"),
data/lib/rbi/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RBI
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-11 00:00:00.000000000 Z
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sorbet-runtime
14
+ name: prism
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.9204
19
+ version: 0.15.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.17'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 0.5.9204
29
+ version: 0.15.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.17'
27
33
  - !ruby/object:Gem::Dependency
28
- name: yarp
34
+ name: sorbet-runtime
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: 0.11.0
39
+ version: 0.5.9204
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: 0.11.0
46
+ version: 0.5.9204
41
47
  description:
42
48
  email:
43
49
  - ruby@shopify.com
@@ -86,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
92
  - !ruby/object:Gem::Version
87
93
  version: '0'
88
94
  requirements: []
89
- rubygems_version: 3.4.19
95
+ rubygems_version: 3.4.21
90
96
  signing_key:
91
97
  specification_version: 4
92
98
  summary: RBI generation framework