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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/steadfast/quote.rb +13 -6
- data/lib/steadfast/sourcifier.rb +151 -112
- data/lib/steadfast/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cb638379609c138ddd9d582bc651c4c89e1ea5109687ff1455fe47a5c22995c
|
|
4
|
+
data.tar.gz: 869bf5c02b66b1ecfcc5cfabb2f506cd9d8e3ee1ccb6f2e96304e4d9725cddbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/steadfast/quote.rb
CHANGED
|
@@ -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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
127
|
-
|
|
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
|
data/lib/steadfast/sourcifier.rb
CHANGED
|
@@ -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:
|
|
19
|
-
alias_method:
|
|
20
|
-
alternation_pattern:
|
|
21
|
-
and:
|
|
22
|
-
assoc_splat:
|
|
23
|
-
back_reference_read:
|
|
24
|
-
block:
|
|
25
|
-
block_argument:
|
|
26
|
-
block_local_variable:
|
|
27
|
-
block_parameter:
|
|
28
|
-
break:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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:
|
|
64
|
-
instance_variable_read:
|
|
65
|
-
instance_variable_target:
|
|
66
|
-
instance_variable_write:
|
|
67
|
-
integer:
|
|
68
|
-
it_parameters:
|
|
69
|
-
it_local_variable_read:
|
|
70
|
-
keyword_rest_parameter:
|
|
71
|
-
keyword_parameter:
|
|
72
|
-
lambda:
|
|
73
|
-
local_variable_and_write:
|
|
74
|
-
local_variable_operator_write:
|
|
75
|
-
local_variable_or_write:
|
|
76
|
-
local_variable_read:
|
|
77
|
-
local_variable_target:
|
|
78
|
-
local_variable_write:
|
|
79
|
-
match_predicate:
|
|
80
|
-
match_required:
|
|
81
|
-
match_write:
|
|
82
|
-
module:
|
|
83
|
-
next:
|
|
84
|
-
nil:
|
|
85
|
-
no_keywords_parameter:
|
|
86
|
-
numbered_parameters:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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|
|
data/lib/steadfast/version.rb
CHANGED