to_source 0.2.0 → 0.2.5
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.
- data/Changelog.md +37 -1
- data/Gemfile +1 -2
- data/Gemfile.devtools +6 -14
- data/README.md +3 -3
- data/TODO +2 -0
- data/lib/to_source/visitor.rb +130 -23
- data/lib/to_source.rb +1 -1
- data/spec/unit/to_source/visitor/class_methods/run_spec.rb +82 -13
- data/to_source.gemspec +2 -6
- metadata +4 -5
- data/lib/to_source/version.rb +0 -3
data/Changelog.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
# v0.2.5 2012-12-14
|
|
2
|
+
|
|
3
|
+
* [fixed] Emit unary operators correctly
|
|
4
|
+
* [fixed] Define with optional splat and block argument
|
|
5
|
+
* [fixed] Emit arguments to break keyword
|
|
6
|
+
* [change] Uglify output of binary operators with unneded paranteses. Correct output > nice output.
|
|
7
|
+
* [fixed] Emit nested binary operators correctly.
|
|
8
|
+
* [fixed] Emit element reference on self correctly. self[foo].
|
|
9
|
+
|
|
10
|
+
# v0.2.4 2012-12-07
|
|
11
|
+
|
|
12
|
+
* [feature] Allow to emit pattern variables as root node
|
|
13
|
+
* [fixed] Emit send with splat and block argument correctly
|
|
14
|
+
|
|
15
|
+
[Compare v0.2.3..v0.2.4](https://github.com/mbj/to_source/compare/v0.2.3...v0.2.4)
|
|
16
|
+
|
|
17
|
+
# v0.2.3 2012-12-07
|
|
18
|
+
|
|
19
|
+
* [fixed] Nuke dangling require (sorry for not running specs after gemspec change)
|
|
20
|
+
|
|
21
|
+
[Compare v0.2.2..v0.2.3](https://github.com/mbj/to_source/compare/v0.2.2...v0.2.3)
|
|
22
|
+
|
|
23
|
+
# v0.2.2 2012-12-07
|
|
24
|
+
|
|
25
|
+
* [fixed] Emit of pattern arguments with no formal arguments present
|
|
26
|
+
* [fixed] Missed to require set
|
|
27
|
+
|
|
28
|
+
[Compare v0.2.1..v0.2.2](https://github.com/mbj/to_source/compare/v0.2.1...v0.2.2)
|
|
29
|
+
|
|
30
|
+
# v0.2.1 2012-12-07
|
|
31
|
+
|
|
32
|
+
* [fixed] Emit of def on splat with block
|
|
33
|
+
* [fixed] Emit of pattern args
|
|
34
|
+
|
|
35
|
+
[Compare v0.2.0..v0.2.1](https://github.com/mbj/to_source/compare/v0.2.0...v0.2.1)
|
|
36
|
+
|
|
1
37
|
# v0.2.0 2012-12-07
|
|
2
38
|
|
|
3
39
|
* [BRAKING CHANGE] Remove core extension Rubinius::AST::Node#to_source (mbj)
|
|
@@ -8,4 +44,4 @@
|
|
|
8
44
|
* [feature] Introduce metric tools via devtools
|
|
9
45
|
* [fixed] Lots of transitvity edge cases
|
|
10
46
|
|
|
11
|
-
[Compare v0.1.3..v0.2.0](https://github.com/
|
|
47
|
+
[Compare v0.1.3..v0.2.0](https://github.com/mbj/to_source/ompare/v0.1.3...v0.2.0)
|
data/Gemfile
CHANGED
|
@@ -2,7 +2,6 @@ source :rubygems
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
gem '
|
|
6
|
-
gem 'devtools', :git => 'https://github.com/mbj/devtools.git', :branch => 'rspec-2-mutant'
|
|
5
|
+
gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
|
|
7
6
|
|
|
8
7
|
eval File.read('Gemfile.devtools')
|
data/Gemfile.devtools
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
group :development do
|
|
2
|
-
gem 'rake', '~> 0
|
|
1
|
+
group :development do
|
|
2
|
+
gem 'rake', '~> 10.0'
|
|
3
3
|
gem 'rspec', '~> 2.12.0'
|
|
4
4
|
gem 'yard', '~> 0.8.3'
|
|
5
5
|
end
|
|
@@ -26,27 +26,19 @@ group :metrics do
|
|
|
26
26
|
gem 'flog', '~> 2.5.1'
|
|
27
27
|
gem 'reek', '~> 1.2.8', :git => 'https://github.com/dkubb/reek.git'
|
|
28
28
|
gem 'roodi', '~> 2.1.0'
|
|
29
|
-
gem 'yardstick', '~> 0.
|
|
30
|
-
gem '
|
|
29
|
+
gem 'yardstick', '~> 0.8.0'
|
|
30
|
+
gem 'mutant', '~> 0.2.5'
|
|
31
31
|
|
|
32
32
|
platforms :ruby_18, :ruby_19 do
|
|
33
33
|
# this indirectly depends on ffi which does not build on ruby-head
|
|
34
34
|
gem 'yard-spellcheck', '~> 0.1.5'
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
platforms :
|
|
38
|
-
gem '
|
|
39
|
-
gem 'fattr', '~> 2.2.0' # for metric_fu
|
|
40
|
-
gem 'json', '~> 1.7.3' # for metric_fu rake task
|
|
41
|
-
gem 'map', '~> 6.0.1' # for metric_fu
|
|
42
|
-
gem 'metric_fu', '~> 2.1.1'
|
|
43
|
-
gem 'mspec', '~> 1.5.17'
|
|
44
|
-
gem 'rcov', '~> 1.0.0'
|
|
37
|
+
platforms :mri_19 do
|
|
38
|
+
gem 'simplecov', '~> 0.7'
|
|
45
39
|
end
|
|
46
40
|
|
|
47
41
|
platforms :rbx do
|
|
48
42
|
gem 'pelusa', '~> 0.2.1'
|
|
49
|
-
gem 'anima', '~> 0.0.1', :git => 'https://github.com/mbj/anima.git'
|
|
50
|
-
gem 'mutant', '~> 0.0.1', :git => 'https://github.com/mbj/mutant.git'
|
|
51
43
|
end
|
|
52
44
|
end
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
to_source
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
-
[](https://codeclimate.com/github/
|
|
4
|
+
[](http://travis-ci.org/txus/to_source)
|
|
5
|
+
[](https://gemnasium.com/txus/to_source)
|
|
6
|
+
[](https://codeclimate.com/github/txus/to_source)
|
|
7
7
|
|
|
8
8
|
Reverse parser to generate source code from the Rubinius AST. Also works well under MRI.
|
|
9
9
|
|
data/TODO
CHANGED
data/lib/to_source/visitor.rb
CHANGED
|
@@ -16,6 +16,28 @@ module ToSource
|
|
|
16
16
|
new(node).output
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# Return handler registry
|
|
20
|
+
#
|
|
21
|
+
# @return [Hash]
|
|
22
|
+
#
|
|
23
|
+
# @api private
|
|
24
|
+
#
|
|
25
|
+
def self.registry
|
|
26
|
+
@registry ||= {}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Register handler class
|
|
30
|
+
#
|
|
31
|
+
# @param [Class:Rubinius::AST::Node] node_klass
|
|
32
|
+
#
|
|
33
|
+
# @return [undefined]
|
|
34
|
+
#
|
|
35
|
+
# @api private
|
|
36
|
+
#
|
|
37
|
+
def self.register(node_klass)
|
|
38
|
+
registry[node_klass]=self
|
|
39
|
+
end
|
|
40
|
+
|
|
19
41
|
# Return the source code of AST
|
|
20
42
|
#
|
|
21
43
|
# @return [String]
|
|
@@ -51,9 +73,14 @@ module ToSource
|
|
|
51
73
|
# @api private
|
|
52
74
|
#
|
|
53
75
|
def dispatch(node)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
76
|
+
handler = self.class.registry.fetch(node.class) do
|
|
77
|
+
name = node.node_name
|
|
78
|
+
name = "#{name}_def" if %w(class module).include?(name)
|
|
79
|
+
__send__(name, node)
|
|
80
|
+
nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
handler.run(self, node) if handler
|
|
57
84
|
end
|
|
58
85
|
|
|
59
86
|
# Emit file
|
|
@@ -121,6 +148,10 @@ module ToSource
|
|
|
121
148
|
#
|
|
122
149
|
def break(node)
|
|
123
150
|
emit('break')
|
|
151
|
+
if node.value.class != Rubinius::AST::NilLiteral
|
|
152
|
+
emit(' ')
|
|
153
|
+
dispatch(node.value)
|
|
154
|
+
end
|
|
124
155
|
end
|
|
125
156
|
|
|
126
157
|
# Emit next
|
|
@@ -1020,21 +1051,50 @@ module ToSource
|
|
|
1020
1051
|
end
|
|
1021
1052
|
end
|
|
1022
1053
|
|
|
1023
|
-
|
|
1054
|
+
UNARY_OPERATORS = %w(
|
|
1055
|
+
! ~ -@ +@
|
|
1056
|
+
).map(&:to_sym).to_set.freeze
|
|
1057
|
+
|
|
1058
|
+
UNARY_MAPPING = {
|
|
1059
|
+
:-@ => :-,
|
|
1060
|
+
:+@ => :+,
|
|
1061
|
+
}.freeze
|
|
1062
|
+
|
|
1063
|
+
# Emit unary operator
|
|
1024
1064
|
#
|
|
1025
1065
|
# @param [Rubinius::AST::Node] node
|
|
1026
1066
|
#
|
|
1027
|
-
# @return [
|
|
1067
|
+
# @return [true]
|
|
1068
|
+
# if node was emitted
|
|
1069
|
+
#
|
|
1070
|
+
# @return [false]
|
|
1071
|
+
# otherwise
|
|
1028
1072
|
#
|
|
1029
1073
|
# @api private
|
|
1030
1074
|
#
|
|
1031
|
-
def
|
|
1032
|
-
|
|
1033
|
-
|
|
1075
|
+
def unary_operator(node)
|
|
1076
|
+
name = node.name
|
|
1077
|
+
|
|
1078
|
+
if UNARY_OPERATORS.include?(name)
|
|
1079
|
+
emit(UNARY_MAPPING.fetch(name, name))
|
|
1034
1080
|
dispatch(node.receiver)
|
|
1035
|
-
return
|
|
1081
|
+
return true
|
|
1036
1082
|
end
|
|
1037
1083
|
|
|
1084
|
+
false
|
|
1085
|
+
end
|
|
1086
|
+
|
|
1087
|
+
# Emit send node
|
|
1088
|
+
#
|
|
1089
|
+
# @param [Rubinius::AST::Node] node
|
|
1090
|
+
#
|
|
1091
|
+
# @return [undefined]
|
|
1092
|
+
#
|
|
1093
|
+
# @api private
|
|
1094
|
+
#
|
|
1095
|
+
def send(node)
|
|
1096
|
+
return if unary_operator(node)
|
|
1097
|
+
|
|
1038
1098
|
if receiver(node)
|
|
1039
1099
|
emit('.')
|
|
1040
1100
|
end
|
|
@@ -1073,13 +1133,16 @@ module ToSource
|
|
|
1073
1133
|
array_body(array)
|
|
1074
1134
|
is_block_pass = block.kind_of?(Rubinius::AST::BlockPass)
|
|
1075
1135
|
|
|
1136
|
+
empty = array.empty?
|
|
1137
|
+
|
|
1076
1138
|
if arguments.splat
|
|
1077
|
-
emit(', ') unless
|
|
1139
|
+
emit(', ') unless empty
|
|
1078
1140
|
dispatch(arguments.splat)
|
|
1141
|
+
empty = false
|
|
1079
1142
|
end
|
|
1080
1143
|
|
|
1081
1144
|
if is_block_pass
|
|
1082
|
-
emit(', ') unless
|
|
1145
|
+
emit(', ') unless empty
|
|
1083
1146
|
block_pass(block)
|
|
1084
1147
|
end
|
|
1085
1148
|
|
|
@@ -1111,10 +1174,7 @@ module ToSource
|
|
|
1111
1174
|
# @api private
|
|
1112
1175
|
#
|
|
1113
1176
|
def element_reference(node)
|
|
1114
|
-
|
|
1115
|
-
dispatch(node.receiver)
|
|
1116
|
-
end
|
|
1117
|
-
|
|
1177
|
+
dispatch(node.receiver)
|
|
1118
1178
|
arguments(node,'[',']')
|
|
1119
1179
|
end
|
|
1120
1180
|
|
|
@@ -1130,6 +1190,7 @@ module ToSource
|
|
|
1130
1190
|
if node.name == :[]
|
|
1131
1191
|
return element_reference(node)
|
|
1132
1192
|
end
|
|
1193
|
+
|
|
1133
1194
|
return if process_binary_operator(node)
|
|
1134
1195
|
|
|
1135
1196
|
if receiver(node)
|
|
@@ -1297,7 +1358,7 @@ module ToSource
|
|
|
1297
1358
|
emit(' do')
|
|
1298
1359
|
|
|
1299
1360
|
arguments = node.arguments
|
|
1300
|
-
unless arguments.
|
|
1361
|
+
unless arguments.required.empty?
|
|
1301
1362
|
emit(' ')
|
|
1302
1363
|
formal_arguments_generic(node.arguments,'|','|')
|
|
1303
1364
|
end
|
|
@@ -1347,9 +1408,11 @@ module ToSource
|
|
|
1347
1408
|
# @api private
|
|
1348
1409
|
#
|
|
1349
1410
|
def and(node)
|
|
1411
|
+
emit('(')
|
|
1350
1412
|
dispatch(node.left)
|
|
1351
1413
|
emit(' && ')
|
|
1352
1414
|
dispatch(node.right)
|
|
1415
|
+
emit(')')
|
|
1353
1416
|
end
|
|
1354
1417
|
|
|
1355
1418
|
# Emit or
|
|
@@ -1361,9 +1424,11 @@ module ToSource
|
|
|
1361
1424
|
# @api private
|
|
1362
1425
|
#
|
|
1363
1426
|
def or(node)
|
|
1427
|
+
emit('(')
|
|
1364
1428
|
dispatch(node.left)
|
|
1365
1429
|
emit(' || ')
|
|
1366
1430
|
dispatch(node.right)
|
|
1431
|
+
emit(')')
|
|
1367
1432
|
end
|
|
1368
1433
|
|
|
1369
1434
|
# Emit and operation with assignment
|
|
@@ -1522,6 +1587,36 @@ module ToSource
|
|
|
1522
1587
|
kend
|
|
1523
1588
|
end
|
|
1524
1589
|
|
|
1590
|
+
# Emit pattern variable
|
|
1591
|
+
#
|
|
1592
|
+
# @param [Rubinius::AST::PatternVariable] node
|
|
1593
|
+
#
|
|
1594
|
+
# @return [undefined]
|
|
1595
|
+
#
|
|
1596
|
+
# @api private
|
|
1597
|
+
#
|
|
1598
|
+
def pattern_variable(node)
|
|
1599
|
+
emit(node.name)
|
|
1600
|
+
end
|
|
1601
|
+
|
|
1602
|
+
# Emit pattern arguments
|
|
1603
|
+
#
|
|
1604
|
+
# @param [Rubinius::AST::PatternArguments] node
|
|
1605
|
+
#
|
|
1606
|
+
# @return [undefined]
|
|
1607
|
+
#
|
|
1608
|
+
# @api private
|
|
1609
|
+
#
|
|
1610
|
+
def pattern_arguments(node)
|
|
1611
|
+
emit('(')
|
|
1612
|
+
arguments = node.arguments.body
|
|
1613
|
+
arguments.each_with_index do |argument, index|
|
|
1614
|
+
dispatch(argument)
|
|
1615
|
+
emit(', ') unless index == arguments.size - 1
|
|
1616
|
+
end
|
|
1617
|
+
emit(')')
|
|
1618
|
+
end
|
|
1619
|
+
|
|
1525
1620
|
# Emit formal arguments as shared between ruby18 and ruby19 mode
|
|
1526
1621
|
#
|
|
1527
1622
|
# @param [Rubinius::AST::Node] node
|
|
@@ -1530,32 +1625,42 @@ module ToSource
|
|
|
1530
1625
|
#
|
|
1531
1626
|
# @api private
|
|
1532
1627
|
#
|
|
1533
|
-
def formal_arguments_generic(node,open,close)
|
|
1534
|
-
|
|
1535
|
-
required
|
|
1628
|
+
def formal_arguments_generic(node, open, close)
|
|
1629
|
+
required, defaults, splat, block_arg = node.required, node.defaults, node.splat, node.block_arg
|
|
1630
|
+
return unless required.any? or defaults or splat or block_arg
|
|
1536
1631
|
|
|
1537
1632
|
emit(open)
|
|
1538
|
-
|
|
1633
|
+
|
|
1634
|
+
required.each_with_index do |node, index|
|
|
1635
|
+
if node.kind_of?(Rubinius::AST::Node)
|
|
1636
|
+
dispatch(node)
|
|
1637
|
+
else
|
|
1638
|
+
emit(node)
|
|
1639
|
+
end
|
|
1640
|
+
emit(', ') unless index == required.size-1
|
|
1641
|
+
end
|
|
1539
1642
|
|
|
1540
1643
|
empty = required.empty?
|
|
1541
1644
|
|
|
1542
1645
|
if defaults
|
|
1543
1646
|
emit(', ') unless empty
|
|
1544
1647
|
dispatch(node.defaults)
|
|
1648
|
+
empty = false
|
|
1545
1649
|
end
|
|
1546
1650
|
|
|
1547
1651
|
if splat
|
|
1548
1652
|
emit(', ') unless empty
|
|
1549
1653
|
emit('*')
|
|
1654
|
+
empty = false
|
|
1550
1655
|
unless splat == :@unnamed_splat
|
|
1551
1656
|
emit(splat)
|
|
1552
1657
|
end
|
|
1553
1658
|
end
|
|
1554
1659
|
|
|
1555
|
-
if
|
|
1660
|
+
if block_arg
|
|
1556
1661
|
emit(', ') unless empty
|
|
1557
1662
|
|
|
1558
|
-
dispatch(
|
|
1663
|
+
dispatch(block_arg)
|
|
1559
1664
|
end
|
|
1560
1665
|
|
|
1561
1666
|
emit(close)
|
|
@@ -1694,6 +1799,7 @@ module ToSource
|
|
|
1694
1799
|
emit('&')
|
|
1695
1800
|
dispatch(node.body)
|
|
1696
1801
|
end
|
|
1802
|
+
alias_method :block_pass19, :block_pass
|
|
1697
1803
|
|
|
1698
1804
|
# Emit return statement
|
|
1699
1805
|
#
|
|
@@ -1736,12 +1842,13 @@ module ToSource
|
|
|
1736
1842
|
|
|
1737
1843
|
operand = node.arguments.array[0]
|
|
1738
1844
|
|
|
1845
|
+
emit('(')
|
|
1739
1846
|
dispatch(node.receiver)
|
|
1740
1847
|
|
|
1741
1848
|
emit(" #{name.to_s} ")
|
|
1742
1849
|
dispatch(operand)
|
|
1743
1850
|
|
|
1744
|
-
|
|
1851
|
+
emit(')')
|
|
1745
1852
|
end
|
|
1746
1853
|
end
|
|
1747
1854
|
end
|
data/lib/to_source.rb
CHANGED
|
@@ -361,6 +361,10 @@ describe ToSource::Visitor,'.run' do
|
|
|
361
361
|
assert_source 'foo[index]'
|
|
362
362
|
end
|
|
363
363
|
|
|
364
|
+
context 'as element reference on self' do
|
|
365
|
+
assert_source 'self[foo]'
|
|
366
|
+
end
|
|
367
|
+
|
|
364
368
|
context 'without arguments' do
|
|
365
369
|
assert_source 'foo.bar'
|
|
366
370
|
end
|
|
@@ -398,6 +402,23 @@ describe ToSource::Visitor,'.run' do
|
|
|
398
402
|
end
|
|
399
403
|
end
|
|
400
404
|
|
|
405
|
+
context 'with block that takes pattern and formal arguments' do
|
|
406
|
+
assert_source <<-RUBY
|
|
407
|
+
foo.bar do |(a, b), c|
|
|
408
|
+
d
|
|
409
|
+
end
|
|
410
|
+
RUBY
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
context 'with block that takes pattern and no formal arguments' do
|
|
415
|
+
assert_source <<-RUBY
|
|
416
|
+
foo.bar do |(a, b)|
|
|
417
|
+
d
|
|
418
|
+
end
|
|
419
|
+
RUBY
|
|
420
|
+
end
|
|
421
|
+
|
|
401
422
|
context 'with block that takes arguments' do
|
|
402
423
|
assert_source <<-RUBY
|
|
403
424
|
foo.bar do |a|
|
|
@@ -421,12 +442,15 @@ describe ToSource::Visitor,'.run' do
|
|
|
421
442
|
|
|
422
443
|
context 'with formal splat and block' do
|
|
423
444
|
assert_source <<-RUBY
|
|
424
|
-
foo
|
|
425
|
-
some_stuff
|
|
426
|
-
end
|
|
445
|
+
foo(bar, *args)
|
|
427
446
|
RUBY
|
|
428
447
|
end
|
|
429
448
|
|
|
449
|
+
context 'with splat and block argument' do
|
|
450
|
+
assert_source <<-RUBY
|
|
451
|
+
foo(*args, &block)
|
|
452
|
+
RUBY
|
|
453
|
+
end
|
|
430
454
|
|
|
431
455
|
context 'with passing block argument' do
|
|
432
456
|
assert_source 'foo.bar(&baz)'
|
|
@@ -481,6 +505,10 @@ describe ToSource::Visitor,'.run' do
|
|
|
481
505
|
assert_source 'break'
|
|
482
506
|
end
|
|
483
507
|
|
|
508
|
+
context 'break with arguments' do
|
|
509
|
+
assert_source 'break a'
|
|
510
|
+
end
|
|
511
|
+
|
|
484
512
|
context 'next' do
|
|
485
513
|
assert_source 'next'
|
|
486
514
|
end
|
|
@@ -514,38 +542,43 @@ describe ToSource::Visitor,'.run' do
|
|
|
514
542
|
context 'binary operators' do
|
|
515
543
|
%w(+ - * / & | && || << >> == === != <= < <=> > >= =~ !~ ^ **).each do |operator|
|
|
516
544
|
context "on literals #{operator}" do
|
|
517
|
-
assert_source "1 #{operator} 2"
|
|
545
|
+
assert_source "(1 #{operator} 2)"
|
|
518
546
|
end
|
|
519
547
|
|
|
520
548
|
context "on self #{operator}" do
|
|
521
|
-
assert_source "self #{operator} b"
|
|
549
|
+
assert_source "(self #{operator} b)"
|
|
522
550
|
end
|
|
523
551
|
|
|
524
552
|
context "on calls #{operator}" do
|
|
525
|
-
assert_source "a #{operator} b"
|
|
553
|
+
assert_source "(a #{operator} b)"
|
|
526
554
|
end
|
|
555
|
+
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
context 'nested binary operators' do
|
|
559
|
+
assert_source '(a || (b || c))'
|
|
527
560
|
end
|
|
528
561
|
end
|
|
529
562
|
|
|
530
563
|
context 'expansion of shortcuts' do
|
|
531
564
|
context 'on += operator' do
|
|
532
|
-
assert_converts 'a = a + 2', 'a += 2'
|
|
565
|
+
assert_converts 'a = (a + 2)', 'a += 2'
|
|
533
566
|
end
|
|
534
567
|
|
|
535
568
|
context 'on -= operator' do
|
|
536
|
-
assert_converts 'a = a - 2', 'a -= 2'
|
|
569
|
+
assert_converts 'a = (a - 2)', 'a -= 2'
|
|
537
570
|
end
|
|
538
571
|
|
|
539
572
|
context 'on **= operator' do
|
|
540
|
-
assert_converts 'a = a ** 2', 'a **= 2'
|
|
573
|
+
assert_converts 'a = (a ** 2)', 'a **= 2'
|
|
541
574
|
end
|
|
542
575
|
|
|
543
576
|
context 'on *= operator' do
|
|
544
|
-
assert_converts 'a = a * 2', 'a *= 2'
|
|
577
|
+
assert_converts 'a = (a * 2)', 'a *= 2'
|
|
545
578
|
end
|
|
546
579
|
|
|
547
580
|
context 'on /= operator' do
|
|
548
|
-
assert_converts 'a = a / 2', 'a /= 2'
|
|
581
|
+
assert_converts 'a = (a / 2)', 'a /= 2'
|
|
549
582
|
end
|
|
550
583
|
|
|
551
584
|
context 'on &&= operator' do
|
|
@@ -565,6 +598,18 @@ describe ToSource::Visitor,'.run' do
|
|
|
565
598
|
context 'double negation' do
|
|
566
599
|
assert_source '!!1'
|
|
567
600
|
end
|
|
601
|
+
|
|
602
|
+
context 'unary match' do
|
|
603
|
+
assert_source '~a'
|
|
604
|
+
end
|
|
605
|
+
|
|
606
|
+
context 'unary minus' do
|
|
607
|
+
assert_source '-a'
|
|
608
|
+
end
|
|
609
|
+
|
|
610
|
+
context 'unary plus' do
|
|
611
|
+
assert_source '+a'
|
|
612
|
+
end
|
|
568
613
|
end
|
|
569
614
|
|
|
570
615
|
context 'if statement' do
|
|
@@ -953,6 +998,22 @@ describe ToSource::Visitor,'.run' do
|
|
|
953
998
|
RUBY
|
|
954
999
|
end
|
|
955
1000
|
|
|
1001
|
+
context 'with optional and splat argument' do
|
|
1002
|
+
assert_source <<-RUBY
|
|
1003
|
+
def foo(baz = true, *bor)
|
|
1004
|
+
bar
|
|
1005
|
+
end
|
|
1006
|
+
RUBY
|
|
1007
|
+
end
|
|
1008
|
+
|
|
1009
|
+
context 'with optional and splat and block argument' do
|
|
1010
|
+
assert_source <<-RUBY
|
|
1011
|
+
def foo(baz = true, *bor, &block)
|
|
1012
|
+
bar
|
|
1013
|
+
end
|
|
1014
|
+
RUBY
|
|
1015
|
+
end
|
|
1016
|
+
|
|
956
1017
|
context 'with required optional and splat argument' do
|
|
957
1018
|
assert_source <<-RUBY
|
|
958
1019
|
def foo(bar, baz = true, *bor)
|
|
@@ -963,7 +1024,7 @@ describe ToSource::Visitor,'.run' do
|
|
|
963
1024
|
|
|
964
1025
|
context 'with block argument' do
|
|
965
1026
|
assert_source <<-RUBY
|
|
966
|
-
def
|
|
1027
|
+
def foo(&block)
|
|
967
1028
|
bar
|
|
968
1029
|
end
|
|
969
1030
|
RUBY
|
|
@@ -971,7 +1032,15 @@ describe ToSource::Visitor,'.run' do
|
|
|
971
1032
|
|
|
972
1033
|
context 'with required and block arguments' do
|
|
973
1034
|
assert_source <<-RUBY
|
|
974
|
-
def
|
|
1035
|
+
def foo(bar, &block)
|
|
1036
|
+
bar
|
|
1037
|
+
end
|
|
1038
|
+
RUBY
|
|
1039
|
+
end
|
|
1040
|
+
|
|
1041
|
+
context 'with spat and block arguments' do
|
|
1042
|
+
assert_source <<-RUBY
|
|
1043
|
+
def foo(*bar, &block)
|
|
975
1044
|
bar
|
|
976
1045
|
end
|
|
977
1046
|
RUBY
|
data/to_source.gemspec
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
$:.push File.expand_path('../lib', __FILE__)
|
|
3
|
-
|
|
4
|
-
require 'to_source/version'
|
|
5
|
-
|
|
6
2
|
Gem::Specification.new do |s|
|
|
7
3
|
s.name = 'to_source'
|
|
8
|
-
s.version =
|
|
4
|
+
s.version = '0.2.5'
|
|
9
5
|
s.authors = ['Josep M. Bach', 'Markus Schirp']
|
|
10
6
|
s.email = ['josep.m.bach@gmail.com', 'mbj@seonic.net']
|
|
11
7
|
s.homepage = 'http://github.com/txus/to_source'
|
|
@@ -18,5 +14,5 @@ Gem::Specification.new do |s|
|
|
|
18
14
|
s.require_paths = ['lib']
|
|
19
15
|
|
|
20
16
|
s.add_dependency('adamantium', '~> 0.0.3')
|
|
21
|
-
s.add_dependency('mutant-melbourne', '~> 2.0.
|
|
17
|
+
s.add_dependency('mutant-melbourne', '~> 2.0.3')
|
|
22
18
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: to_source
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2012-12-
|
|
13
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: adamantium
|
|
@@ -35,7 +35,7 @@ dependencies:
|
|
|
35
35
|
requirements:
|
|
36
36
|
- - ~>
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: 2.0.
|
|
38
|
+
version: 2.0.3
|
|
39
39
|
type: :runtime
|
|
40
40
|
prerelease: false
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ~>
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 2.0.
|
|
46
|
+
version: 2.0.3
|
|
47
47
|
description: Transform your Rubinius AST nodes back to source code. Reverse parsing!
|
|
48
48
|
email:
|
|
49
49
|
- josep.m.bach@gmail.com
|
|
@@ -70,7 +70,6 @@ files:
|
|
|
70
70
|
- config/site.reek
|
|
71
71
|
- config/yardstick.yml
|
|
72
72
|
- lib/to_source.rb
|
|
73
|
-
- lib/to_source/version.rb
|
|
74
73
|
- lib/to_source/visitor.rb
|
|
75
74
|
- spec/spec_helper.rb
|
|
76
75
|
- spec/unit/to_source/visitor/class_methods/run_spec.rb
|
data/lib/to_source/version.rb
DELETED