rkelly-turbo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +38 -0
  3. data/Manifest.txt +203 -0
  4. data/README.rdoc +135 -0
  5. data/Rakefile +41 -0
  6. data/lib/parser.y +883 -0
  7. data/lib/rkelly.rb +14 -0
  8. data/lib/rkelly/char_pos.rb +39 -0
  9. data/lib/rkelly/char_range.rb +33 -0
  10. data/lib/rkelly/constants.rb +3 -0
  11. data/lib/rkelly/generated_parser.rb +3380 -0
  12. data/lib/rkelly/js.rb +14 -0
  13. data/lib/rkelly/js/array.rb +15 -0
  14. data/lib/rkelly/js/base.rb +91 -0
  15. data/lib/rkelly/js/boolean.rb +21 -0
  16. data/lib/rkelly/js/function.rb +39 -0
  17. data/lib/rkelly/js/function_prototype.rb +15 -0
  18. data/lib/rkelly/js/global_object.rb +52 -0
  19. data/lib/rkelly/js/math.rb +10 -0
  20. data/lib/rkelly/js/nan.rb +18 -0
  21. data/lib/rkelly/js/number.rb +22 -0
  22. data/lib/rkelly/js/object.rb +30 -0
  23. data/lib/rkelly/js/object_prototype.rb +14 -0
  24. data/lib/rkelly/js/property.rb +20 -0
  25. data/lib/rkelly/js/scope.rb +6 -0
  26. data/lib/rkelly/js/string.rb +21 -0
  27. data/lib/rkelly/lexeme.rb +18 -0
  28. data/lib/rkelly/nodes.rb +25 -0
  29. data/lib/rkelly/nodes/binary_node.rb +18 -0
  30. data/lib/rkelly/nodes/bracket_accessor_node.rb +11 -0
  31. data/lib/rkelly/nodes/case_clause_node.rb +11 -0
  32. data/lib/rkelly/nodes/comma_node.rb +11 -0
  33. data/lib/rkelly/nodes/conditional_node.rb +11 -0
  34. data/lib/rkelly/nodes/dot_accessor_node.rb +11 -0
  35. data/lib/rkelly/nodes/for_in_node.rb +12 -0
  36. data/lib/rkelly/nodes/for_node.rb +13 -0
  37. data/lib/rkelly/nodes/function_call_node.rb +16 -0
  38. data/lib/rkelly/nodes/function_decl_node.rb +6 -0
  39. data/lib/rkelly/nodes/function_expr_node.rb +12 -0
  40. data/lib/rkelly/nodes/if_node.rb +12 -0
  41. data/lib/rkelly/nodes/label_node.rb +11 -0
  42. data/lib/rkelly/nodes/new_expr_node.rb +11 -0
  43. data/lib/rkelly/nodes/node.rb +116 -0
  44. data/lib/rkelly/nodes/not_strict_equal_node.rb +6 -0
  45. data/lib/rkelly/nodes/op_equal_node.rb +16 -0
  46. data/lib/rkelly/nodes/postfix_node.rb +11 -0
  47. data/lib/rkelly/nodes/prefix_node.rb +6 -0
  48. data/lib/rkelly/nodes/property_node.rb +13 -0
  49. data/lib/rkelly/nodes/resolve_node.rb +19 -0
  50. data/lib/rkelly/nodes/strict_equal_node.rb +6 -0
  51. data/lib/rkelly/nodes/try_node.rb +13 -0
  52. data/lib/rkelly/nodes/var_decl_node.rb +15 -0
  53. data/lib/rkelly/parser.rb +106 -0
  54. data/lib/rkelly/runtime.rb +36 -0
  55. data/lib/rkelly/runtime/ruby_function.rb +13 -0
  56. data/lib/rkelly/runtime/scope_chain.rb +57 -0
  57. data/lib/rkelly/syntax_error.rb +4 -0
  58. data/lib/rkelly/token.rb +27 -0
  59. data/lib/rkelly/tokenizer.rb +255 -0
  60. data/lib/rkelly/visitable.rb +31 -0
  61. data/lib/rkelly/visitors.rb +4 -0
  62. data/lib/rkelly/visitors/dot_visitor.rb +228 -0
  63. data/lib/rkelly/visitors/ecma_visitor.rb +328 -0
  64. data/lib/rkelly/visitors/enumerable_visitor.rb +18 -0
  65. data/lib/rkelly/visitors/evaluation_visitor.rb +419 -0
  66. data/lib/rkelly/visitors/function_visitor.rb +46 -0
  67. data/lib/rkelly/visitors/pointcut_visitor.rb +31 -0
  68. data/lib/rkelly/visitors/real_sexp_visitor.rb +16 -0
  69. data/lib/rkelly/visitors/sexp_visitor.rb +373 -0
  70. data/lib/rkelly/visitors/visitor.rb +149 -0
  71. data/test/ecma_script_test_case.rb +21 -0
  72. data/test/execute_test_case.rb +16 -0
  73. data/test/execution_contexts/test_10_1_3-1.rb +32 -0
  74. data/test/expressions/test_11_3_1.rb +64 -0
  75. data/test/expressions/test_11_3_2.rb +64 -0
  76. data/test/expressions/test_11_4_2.rb +13 -0
  77. data/test/expressions/test_11_4_3.rb +52 -0
  78. data/test/expressions/test_11_4_4.rb +68 -0
  79. data/test/expressions/test_11_4_5.rb +69 -0
  80. data/test/expressions/test_11_4_6.rb +94 -0
  81. data/test/expressions/test_11_4_8.rb +28 -0
  82. data/test/expressions/test_11_4_9.rb +103 -0
  83. data/test/expressions/test_11_5_1.rb +51 -0
  84. data/test/expressions/test_11_5_2.rb +80 -0
  85. data/test/expressions/test_11_5_3.rb +88 -0
  86. data/test/expressions/test_11_6_1-1.rb +19 -0
  87. data/test/expressions/test_11_9_1.rb +19 -0
  88. data/test/function/test_15_3_1_1-1.rb +34 -0
  89. data/test/global_object/test_15_1_1_1.rb +29 -0
  90. data/test/global_object/test_15_1_1_2.rb +17 -0
  91. data/test/global_object/test_15_1_1_3.rb +9 -0
  92. data/test/helper.rb +5 -0
  93. data/test/node_test_case.rb +11 -0
  94. data/test/object/test_15_2_1_1.rb +257 -0
  95. data/test/object/test_15_2_1_2.rb +21 -0
  96. data/test/object/test_15_2_2_1.rb +52 -0
  97. data/test/statements/test_12_5-1.rb +27 -0
  98. data/test/test_add_node.rb +8 -0
  99. data/test/test_arguments_node.rb +8 -0
  100. data/test/test_array_node.rb +9 -0
  101. data/test/test_assign_expr_node.rb +8 -0
  102. data/test/test_automatic_semicolon_insertion.rb +137 -0
  103. data/test/test_bit_and_node.rb +8 -0
  104. data/test/test_bit_or_node.rb +8 -0
  105. data/test/test_bit_x_or_node.rb +8 -0
  106. data/test/test_bitwise_not_node.rb +8 -0
  107. data/test/test_block_node.rb +14 -0
  108. data/test/test_bracket_accessor_node.rb +16 -0
  109. data/test/test_break_node.rb +11 -0
  110. data/test/test_case_block_node.rb +11 -0
  111. data/test/test_case_clause_node.rb +15 -0
  112. data/test/test_char_pos.rb +39 -0
  113. data/test/test_char_range.rb +29 -0
  114. data/test/test_comma_node.rb +13 -0
  115. data/test/test_comments.rb +45 -0
  116. data/test/test_conditional_node.rb +17 -0
  117. data/test/test_const_statement_node.rb +14 -0
  118. data/test/test_continue_node.rb +11 -0
  119. data/test/test_delete_node.rb +8 -0
  120. data/test/test_divide_node.rb +8 -0
  121. data/test/test_do_while_node.rb +13 -0
  122. data/test/test_dot_accessor_node.rb +9 -0
  123. data/test/test_ecma_visitor.rb +213 -0
  124. data/test/test_element_node.rb +8 -0
  125. data/test/test_empty_statement_node.rb +8 -0
  126. data/test/test_equal_node.rb +8 -0
  127. data/test/test_evaluation_visitor.rb +66 -0
  128. data/test/test_expression_statement_node.rb +10 -0
  129. data/test/test_false_node.rb +8 -0
  130. data/test/test_for_in_node.rb +17 -0
  131. data/test/test_for_node.rb +24 -0
  132. data/test/test_function_body_node.rb +8 -0
  133. data/test/test_function_call_node.rb +10 -0
  134. data/test/test_function_decl_node.rb +16 -0
  135. data/test/test_function_expr_node.rb +16 -0
  136. data/test/test_function_visitor.rb +26 -0
  137. data/test/test_getter_property_node.rb +10 -0
  138. data/test/test_global_object.rb +49 -0
  139. data/test/test_greater_node.rb +8 -0
  140. data/test/test_greater_or_equal_node.rb +8 -0
  141. data/test/test_if_node.rb +17 -0
  142. data/test/test_in_node.rb +8 -0
  143. data/test/test_instance_of_node.rb +8 -0
  144. data/test/test_label_node.rb +13 -0
  145. data/test/test_left_shift_node.rb +8 -0
  146. data/test/test_less_node.rb +8 -0
  147. data/test/test_less_or_equal_node.rb +8 -0
  148. data/test/test_line_number.rb +81 -0
  149. data/test/test_logical_and_node.rb +8 -0
  150. data/test/test_logical_not_node.rb +8 -0
  151. data/test/test_logical_or_node.rb +8 -0
  152. data/test/test_modulus_node.rb +8 -0
  153. data/test/test_multiply_node.rb +8 -0
  154. data/test/test_new_expr_node.rb +9 -0
  155. data/test/test_not_equal_node.rb +8 -0
  156. data/test/test_not_strict_equal_node.rb +8 -0
  157. data/test/test_null_node.rb +8 -0
  158. data/test/test_number_node.rb +8 -0
  159. data/test/test_object_literal_node.rb +9 -0
  160. data/test/test_op_and_equal_node.rb +10 -0
  161. data/test/test_op_divide_equal_node.rb +10 -0
  162. data/test/test_op_equal_node.rb +10 -0
  163. data/test/test_op_l_shift_equal_node.rb +10 -0
  164. data/test/test_op_minus_equal_node.rb +10 -0
  165. data/test/test_op_mod_equal_node.rb +10 -0
  166. data/test/test_op_multiply_equal_node.rb +10 -0
  167. data/test/test_op_or_equal_node.rb +10 -0
  168. data/test/test_op_plus_equal_node.rb +10 -0
  169. data/test/test_op_r_shift_equal_node.rb +10 -0
  170. data/test/test_op_u_r_shift_equal_node.rb +10 -0
  171. data/test/test_op_x_or_equal_node.rb +10 -0
  172. data/test/test_parameter_node.rb +8 -0
  173. data/test/test_parser.rb +1434 -0
  174. data/test/test_pointcut_visitor.rb +34 -0
  175. data/test/test_postfix_node.rb +8 -0
  176. data/test/test_prefix_node.rb +8 -0
  177. data/test/test_property_node.rb +8 -0
  178. data/test/test_regexp_node.rb +8 -0
  179. data/test/test_resolve_node.rb +22 -0
  180. data/test/test_return_node.rb +11 -0
  181. data/test/test_right_shift_node.rb +8 -0
  182. data/test/test_rkelly.rb +19 -0
  183. data/test/test_runtime.rb +12 -0
  184. data/test/test_scope_chain.rb +50 -0
  185. data/test/test_setter_property_node.rb +10 -0
  186. data/test/test_source_elements.rb +9 -0
  187. data/test/test_strict_equal_node.rb +8 -0
  188. data/test/test_string_node.rb +8 -0
  189. data/test/test_subtract_node.rb +8 -0
  190. data/test/test_switch_node.rb +12 -0
  191. data/test/test_this_node.rb +8 -0
  192. data/test/test_throw_node.rb +7 -0
  193. data/test/test_tokenizer.rb +285 -0
  194. data/test/test_true_node.rb +8 -0
  195. data/test/test_try_node.rb +59 -0
  196. data/test/test_type_of_node.rb +8 -0
  197. data/test/test_unary_minus_node.rb +8 -0
  198. data/test/test_unary_plus_node.rb +8 -0
  199. data/test/test_unsigned_right_shift_node.rb +8 -0
  200. data/test/test_var_decl_node.rb +21 -0
  201. data/test/test_var_statement_node.rb +14 -0
  202. data/test/test_void_node.rb +8 -0
  203. data/test/test_while_node.rb +15 -0
  204. data/test/test_with_node.rb +8 -0
  205. metadata +293 -0
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class NullNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = NullNode.new('null')
6
+ assert_sexp [:nil], node
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class NumberNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = NumberNode.new(10)
6
+ assert_sexp [:lit, 10], node
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ObjectLiteralNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ property = PropertyNode.new('foo', NumberNode.new(10))
6
+ node = ObjectLiteralNode.new([property])
7
+ assert_sexp([:object, [[:property, :foo, [:lit, 10]]]], node)
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpAndEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpAndEqualNode.new(resolve, number)
8
+ assert_sexp([:op_and_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpDivideEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpDivideEqualNode.new(resolve, number)
8
+ assert_sexp([:op_divide_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpEqualNode.new(resolve, number)
8
+ assert_sexp([:op_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpLShiftEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpLShiftEqualNode.new(resolve, number)
8
+ assert_sexp([:op_lshift_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpMinusEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpMinusEqualNode.new(resolve, number)
8
+ assert_sexp([:op_minus_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpModEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpModEqualNode.new(resolve, number)
8
+ assert_sexp([:op_mod_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpMultiplyEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpMultiplyEqualNode.new(resolve, number)
8
+ assert_sexp([:op_multiply_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpOrEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpOrEqualNode.new(resolve, number)
8
+ assert_sexp([:op_or_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpPlusEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpPlusEqualNode.new(resolve, number)
8
+ assert_sexp([:op_plus_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpRShiftEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpRShiftEqualNode.new(resolve, number)
8
+ assert_sexp([:op_rshift_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpURShiftEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpURShiftEqualNode.new(resolve, number)
8
+ assert_sexp([:op_urshift_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class OpXOrEqualNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ resolve = ResolveNode.new('foo')
6
+ number = NumberNode.new(10)
7
+ node = OpXOrEqualNode.new(resolve, number)
8
+ assert_sexp([:op_xor_equal, [:resolve, 'foo'], [:lit, 10]], node)
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ParameterNodeTest < NodeTestCase
4
+ def test_to_sexp
5
+ node = ParameterNode.new('a')
6
+ assert_sexp([:param, 'a'], node)
7
+ end
8
+ end
@@ -0,0 +1,1434 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class ParserTest < Test::Unit::TestCase
4
+ def setup
5
+ @parser = RKelly::Parser.new
6
+ end
7
+
8
+ def test_birthday!
9
+ assert_raises(RKelly::SyntaxError) do
10
+ RKelly::Parser.new.parse "Happy birthday, tenderlove!"
11
+ end
12
+ end
13
+
14
+ def test_array_access
15
+ assert_sexp(
16
+ [
17
+ [:var,
18
+ [[:var_decl, :a,
19
+ [:assign, [:bracket_access, [:resolve, "foo"], [:lit, 10]]],
20
+ ]]
21
+ ]
22
+ ],
23
+ @parser.parse('var a = foo[10];'))
24
+ end
25
+
26
+ def test_function_expr_anon_no_args
27
+ assert_sexp(
28
+ [[:var,
29
+ [[:var_decl, :foo, [:assign,
30
+ [:func_expr, "function", [], [:func_body, []]]
31
+ ]]]
32
+ ]],
33
+ @parser.parse("var foo = function() { }"))
34
+ end
35
+
36
+ def test_function_body_expr_anon_no_args
37
+ assert_sexp(
38
+ [[:var,
39
+ [[:var_decl, :foo, [:assign,
40
+ [:func_expr, "function", [],
41
+ [:func_body,
42
+ [[:var, [[:var_decl, :a, [:assign, [:lit, 10]]]]]]
43
+ ]
44
+ ]
45
+ ]]]
46
+ ]],
47
+ @parser.parse("var foo = function() { var a = 10; }"))
48
+ end
49
+
50
+ def test_function_expr_anon_single_arg
51
+ assert_sexp(
52
+ [[:var,
53
+ [[:var_decl, :foo, [:assign,
54
+ [:func_expr, "function", [[:param, "a"]], [:func_body, []]]
55
+ ]]]
56
+ ]],
57
+ @parser.parse("var foo = function(a) { }"))
58
+ end
59
+
60
+ def test_function_expr_anon
61
+ assert_sexp(
62
+ [[:var,
63
+ [[:var_decl, :foo, [:assign,
64
+ [:func_expr, "function", [[:param, "a"], [:param, 'b']], [:func_body, []]]
65
+ ]]]
66
+ ]],
67
+ @parser.parse("var foo = function(a,b) { }"))
68
+ end
69
+
70
+ def test_function_expr_no_args
71
+ assert_sexp(
72
+ [[:var,
73
+ [[:var_decl, :foo, [:assign,
74
+ [:func_expr, 'aaron', [], [:func_body, []]]
75
+ ]]]
76
+ ]],
77
+ @parser.parse("var foo = function aaron() { }"))
78
+ end
79
+
80
+ def test_function_expr_with_args
81
+ assert_sexp(
82
+ [[:var,
83
+ [[:var_decl, :foo, [:assign,
84
+ [:func_expr, 'aaron', [[:param, 'a'], [:param, 'b']], [:func_body, []]]
85
+ ]]]
86
+ ]],
87
+ @parser.parse("var foo = function aaron(a, b) { }"))
88
+ end
89
+
90
+ def test_labelled_statement
91
+ assert_sexp([[:label, :foo, [:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]],
92
+ @parser.parse('foo: var x = 10;'))
93
+ assert_sexp([[:label, :foo, [:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]],
94
+ @parser.parse('foo: var x = 10'))
95
+ end
96
+
97
+ def test_throw_statement
98
+ assert_sexp([[:throw, [:lit, 10]]], @parser.parse('throw 10;'))
99
+ assert_sexp([[:throw, [:lit, 10]]], @parser.parse('throw 10'))
100
+ end
101
+
102
+ def test_object_literal
103
+ assert_sexp(
104
+ [[:var,
105
+ [[:var_decl, :foo, [:assign,
106
+ [:object, [[:property, :bar, [:lit, 10]]]]
107
+ ]]]
108
+ ]],
109
+ @parser.parse('var foo = { bar: 10 }'))
110
+ assert_sexp(
111
+ [[:var,
112
+ [[:var_decl, :foo, [:assign,
113
+ [:object, []]
114
+ ]]]
115
+ ]],
116
+ @parser.parse('var foo = { }'))
117
+ assert_sexp(
118
+ [[:var,
119
+ [[:var_decl, :foo, [:assign,
120
+ [:object, [[:property, '"bar"'.to_sym, [:lit, 10]]]]
121
+ ]]]
122
+ ]],
123
+ @parser.parse('var foo = { "bar": 10 }'))
124
+ assert_sexp(
125
+ [[:var,
126
+ [[:var_decl, :foo, [:assign,
127
+ [:object, [[:property, :"5", [:lit, 10]]]]
128
+ ]]]
129
+ ]],
130
+ @parser.parse('var foo = { 5: 10 }'))
131
+ end
132
+
133
+ def test_object_literal_getter
134
+ assert_sexp(
135
+ [[:var,
136
+ [[:var_decl, :foo, [:assign,
137
+ [:object, [[:getter, :a, [:func_expr, nil, [], [:func_body, []]]]]]
138
+ ]]]
139
+ ]],
140
+ @parser.parse('var foo = { get a() { } }'))
141
+ end
142
+
143
+ def test_object_literal_setter
144
+ assert_sexp(
145
+ [[:var,
146
+ [[:var_decl, :foo, [:assign,
147
+ [:object, [[:setter, :a,
148
+ [:func_expr, nil, [[:param, 'foo']], [:func_body, []]]
149
+ ]]]
150
+ ]]]
151
+ ]],
152
+ @parser.parse('var foo = { set a(foo) { } }'))
153
+ end
154
+
155
+ def test_object_literal_multi
156
+ assert_sexp(
157
+ [[:var,
158
+ [[:var_decl, :foo, [:assign,
159
+ [:object, [
160
+ [:property, :bar, [:lit, 10]],
161
+ [:property, :baz, [:lit, 1]]
162
+ ]]
163
+ ]]]
164
+ ]],
165
+ @parser.parse('var foo = { bar: 10, baz: 1 }'))
166
+ assert_sexp(
167
+ [[:var,
168
+ [[:var_decl, :foo, [:assign,
169
+ [:object, [
170
+ [:property, :bar, [:lit, 10]],
171
+ [:property, :baz, [:lit, 1]]
172
+ ]]
173
+ ]]]
174
+ ]],
175
+ @parser.parse('var foo = { bar: 10, baz: 1, }'))
176
+ end
177
+
178
+ # ECMAScript 5.1 allows use of keywords for property names.
179
+
180
+ def test_object_literal_with_keywords_as_property_names
181
+ assert_sexp(
182
+ [[:var,
183
+ [[:var_decl, :foo, [:assign,
184
+ [:object, [[:property, :"var", [:lit, 10]]]]
185
+ ]]]
186
+ ]],
187
+ @parser.parse('var foo = { var: 10 }'))
188
+ end
189
+
190
+ def test_object_literal_with_literal_as_property_name
191
+ assert_sexp(
192
+ [[:var,
193
+ [[:var_decl, :foo, [:assign,
194
+ [:object, [[:property, :"null", [:lit, 10]]]]
195
+ ]]]
196
+ ]],
197
+ @parser.parse('var foo = { null: 10 }'))
198
+ end
199
+
200
+ def test_object_literal_with_reserved_keyword_as_property_name
201
+ assert_sexp(
202
+ [[:var,
203
+ [[:var_decl, :foo, [:assign,
204
+ [:object, [[:property, :"class", [:lit, 10]]]]
205
+ ]]]
206
+ ]],
207
+ @parser.parse('var foo = { class: 10 }'))
208
+ end
209
+
210
+ def test_object_literal_getter_with_keyword_as_getter_name
211
+ assert_sexp(
212
+ [[:var,
213
+ [[:var_decl, :foo, [:assign,
214
+ [:object, [[:getter, :if, [:func_expr, nil, [], [:func_body, []]]]]]
215
+ ]]]
216
+ ]],
217
+ @parser.parse('var foo = { get if() { } }'))
218
+ end
219
+
220
+ def test_object_literal_setter_with_keyword_as_setter_name
221
+ assert_sexp(
222
+ [[:var,
223
+ [[:var_decl, :foo, [:assign,
224
+ [:object, [[:setter, :return, [:func_expr, nil, [[:param, "v"]], [:func_body, []]]]]]
225
+ ]]]
226
+ ]],
227
+ @parser.parse('var foo = { set return(v) { } }'))
228
+ end
229
+
230
+ def test_dot_access_with_keyword
231
+ assert_sexp([[:expression,
232
+ [:dot_access,
233
+ [:resolve, "bar"],
234
+ 'var',
235
+ ]
236
+ ]],
237
+ @parser.parse('bar.var;'))
238
+ end
239
+
240
+ def test_dot_access_with_keyword_on_function_call
241
+ assert_sexp([[:expression,
242
+ [:dot_access,
243
+ [:function_call, [:resolve, "bar"], [:args, []]],
244
+ 'var',
245
+ ]
246
+ ]],
247
+ @parser.parse('bar().var;'))
248
+ end
249
+
250
+
251
+ def test_this
252
+ assert_sexp(
253
+ [[:var, [[:var_decl, :foo, [:assign, [:this]]]]]],
254
+ @parser.parse('var foo = this;')
255
+ )
256
+ end
257
+
258
+ def test_array_literal
259
+ assert_sexp(
260
+ [[:var, [[:var_decl, :foo, [:assign,
261
+ [:array, [[:element, [:lit, 1]]]]
262
+ ]]]]],
263
+ @parser.parse('var foo = [1];')
264
+ )
265
+ assert_sexp(
266
+ [[:var, [[:var_decl, :foo, [:assign,
267
+ [:array, [
268
+ nil,
269
+ nil,
270
+ [:element, [:lit, 1]]
271
+ ]]
272
+ ]]]]],
273
+ @parser.parse('var foo = [,,1];')
274
+ )
275
+ assert_sexp(
276
+ [[:var, [[:var_decl, :foo, [:assign,
277
+ [:array, [
278
+ [:element, [:lit, 1]],
279
+ nil,
280
+ nil,
281
+ [:element, [:lit, 2]]
282
+ ]]
283
+ ]]]]],
284
+ @parser.parse('var foo = [1,,,2];')
285
+ )
286
+ assert_sexp(
287
+ [[:var, [[:var_decl, :foo, [:assign,
288
+ [:array, [
289
+ [:element, [:lit, 1]],
290
+ nil,
291
+ nil,
292
+ ]]
293
+ ]]]]],
294
+ @parser.parse('var foo = [1,,,];')
295
+ )
296
+ assert_sexp(
297
+ [[:var, [[:var_decl, :foo, [:assign,
298
+ [:array, [
299
+ ]]
300
+ ]]]]],
301
+ @parser.parse('var foo = [];')
302
+ )
303
+ assert_sexp(
304
+ [[:var, [[:var_decl, :foo, [:assign,
305
+ [:array, [
306
+ nil, nil
307
+ ]]
308
+ ]]]]],
309
+ @parser.parse('var foo = [,,];')
310
+ )
311
+ end
312
+
313
+ def test_primary_expr_paren
314
+ assert_sexp(
315
+ [[:var,
316
+ [[:var_decl, :a, [:assign, [:lit, 10]]]]
317
+ ]],
318
+ @parser.parse('var a = (10);'))
319
+ end
320
+
321
+ def test_expression_statement
322
+ assert_sexp(
323
+ [[:expression, [:dot_access, [:resolve, "foo"], "bar"]]],
324
+ @parser.parse('foo.bar;')
325
+ )
326
+ assert_sexp(
327
+ [[:expression, [:dot_access, [:resolve, "foo"], "bar"]]],
328
+ @parser.parse('foo.bar')
329
+ )
330
+ end
331
+
332
+ def test_expr_comma
333
+ assert_sexp([[:expression, [:comma,
334
+ [:op_equal, [:resolve, 'i'], [:lit, 10]],
335
+ [:op_equal, [:resolve, 'j'], [:lit, 11]]]]],
336
+ @parser.parse('i = 10, j = 11;')
337
+ )
338
+ end
339
+
340
+ def test_op_plus_equal
341
+ assert_sexp([[:expression, [:op_plus_equal, [:resolve, 'i'], [:lit, 10]]]],
342
+ @parser.parse('i += 10'))
343
+ end
344
+
345
+ def test_op_minus_equal
346
+ assert_sexp([[:expression, [:op_minus_equal, [:resolve, 'i'], [:lit, 10]]]],
347
+ @parser.parse('i -= 10'))
348
+ end
349
+
350
+ def test_op_multiply_equal
351
+ assert_sexp([[:expression, [:op_multiply_equal, [:resolve, 'i'], [:lit, 10]]]],
352
+ @parser.parse('i *= 10'))
353
+ end
354
+
355
+ def test_op_divide_equal
356
+ assert_sexp([[:expression, [:op_divide_equal, [:resolve, 'i'], [:lit, 10]]]],
357
+ @parser.parse('i /= 10'))
358
+ end
359
+
360
+ def test_op_lshift_equal
361
+ assert_sexp([[:expression, [:op_lshift_equal, [:resolve, 'i'], [:lit, 10]]]],
362
+ @parser.parse('i <<= 10'))
363
+ end
364
+
365
+ def test_op_rshift_equal
366
+ assert_sexp([[:expression, [:op_rshift_equal, [:resolve, 'i'], [:lit, 10]]]],
367
+ @parser.parse('i >>= 10'))
368
+ end
369
+
370
+ def test_op_urshift_equal
371
+ assert_sexp([[:expression, [:op_urshift_equal, [:resolve, 'i'], [:lit, 10]]]],
372
+ @parser.parse('i >>>= 10'))
373
+ end
374
+
375
+ def test_op_and_equal
376
+ assert_sexp([[:expression, [:op_and_equal, [:resolve, 'i'], [:lit, 10]]]],
377
+ @parser.parse('i &= 10'))
378
+ end
379
+
380
+ def test_op_xor_equal
381
+ assert_sexp([[:expression, [:op_xor_equal, [:resolve, 'i'], [:lit, 10]]]],
382
+ @parser.parse('i ^= 10'))
383
+ end
384
+
385
+ def test_op_or_equal
386
+ assert_sexp([[:expression, [:op_or_equal, [:resolve, 'i'], [:lit, 10]]]],
387
+ @parser.parse('i |= 10'))
388
+ end
389
+
390
+ def test_op_mod_equal
391
+ assert_sexp([[:expression, [:op_mod_equal, [:resolve, 'i'], [:lit, 10]]]],
392
+ @parser.parse('i %= 10'))
393
+ end
394
+
395
+ def test_bracket_access_no_bf
396
+ assert_sexp(
397
+ [[:expression,
398
+ [:bracket_access, [:resolve, "foo"], [:lit, 10]],
399
+ ]],
400
+ @parser.parse('foo[10];'))
401
+ end
402
+
403
+ def test_new_member_expr_no_bf
404
+ assert_sexp(
405
+ [[:expression,
406
+ [:new_expr, [:resolve, "foo"], [:args, []]],
407
+ ]],
408
+ @parser.parse('new foo();'))
409
+ end
410
+
411
+ def test_resolve_function_call
412
+ assert_sexp([[:var,
413
+ [[:var_decl,
414
+ :x,
415
+ [:assign, [:function_call, [:resolve, "bar"], [:args, []]]]
416
+ ]]
417
+ ]],
418
+ @parser.parse('var x = bar();'))
419
+ assert_sexp([[:var,
420
+ [[:var_decl,
421
+ :x,
422
+ [:assign, [:function_call, [:resolve, "bar"], [:args, [[:lit, 10]]]]]
423
+ ]]
424
+ ]],
425
+ @parser.parse('var x = bar(10);'))
426
+ assert_sexp([[:var,
427
+ [[:var_decl,
428
+ :x,
429
+ [:assign, [:function_call, [:resolve, "bar"], [:args, [
430
+ [:resolve, 'a'],
431
+ [:lit, 10]
432
+ ]]]]
433
+ ]]
434
+ ]],
435
+ @parser.parse('var x = bar(a,10);'))
436
+ end
437
+
438
+ def test_function_no_bf
439
+ assert_sexp([[:expression,
440
+ [:function_call, [:resolve, "bar"], [:args, []]]
441
+ ]],
442
+ @parser.parse('bar();'))
443
+ end
444
+
445
+ def test_function_on_function_no_bf
446
+ assert_sexp([[:expression,
447
+ [:function_call,
448
+ [:function_call, [:resolve, "bar"], [:args, []]],
449
+ [:args, []]
450
+ ]
451
+ ]],
452
+ @parser.parse('bar()();'))
453
+ end
454
+
455
+ def test_bracket_on_function_no_bf
456
+ assert_sexp([[:expression,
457
+ [:bracket_access,
458
+ [:function_call, [:resolve, "bar"], [:args, []]],
459
+ [:lit, 1],
460
+ ]
461
+ ]],
462
+ @parser.parse('bar()[1];'))
463
+ end
464
+
465
+ def test_dot_on_function_no_bf
466
+ assert_sexp([[:expression,
467
+ [:dot_access,
468
+ [:function_call, [:resolve, "bar"], [:args, []]],
469
+ 'baz',
470
+ ]
471
+ ]],
472
+ @parser.parse('bar().baz;'))
473
+ end
474
+
475
+ def test_new_expr_no_bf
476
+ assert_sexp([[:expression, [:new_expr, [:resolve, 'foo'], [:args, []]]]],
477
+ @parser.parse('new foo;'))
478
+ end
479
+
480
+ def test_new_expr
481
+ assert_sexp([[:var, [[:var_decl, :a, [:assign, [:new_expr, [:resolve, 'foo'], [:args, []]]]]]]],
482
+ @parser.parse('var a = new foo;'))
483
+ end
484
+
485
+ def test_postfix_expr
486
+ assert_sexp([[:var,
487
+ [[:var_decl,
488
+ :x,
489
+ [:assign, [:postfix, [:lit, 10], '++']]]]]],
490
+ @parser.parse('var x = 10++;'))
491
+ assert_sexp([[:var,
492
+ [[:var_decl,
493
+ :x,
494
+ [:assign, [:postfix, [:lit, 10], '--']]]]]],
495
+ @parser.parse('var x = 10--;'))
496
+ end
497
+
498
+ def test_postfix_expr_no_bf
499
+ assert_sexp([[:expression,
500
+ [:postfix, [:lit, 10], '++']]],
501
+ @parser.parse('10++;'))
502
+ assert_sexp([[:expression,
503
+ [:postfix, [:lit, 10], '--']]],
504
+ @parser.parse('10--;'))
505
+ end
506
+
507
+ def test_unary_delete
508
+ assert_sexp([[:expression, [:delete, [:resolve, 'foo']]]],
509
+ @parser.parse('delete foo;'))
510
+ end
511
+
512
+ def test_unary_void
513
+ assert_sexp([[:expression, [:void, [:resolve, 'foo']]]],
514
+ @parser.parse('void foo;'))
515
+ end
516
+
517
+ def test_unary_typeof
518
+ assert_sexp([[:expression, [:typeof, [:resolve, 'foo']]]],
519
+ @parser.parse('typeof foo;'))
520
+ end
521
+
522
+ def test_unary_prefix
523
+ assert_sexp([[:expression, [:prefix, [:lit, 10], '++']]],
524
+ @parser.parse('++10;'))
525
+ assert_sexp([[:expression, [:prefix, [:lit, 10], '--']]],
526
+ @parser.parse('--10;'))
527
+ end
528
+
529
+ def test_unary_plus
530
+ assert_sexp([[:expression, [:u_plus, [:lit, 10]]]],
531
+ @parser.parse('+10;'))
532
+ end
533
+
534
+ def test_unary_minus
535
+ assert_sexp([[:expression, [:u_minus, [:lit, 10]]]],
536
+ @parser.parse('-10;'))
537
+ end
538
+
539
+ def test_unary_bitwise_not
540
+ assert_sexp([[:expression, [:bitwise_not, [:lit, 10]]]],
541
+ @parser.parse('~10;'))
542
+ end
543
+
544
+ def test_unary_logical_not
545
+ assert_sexp([[:expression, [:not, [:lit, 10]]]],
546
+ @parser.parse('!10;'))
547
+ end
548
+
549
+ def test_multiply
550
+ assert_sexp([[:var,
551
+ [[:var_decl,
552
+ :x,
553
+ [:assign, [:multiply, [:lit, 5], [:lit, 10]]]
554
+ ]]
555
+ ]],
556
+ @parser.parse('var x = 5 * 10;'))
557
+ end
558
+
559
+ def test_multiply_no_bf
560
+ assert_sexp([[:expression, [:multiply, [:lit, 5], [:lit, 10]] ]],
561
+ @parser.parse('5 * 10;'))
562
+ end
563
+
564
+ def test_divide
565
+ assert_sexp([[:var,
566
+ [[:var_decl,
567
+ :x,
568
+ [:assign, [:divide, [:lit, 5], [:lit, 10]]]
569
+ ]]
570
+ ]],
571
+ @parser.parse('var x = 5 / 10;'))
572
+ end
573
+
574
+ def test_divide_no_bf
575
+ assert_sexp([[:expression, [:divide, [:lit, 5], [:lit, 10]] ]],
576
+ @parser.parse('5 / 10;'))
577
+ end
578
+
579
+ def test_modulus
580
+ assert_sexp([[:var,
581
+ [[:var_decl,
582
+ :x,
583
+ [:assign, [:modulus, [:lit, 5], [:lit, 10]]]
584
+ ]]
585
+ ]],
586
+ @parser.parse('var x = 5 % 10;'))
587
+ end
588
+
589
+ def test_modulus_no_bf
590
+ assert_sexp([[:expression, [:modulus, [:lit, 5], [:lit, 10]] ]],
591
+ @parser.parse('5 % 10;'))
592
+ end
593
+
594
+ def test_add
595
+ assert_sexp([[:var,
596
+ [[:var_decl,
597
+ :x,
598
+ [:assign, [:add, [:lit, 5], [:lit, 10]]]
599
+ ]]
600
+ ]],
601
+ @parser.parse('var x = 5 + 10;'))
602
+ end
603
+
604
+ def test_add_no_bf
605
+ assert_sexp([[:expression, [:add, [:lit, 5], [:lit, 10]] ]],
606
+ @parser.parse('5 + 10;'))
607
+ end
608
+
609
+ def test_subtract
610
+ assert_sexp([[:var,
611
+ [[:var_decl,
612
+ :x,
613
+ [:assign, [:subtract, [:lit, 5], [:lit, 10]]]
614
+ ]]
615
+ ]],
616
+ @parser.parse('var x = 5 - 10;'))
617
+ end
618
+
619
+ def test_subtract_no_bf
620
+ assert_sexp([[:expression, [:subtract, [:lit, 5], [:lit, 10]] ]],
621
+ @parser.parse('5 - 10;'))
622
+ end
623
+
624
+ def test_lshift
625
+ assert_sexp([[:var,
626
+ [[:var_decl,
627
+ :x,
628
+ [:assign, [:lshift, [:lit, 5], [:lit, 10]]]
629
+ ]]
630
+ ]],
631
+ @parser.parse('var x = 5 << 10;'))
632
+ end
633
+
634
+ def test_lshift_no_bf
635
+ assert_sexp([[:expression, [:lshift, [:lit, 5], [:lit, 10]] ]],
636
+ @parser.parse('5 << 10;'))
637
+ end
638
+
639
+ def test_rshift
640
+ assert_sexp([[:var,
641
+ [[:var_decl,
642
+ :x,
643
+ [:assign, [:rshift, [:lit, 5], [:lit, 10]]]
644
+ ]]
645
+ ]],
646
+ @parser.parse('var x = 5 >> 10;'))
647
+ end
648
+
649
+ def test_rshift_no_bf
650
+ assert_sexp([[:expression, [:rshift, [:lit, 5], [:lit, 10]] ]],
651
+ @parser.parse('5 >> 10;'))
652
+ end
653
+
654
+ def test_urshift
655
+ assert_sexp([[:var,
656
+ [[:var_decl,
657
+ :x,
658
+ [:assign, [:urshift, [:lit, 5], [:lit, 10]]]
659
+ ]]
660
+ ]],
661
+ @parser.parse('var x = 5 >>> 10;'))
662
+ end
663
+
664
+ def test_urshift_no_bf
665
+ assert_sexp([[:expression, [:urshift, [:lit, 5], [:lit, 10]] ]],
666
+ @parser.parse('5 >>> 10;'))
667
+ end
668
+
669
+ def test_less
670
+ assert_sexp([[:var,
671
+ [[:var_decl,
672
+ :x,
673
+ [:assign, [:less, [:lit, 5], [:lit, 10]]]
674
+ ]]
675
+ ]],
676
+ @parser.parse('var x = 5 < 10;'))
677
+ end
678
+
679
+ def test_less_no_bf
680
+ assert_sexp([[:expression, [:less, [:lit, 5], [:lit, 10]] ]],
681
+ @parser.parse('5 < 10;'))
682
+ end
683
+
684
+ def test_less_no_in
685
+ assert_sexp(
686
+ for_loop_sexp([:less, [:resolve, 'foo'], [:lit, 10]]),
687
+ @parser.parse('for(foo < 10; foo < 10; foo++) { var x = 10; }')
688
+ )
689
+ end
690
+
691
+ def test_greater
692
+ assert_sexp([[:var,
693
+ [[:var_decl,
694
+ :x,
695
+ [:assign, [:greater, [:lit, 5], [:lit, 10]]]
696
+ ]]
697
+ ]],
698
+ @parser.parse('var x = 5 > 10;'))
699
+ end
700
+
701
+ def test_greater_no_bf
702
+ assert_sexp([[:expression, [:greater, [:lit, 5], [:lit, 10]] ]],
703
+ @parser.parse('5 > 10;'))
704
+ end
705
+
706
+ def test_greater_no_in
707
+ assert_sexp(
708
+ for_loop_sexp([:greater, [:resolve, 'foo'], [:lit, 10]]),
709
+ @parser.parse('for(foo > 10; foo < 10; foo++) { var x = 10; }')
710
+ )
711
+ end
712
+
713
+ def test_less_or_equal
714
+ assert_sexp([[:var,
715
+ [[:var_decl,
716
+ :x,
717
+ [:assign, [:less_or_equal, [:lit, 5], [:lit, 10]]]
718
+ ]]
719
+ ]],
720
+ @parser.parse('var x = 5 <= 10;'))
721
+ end
722
+
723
+ def test_less_or_equal_no_bf
724
+ assert_sexp([[:expression, [:less_or_equal, [:lit, 5], [:lit, 10]] ]],
725
+ @parser.parse('5 <= 10;'))
726
+ end
727
+
728
+ def test_less_or_equal_no_in
729
+ assert_sexp(
730
+ for_loop_sexp([:less_or_equal, [:resolve, 'foo'], [:lit, 10]]),
731
+ @parser.parse('for(foo <= 10; foo < 10; foo++) { var x = 10; }')
732
+ )
733
+ end
734
+
735
+ def test_greater_or_equal
736
+ assert_sexp([[:var,
737
+ [[:var_decl,
738
+ :x,
739
+ [:assign, [:greater_or_equal, [:lit, 5], [:lit, 10]]]
740
+ ]]
741
+ ]],
742
+ @parser.parse('var x = 5 >= 10;'))
743
+ end
744
+
745
+ def test_greater_or_equal_no_bf
746
+ assert_sexp([[:expression, [:greater_or_equal, [:lit, 5], [:lit, 10]] ]],
747
+ @parser.parse('5 >= 10;'))
748
+ end
749
+
750
+ def test_greater_or_equal_no_in
751
+ assert_sexp(
752
+ for_loop_sexp([:greater_or_equal, [:resolve, 'foo'], [:lit, 10]]),
753
+ @parser.parse('for(foo >= 10; foo < 10; foo++) { var x = 10; }')
754
+ )
755
+ end
756
+
757
+ def test_instance_of
758
+ assert_sexp([[:var,
759
+ [[:var_decl,
760
+ :x,
761
+ [:assign, [:instance_of, [:lit, 5], [:lit, 10]]]
762
+ ]]
763
+ ]],
764
+ @parser.parse('var x = 5 instanceof 10;'))
765
+ end
766
+
767
+ def test_instanceof_no_bf
768
+ assert_sexp([[:expression, [:instance_of, [:lit, 5], [:lit, 10]] ]],
769
+ @parser.parse('5 instanceof 10;'))
770
+ end
771
+
772
+ def test_instanceof_no_in
773
+ assert_sexp(for_loop_sexp([:instance_of, [:resolve, 'foo'], [:lit, 10]]),
774
+ @parser.parse('for(foo instanceof 10; foo < 10; foo++) { var x = 10; }'))
775
+ end
776
+
777
+ def test_equal_equal
778
+ assert_sexp([[:var,
779
+ [[:var_decl,
780
+ :x,
781
+ [:assign, [:equal, [:lit, 5], [:lit, 10]]]
782
+ ]]
783
+ ]],
784
+ @parser.parse('var x = 5 == 10;'))
785
+ end
786
+
787
+ def test_equal_equal_no_bf
788
+ assert_sexp([[:expression, [:equal, [:lit, 5], [:lit, 10]] ]],
789
+ @parser.parse('5 == 10;'))
790
+ end
791
+
792
+ def test_equal_equal_no_in
793
+ assert_sexp(
794
+ for_loop_sexp([:equal, [:resolve, 'foo'], [:lit, 10]]),
795
+ @parser.parse('for(foo == 10; foo < 10; foo++) { var x = 10; }')
796
+ )
797
+ end
798
+
799
+ def test_not_equal
800
+ assert_sexp([[:var,
801
+ [[:var_decl,
802
+ :x,
803
+ [:assign, [:not_equal, [:lit, 5], [:lit, 10]]]
804
+ ]]
805
+ ]],
806
+ @parser.parse('var x = 5 != 10;'))
807
+ end
808
+
809
+ def test_not_equal_no_bf
810
+ assert_sexp([[:expression, [:not_equal, [:lit, 5], [:lit, 10]] ]],
811
+ @parser.parse('5 != 10;'))
812
+ end
813
+
814
+ def test_not_equal_no_in
815
+ assert_sexp(
816
+ for_loop_sexp([:not_equal, [:resolve, 'foo'], [:lit, 10]]),
817
+ @parser.parse('for(foo != 10; foo < 10; foo++) { var x = 10; }')
818
+ )
819
+ end
820
+
821
+ def test_strict_equal
822
+ assert_sexp([[:var,
823
+ [[:var_decl,
824
+ :x,
825
+ [:assign, [:strict_equal, [:lit, 5], [:lit, 10]]]
826
+ ]]
827
+ ]],
828
+ @parser.parse('var x = 5 === 10;'))
829
+ end
830
+
831
+ def test_strict_equal_no_bf
832
+ assert_sexp([[:expression, [:strict_equal, [:lit, 5], [:lit, 10]] ]],
833
+ @parser.parse('5 === 10;'))
834
+ end
835
+
836
+ def test_strict_equal_no_in
837
+ assert_sexp(
838
+ for_loop_sexp([:strict_equal, [:resolve, 'foo'], [:lit, 10]]),
839
+ @parser.parse('for(foo === 10; foo < 10; foo++) { var x = 10; }')
840
+ )
841
+ end
842
+
843
+ def test_not_strict_equal
844
+ assert_sexp([[:var,
845
+ [[:var_decl,
846
+ :x,
847
+ [:assign, [:not_strict_equal, [:lit, 5], [:lit, 10]]]
848
+ ]]
849
+ ]],
850
+ @parser.parse('var x = 5 !== 10;'))
851
+ end
852
+
853
+ def test_not_strict_equal_no_bf
854
+ assert_sexp([[:expression, [:not_strict_equal, [:lit, 5], [:lit, 10]] ]],
855
+ @parser.parse('5 !== 10;'))
856
+ end
857
+
858
+ def test_not_strict_equal_no_in
859
+ assert_sexp(
860
+ for_loop_sexp([:not_strict_equal, [:resolve, 'foo'], [:lit, 10]]),
861
+ @parser.parse('for(foo !== 10; foo < 10; foo++) { var x = 10; }')
862
+ )
863
+ end
864
+
865
+ def test_bit_and
866
+ assert_sexp([[:var,
867
+ [[:var_decl,
868
+ :x,
869
+ [:assign, [:bit_and, [:lit, 5], [:lit, 10]]]
870
+ ]]
871
+ ]],
872
+ @parser.parse('var x = 5 & 10;'))
873
+ end
874
+
875
+ def test_bit_and_no_bf
876
+ assert_sexp([[:expression, [:bit_and, [:lit, 5], [:lit, 10]] ]],
877
+ @parser.parse('5 & 10;'))
878
+ end
879
+
880
+ def test_bit_and_no_in
881
+ assert_sexp(
882
+ for_loop_sexp([:bit_and, [:resolve, 'foo'], [:lit, 10]]),
883
+ @parser.parse('for(foo & 10; foo < 10; foo++) { var x = 10; }')
884
+ )
885
+ end
886
+
887
+ def test_bit_xor
888
+ assert_sexp([[:var,
889
+ [[:var_decl,
890
+ :x,
891
+ [:assign, [:bit_xor, [:lit, 5], [:lit, 10]]]
892
+ ]]
893
+ ]],
894
+ @parser.parse('var x = 5 ^ 10;'))
895
+ end
896
+
897
+ def test_bit_xor_no_bf
898
+ assert_sexp([[:expression, [:bit_xor, [:lit, 5], [:lit, 10]] ]],
899
+ @parser.parse('5 ^ 10;'))
900
+ end
901
+
902
+ def test_bit_xor_no_in
903
+ assert_sexp(
904
+ for_loop_sexp([:bit_xor, [:resolve, 'foo'], [:lit, 10]]),
905
+ @parser.parse('for(foo ^ 10; foo < 10; foo++) { var x = 10; }')
906
+ )
907
+ end
908
+
909
+ def test_bit_or
910
+ assert_sexp([[:var,
911
+ [[:var_decl,
912
+ :x,
913
+ [:assign, [:bit_or, [:lit, 5], [:lit, 10]]]
914
+ ]]
915
+ ]],
916
+ @parser.parse('var x = 5 | 10;'))
917
+ end
918
+
919
+ def test_bit_or_no_bf
920
+ assert_sexp([[:expression, [:bit_or, [:lit, 5], [:lit, 10]] ]],
921
+ @parser.parse('5 | 10;'))
922
+ end
923
+
924
+ def test_bit_or_no_in
925
+ assert_sexp(
926
+ for_loop_sexp([:bit_or, [:resolve, 'foo'], [:lit, 10]]),
927
+ @parser.parse('for(foo | 10; foo < 10; foo++) { var x = 10; }')
928
+ )
929
+ end
930
+
931
+ def test_and
932
+ assert_sexp([[:var,
933
+ [[:var_decl,
934
+ :x,
935
+ [:assign, [:and, [:lit, 5], [:lit, 10]]]
936
+ ]]
937
+ ]],
938
+ @parser.parse('var x = 5 && 10;'))
939
+ end
940
+
941
+ def test_and_no_bf
942
+ assert_sexp([[:expression, [:and, [:lit, 5], [:lit, 10]] ]],
943
+ @parser.parse('5 && 10;'))
944
+ end
945
+
946
+ def test_and_no_in
947
+ assert_sexp(
948
+ for_loop_sexp([:and, [:resolve, 'foo'], [:lit, 10]]),
949
+ @parser.parse('for(foo && 10; foo < 10; foo++) { var x = 10; }')
950
+ )
951
+ end
952
+
953
+ def test_or
954
+ assert_sexp([[:var,
955
+ [[:var_decl,
956
+ :x,
957
+ [:assign, [:or, [:lit, 5], [:lit, 10]]]
958
+ ]]
959
+ ]],
960
+ @parser.parse('var x = 5 || 10;'))
961
+ end
962
+
963
+ def test_or_no_bf
964
+ assert_sexp([[:expression, [:or, [:lit, 5], [:lit, 10]] ]],
965
+ @parser.parse('5 || 10;'))
966
+ end
967
+
968
+ def test_or_no_in
969
+ assert_sexp(
970
+ for_loop_sexp([:or, [:resolve, 'foo'], [:lit, 10]]),
971
+ @parser.parse('for(foo || 10; foo < 10; foo++) { var x = 10; }')
972
+ )
973
+ end
974
+
975
+ def test_conditional_expr
976
+ assert_sexp([
977
+ var_sexp('x', [:conditional, [:less, [:lit, 5], [:lit, 10]], [:lit, 20], [:lit, 30]])
978
+ ],
979
+ @parser.parse('var x = 5 < 10 ? 20 : 30;')
980
+ )
981
+ end
982
+
983
+ def test_conditional_expr_no_bf
984
+ assert_sexp([[:expression,
985
+ [:conditional, [:less, [:lit, 5], [:lit, 10]], [:lit, 20], [:lit, 30]]
986
+ ]],
987
+ @parser.parse('5 < 10 ? 20 : 30;')
988
+ )
989
+ end
990
+
991
+ def test_for_expr_comma
992
+ @parser.parse('for(y = 20, x = 10; foo < 10; foo++) {}')
993
+ assert_sexp(
994
+ for_loop_sexp([:comma,
995
+ [:op_equal, [:resolve, 'y'], [:lit, 20]],
996
+ [:op_equal, [:resolve, 'x'], [:lit, 10]]]
997
+ ),
998
+ @parser.parse('for(y = 20, x = 10; foo < 10; foo++) { var x = 10; }')
999
+ )
1000
+ end
1001
+
1002
+ def test_conditional_expr_no_in
1003
+ assert_sexp(
1004
+ for_loop_sexp([:conditional, [:less, [:lit, 5], [:lit, 10]], [:lit, 20], [:lit, 30]]),
1005
+ @parser.parse('for(5 < 10 ? 20 : 30; foo < 10; foo++) { var x = 10; }')
1006
+ )
1007
+ end
1008
+
1009
+ def test_block_node
1010
+ assert_sexp([[:block, []]], @parser.parse('{ }'))
1011
+ assert_sexp([[:block, [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]]]],
1012
+ @parser.parse('{ var foo = 10; }'))
1013
+
1014
+ assert_sexp([
1015
+ [:block, [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]]],
1016
+ [:var, [[:var_decl, :bax, [:assign, [:lit, 20]]]]],
1017
+ ],
1018
+ @parser.parse('{ var foo = 10 } var bax = 20;'))
1019
+ end
1020
+
1021
+ def test_if_no_else
1022
+ assert_sexp([[:if,
1023
+ [:and, [:lit, 5], [:lit, 10]],
1024
+ [:var, [[:var_decl, :foo, [:assign, [:lit, 20]]]]],
1025
+ ]], @parser.parse('if(5 && 10) var foo = 20;'))
1026
+ end
1027
+
1028
+ def test_if_else
1029
+ assert_sexp([[:if,
1030
+ [:and, [:lit, 5], [:lit, 10]],
1031
+ [:var, [[:var_decl, :foo, [:assign, [:lit, 20]]]]],
1032
+ [:var, [[:var_decl, :bar, [:assign, [:lit, 5]]]]],
1033
+ ]], @parser.parse(' if(5 && 10) var foo = 20; else var bar = 5; '))
1034
+ end
1035
+
1036
+ def test_if_comma
1037
+ assert_sexp(
1038
+ [[:if,
1039
+ [:comma,
1040
+ [:op_equal, [:resolve, "i"], [:lit, 10]],
1041
+ [:op_equal, [:resolve, "j"], [:lit, 11]]],
1042
+ [:block, []]]],
1043
+ @parser.parse('if(i = 10, j = 11) { }')
1044
+ )
1045
+ end
1046
+
1047
+ def test_in
1048
+ assert_sexp([[:var,
1049
+ [[:var_decl, :x, [:assign,
1050
+ [:in, [:lit, 0], [:resolve, "foo"]]
1051
+ ]]]
1052
+ ]],
1053
+ @parser.parse('var x = 0 in foo;'))
1054
+ end
1055
+
1056
+ def test_in_no_bf
1057
+ assert_sexp([[:expression, [:in, [:lit, 0], [:resolve, "foo"]]]],
1058
+ @parser.parse('0 in foo;'))
1059
+ end
1060
+
1061
+ def test_do_while
1062
+ assert_sexp([[:do_while, [:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]],
1063
+ [:true]]],
1064
+ @parser.parse('do var x = 10; while(true);'))
1065
+ assert_sexp([[:do_while, [:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]],
1066
+ [:true]]],
1067
+ @parser.parse('do var x = 10; while(true)'))
1068
+ end
1069
+
1070
+ def test_while
1071
+ assert_sexp([[:while,
1072
+ [:true],
1073
+ [:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]],
1074
+ ]],
1075
+ @parser.parse('while(true) var x = 10;'))
1076
+ end
1077
+
1078
+ def test_for_with_semi
1079
+ assert_sexp([[:for, nil, nil, nil,
1080
+ [:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]],
1081
+ ]], @parser.parse('for( ; ; ) var x = 10;'))
1082
+
1083
+ assert_sexp([[:for,
1084
+ [:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]],
1085
+ [:less, [:resolve, 'foo'], [:lit, 10]],
1086
+ [:postfix, [:resolve, 'foo'], '++'],
1087
+ [:block, [[:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]]]
1088
+ ], @parser.parse('for(var foo = 10; foo < 10; foo++) { var x = 10; }'))
1089
+ assert_sexp([[:for,
1090
+ [:op_equal, [:resolve, 'foo'], [:lit, 10]],
1091
+ [:less, [:resolve, 'foo'], [:lit, 10]],
1092
+ [:postfix, [:resolve, 'foo'], '++'],
1093
+ [:block, [[:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]]]
1094
+ ], @parser.parse('for(foo = 10; foo < 10; foo++) { var x = 10; }'))
1095
+
1096
+ assert_sexp(for_loop_sexp([:var, [[:var_decl, :x, [:assign, [:lit, 10]]],
1097
+ [:var_decl, :y, [:assign, [:lit, 20]]]]]),
1098
+ @parser.parse('for(var x = 10, y = 20; foo < 10; foo++) { var x = 10; }'))
1099
+
1100
+ assert_sexp(for_loop_sexp([:var, [[:var_decl, :foo, nil]]]),
1101
+ @parser.parse('for(var foo; foo < 10; foo++) { var x = 10; }'))
1102
+ end
1103
+
1104
+ def test_for_expr_in_expr
1105
+ assert_sexp(
1106
+ for_in_sexp([:resolve, 'foo'], [:resolve, 'bar']),
1107
+ @parser.parse('for(foo in bar) { var x = 10; }')
1108
+ )
1109
+ end
1110
+
1111
+ def test_for_var_ident_in_expr
1112
+ assert_sexp(
1113
+ for_in_sexp([:var_decl, :foo, nil], [:resolve, 'bar']),
1114
+ @parser.parse('for(var foo in bar) { var x = 10; }')
1115
+ )
1116
+ end
1117
+
1118
+ def test_for_var_ident_init_in_expr
1119
+ assert_sexp(
1120
+ for_in_sexp([:var_decl, :foo, [:assign,[:lit, 10]]], [:resolve, 'bar']),
1121
+ @parser.parse('for(var foo = 10 in bar) { var x = 10; }')
1122
+ )
1123
+ end
1124
+
1125
+ def test_try_finally
1126
+ assert_sexp([[ :try,
1127
+ [:block,
1128
+ [[:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]
1129
+ ],
1130
+ nil,
1131
+ nil,
1132
+ [:block,
1133
+ [[:var, [[:var_decl, :x, [:assign, [:lit, 20]]]]]]
1134
+ ]
1135
+ ]],
1136
+ @parser.parse('try { var x = 10; } finally { var x = 20; }'))
1137
+ end
1138
+
1139
+ def test_try_catch
1140
+ assert_sexp([[ :try,
1141
+ [:block,
1142
+ [[:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]
1143
+ ],
1144
+ 'a',
1145
+ [:block,
1146
+ [[:var, [[:var_decl, :x, [:assign, [:lit, 20]]]]]]
1147
+ ],
1148
+ nil,
1149
+ ]],
1150
+ @parser.parse('try { var x = 10; } catch(a) { var x = 20; }'))
1151
+ end
1152
+
1153
+ def test_try_catch_finally
1154
+ assert_sexp([[ :try,
1155
+ [:block,
1156
+ [[:var, [[:var_decl, :baz, [:assign, [:lit, 69]]]]]]
1157
+ ],
1158
+ 'a',
1159
+ [:block,
1160
+ [[:var, [[:var_decl, :bar, [:assign, [:lit, 20]]]]]]
1161
+ ],
1162
+ [:block,
1163
+ [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]]
1164
+ ]
1165
+ ]],
1166
+ @parser.parse('try { var baz = 69; } catch(a) { var bar = 20; } finally { var foo = 10; }'))
1167
+ end
1168
+
1169
+ def test_with
1170
+ assert_sexp([[:with, [:resolve, 'o'], [:expression, [:resolve, 'x']]]],
1171
+ @parser.parse('with (o) x;')
1172
+ )
1173
+ end
1174
+
1175
+ def test_switch_no_case
1176
+ assert_sexp([[:switch, [:resolve, 'o'], [:case_block, []]]],
1177
+ @parser.parse('switch(o) { }')
1178
+ )
1179
+ end
1180
+
1181
+ def test_switch_case_no_statement
1182
+ assert_sexp([[:switch, [:resolve, 'o'], [:case_block, [[:case, [:resolve, 'j'], []]]]]],
1183
+ @parser.parse('switch(o) { case j: }')
1184
+ )
1185
+ end
1186
+
1187
+ def test_switch_case
1188
+ assert_sexp([[:switch, [:resolve, 'o'],
1189
+ [:case_block,
1190
+ [[:case, [:resolve, 'j'], [[:expression, [:resolve, 'foo']]]]]
1191
+ ]
1192
+ ]],
1193
+ @parser.parse('switch(o) { case j: foo; }')
1194
+ )
1195
+ end
1196
+
1197
+ def test_switch_case_case
1198
+ assert_sexp([[:switch, [:resolve, 'o'],
1199
+ [:case_block,[
1200
+ [:case, [:resolve, 'j'], [[:expression, [:resolve, 'foo']]]],
1201
+ [:case, [:resolve, 'k'], [[:expression, [:resolve, 'bar']]]],
1202
+ ]]
1203
+ ]],
1204
+ @parser.parse('switch(o) { case j: foo; case k: bar; }')
1205
+ )
1206
+ end
1207
+
1208
+ def test_switch_default
1209
+ assert_sexp([[:switch, [:resolve, 'o'],
1210
+ [:case_block,[
1211
+ [:case, nil, [[:expression, [:resolve, 'bar']]]],
1212
+ ]]
1213
+ ]],
1214
+ @parser.parse('switch(o) { default: bar; }')
1215
+ )
1216
+ end
1217
+
1218
+ def test_switch_default_no_expr
1219
+ assert_sexp([[:switch, [:resolve, 'o'],
1220
+ [:case_block,[
1221
+ [:case, nil, []],
1222
+ ]]
1223
+ ]],
1224
+ @parser.parse('switch(o) { default: }')
1225
+ )
1226
+ end
1227
+
1228
+ def test_function_call_on_function
1229
+ assert_sexp([[:var,
1230
+ [[:var_decl,
1231
+ :x,
1232
+ [:assign, [:function_call,
1233
+ [:function_call, [:resolve, "bar"], [:args, []]],
1234
+ [:args, []]]]
1235
+ ]]
1236
+ ]],
1237
+ @parser.parse('var x = bar()();'))
1238
+ end
1239
+
1240
+ def test_bracket_on_function
1241
+ assert_sexp([[:var,
1242
+ [[:var_decl,
1243
+ :x,
1244
+ [:assign, [:bracket_access,
1245
+ [:function_call, [:resolve, "bar"], [:args, []]],
1246
+ [:lit, 1]
1247
+ ]]
1248
+ ]]
1249
+ ]],
1250
+ @parser.parse('var x = bar()[1];'))
1251
+ end
1252
+
1253
+ def test_dot_on_function
1254
+ assert_sexp([[:var,
1255
+ [[:var_decl,
1256
+ :x,
1257
+ [:assign, [:dot_access,
1258
+ [:function_call, [:resolve, "bar"], [:args, []]],
1259
+ 'baz'
1260
+ ]]
1261
+ ]]
1262
+ ]],
1263
+ @parser.parse('var x = bar().baz;'))
1264
+ end
1265
+
1266
+ def test_dot_access
1267
+ assert_sexp(
1268
+ [[:var,
1269
+ [[:var_decl, :a, [:assign, [:dot_access, [:resolve, "foo"], "bar"]]]]
1270
+ ]],
1271
+ @parser.parse('var a = foo.bar;'))
1272
+ end
1273
+
1274
+ def test_new_member_expr
1275
+ assert_sexp(
1276
+ [[:var,
1277
+ [[:var_decl, :a,
1278
+ [:assign, [:new_expr, [:resolve, "foo"], [:args, []]]]
1279
+ ]]
1280
+ ]],
1281
+ @parser.parse('var a = new foo();'))
1282
+ end
1283
+
1284
+ def test_empty_statement
1285
+ assert_sexp(
1286
+ [
1287
+ [:const, [[:const_decl, :foo, [:assign, [:lit, 10]]]]],
1288
+ [:empty]
1289
+ ],
1290
+ @parser.parse('const foo = 10; ;')
1291
+ )
1292
+ end
1293
+
1294
+ def test_debugger_statement
1295
+ assert_sexp(
1296
+ [ [:empty] ],
1297
+ @parser.parse('debugger;')
1298
+ )
1299
+ assert_sexp(
1300
+ [ [:empty] ],
1301
+ @parser.parse('debugger')
1302
+ )
1303
+ end
1304
+
1305
+ def test_function_decl
1306
+ assert_sexp([[:func_decl, 'foo', [], [:func_body, []]]],
1307
+ @parser.parse('function foo() { }'))
1308
+ end
1309
+
1310
+ def test_function_decl_params
1311
+ assert_sexp([[:func_decl, 'foo', [[:param, 'a']], [:func_body, []]]],
1312
+ @parser.parse('function foo(a) { }'))
1313
+ end
1314
+
1315
+ def test_const_statement
1316
+ assert_sexp(
1317
+ [[:const, [[:const_decl, :foo, [:assign, [:lit, 10]]]]]],
1318
+ @parser.parse('const foo = 10;')
1319
+ )
1320
+ end
1321
+
1322
+ def test_const_decl_list
1323
+ assert_sexp(
1324
+ [[:const,
1325
+ [
1326
+ [:const_decl, :foo, [:assign, [:lit, 10]]],
1327
+ [:const_decl, :bar, [:assign, [:lit, 1]]],
1328
+ ]]],
1329
+ @parser.parse('const foo = 10, bar = 1;')
1330
+ )
1331
+ end
1332
+
1333
+ def test_const_decl_no_init
1334
+ assert_sexp(
1335
+ [[:const, [[:const_decl, :foo, nil]]]],
1336
+ @parser.parse('const foo;')
1337
+ )
1338
+ end
1339
+
1340
+ def test_const_statement_error
1341
+ assert_sexp(
1342
+ [[:const, [[:const_decl, :foo, [:assign, [:lit, 10]]]]]],
1343
+ @parser.parse('const foo = 10')
1344
+ )
1345
+ end
1346
+
1347
+ def test_variable_statement
1348
+ assert_sexp(
1349
+ [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]],
1350
+ @parser.parse('var foo = 10;')
1351
+ )
1352
+ end
1353
+
1354
+ def test_variable_declaration_no_init
1355
+ assert_sexp(
1356
+ [[:var, [[:var_decl, :foo, nil]]]],
1357
+ @parser.parse('var foo;')
1358
+ )
1359
+ end
1360
+
1361
+ def test_variable_declaration_nil_init
1362
+ assert_sexp(
1363
+ [[:var, [[:var_decl, :foo, [:assign, [:nil]]]]]],
1364
+ @parser.parse('var foo = null;')
1365
+ )
1366
+ end
1367
+
1368
+ def test_variable_statement_no_semi
1369
+ assert_sexp(
1370
+ [[:var, [[:var_decl, :foo, [:assign, [:lit, 10]]]]]],
1371
+ @parser.parse('var foo = 10')
1372
+ )
1373
+ end
1374
+
1375
+ def test_return_statement
1376
+ assert_sexp(
1377
+ [[:return]],
1378
+ @parser.parse('return;')
1379
+ )
1380
+ assert_sexp(
1381
+ [[:return]],
1382
+ @parser.parse('return')
1383
+ )
1384
+ assert_sexp(
1385
+ [[:return, [:lit, 10]]],
1386
+ @parser.parse('return 10;')
1387
+ )
1388
+ assert_sexp(
1389
+ [[:return, [:lit, 10]]],
1390
+ @parser.parse('return 10')
1391
+ )
1392
+ end
1393
+
1394
+ def test_break_statement
1395
+ assert_sexp([[:break]], @parser.parse('break;'))
1396
+ assert_sexp([[:break]], @parser.parse('break'))
1397
+ assert_sexp([[:break, 'foo']], @parser.parse('break foo;'))
1398
+ assert_sexp([[:break, 'foo']], @parser.parse('break foo'))
1399
+ end
1400
+
1401
+ def test_continue_statement
1402
+ assert_sexp([[:continue]], @parser.parse('continue;'))
1403
+ assert_sexp([[:continue]], @parser.parse('continue'))
1404
+ assert_sexp([[:continue, 'foo']], @parser.parse('continue foo;'))
1405
+ assert_sexp([[:continue, 'foo']], @parser.parse('continue foo'))
1406
+ end
1407
+
1408
+ def test_variable_declaration_list
1409
+ assert_sexp(
1410
+ [[:var,
1411
+ [
1412
+ [:var_decl, :foo, [:assign, [:lit, 10]]],
1413
+ [:var_decl, :bar, [:assign, [:lit, 1]]],
1414
+ ]]],
1415
+ @parser.parse('var foo = 10, bar = 1;')
1416
+ )
1417
+ end
1418
+
1419
+ def assert_sexp(expected, node)
1420
+ assert_equal(expected, node.to_sexp)
1421
+ end
1422
+
1423
+ def var_sexp(variable_name, val = [:lit, 10])
1424
+ [:var, [[:var_decl, variable_name.to_sym, [:assign, val]]]]
1425
+ end
1426
+
1427
+ def for_in_sexp(variable, list)
1428
+ [[:for_in, variable, list, [:block, [[:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]]]]
1429
+ end
1430
+
1431
+ def for_loop_sexp(init, test = [:less, [:resolve, 'foo'], [:lit, 10]], exec = [:postfix, [:resolve, 'foo'], '++'])
1432
+ [[:for, init, test, exec, [:block, [[:var, [[:var_decl, :x, [:assign, [:lit, 10]]]]]]]]]
1433
+ end
1434
+ end