minjs 0.1.7 → 0.1.10

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.
@@ -56,6 +56,10 @@ module Minjs
56
56
 
57
57
  self
58
58
  end
59
+
60
+ def ==(obj)
61
+ self.class == obj.class and self.val == obj.val and self.val2 == obj.val2
62
+ end
59
63
  end
60
64
 
61
65
  module UnaryOperation
@@ -73,6 +77,10 @@ module Minjs
73
77
 
74
78
  self
75
79
  end
80
+
81
+ def ==(obj)
82
+ self.class == obj.class and self.val == obj.val
83
+ end
76
84
  end
77
85
 
78
86
  module AssignmentOperation
@@ -85,6 +93,7 @@ module Minjs
85
93
  end
86
94
  self
87
95
  end
96
+
88
97
  def add_paren
89
98
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
90
99
  @val = ExpParen.new(@val)
@@ -94,6 +103,18 @@ module Minjs
94
103
  end
95
104
  self
96
105
  end
106
+
107
+ def ==(obj)
108
+ self.class == obj.class and self.val == obj.val and self.val2 == obj.val2
109
+ end
110
+
111
+ def ecma262_typeof
112
+ if @val2.respond_to? :ecma262_typeof
113
+ @val2.ecma262_typeof
114
+ else
115
+ nil
116
+ end
117
+ end
97
118
  end
98
119
 
99
120
  class ExpArg1 < Exp
@@ -108,7 +129,7 @@ module Minjs
108
129
  end
109
130
 
110
131
  def replace(from, to)
111
- if @val == from
132
+ if @val .eql? from
112
133
  @val = to
113
134
  end
114
135
  end
@@ -121,12 +142,6 @@ module Minjs
121
142
  def to_js(options = {})
122
143
  concat options, sym, @val
123
144
  end
124
-
125
- # def reduce(parent)
126
- # if @val.kind_of?(Literal) and !@val.kind_of? IdentifierName
127
- # #TODO
128
- # end
129
- # end
130
145
  end
131
146
 
132
147
  class ExpArg2 < Exp
@@ -142,9 +157,9 @@ module Minjs
142
157
  end
143
158
 
144
159
  def replace(from, to)
145
- if @val == from
160
+ if @val .eql? from
146
161
  @val = to
147
- elsif @val2 == from
162
+ elsif @val2 .eql? from
148
163
  @val2 = to
149
164
  end
150
165
  end
@@ -158,12 +173,6 @@ module Minjs
158
173
  def to_js(options = {})
159
174
  concat options, @val, sym, @val2
160
175
  end
161
-
162
- # def reduce(parent)
163
- # if @val.kind_of?(Literal) and !@val.kind_of? IdentifierName
164
- # #TODO
165
- # end
166
- # end
167
176
  end
168
177
 
169
178
  #
@@ -185,7 +194,7 @@ module Minjs
185
194
  end
186
195
 
187
196
  def replace(from, to)
188
- if @val == from
197
+ if @val .eql? from
189
198
  @val = to
190
199
  end
191
200
  end
@@ -195,6 +204,10 @@ module Minjs
195
204
  yield self, parent
196
205
  end
197
206
 
207
+ def ==(obj)
208
+ self.class == obj.class and @val == obj.val
209
+ end
210
+
198
211
  def to_js(options = {})
199
212
  "(#{@val.to_js(options)})"
200
213
  end
@@ -218,6 +231,14 @@ module Minjs
218
231
  def add_paren
219
232
  self
220
233
  end
234
+
235
+ def ecma262_typeof
236
+ if @val.respond_to? :ecma262_typeof
237
+ @val.ecma262_typeof
238
+ else
239
+ nil
240
+ end
241
+ end
221
242
  end
222
243
  #
223
244
  # 11.2 Left-Hand-Side Expressions
@@ -237,6 +258,12 @@ module Minjs
237
258
  yield self, parent
238
259
  end
239
260
 
261
+ def ==(obj)
262
+ self.class == obj.class and
263
+ @val == obj.val and
264
+ @val2 == obj.val2
265
+ end
266
+
240
267
  def to_js(options = {})
241
268
  "#{@val.to_js(options)}[#{@val2.to_js(options)}]"
242
269
  end
@@ -281,6 +308,12 @@ module Minjs
281
308
  yield self, parent
282
309
  end
283
310
 
