steadfast 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3856e55251f5e48be25a1cb9f03df36743ab36e8bfa18068b33045a977205cfc
4
- data.tar.gz: f04e002ad7a9b54e3f80f848a82cbb8efd0fd71980b7066e581473a5512b4b9a
3
+ metadata.gz: 8cb638379609c138ddd9d582bc651c4c89e1ea5109687ff1455fe47a5c22995c
4
+ data.tar.gz: 869bf5c02b66b1ecfcc5cfabb2f506cd9d8e3ee1ccb6f2e96304e4d9725cddbb
5
5
  SHA512:
6
- metadata.gz: f31437cf5dd75e56eae0342d6055c50fcd82726130b22b07cbababa4dd45f7955b03497ca5ac572747a101d9bf6e5aced9b49c8c21c55bae9bf73e7c1e2b6f1c
7
- data.tar.gz: 2cc985fff855606d568445392bbaf289eb12d0876bd6879dcad7a6d01686aad46f883e0c981254b686fabeddc4d9222b4358145f733e9ae69ccd572c96547cc2
6
+ metadata.gz: 71bfa853f0cc05c979e2abb8918167c99bde44e0b181d5347a0719ceec7551597393ae02eaed37b73a1fb2c342ac10a9778d35c664c2476c24ab580a7a13ba54
7
+ data.tar.gz: 5e5cefe1d89228fa9518456a1df81903157e472522b73d3cebad05d309dfbebccb56304f46c122921d7341bd9f3ac046177a791bf5a65f01a416b7bb213206d8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.6.0 2026-11-27
2
+
3
+ - Add support for emit-nothing with `unquote(:__nop__)`
4
+ - Refactor unquote code, fix rewriting of nested quote expressions
5
+ - Sourcifier: Add support for missing node types (thanks @joeldrapper !)
6
+ - Sourcifier: fix `HashPatternNode` with rest
7
+
1
8
  # 0.5.0 2026-11-26
2
9
 
3
10
  - Add examples
@@ -119,18 +119,23 @@ module Steadfast
119
119
  # @return [Ruby::Prism::Node]
120
120
  def __unquote_evaluate__(node, binding)
121
121
  if node.arguments && (node.arguments.arguments.size == 1) && !node.block
122
- arg = __unquote_rewrite_nested_quote__(node.arguments.arguments[0], binding)
123
- v = Steadfast.eval_ast(arg, nil, binding)
124
- __unquote_convert_value__(v, node)
122
+ # unquote(expr)
123
+ __unquote_evaluate_target_node__(node.arguments.arguments[0], binding, node)
125
124
  elsif node.block && !node.arguments
126
- ast = __unquote_rewrite_nested_quote__(node.block.body, binding)
127
- v = Steadfast.eval_ast(node.block.body, nil, binding)
128
- __unquote_convert_value__(v, node)
125
+ # unquote { expr }
126
+ __unquote_evaluate_target_node__(node.block.body, binding, node)
129
127
  else
128
+ # unquote(), unquote(expr) { expr }
130
129
  raise ArgumentError, "Invalid unquote arguments"
131
130
  end
132
131
  end
133
132
 
133
+ def __unquote_evaluate_target_node__(node, binding, location)
134
+ node2 = __unquote_rewrite_nested_quote__(node, binding)
135
+ v = Steadfast.eval_ast(node2, nil, binding)
136
+ __unquote_convert_value__(v, location)
137
+ end
138
+
134
139
  # Rewrites nested calls to quote inside an unquote block or expression.
135
140
  #
136
141
  # @param node [Ruby::Prism::Node]
@@ -156,6 +161,8 @@ module Steadfast
156
161
  # @return [Ruby::Prism::Node]
157
162
  def __unquote_convert_value__(value, location)
158
163
  case value
164
+ when :__nop__
165
+ nil
159
166
  when Integer, Float, String, Symbol, Range, Regexp, nil, true, false, Hash, Class, Module
160
167
  Steadfast.make_literal(value, location:)
161
168
  when Array
@@ -15,102 +15,126 @@ module Steadfast
15
15
  # its visit plan. Nodes requiring special logic have normal visit_xxx_node
16
16
  # method below.
