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.
- checksums.yaml +4 -4
- data/lib/minjs/compressor.rb +371 -226
- data/lib/minjs/ecma262/base.rb +61 -15
- data/lib/minjs/ecma262/exp.rb +202 -75
- data/lib/minjs/ecma262/lit.rb +81 -5
- data/lib/minjs/ecma262/punc.rb +4 -0
- data/lib/minjs/ecma262/st.rb +254 -149
- data/lib/minjs/version.rb +1 -1
- metadata +2 -2
data/lib/minjs/ecma262/st.rb
CHANGED
@@ -13,8 +13,8 @@ module Minjs
|
|
13
13
|
999
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def empty?
|
17
|
+
false
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -24,9 +24,13 @@ module Minjs
|
|
24
24
|
class StBlock < St
|
25
25
|
attr_reader :statement_list
|
26
26
|
|
27
|
-
#statement_list:
|
27
|
+
#statement_list:StatementList
|
28
28
|
def initialize(statement_list)
|
29
|
-
|
29
|
+
if statement_list.kind_of? Array
|
30
|
+
@statement_list = StatementList.new(statement_list)
|
31
|
+
else
|
32
|
+
@statement_list = statement_list
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
def deep_dup
|
@@ -38,6 +42,11 @@ module Minjs
|
|
38
42
|
yield self, parent
|
39
43
|
end
|
40
44
|
|
45
|
+
def ==(obj)
|
46
|
+
self.class == obj.class and
|
47
|
+
@statement_list == obj.statement_list
|
48
|
+
end
|
49
|
+
|
41
50
|
def to_js(options = {})
|
42
51
|
concat(options, "{", @statement_list, "}")
|
43
52
|
end
|
@@ -50,29 +59,43 @@ module Minjs
|
|
50
59
|
end
|
51
60
|
|
52
61
|
def to_exp(options = {})
|
53
|
-
statement_list.
|
54
|
-
|
62
|
+
@statement_list.statement_list.select{|s|
|
63
|
+
s.class != StEmpty
|
64
|
+
}[0].to_exp.deep_dup
|
65
|
+
|
55
66
|
end
|
56
67
|
|
57
68
|
def to_statement?
|
58
69
|
t = @statement_list.statement_list.select{|s|
|
59
70
|
s.class != StEmpty
|
60
71
|
}
|
61
|
-
t.length == 1
|
72
|
+
t.length == 1 || t.length == 0
|
62
73
|
end
|
63
74
|
|
64
75
|
def to_statement
|
65
|
-
statement_list.remove_empty_statement
|
66
|
-
@statement_list[0]
|
67
|
-
end
|
68
|
-
|
69
|
-
def last_statement
|
70
|
-
list = [self]
|
71
76
|
t = @statement_list.statement_list.select{|s|
|
72
77
|
s.class != StEmpty
|
73
78
|
}
|
74
|
-
|
75
|
-
|
79
|
+
|
80
|
+
if t[0]
|
81
|
+
t[0].deep_dup
|
82
|
+
else
|
83
|
+
StEmpty.new
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def empty?
|
88
|
+
@statement_list.statement_list.select{|s|
|
89
|
+
s.class != StEmpty
|
90
|
+
}.length == 0
|
91
|
+
end
|
92
|
+
|
93
|
+
def [](i)
|
94
|
+
@statement_list[i]
|
95
|
+
end
|
96
|
+
|
97
|
+
def remove_empty_statement
|
98
|
+
statement_list.remove_empty_statement
|
76
99
|
end
|
77
100
|
end
|
78
101
|
#
|
@@ -99,10 +122,10 @@ module Minjs
|
|
99
122
|
|
100
123
|
def replace(from, to)
|
101
124
|
@vars.each do |x|
|
102
|
-
if x[0]
|
125
|
+
if x[0] .eql? from
|
103
126
|
x[0] = to
|
104
127
|
break
|
105
|
-
elsif x[1] and x[1]
|
128
|
+
elsif x[1] and x[1] .eql? from
|
106
129
|
x[1] = to
|
107
130
|
break
|
108
131
|
end
|
@@ -119,6 +142,10 @@ module Minjs
|
|
119
142
|
yield self, parent
|
120
143
|
end
|
121
144
|
|
145
|
+
def ==(obj)
|
146
|
+
self.class == obj.class and @vars == obj.vars
|
147
|
+
end
|
148
|
+
|
122
149
|
def to_js(options = {})
|
123
150
|
t = concat(options, :var, @vars.collect{|x|
|
124
151
|
if x[1]
|
@@ -164,10 +191,6 @@ module Minjs
|
|
164
191
|
end
|
165
192
|
self
|
166
193
|
end
|
167
|
-
|
168
|
-
def last_statement
|
169
|
-
[self]
|
170
|
-
end
|
171
194
|
end
|
172
195
|
|
173
196
|
#12.3 empty
|
@@ -183,11 +206,16 @@ module Minjs
|
|
183
206
|
yield self, parent
|
184
207
|
end
|
185
208
|
|
209
|
+
def ==(obj)
|
210
|
+
self.class == obj.class
|
211
|
+
end
|
212
|
+
|
186
213
|
def to_js(options = {})
|
187
|
-
"
|
214
|
+
";;"
|
188
215
|
end
|
189
|
-
|
190
|
-
|
216
|
+
|
217
|
+
def empty?
|
218
|
+
true
|
191
219
|
end
|
192
220
|
end
|
193
221
|
|
@@ -204,7 +232,7 @@ module Minjs
|
|
204
232
|
end
|
205
233
|
|
206
234
|
def replace(from, to)
|
207
|
-
if @exp
|
235
|
+
if @exp .eql? from
|
208
236
|
@exp = to
|
209
237
|
end
|
210
238
|
end
|
@@ -214,12 +242,16 @@ module Minjs
|
|
214
242
|
yield self, parent
|
215
243
|
end
|
216
244
|
|
245
|
+
def ==(obj)
|
246
|
+
self.class == obj.class and @exp == obj.exp
|
247
|
+
end
|
248
|
+
|
217
249
|
def to_js(options = {})
|
218
250
|
concat(options, @exp, ";")
|
219
251
|
end
|
220
252
|
|
221
253
|
def to_exp(options = {})
|
222
|
-
@exp
|
254
|
+
@exp.deep_dup
|
223
255
|
end
|
224
256
|
|
225
257
|
def to_exp?
|
@@ -235,10 +267,6 @@ module Minjs
|
|
235
267
|
def add_paren
|
236
268
|
self
|
237
269
|
end
|
238
|
-
|
239
|
-
def last_statement
|
240
|
-
[self]
|
241
|
-
end
|
242
270
|
end
|
243
271
|
|
244
272
|
#12.5
|
@@ -256,11 +284,11 @@ module Minjs
|
|
256
284
|
end
|
257
285
|
|
258
286
|
def replace(from, to)
|
259
|
-
if from
|
287
|
+
if from .eql? @cond
|
260
288
|
@cond = to
|
261
|
-
elsif from
|
289
|
+
elsif from .eql? @then_st
|
262
290
|
@then_st = to
|
263
|
-
elsif from
|
291
|
+
elsif from .eql? @else_st
|
264
292
|
@else_st = to
|
265
293
|
end
|
266
294
|
end
|
@@ -278,6 +306,13 @@ module Minjs
|
|
278
306
|
self.class.new(@cond.deep_dup, @then_st.deep_dup, @else_st ? @else_st.deep_dup : nil)
|
279
307
|
end
|
280
308
|
|
309
|
+
def ==(obj)
|
310
|
+
self.class == obj.class and
|
311
|
+
@cond == obj.cond and
|
312
|
+
@then_st == obj.then_st and
|
313
|
+
@else_st == obj.else_st
|
314
|
+
end
|
315
|
+
|
281
316
|
def to_js(options = {})
|
282
317
|
if @else_st
|
283
318
|
concat options, :if, "(", @cond, ")", @then_st, :else, @else_st
|
@@ -295,10 +330,25 @@ module Minjs
|
|
295
330
|
end
|
296
331
|
|
297
332
|
def to_return
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
333
|
+
then_exp = then_st.exp;
|
334
|
+
else_exp = else_st.exp;
|
335
|
+
|
336
|
+
if then_exp.nil?
|
337
|
+
then_exp = ExpVoid.new(ECMA262Numeric.new(0))
|
338
|
+
end
|
339
|
+
if else_exp.nil?
|
340
|
+
else_exp = ExpVoid.new(ECMA262Numeric.new(0))
|
341
|
+
end
|
342
|
+
if @else_st
|
343
|
+
ret = StReturn.new(ExpCond.new(@cond, then_exp, else_exp).add_paren)
|
344
|
+
else
|
345
|
+
ret = StReturn.new(ExpLogicalAnd.new(@cond, then_exp).add_paren)
|
346
|
+
end
|
347
|
+
if ret.to_js.length <= to_js.length
|
348
|
+
ret
|
349
|
+
else
|
350
|
+
self
|
351
|
+
end
|
302
352
|
end
|
303
353
|
|
304
354
|
def to_exp?
|
@@ -312,23 +362,23 @@ module Minjs
|
|
312
362
|
end
|
313
363
|
|
314
364
|
def to_exp(options = {})
|
315
|
-
|
365
|
+
cond = @cond.deep_dup
|
316
366
|
if !@else_st
|
317
367
|
then_exp = @then_st.to_exp(options)
|
318
|
-
if
|
319
|
-
return ExpParen.new(ExpLogicalOr.new(ExpParen.new(
|
368
|
+
if cond.kind_of? ExpLogicalNot
|
369
|
+
return ExpParen.new(ExpLogicalOr.new(ExpParen.new(cond.val), ExpParen.new(then_exp)))
|
320
370
|
else
|
321
|
-
return ExpParen.new(ExpLogicalAnd.new(ExpParen.new(
|
371
|
+
return ExpParen.new(ExpLogicalAnd.new(ExpParen.new(cond), ExpParen.new(then_exp)))
|
322
372
|
end
|
323
373
|
else
|
324
374
|
then_exp = ExpParen.new(@then_st.to_exp(options))
|
325
375
|
else_exp = ExpParen.new(@else_st.to_exp(options))
|
326
376
|
end
|
327
377
|
|
328
|
-
if
|
329
|
-
ExpCond.new(ExpParen.new(
|
378
|
+
if cond.kind_of? ExpLogicalNot
|
379
|
+
ExpCond.new(ExpParen.new(cond.val), else_exp, then_exp)
|
330
380
|
else
|
331
|
-
ExpCond.new(ExpParen.new(
|
381
|
+
ExpCond.new(ExpParen.new(cond), then_exp, else_exp)
|
332
382
|
end
|
333
383
|
end
|
334
384
|
|
@@ -343,12 +393,12 @@ module Minjs
|
|
343
393
|
self
|
344
394
|
end
|
345
395
|
|
346
|
-
def
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
396
|
+
def remove_empty_statement
|
397
|
+
if @then_st.kind_of? StBlock
|
398
|
+
@then_st.remove_empty_statement
|
399
|
+
end
|
400
|
+
if @else_st.kind_of? StBlock
|
401
|
+
@else_st.remove_empty_statement
|
352
402
|
end
|
353
403
|
end
|
354
404
|
end
|
@@ -366,7 +416,7 @@ module Minjs
|
|
366
416
|
end
|
367
417
|
|
368
418
|
def replace(from, to)
|
369
|
-
if from
|
419
|
+
if from .eql? @statement
|
370
420
|
@statement = to
|
371
421
|
end
|
372
422
|
end
|
@@ -377,6 +427,12 @@ module Minjs
|
|
377
427
|
yield self, parent
|
378
428
|
end
|
379
429
|
|
430
|
+
def ==(obj)
|
431
|
+
self.class == obj.class and
|
432
|
+
@exp == obj.exp and
|
433
|
+
@statement == obj.statement
|
434
|
+
end
|
435
|
+
|
380
436
|
def to_js(options = {})
|
381
437
|
if @statement.kind_of? StBlock and @statement.statement_list.length == 1
|
382
438
|
statement = @statement.statement_list.statement_list[0]
|
@@ -397,14 +453,11 @@ module Minjs
|
|
397
453
|
def add_paren
|
398
454
|
self
|
399
455
|
end
|
400
|
-
|
401
|
-
def last_statement
|
402
|
-
list = [self]
|
403
|
-
list.concat @statement.last_statement
|
404
|
-
end
|
405
456
|
end
|
406
457
|
|
407
458
|
class StDoWhile < St
|
459
|
+
attr_reader :exp, :statement
|
460
|
+
|
408
461
|
def initialize(exp, statement)
|
409
462
|
@exp, @statement = exp, statement
|
410
463
|
end
|
@@ -414,7 +467,7 @@ module Minjs
|
|
414
467
|
end
|
415
468
|
|
416
469
|
def replace(from, to)
|
417
|
-
if from
|
470
|
+
if from .eql? @statement
|
418
471
|
@statement = to
|
419
472
|
end
|
420
473
|
end
|
@@ -425,6 +478,12 @@ module Minjs
|
|
425
478
|
yield self, parent
|
426
479
|
end
|
427
480
|
|
481
|
+
def ==(obj)
|
482
|
+
self.class == obj.class and
|
483
|
+
@exp == obj.exp and
|
484
|
+
@statement == obj.statement
|
485
|
+
end
|
486
|
+
|
428
487
|
def to_js(options = {})
|
429
488
|
if @statement.kind_of? StBlock and @statement.statement_list.length == 1
|
430
489
|
statement = @statement.statement_list.statement_list[0]
|
@@ -445,11 +504,6 @@ module Minjs
|
|
445
504
|
def add_paren
|
446
505
|
self
|
447
506
|
end
|
448
|
-
|
449
|
-
def last_statement
|
450
|
-
list = [self]
|
451
|
-
list.concat @statement.last_statement
|
452
|
-
end
|
453
507
|
end
|
454
508
|
|
455
509
|
#
|
@@ -473,13 +527,13 @@ module Minjs
|
|
473
527
|
end
|
474
528
|
|
475
529
|
def replace(from, to)
|
476
|
-
if from
|
530
|
+
if from .eql? @exp1
|
477
531
|
@exp1 = to
|
478
|
-
elsif from
|
532
|
+
elsif from .eql? @exp2
|
479
533
|
@exp2 = to
|
480
|
-
elsif from
|
534
|
+
elsif from .eql? @exp3
|
481
535
|
@exp3 = to
|
482
|
-
elsif from
|
536
|
+
elsif from .eql? @statement
|
483
537
|
@statement = to
|
484
538
|
end
|
485
539
|
end
|
@@ -492,6 +546,14 @@ module Minjs
|
|
492
546
|
yield self, parent
|
493
547
|
end
|
494
548
|
|
549
|
+
def ==(obj)
|
550
|
+
self.class == obj.class and
|
551
|
+
@exp1 == obj.exp1 and
|
552
|
+
@exp2 == obj.exp2 and
|
553
|
+
@exp3 == obj.exp3 and
|
554
|
+
@statement == obj.statement
|
555
|
+
end
|
556
|
+
|
495
557
|
def to_js(options = {})
|
496
558
|
if @statement.kind_of? StBlock and @statement.statement_list.length == 1
|
497
559
|
statement = @statement.statement_list.statement_list[0]
|
@@ -518,11 +580,6 @@ module Minjs
|
|
518
580
|
def add_paren
|
519
581
|
self
|
520
582
|
end
|
521
|
-
|
522
|
-
def last_statement
|
523
|
-
list = [self]
|
524
|
-
list.concat @statement.last_statement
|
525
|
-
end
|
526
583
|
end
|
527
584
|
|
528
585
|
#
|
@@ -530,6 +587,7 @@ module Minjs
|
|
530
587
|
#
|
531
588
|
class StForVar < St
|
532
589
|
attr_reader :context
|
590
|
+
attr_reader :var_decl_list, :exp2, :exp3, :statement
|
533
591
|
|
534
592
|
#
|
535
593
|
# var_decl_list
|
@@ -554,7 +612,7 @@ module Minjs
|
|
554
612
|
end
|
555
613
|
|
556
614
|
def replace(from, to)
|
557
|
-
if from
|
615
|
+
if from .eql? @statement
|
558
616
|
@statement = to
|
559
617
|
end
|
560
618
|
end
|
@@ -592,6 +650,14 @@ module Minjs
|
|
592
650
|
StFor.new(tt, @exp2, @exp3, @statement)
|
593
651
|
end
|
594
652
|
|
653
|
+
def ==(obj)
|
654
|
+
self.class == obj.class and
|
655
|
+
@var_decl_list == obj.var_decl_list and
|
656
|
+
@exp2 == obj.exp2 and
|
657
|
+
@exp3 == obj.exp3 and
|
658
|
+
@statement == obj.statement
|
659
|
+
end
|
660
|
+
|
595
661
|
def to_js(options = {})
|
596
662
|
if @statement.kind_of? StBlock and @statement.statement_list.length == 1
|
597
663
|
statement = @statement.statement_list.statement_list[0]
|
@@ -628,14 +694,11 @@ module Minjs
|
|
628
694
|
def add_paren
|
629
695
|
self
|
630
696
|
end
|
631
|
-
|
632
|
-
def last_statement
|
633
|
-
list = [self]
|
634
|
-
list.concat @statement.last_statement
|
635
|
-
end
|
636
697
|
end
|
637
698
|
|
638
699
|
class StForIn < St
|
700
|
+
attr_reader :exp1, :exp2, :statement
|
701
|
+
|
639
702
|
def initialize(exp1, exp2, statement)
|
640
703
|
@exp1 = exp1
|
641
704
|
@exp2 = exp2
|
@@ -647,7 +710,7 @@ module Minjs
|
|
647
710
|
end
|
648
711
|
|
649
712
|
def replace(from, to)
|
650
|
-
if from
|
713
|
+
if from .eql? @statement
|
651
714
|
@statement = to
|
652
715
|
end
|
653
716
|
end
|
@@ -659,6 +722,13 @@ module Minjs
|
|
659
722
|
yield self, parent
|
660
723
|
end
|
661
724
|
|
725
|
+
def ==(obj)
|
726
|
+
self.class == obj.class and
|
727
|
+
@exp1 == obj.exp1 and
|
728
|
+
@exp2 == obj.exp2 and
|
729
|
+
@statement == obj.statement
|
730
|
+
end
|
731
|
+
|
662
732
|
def to_js(options = {})
|
663
733
|
if @statement.kind_of? StBlock and @statement.statement_list.length == 1
|
664
734
|
statement = @statement.statement_list.statement_list[0]
|
@@ -685,15 +755,11 @@ module Minjs
|
|
685
755
|
end
|
686
756
|
self
|
687
757
|
end
|
688
|
-
|
689
|
-
def last_statement
|
690
|
-
list = [self]
|
691
|
-
list.concat @statement.last_statement
|
692
|
-
end
|
693
758
|
end
|
694
759
|
|
695
760
|
class StForInVar < St
|
696
761
|
attr_reader :context
|
762
|
+
attr_reader :var_decl, :exp2, :statement
|
697
763
|
|
698
764
|
def initialize(context, var_decl, exp2, statement)
|
699
765
|
@context = context
|
@@ -718,7 +784,7 @@ module Minjs
|
|
718
784
|
end
|
719
785
|
|
720
786
|
def replace(from, to)
|
721
|
-
if from
|
787
|
+
if from .eql? @statement
|
722
788
|
@statement = to
|
723
789
|
end
|
724
790
|
end
|
@@ -732,6 +798,13 @@ module Minjs
|
|
732
798
|
StForIn.new(t, @exp2, @statement)
|
733
799
|
end
|
734
800
|
|
801
|
+
def ==(obj)
|
802
|
+
self.class == obj.class and
|
803
|
+
@var_decl == obj.var_decl and
|
804
|
+
@exp2 == obj.exp2 and
|
805
|
+
@statement == obj.statement
|
806
|
+
end
|
807
|
+
|
735
808
|
def to_js(options = {})
|
736
809
|
if @statement.kind_of? StBlock and @statement.statement_list.length == 1
|
737
810
|
statement = @statement.statement_list.statement_list[0]
|
@@ -761,16 +834,13 @@ module Minjs
|
|
761
834
|
def add_paren
|
762
835
|
self
|
763
836
|
end
|
764
|
-
|
765
|
-
def last_statement
|
766
|
-
list = [self]
|
767
|
-
list.concat @statement.last_statement
|
768
|
-
end
|
769
837
|
end
|
770
838
|
|
771
839
|
|
772
840
|
#12.7
|
773
841
|
class StContinue < St
|
842
|
+
attr_reader :exp
|
843
|
+
|
774
844
|
def initialize(exp = nil)
|
775
845
|
@exp = exp
|
776
846
|
end
|
@@ -784,6 +854,11 @@ module Minjs
|
|
784
854
|
yield self, parent
|
785
855
|
end
|
786
856
|
|
857
|
+
def ==(obj)
|
858
|
+
self.class == obj.class and
|
859
|
+
@exp == obj.exp
|
860
|
+
end
|
861
|
+
|
787
862
|
def to_js(options = {})
|
788
863
|
if @exp
|
789
864
|
concat options, :continue, @exp, ";"
|
@@ -791,14 +866,12 @@ module Minjs
|
|
791
866
|
concat options, :continue, ";"
|
792
867
|
end
|
793
868
|
end
|
794
|
-
|
795
|
-
def last_statement
|
796
|
-
[self]
|
797
|
-
end
|
798
869
|
end
|
799
870
|
|
800
871
|
#12.8
|
801
872
|
class StBreak < St
|
873
|
+
attr_reader :exp
|
874
|
+
|
802
875
|
def initialize(exp = nil)
|
803
876
|
@exp = exp
|
804
877
|
end
|
@@ -812,6 +885,11 @@ module Minjs
|
|
812
885
|
yield self, parent
|
813
886
|
end
|
814
887
|
|
888
|
+
def ==(obj)
|
889
|
+
self.class == obj.class and
|
890
|
+
@exp == obj.exp
|
891
|
+
end
|
892
|
+
|
815
893
|
def to_js(options = {})
|
816
894
|
if @exp
|
817
895
|
concat options, :break, @exp, ";"
|
@@ -819,10 +897,6 @@ module Minjs
|
|
819
897
|
concat options, :break, ";"
|
820
898
|
end
|
821
899
|
end
|
822
|
-
|
823
|
-
def last_statement
|
824
|
-
[self]
|
825
|
-
end
|
826
900
|
end
|
827
901
|
|
828
902
|
#12.9
|
@@ -842,7 +916,7 @@ module Minjs
|
|
842
916
|
end
|
843
917
|
|
844
918
|
def replace(from, to)
|
845
|
-
if from
|
919
|
+
if from .eql? @exp
|
846
920
|
@exp = to
|
847
921
|
end
|
848
922
|
end
|
@@ -860,6 +934,10 @@ module Minjs
|
|
860
934
|
self
|
861
935
|
end
|
862
936
|
|
937
|
+
def ==(obj)
|
938
|
+
self.class == obj.class and @exp == obj.exp
|
939
|
+
end
|
940
|
+
|
863
941
|
def to_js(options = {})
|
864
942
|
if @exp
|
865
943
|
concat options, :return, @exp, ";"
|
@@ -878,20 +956,26 @@ module Minjs
|
|
878
956
|
def add_paren
|
879
957
|
self
|
880
958
|
end
|
881
|
-
|
882
|
-
def last_statement
|
883
|
-
[self]
|
884
|
-
end
|
885
959
|
end
|
886
960
|
#12.10
|
887
961
|
class StWith < St
|
962
|
+
attr_reader :exp, :statement
|
963
|
+
|
888
964
|
def initialize(exp, statement)
|
889
965
|
@exp = exp
|
890
966
|
@statement = statement
|
891
967
|
end
|
892
968
|
|
893
969
|
def deep_dup
|
894
|
-
self.class.new(@exp)
|
970
|
+
self.class.new(@exp, @statement)
|
971
|
+
end
|
972
|
+
|
973
|
+
def replace(from, to)
|
974
|
+
if @exp .eql? from
|
975
|
+
@exp = to
|
976
|
+
elsif @statement = to
|
977
|
+
@statement = to
|
978
|
+
end
|
895
979
|
end
|
896
980
|
|
897
981
|
def traverse(parent, &block)
|
@@ -900,6 +984,12 @@ module Minjs
|
|
900
984
|
yield self, parent
|
901
985
|
end
|
902
986
|
|
987
|
+
def ==(obj)
|
988
|
+
self.class == obj.class and
|
989
|
+
@exp == obj.exp and
|
990
|
+
@statement == obj.statement
|
991
|
+
end
|
992
|
+
|
903
993
|
def to_js(options = {})
|
904
994
|
concat options, :with, "(", @exp, ")", @statement
|
905
995
|
end
|
@@ -914,14 +1004,11 @@ module Minjs
|
|
914
1004
|
def add_paren
|
915
1005
|
self
|
916
1006
|
end
|
917
|
-
|
918
|
-
def last_statement
|
919
|
-
list = [self]
|
920
|
-
list.concat @statement.last_statement
|
921
|
-
end
|
922
1007
|
end
|
923
1008
|
#12.11
|
924
1009
|
class StSwitch < St
|
1010
|
+
attr_reader :exp, :blocks
|
1011
|
+
|
925
1012
|
#
|
926
1013
|
# block: [condition, blocks]
|
927
1014
|
#
|
@@ -933,14 +1020,17 @@ module Minjs
|
|
933
1020
|
def deep_dup
|
934
1021
|
self.class.new(@exp,
|
935
1022
|
@blocks.collect{|x, y|
|
936
|
-
[
|
1023
|
+
[
|
1024
|
+
x ? x.deep_dup : nil,
|
1025
|
+
y ? y.deep_dup : nil
|
1026
|
+
]
|
937
1027
|
})
|
938
1028
|
end
|
939
1029
|
|
940
1030
|
def replace(from, to)
|
941
|
-
if @exp
|
1031
|
+
if @exp .eql? from
|
942
1032
|
@exp = to
|
943
|
-
elsif @blocks
|
1033
|
+
elsif @blocks .eql? from
|
944
1034
|
@blocks = to
|
945
1035
|
end
|
946
1036
|
end
|
@@ -956,6 +1046,11 @@ module Minjs
|
|
956
1046
|
yield self, parent
|
957
1047
|
end
|
958
1048
|
|
1049
|
+
def ==(obj)
|
1050
|
+
self.class == obj.class and
|
1051
|
+
@exp == obj.exp and
|
1052
|
+
@blocks == obj.blocks
|
1053
|
+
end
|
959
1054
|
def to_js(options = {})
|
960
1055
|
t = concat(options, :switch, "(", @exp, ")", "{")
|
961
1056
|
@blocks.each do |b|
|
@@ -983,48 +1078,48 @@ module Minjs
|
|
983
1078
|
def add_paren
|
984
1079
|
self
|
985
1080
|
end
|
986
|
-
|
987
|
-
def last_statement
|
988
|
-
list = [self]
|
989
|
-
end
|
990
1081
|
end
|
991
1082
|
#12.12
|
992
1083
|
class StLabelled < St
|
993
|
-
|
994
|
-
|
1084
|
+
attr_reader :label, :statement
|
1085
|
+
|
1086
|
+
def initialize(label, statement)
|
1087
|
+
@label = label
|
995
1088
|
@statement = statement
|
996
1089
|
end
|
997
1090
|
|
998
1091
|
def deep_dup
|
999
|
-
self.class.new(@
|
1092
|
+
self.class.new(@label, @statement)
|
1000
1093
|
end
|
1001
1094
|
|
1002
1095
|
def replace(from, to)
|
1003
|
-
if from
|
1004
|
-
@
|
1005
|
-
elsif from
|
1096
|
+
if from .eql? @label
|
1097
|
+
@label = to
|
1098
|
+
elsif from .eql? @statement
|
1006
1099
|
@statement = to
|
1007
1100
|
end
|
1008
1101
|
end
|
1009
1102
|
|
1010
1103
|
def traverse(parent, &block)
|
1011
|
-
@
|
1104
|
+
@label.traverse(self, &block)
|
1012
1105
|
@statement.traverse(self, &block)
|
1013
1106
|
yield self, parent
|
1014
1107
|
end
|
1015
1108
|
|
1016
|
-
def
|
1017
|
-
|
1109
|
+
def ==(obj)
|
1110
|
+
self.class == obj.class and
|
1111
|
+
@label == obj.label and
|
1112
|
+
@statement == obj.statement
|
1018
1113
|
end
|
1019
|
-
|
1020
|
-
|
1021
|
-
list = [self]
|
1022
|
-
list.concat @statement.last_statement
|
1114
|
+
def to_js(options = {})
|
1115
|
+
concat options, @label, ":", @statement
|
1023
1116
|
end
|
1024
1117
|
end
|
1025
1118
|
|
1026
1119
|
#12.13
|
1027
1120
|
class StThrow < St
|
1121
|
+
attr_reader :exp
|
1122
|
+
|
1028
1123
|
def initialize(exp)
|
1029
1124
|
@exp = exp
|
1030
1125
|
end
|
@@ -1038,12 +1133,13 @@ module Minjs
|
|
1038
1133
|
yield self, parent
|
1039
1134
|
end
|
1040
1135
|
|
1041
|
-
def
|
1042
|
-
|
1136
|
+
def ==(obj)
|
1137
|
+
self.class == obj.class and
|
1138
|
+
@exp == obj.exp
|
1043
1139
|
end
|
1044
1140
|
|
1045
|
-
def
|
1046
|
-
|
1141
|
+
def to_js(options = {})
|
1142
|
+
concat options, :throw, @exp, ";"
|
1047
1143
|
end
|
1048
1144
|
end
|
1049
1145
|
|
@@ -1062,17 +1158,17 @@ module Minjs
|
|
1062
1158
|
end
|
1063
1159
|
|
1064
1160
|
def deep_dup
|
1065
|
-
self.class.new(@try, @catch, @finally)
|
1161
|
+
self.class.new(@context, @catch_context, @try, @catch, @finally)
|
1066
1162
|
end
|
1067
1163
|
|
1068
1164
|
def replace(from, to)
|
1069
|
-
if from
|
1165
|
+
if from .eql? @try
|
1070
1166
|
@try = to
|
1071
|
-
elsif from
|
1167
|
+
elsif from .eql? @catch[0]
|
1072
1168
|
@catch[0] = to
|
1073
|
-
elsif from
|
1169
|
+
elsif from .eql? @catch[1]
|
1074
1170
|
@catch[1] = to
|
1075
|
-
elsif from
|
1171
|
+
elsif from .eql? @finally
|
1076
1172
|
@finally = to
|
1077
1173
|
end
|
1078
1174
|
end
|
@@ -1087,6 +1183,13 @@ module Minjs
|
|
1087
1183
|
yield self, parent
|
1088
1184
|
end
|
1089
1185
|
|
1186
|
+
def ==(obj)
|
1187
|
+
self.class == obj.class and
|
1188
|
+
self.try == obj.try and
|
1189
|
+
self.catch == obj.catch and
|
1190
|
+
self.finally == obj.finally
|
1191
|
+
end
|
1192
|
+
|
1090
1193
|
def to_js(options = {})
|
1091
1194
|
if @catch and @finally
|
1092
1195
|
concat(options, :try, @try, :catch, "(", @catch[0], ")", @catch[1], :finally, @finally)
|
@@ -1096,9 +1199,6 @@ module Minjs
|
|
1096
1199
|
concat(options, :try, @try, :finally, @finally)
|
1097
1200
|
end
|
1098
1201
|
end
|
1099
|
-
def last_statement
|
1100
|
-
[self]
|
1101
|
-
end
|
1102
1202
|
end
|
1103
1203
|
|
1104
1204
|
#12.15
|
@@ -1107,15 +1207,17 @@ module Minjs
|
|
1107
1207
|
self.class.new
|
1108
1208
|
end
|
1109
1209
|
|
1110
|
-
def traverse
|
1210
|
+
def traverse(parent, &block)
|
1111
1211
|
yield self, parent
|
1112
1212
|
end
|
1213
|
+
|
1214
|
+
def ==(obj)
|
1215
|
+
self.class == obj.class
|
1216
|
+
end
|
1217
|
+
|
1113
1218
|
def to_js(options = {})
|
1114
1219
|
concat options, :debugger, ";"
|
1115
1220
|
end
|
1116
|
-
def last_statement
|
1117
|
-
[self]
|
1118
|
-
end
|
1119
1221
|
end
|
1120
1222
|
|
1121
1223
|
#
|
@@ -1130,10 +1232,10 @@ module Minjs
|
|
1130
1232
|
attr_reader :context
|
1131
1233
|
|
1132
1234
|
def initialize(context, name, args, statements, options = {})
|
1235
|
+
@context = context
|
1133
1236
|
@name = name
|
1134
1237
|
@args = args #=> array
|
1135
1238
|
@statements = statements #=> Prog
|
1136
|
-
@context = context
|
1137
1239
|
@decl = options[:decl]
|
1138
1240
|
@getter = options[:getter]
|
1139
1241
|
@setter = options[:setter]
|
@@ -1159,6 +1261,13 @@ module Minjs
|
|
1159
1261
|
yield self, parent
|
1160
1262
|
end
|
1161
1263
|
|
1264
|
+
def ==(obj)
|
1265
|
+
self.class == obj.class and
|
1266
|
+
@name == obj.name and
|
1267
|
+
@args == obj.args and
|
1268
|
+
@statements == obj.statements
|
1269
|
+
end
|
1270
|
+
|
1162
1271
|
def to_js(options = {})
|
1163
1272
|
_args = @args.collect{|x|x.to_js(options)}.join(",")
|
1164
1273
|
if @getter
|
@@ -1181,10 +1290,6 @@ module Minjs
|
|
1181
1290
|
def decl?
|
1182
1291
|
@decl
|
1183
1292
|
end
|
1184
|
-
|
1185
|
-
def last_statement
|
1186
|
-
[self]
|
1187
|
-
end
|
1188
1293
|
end
|
1189
1294
|
end
|
1190
1295
|
end
|