311
+ def ==(obj)
312
+ self.class == obj.class and
313
+ @val == obj.val and
314
+ @val2 == obj.val2
315
+ end
316
+
284
317
  def to_js(options = {})
285
318
  "#{@val.to_js(options)}.#{@val2.val}"
286
319
  end
@@ -294,7 +327,7 @@ module Minjs
294
327
 
295
328
  def add_paren
296
329
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
297
- @val = ExpPare.new(@val)
330
+ @val = ExpParen.new(@val)
298
331
  end
299
332
  self
300
333
  end
@@ -316,13 +349,14 @@ module Minjs
316
349
  end
317
350
 
318
351
  def deep_dup
319
- self.class.new(@name.deep_dup, @args.collect{|x| x.deep_dup})
352
+ self.class.new(@name.deep_dup,
353
+ @args ? @args.collect{|x| x.deep_dup} : nil)
320
354
  end
321
355
 
322
356
  def replace(from, to)
323
357
  @args.each_index do |i|
324
358
  arg = @args[i]
325
- if arg == from
359
+ if arg .eql? from
326
360
  @args[i] = to
327
361
  break
328
362
  end
@@ -337,6 +371,10 @@ module Minjs
337
371
  yield self, parent
338
372
  end
339
373
 
374
+ def ==(obj)
375
+ self.class == obj.class and @name == obj.name and @args == obj.args
376
+ end
377
+
340
378
  def to_js(options = {})
341
379
  args = @args.collect{|x| x.to_js(options)}.join(",")
342
380
  "#{@name.to_js(options)}(#{args})"
@@ -381,22 +419,24 @@ module Minjs
381
419
  # new M(a,b,c...)
382
420
  #
383
421
  class ExpNew < Exp
422
+ attr_reader :name, :args
423
+
384
424
  def initialize(name, args)
385
425
  @name = name
386
426
  @args = args
387
427
  end
388
428
 
389
429
  def priority
390
- PRIORITY_LEFT_HAND_SIDE
430
+ PRIORITY_LEFT_HAND_SIDE + ((args && args.length == 0) ? 1 : 0)
391
431
  end
392
432
 
393
433
  def deep_dup
394
434
  self.class.new(@name,
395
- @args.collect{|x| x.deep_dup})
435
+ @args ? @args.collect{|x| x.deep_dup} : nil)
396
436
  end
397
437
 
398
438
  def replace(from, to)
399
- if @name == from
439
+ if @name .eql? from
400
440
  @name = from
401
441
  elsif @args and (idx = @args.index(from))
402
442
  @args[idx] = to
@@ -413,8 +453,12 @@ module Minjs
413
453
  yield self, parent
414
454
  end
415
455
 
456
+ def ==(obj)
457
+ self.class == obj.class and @name == obj.name and @args == obj.args
458
+ end
459
+
416
460
  def to_js(options = {})
417
- if @args
461
+ if @args and @args.length > 0
418
462
  args = @args.collect{|x| x.to_js(options)}.join(",")
419
463
  concat options, :new, @name, '(', args, ')'
420
464
  else
@@ -538,6 +582,10 @@ module Minjs
538
582
  def priority
539
583
  PRIORITY_UNARY
540
584
  end
585
+
586
+ def ecma262_typeof
587
+ :number
588
+ end
541
589
  end
542
590
  class ExpPreDec < ExpArg1
543
591
  include UnaryOperation
@@ -548,6 +596,10 @@ module Minjs
548
596
  def priority
549
597
  PRIORITY_UNARY
550
598
  end
599
+
600
+ def ecma262_typeof
601
+ :number
602
+ end
551
603
  end
552
604
  class ExpPositive < ExpArg1
553
605
  include UnaryOperation
@@ -703,6 +755,10 @@ module Minjs
703
755
  end
704
756
  =end
705
757
  end
758
+
759
+ def ecma262_typeof
760
+ :number
761
+ end
706
762
  end
707
763
 
708
764
  #
@@ -726,9 +782,14 @@ module Minjs
726
782
  def sym
727
783
  "%"
728
784
  end
785
+
729
786
  def priority
730
787
  PRIORITY_MULTIPLICATIVE
731
788
  end
789
+
790
+ def ecma262_typeof
791
+ :number
792
+ end
732
793
  end
733
794
 
734
795
  #
@@ -763,31 +824,7 @@ module Minjs
763
824
  if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.integer? and @val2.integer?
764
825
  parent.replace(self, ECMA262Numeric.new(@val.to_num + @val2.to_num))
765
826
  end
766
- =begin
767
- if @val2.kind_of? ECMA262Numeric and @val2.integer?
768
- # ((a + N) + M) or ((N + a) + M)
769
- if @val.kind_of? ExpAdd
770
- if @val.val2.kind_of? ECMA262Numeric and @val.val2.integer?
771
- @val2 = ECMA262Numeric.new(@val.val2.to_num + @val2.to_num)
772
- @val = @val.val
773
- elsif @val.val.kind_of? ECMA262Numeric and @val.val.integer?
774
- @val2 = ECMA262Numeric.new(@val.val.to_num + @val2.to_num)
775
- @val = @val.val2
776
- end
777
- # ((a - N) + M) or ((N - a) + M)
778
- elsif @val.kind_of? ExpSub
779
- if @val.val2.kind_of? ECMA262Numeric and @val.val2.integer?
780
- @val2 = ECMA262Numeric.new(-(@val.val2.to_num - @val2.to_num))
781
- @val = @val.val
782
- elsif @val.val.kind_of? ECMA262Numeric and @val.val.integer?
783
- @val2 = ECMA262Numeric.new(-(@val.val.to_num - @val2.to_num))
784
- @val = @val.val2
785
- end
786
- end
787
- end
788
- =end
789
827
  end
790
-
791
828
  end
792
829
  #
793
830
  # 11.6.2 The Subtraction Operator ( - )
@@ -816,31 +853,11 @@ module Minjs
816
853
  if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.integer? and @val2.integer?
817
854
  parent.replace(self, ECMA262Numeric.new(@val.to_num - @val2.to_num))
818
855
  end
819
- =begin
820
- if @val2.kind_of? ECMA262Numeric and @val2.integer?
821
- # ((a - N) - M) or ((N - a) - M)
822
- if @val.kind_of? ExpSub
823
- if @val.val2.kind_of? ECMA262Numeric and @val.val2.integer?
824
- @val2 = ECMA262Numeric.new(@val.val2.to_num + @val2.to_num)
825
- @val = @val.val
826
- elsif @val.val.kind_of? ECMA262Numeric and @val.val.integer?
827
- @val2 = ECMA262Numeric.new(@val.val.to_num + @val2.to_num)
828
- @val = @val.val2
829
- end
830
- # ((a + N) - M) or ((N + a) - M)
831
- elsif @val.kind_of? ExpAdd
832
- if @val.val2.kind_of? ECMA262Numeric and @val.val2.integer?
833
- @val2 = ECMA262Numeric.new(-(@val.val2.to_num - @val2.to_num))
834
- @val = @val.val
835
- elsif @val.val.kind_of? ECMA262Numeric and @val.val.integer?
836
- @val2 = ECMA262Numeric.new(-(@val.val.to_num - @val2.to_num))
837
- @val = @val.val2
838
- end
839
- end
840
- end
841
- =end
842
856
  end
843
857
 
858
+ def ecma262_typeof
859
+ :number
860
+ end
844
861
  end
845
862
 
846
863
  #
@@ -851,9 +868,14 @@ module Minjs
851
868
  def sym
852
869
  "<<"
853
870
  end
871
+
854
872
  def priority
855
873
  PRIORITY_SHIFT
856
874
  end
875
+
876
+ def ecma262_typeof
877
+ :number
878
+ end
857
879
  end
858
880
  #
859
881
  # 11.7.2 The Signed Right Shift Operator ( >> )
@@ -863,9 +885,14 @@ module Minjs
863
885
  def sym
864
886
  ">>"
865
887
  end
888
+
866
889
  def priority
867
890
  PRIORITY_SHIFT
868
891
  end
892
+
893
+ def ecma262_typeof
894
+ :number
895
+ end
869
896
  end
870
897
  #
871
898
  # 11.7.3 The Unsigned Right Shift Operator ( >>> )
@@ -875,9 +902,14 @@ module Minjs
875
902
  def sym
876
903
  ">>>"
877
904
  end
905
+
878
906
  def priority
879
907
  PRIORITY_SHIFT
880
908
  end
909
+
910
+ def ecma262_typeof
911
+ :number
912
+ end
881
913
  end
882
914
  #
883
915
  # 11.8.1 The Less-than Operator ( < )
@@ -887,9 +919,14 @@ module Minjs
887
919
  def sym
888
920
  "<"
889
921
  end
922
+
890
923
  def priority
891
924
  PRIORITY_RELATIONAL
892
925
  end
926
+
927
+ def ecma262_typeof
928
+ :boolean
929
+ end
893
930
  end
894
931
 
895
932
  #
@@ -900,9 +937,14 @@ module Minjs
900
937
  def sym
901
938
  ">"
902
939
  end
940
+
903
941
  def priority
904
942
  PRIORITY_RELATIONAL
905
943
  end
944
+
945
+ def ecma262_typeof
946
+ :boolean
947
+ end
906
948
  end
907
949
  #
908
950
  # 11.8.3 The Less-than-or-equal Operator ( <= )
@@ -912,9 +954,14 @@ module Minjs
912
954
  def sym
913
955
  "<="
914
956
  end
957
+
915
958
  def priority
916
959
  PRIORITY_RELATIONAL
917
960
  end
961
+
962
+ def ecma262_typeof
963
+ :boolean
964
+ end
918
965
  end
919
966
  #
920
967
  # 11.8.4 The Greater-than-or-equal Operator ( >= )
@@ -924,9 +971,14 @@ module Minjs
924
971
  def sym
925
972
  ">="
926
973
  end
974
+
927
975
  def priority
928
976
  PRIORITY_RELATIONAL
929
977
  end
978
+
979
+ def ecma262_typeof
980
+ :boolean
981
+ end
930
982
  end
931
983
  #
932
984
  # 11.8.6 The instanceof operator
@@ -936,9 +988,14 @@ module Minjs
936
988
  def sym
937
989
  "instanceof"
938
990
  end
991
+
939
992
  def priority
940
993
  PRIORITY_RELATIONAL
941
994
  end
995
+
996
+ def ecma262_typeof
997
+ :boolean
998
+ end
942
999
  end
943
1000
  #
944
1001
  # 11.8.7 The in operator
@@ -948,9 +1005,14 @@ module Minjs
948
1005
  def sym
949
1006
  "in"
950
1007
  end
1008
+
951
1009
  def priority
952
1010
  PRIORITY_RELATIONAL
953
1011
  end
1012
+
1013
+ def ecma262_typeof
1014
+ :boolean
1015
+ end
954
1016
  end
955
1017
  #
956
1018
  # 11.9.1 The Equals Operator ( == )
@@ -960,9 +1022,14 @@ module Minjs
960
1022
  def sym
961
1023
  "=="
962
1024
  end
1025
+
963
1026
  def priority
964
1027
  PRIORITY_EQUALITY
965
1028
  end
1029
+
1030
+ def ecma262_typeof
1031
+ :boolean
1032
+ end
966
1033
  end
967
1034
  #
968
1035
  # 11.9.2 The Does-not-equals Operator ( != )
@@ -972,9 +1039,14 @@ module Minjs
972
1039
  def sym
973
1040
  "!="
974
1041
  end
1042
+
975
1043
  def priority
976
1044
  PRIORITY_EQUALITY
977
1045
  end
1046
+
1047
+ def ecma262_typeof
1048
+ :boolean
1049
+ end
978
1050
  end
979
1051
  #
980
1052
  # 11.9.4 The Strict Equals Operator ( === )
@@ -991,10 +1063,14 @@ module Minjs
991
1063
 
992
1064
  def reduce(parent)
993
1065
  if @val.respond_to?(:ecma262_typeof) and @val2.respond_to?(:ecma262_typeof) and
994
- @val.ecma262_typeof == @val2.ecma262_typeof
1066
+ (t = @val.ecma262_typeof) == @val2.ecma262_typeof and !t.nil?
995
1067
  parent.replace(self, ExpEq.new(@val, @val2))
996
1068
  end
997
1069
  end
1070
+
1071
+ def ecma262_typeof
1072
+ :boolean
1073
+ end
998
1074
  end
999
1075
  #
1000
1076
  # 11.9.5 The Strict Does-not-equal Operator ( !== )
@@ -1011,10 +1087,14 @@ module Minjs
1011
1087
 
1012
1088
  def reduce(parent)
1013
1089
  if @val.respond_to?(:ecma262_typeof) and @val2.respond_to?(:ecma262_typeof) and
1014
- @val.ecma262_typeof == @val2.ecma262_typeof
1090
+ (t = @val.ecma262_typeof) == @val2.ecma262_typeof and !t.nil?
1015
1091
  parent.replace(self, ExpNotEq.new(@val, @val2))
1016
1092
  end
1017
1093
  end
1094
+
1095
+ def ecma262_typeof
1096
+ :boolean
1097
+ end
1018
1098
  end
1019
1099
  #
1020
1100
  # 11.10 Binary Bitwise Operators
@@ -1034,6 +1114,10 @@ module Minjs
1034
1114
  @val = @val2
1035
1115
  @val2 = t
1036
1116
  end
1117
+
1118
+ def ecma262_typeof
1119
+ :number
1120
+ end
1037
1121
  end
1038
1122
  # ^
1039
1123
  class ExpXor < ExpArg2
@@ -1051,6 +1135,10 @@ module Minjs
1051
1135
  @val = @val2
1052
1136
  @val2 = t
1053
1137
  end
1138
+
1139
+ def ecma262_typeof
1140
+ :number
1141
+ end
1054
1142
  end
1055
1143
 
1056
1144
  # |
@@ -1069,6 +1157,10 @@ module Minjs
1069
1157
  @val = @val2
1070
1158
  @val2 = t
1071
1159
  end
1160
+
1161
+ def ecma262_typeof
1162
+ :number
1163
+ end
1072
1164
  end
1073
1165
  #
1074
1166
  # 11.11 Binary Logical Operators
@@ -1085,6 +1177,14 @@ module Minjs
1085
1177
  PRIORITY_LOGICAL_AND
1086
1178
  end
1087
1179
 
1180
+ def ecma262_typeof
1181
+ if @val.respond_to? :ecma262_typeof and @val2.respond_to? :ecma262_typeof
1182
+ if @val.ecma262_typeof == @val2.ecma262_typeof
1183
+ return @val.ecma262_typeof
1184
+ end
1185
+ end
1186
+ nil
1187
+ end
1088
1188
  end
1089
1189
  # ||
1090
1190
  class ExpLogicalOr < ExpArg2
@@ -1096,6 +1196,15 @@ module Minjs
1096
1196
  def priority
1097
1197
  PRIORITY_LOGICAL_OR
1098
1198
  end
1199
+
1200
+ def ecma262_typeof
1201
+ if @val.respond_to? :ecma262_typeof and @val2.respond_to? :ecma262_typeof
1202
+ if @val.ecma262_typeof == @val2.ecma262_typeof
1203
+ return @val.ecma262_typeof
1204
+ end
1205
+ end
1206
+ nil
1207
+ end
1099
1208
  end
1100
1209
  #
1101
1210
  # 11.12 Conditional Operator ( ? : )
@@ -1103,6 +1212,8 @@ module Minjs
1103
1212
  # val ? val2 : val3
1104
1213
  #
1105
1214
  class ExpCond < Exp
1215
+ attr_reader :val, :val2, :val3
1216
+
1106
1217
  def initialize(val, val2, val3)
1107
1218
  @val = val
1108
1219
  @val2 = val2
@@ -1144,11 +1255,11 @@ module Minjs
1144
1255
  end
1145
1256
 
1146
1257
  def replace(from, to)
1147
- if from == @val
1258
+ if from .eql? @val
1148
1259
  @val = to
1149
- elsif from == @val2
1260
+ elsif from .eql? @val2
1150
1261
  @val2 = to
1151
- elsif from == @val3
1262
+ elsif from .eql? @val3
1152
1263
  @val3 = to
1153
1264
  end
1154
1265
  end
@@ -1160,9 +1271,25 @@ module Minjs
1160
1271
  yield self, parent
1161
1272
  end
1162
1273
 
1274
+ def ==(obj)
1275
+ self.class == obj.class and
1276
+ @val == obj.val and
1277
+ @val2 == obj.val2 and
1278
+ @val3 == obj.val3
1279
+ end
1280
+
1163
1281
  def to_js(options = {})
1164
1282
  "#{@val.to_js(options)}?#{@val2.to_js(options)}:#{@val3.to_js(options)}"
1165
1283
  end
1284
+
1285
+ def ecma262_typeof
1286
+ if @val2.respond_to? :ecma262_typeof and @val3.respond_to? :ecma262_typeof
1287
+ if @val2.ecma262_typeof == @val3.ecma262_typeof
1288
+ return @val2.ecma262_typeof
1289
+ end
1290
+ end
1291
+ nil
1292
+ end
1166
1293
  end
1167
1294
  #
1168
1295
  # 11.13 Assignment Operators