17
17
  VISIT_PLANS = {
18
- alias_global_variable: [:keyword_loc, :whitespace, :new_name, :whitespace, :old_name],
19
- alias_method: [:keyword_loc, :whitespace, :new_name, :whitespace, :old_name],
20
- alternation_pattern: [:left, :whitespace, :operator_loc, :whitespace, :right],
21
- and: [:left, :whitespace, :operator_loc, :whitespace, :right],
22
- assoc_splat: [:operator_loc, :value],
23
- back_reference_read: :emit_verbatim,
24
- block: [:opening_loc, :parameters, :newline, :body, :newline, :closing_loc],
25
- block_argument: [:operator_loc, :expression],
26
- block_local_variable: :emit_verbatim,
27
- block_parameter: [:operator_loc, :name_loc],
28
- break: [:keyword_loc, :whitespace, :arguments],
29
- call_target: [:receiver, :call_operator_loc, :message_loc],
30
- capture_pattern: [:value, :whitespace, :operator_loc, :whitespace, :target],
31
- class: [:class_keyword_loc, :whitespace, :constant_path, :whitespace,
32
- :inheritance_operator_loc, :whitespace, :superclass, :newline,
33
- :body, :newline, :end_keyword_loc],
34
- class_variable_read: :emit_verbatim,
35
- class_variable_target: :emit_verbatim,
36
- class_variable_write: [:name_loc, :operator_loc, :value],
37
- constant_path: [:parent, :delimiter_loc, :name_loc],
38
- constant_path_write: [:target, :operator_loc, :value],
39
- constant_read: :emit_verbatim,
40
- constant_write: [:name_loc, :operator_loc, :value],
41
- defined: [:keyword_loc, :lparen_loc, :value, :rparen_loc],
42
- else: [:else_keyword_loc, :newline, :statements],
43
- embedded_statements: [:opening_loc, :statements, :closing_loc],
44
- embedded_variable: [:operator_loc, :variable],
45
- ensure: [:ensure_keyword_loc, :newline, :statements],
46
- false: :emit_verbatim,
47
- flip_flop: [:left, :operator_loc, :right],
48
- float: :emit_verbatim,
49
- for: [:for_keyword_loc, :whitespace, :index, :whitespace, :in_keyword_loc,
50
- :whitespace, :collection, :whitespace, :do_keyword_loc, :newline,
51
- :statements, :newline, :end_keyword_loc],
52
- forwarding_arguments: :emit_verbatim,
53
- forwarding_parameter: :emit_verbatim,
54
- forwarding_super: [:keyword_loc, :block],
55
- global_variable_read: :emit_verbatim,
56
- global_variable_target: :emit_verbatim,
57
- global_variable_write: [:name_loc, :operator_loc, :value],
58
- implicit: :nop,
59
- implicit_rest: :nop,
60
- in: [:in_loc, :whitespace, :pattern, :whitespace, :then_loc],
61
- index_target: [:receiver, :opening_loc, :arguments, :closing_loc],
18
+ alias_global_variable: [:keyword_loc, :whitespace, :new_name, :whitespace, :old_name],
19
+ alias_method: [:keyword_loc, :whitespace, :new_name, :whitespace, :old_name],
20
+ alternation_pattern: [:left, :whitespace, :operator_loc, :whitespace, :right],
21
+ and: [:left, :whitespace, :operator_loc, :whitespace, :right],
22
+ assoc_splat: [:operator_loc, :value],
23
+ back_reference_read: :emit_verbatim,
24
+ block: [:opening_loc, :parameters, :newline, :body, :newline, :closing_loc],
25
+ block_argument: [:operator_loc, :expression],
26
+ block_local_variable: :emit_verbatim,
27
+ block_parameter: [:operator_loc, :name_loc],
28
+ break: [:keyword_loc, :whitespace, :arguments],
29
+ call_and_write: [:receiver, :call_operator_loc, :message_loc, :whitespace, :operator_loc, :whitespace, :value],
30
+ call_or_write: [:receiver, :call_operator_loc, :message_loc, :whitespace, :operator_loc, :whitespace, :value],
31
+ call_target: [:receiver, :call_operator_loc, :message_loc],
32
+ capture_pattern: [:value, :whitespace, :operator_loc, :whitespace, :target],
33
+ class: [
34
+ :class_keyword_loc, :whitespace, :constant_path, :whitespace,
35
+ :inheritance_operator_loc, :whitespace, :superclass, :newline,
36
+ :body, :newline, :end_keyword_loc
37
+ ],
38
+ class_variable_and_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
39
+ class_variable_operator_write: [:name_loc, :whitespace, :binary_operator_loc, :value],
40
+ class_variable_or_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
41
+ class_variable_read: :emit_verbatim,
42
+ class_variable_target: :emit_verbatim,
43
+ class_variable_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
44
+ constant_and_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
45
+ constant_operator_write: [:name_loc, :whitespace, :binary_operator_loc, :whitespace, :value],
46
+ constant_or_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
47
+ constant_path: [:parent, :delimiter_loc, :name_loc],
48
+ constant_path_and_write: [:target, :whitespace, :operator_loc, :whitespace, :value],
49
+ constant_path_operator_write: [:target, :whitespace, :binary_operator_loc, :whitespace, :value],
50
+ constant_path_or_write: [:target, :whitespace, :operator_loc, :whitespace, :value],
51
+ constant_path_target: [:parent, :delimiter_loc, :name_loc],
52
+ constant_path_write: [:target, :whitespace, :operator_loc, :whitespace, :value],
53
+ constant_read: :emit_verbatim,
54
+ constant_target: :emit_verbatim,
55
+ constant_write: [:name_loc, :operator_loc, :value],
56
+ defined: [:keyword_loc, :lparen_loc, :value, :rparen_loc],
57
+ else: [:else_keyword_loc, :newline, :statements],
58
+ embedded_statements: [:opening_loc, :statements, :closing_loc],
59
+ embedded_variable: [:operator_loc, :variable],
60
+ ensure: [:ensure_keyword_loc, :newline, :statements],
61
+ false: :emit_verbatim,
62
+ flip_flop: [:left, :operator_loc, :right],
63
+ float: :emit_verbatim,
64
+ for: [
65
+ :for_keyword_loc, :whitespace, :index, :whitespace, :in_keyword_loc,
66
+ :whitespace, :collection, :whitespace, :do_keyword_loc, :newline,
67
+ :statements, :newline, :end_keyword_loc
68
+ ],
69
+ forwarding_arguments: :emit_verbatim,
70
+ forwarding_parameter: :emit_verbatim,
71
+ forwarding_super: [:keyword_loc, :block],
72
+ global_variable_and_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
73
+ global_variable_operator_write: [:name_loc, :whitespace, :binary_operator_loc, :whitespace, :value],
74
+ global_variable_or_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
75
+ global_variable_read: :emit_verbatim,
76
+ global_variable_target: :emit_verbatim,
77
+ global_variable_write: [:name_loc, :operator_loc, :value],
78
+ implicit: :nop,
79
+ implicit_rest: :nop,
80
+ in: [:in_loc, :whitespace, :pattern, :whitespace, :then_loc],
81
+ index_target: [:receiver, :opening_loc, :arguments, :closing_loc],
82
+ instance_variable_and_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
62
83
  instance_variable_operator_write: [:name_loc, :whitespace, :binary_operator_loc, :whitespace, :value],
63
- instance_variable_or_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
64
- instance_variable_read: :emit_verbatim,
65
- instance_variable_target: :emit_verbatim,
66
- instance_variable_write: [:name_loc, :operator_loc, :value],
67
- integer: :emit_verbatim,
68
- it_parameters: :nop,
69
- it_local_variable_read: :emit_verbatim,
70
- keyword_rest_parameter: [:operator_loc, :name_loc],
71
- keyword_parameter: :emit_verbatim,
72
- lambda: [:operator_loc, :parameters, :whitespace, :opening_loc, :newline, :body, :newline, :closing_loc],
73
- local_variable_and_write: [:name_loc, :operator_loc, :value],
74
- local_variable_operator_write: [:name_loc, :binary_operator_loc, :value],
75
- local_variable_or_write: [:name_loc, :operator_loc, :value],
76
- local_variable_read: :emit_verbatim,
77
- local_variable_target: :emit_verbatim,
78
- local_variable_write: [:name_loc, :operator_loc, :value],
79
- match_predicate: [:value, :whitespace, :operator_loc, :whitespace, :pattern],
80
- match_required: [:value, :whitespace, :operator_loc, :whitespace, :pattern],
81
- match_write: [:call],
82
- module: [:module_keyword_loc, :whitespace, :constant_path, :newline, :body, :newline, :end_keyword_loc],
83
- next: [:keyword_loc, :whitespace, :arguments],
84
- nil: :emit_verbatim,
85
- no_keywords_parameter: :emit_verbatim,
86
- numbered_parameters: :nop,
87
- optional_parameter: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
88
- optional_keyword_parameter: [:name_loc, :whitespace, :value],
89
- or: [:left, :whitespace, :operator_loc, :whitespace, :right],
90
- parentheses: [:opening_loc, :body, :closing_loc],
91
- program: [:statements],
92
- pinned_expression: [:operator_loc, :lparen_loc, :expression, :rparen_loc],
93
- pinned_variable: [:operator_loc, :variable],
94
- rational: :emit_verbatim,
95
- redo: :emit_verbatim,
96
- regular_expression: :emit_verbatim,
97
- required_parameter: :emit_verbatim,
98
- required_keyword_parameter: :emit_verbatim,
99
- rescue_modifier: [:expression, :whitespace, :keyword_loc, :whitespace, :rescue_expression],
100
- rest_parameter: [:operator_loc, :name_loc],
101
- retry: :emit_verbatim,
102
- return: [:keyword_loc, :whitespace, :arguments],
103
- self: :emit_verbatim,
104
- singleton_class: [:class_keyword_loc, :whitespace, :operator_loc, :whitespace, :expression,
105
- :newline, :body, :newline, :end_keyword_loc],
106
- source_encoding: :emit_verbatim,
107
- source_file: :emit_verbatim,
108
- source_line: :emit_verbatim,
109
- splat: [:operator_loc, :expression],
110
- symbol: :emit_verbatim,
111
- true: :emit_verbatim,
112
- x_string: :emit_verbatim,
113
- yield: [:keyword_loc, :lparen_loc, :arguments, :rparen_loc]
84
+ instance_variable_or_write: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
85
+ instance_variable_read: :emit_verbatim,
86
+ instance_variable_target: :emit_verbatim,
87
+ instance_variable_write: [:name_loc, :operator_loc, :value],
88
+ integer: :emit_verbatim,
89
+ it_parameters: :nop,
90
+ it_local_variable_read: :emit_verbatim,
91
+ keyword_rest_parameter: [:operator_loc, :name_loc],
92
+ keyword_parameter: :emit_verbatim,
93
+ lambda: [:operator_loc, :parameters, :whitespace, :opening_loc, :newline, :body, :newline, :closing_loc],
94
+ local_variable_and_write: [:name_loc, :operator_loc, :value],
95
+ local_variable_operator_write: [:name_loc, :binary_operator_loc, :value],
96
+ local_variable_or_write: [:name_loc, :operator_loc, :value],
97
+ local_variable_read: :emit_verbatim,
98
+ local_variable_target: :emit_verbatim,
99
+ local_variable_write: [:name_loc, :operator_loc, :value],
100
+ match_predicate: [:value, :whitespace, :operator_loc, :whitespace, :pattern],
101
+ match_required: [:value, :whitespace, :operator_loc, :whitespace, :pattern],
102
+ match_write: [:call],
103
+ module: [:module_keyword_loc, :whitespace, :constant_path, :newline, :body, :newline, :end_keyword_loc],
104
+ next: [:keyword_loc, :whitespace, :arguments],
105
+ nil: :emit_verbatim,
106
+ no_keywords_parameter: :emit_verbatim,
107
+ numbered_parameters: :nop,
108
+ numbered_reference_read: :emit_verbatim,
109
+ optional_parameter: [:name_loc, :whitespace, :operator_loc, :whitespace, :value],
110
+ optional_keyword_parameter: [:name_loc, :whitespace, :value],
111
+ or: [:left, :whitespace, :operator_loc, :whitespace, :right],
112
+ parentheses: [:opening_loc, :body, :closing_loc],
113
+ program: [:statements],
114
+ pinned_expression: [:operator_loc, :lparen_loc, :expression, :rparen_loc],
115
+ pinned_variable: [:operator_loc, :variable],
116
+ rational: :emit_verbatim,
117
+ redo: :emit_verbatim,
118
+ regular_expression: :emit_verbatim,
119
+ required_parameter: :emit_verbatim,
120
+ required_keyword_parameter: :emit_verbatim,
121
+ rescue_modifier: [:expression, :whitespace, :keyword_loc, :whitespace, :rescue_expression],
122
+ rest_parameter: [:operator_loc, :name_loc],
123
+ retry: :emit_verbatim,
124
+ return: [:keyword_loc, :whitespace, :arguments],
125
+ self: :emit_verbatim,
126
+ singleton_class: [
127
+ :class_keyword_loc, :whitespace, :operator_loc, :whitespace, :expression,
128
+ :newline, :body, :newline, :end_keyword_loc
129
+ ],
130
+ source_encoding: :emit_verbatim,
131
+ source_file: :emit_verbatim,
132
+ source_line: :emit_verbatim,
133
+ splat: [:operator_loc, :expression],
134
+ symbol: :emit_verbatim,
135
+ true: :emit_verbatim,
136
+ x_string: :emit_verbatim,
137
+ yield: [:keyword_loc, :lparen_loc, :arguments, :rparen_loc]
114
138
  }
115
139
 
116
140
  attr_reader :buffer
@@ -322,6 +346,10 @@ module Steadfast
322
346
  emit_code(node.constant)
323
347
  emit_code(node.opening_loc)
324
348
  visit_comma_separated_nodes(node.elements)
349
+ if node.elements && node.elements.size > 0 && node.rest
350
+ emit_comma
351
+ end
352
+ emit_code(node.rest)
325
353
  emit_code(node.closing_loc)
326
354
  end
327
355
 
@@ -365,23 +393,6 @@ module Steadfast
365
393
  emit('i')
366
394
  end
367
395
 
368
- def visit_interpolated_symbol_node(node)
369
- heredoc = node.opening_loc && node.opening_loc.slice =~ /\<\</
370
- emit_code(node.opening_loc)
371
- emit_newline if heredoc
372
- last_part = nil
373
- node.parts.each { |p|
374
- if heredoc && last_part && p.location.start_line != last_part.location.start_line
375
- emit_newline
376
- end
377
- emit_code(p)
378
- last_part = p
379
- }
380
- emit_newline if heredoc
381
- emit_code(node.closing_loc)
382
- end
383
- alias_method :visit_interpolated_string_node, :visit_interpolated_symbol_node
384
-
385
396
  def visit_index_operator_write_node(node)
386
397
  emit_code(node.receiver)
387
398
  emit_code(node.opening_loc)
@@ -417,12 +428,35 @@ module Steadfast
417
428
  end
418
429
  alias_method :visit_index_and_write_node, :visit_index_or_write_node
419
430
 
431
+ def visit_interpolated_match_last_line_node(node)
432
+ emit_code(node.opening_loc)
433
+ node.parts.each { |p| emit_code(p) }
434
+ emit_code(node.closing_loc)
435
+ end
436
+
420
437
  def visit_interpolated_regular_expression_node(node)
421
438
  emit_code(node.opening_loc)
422
439
  node.parts.each { |p| emit_code(p) }
423
440
  emit_code(node.closing_loc)
424
441
  end
425
442
 
443
+ def visit_interpolated_symbol_node(node)
444
+ heredoc = node.opening_loc && node.opening_loc.slice =~ /\<\</
445
+ emit_code(node.opening_loc)
446
+ emit_newline if heredoc
447
+ last_part = nil
448
+ node.parts.each { |p|
449
+ if heredoc && last_part && p.location.start_line != last_part.location.start_line
450
+ emit_newline
451
+ end
452
+ emit_code(p)
453
+ last_part = p
454
+ }
455
+ emit_newline if heredoc
456
+ emit_code(node.closing_loc)
457
+ end
458
+ alias_method :visit_interpolated_string_node, :visit_interpolated_symbol_node
459
+
426
460
  def visit_interpolated_x_string_node(node)
427
461
  emit_code(node.opening_loc)
428
462
  node.parts.each { |p| emit_code(p) }
@@ -507,6 +541,11 @@ module Steadfast
507
541
  emit_code(node.subsequent)
508
542
  end
509
543
 
544
+ def visit_shareable_constant_node(node)
545
+ emit("# shareable_constant_value: literal\n")
546
+ emit_code(node.write)
547
+ end
548
+
510
549
  def visit_statements_node(node)
511
550
  first = true
512
551
  node.body&.each do |n|
@@ -1,4 +1,4 @@
1
1
  module Steadfast
2
2
  # Steadfast version
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steadfast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner