minjs 0.1.5 → 0.1.7
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 +255 -25
- data/lib/minjs/ecma262/base.rb +0 -67
- data/lib/minjs/ecma262/env.rb +4 -1
- data/lib/minjs/ecma262/exp.rb +371 -80
- data/lib/minjs/ecma262/lit.rb +58 -2
- data/lib/minjs/ecma262/st.rb +123 -43
- data/lib/minjs/func.rb +6 -0
- data/lib/minjs/literal.rb +2 -2
- data/lib/minjs/minjs_compressor.rb +2 -2
- data/lib/minjs/statement.rb +20 -14
- data/lib/minjs/version.rb +1 -1
- metadata +2 -2
data/lib/minjs/ecma262/exp.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
module Minjs
|
2
2
|
module ECMA262
|
3
|
+
PRIORITY_PRIMARY = 10
|
4
|
+
PRIORITY_LEFT_HAND_SIDE = 20
|
5
|
+
PRIORITY_POSTFIX = 30
|
6
|
+
PRIORITY_UNARY = 40
|
7
|
+
PRIORITY_MULTIPLICATIVE = 50
|
8
|
+
PRIORITY_ADDITIVE = 60
|
9
|
+
PRIORITY_SHIFT = 70
|
10
|
+
PRIORITY_RELATIONAL = 80
|
11
|
+
PRIORITY_EQUALITY = 90
|
12
|
+
PRIORITY_BITWISE_AND = 100
|
13
|
+
PRIORITY_BITWISE_XOR = 106
|
14
|
+
PRIORITY_BITWISE_OR = 108
|
15
|
+
PRIORITY_LOGICAL_AND = 110
|
16
|
+
PRIORITY_LOGICAL_OR = 116
|
17
|
+
PRIORITY_CONDITIONAL = 120
|
18
|
+
PRIORITY_ASSIGNMENT = 130
|
19
|
+
PRIORITY_COMMA = 140
|
20
|
+
|
3
21
|
class Exp < Base
|
4
22
|
def traverse
|
5
23
|
yield(self)
|
@@ -15,6 +33,7 @@ module Minjs
|
|
15
33
|
def priority
|
16
34
|
9999
|
17
35
|
end
|
36
|
+
|
18
37
|
end
|
19
38
|
|
20
39
|
module BinaryOperation
|
@@ -25,6 +44,17 @@ module Minjs
|
|
25
44
|
if @val2.kind_of? ExpParen and @val2.val.priority < self.priority
|
26
45
|
@val2 = @val2.val
|
27
46
|
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
def add_paren
|
50
|
+
if @val.priority > self.priority
|
51
|
+
@val = ExpParen.new(@val)
|
52
|
+
end
|
53
|
+
if @val2.priority > self.priority
|
54
|
+
@val2 = ExpParen.new(@val2)
|
55
|
+
end
|
56
|
+
|
57
|
+
self
|
28
58
|
end
|
29
59
|
end
|
30
60
|
|
@@ -33,21 +63,42 @@ module Minjs
|
|
33
63
|
if @val.kind_of? ExpParen and @val.val.priority <= self.priority
|
34
64
|
@val = @val.val if @val.remove_paren?
|
35
65
|
end
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_paren
|
70
|
+
if @val.priority > self.priority
|
71
|
+
@val = ExpParen.new(@val)
|
72
|
+
end
|
73
|
+
|
74
|
+
self
|
36
75
|
end
|
37
76
|
end
|
38
77
|
|
39
78
|
module AssignmentOperation
|
40
79
|
def remove_paren
|
41
|
-
if @val.kind_of? ExpParen and @val.val.priority <=
|
80
|
+
if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
|
42
81
|
@val = @val.val if @val.remove_paren?
|
43
82
|
end
|
44
|
-
if @val2.kind_of? ExpParen and @val2.val.priority <=
|
83
|
+
if @val2.kind_of? ExpParen and @val2.val.priority <= PRIORITY_ASSIGNMENT
|
45
84
|
@val2 = @val2.val
|
46
85
|
end
|
86
|
+
self
|
87
|
+
end
|
88
|
+
def add_paren
|
89
|
+
if @val.priority > PRIORITY_LEFT_HAND_SIDE
|
90
|
+
@val = ExpParen.new(@val)
|
91
|
+
end
|
92
|
+
if @val2.priority > PRIORITY_ASSIGNMENT
|
93
|
+
@val2 = ExpParen.new(@val2)
|
94
|
+
end
|
95
|
+
self
|
47
96
|
end
|
48
97
|
end
|
49
98
|
|
50
99
|
class ExpArg1 < Exp
|
100
|
+
attr_reader :val
|
101
|
+
|
51
102
|
def initialize(val)
|
52
103
|
@val = val
|
53
104
|
end
|
@@ -70,6 +121,12 @@ module Minjs
|
|
70
121
|
def to_js(options = {})
|
71
122
|
concat options, sym, @val
|
72
123
|
end
|
124
|
+
|
125
|
+
# def reduce(parent)
|
126
|
+
# if @val.kind_of?(Literal) and !@val.kind_of? IdentifierName
|
127
|
+
# #TODO
|
128
|
+
# end
|
129
|
+
# end
|
73
130
|
end
|
74
131
|
|
75
132
|
class ExpArg2 < Exp
|
@@ -101,22 +158,12 @@ module Minjs
|
|
101
158
|
def to_js(options = {})
|
102
159
|
concat options, @val, sym, @val2
|
103
160
|
end
|
104
|
-
end
|
105
|
-
|
106
|
-
#
|
107
|
-
# ""
|
108
|
-
#
|
109
|
-
class ExpEmpty < Exp
|
110
|
-
def deep_dup
|
111
|
-
self.class.new
|
112
|
-
end
|
113
161
|
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
162
|
+
# def reduce(parent)
|
163
|
+
# if @val.kind_of?(Literal) and !@val.kind_of? IdentifierName
|
164
|
+
# #TODO
|
165
|
+
# end
|
166
|
+
# end
|
120
167
|
end
|
121
168
|
|
122
169
|
#
|
@@ -130,7 +177,7 @@ module Minjs
|
|
130
177
|
end
|
131
178
|
|
132
179
|
def priority
|
133
|
-
|
180
|
+
PRIORITY_PRIMARY
|
134
181
|
end
|
135
182
|
|
136
183
|
def deep_dup
|
@@ -165,6 +212,11 @@ module Minjs
|
|
165
212
|
if @val.kind_of? ExpParen
|
166
213
|
@val = @val.val if @val.remove_paren?
|
167
214
|
end
|
215
|
+
self
|
216
|
+
end
|
217
|
+
|
218
|
+
def add_paren
|
219
|
+
self
|
168
220
|
end
|
169
221
|
end
|
170
222
|
#
|
@@ -176,7 +228,7 @@ module Minjs
|
|
176
228
|
#
|
177
229
|
class ExpPropBrac < ExpArg2
|
178
230
|
def priority
|
179
|
-
|
231
|
+
PRIORITY_LEFT_HAND_SIDE
|
180
232
|
end
|
181
233
|
|
182
234
|
def traverse(parent, &block)
|
@@ -190,12 +242,20 @@ module Minjs
|
|
190
242
|
end
|
191
243
|
|
192
244
|
def remove_paren
|
193
|
-
if @val.kind_of? ExpParen and @val.val.priority <=
|
245
|
+
if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
|
194
246
|
@val = @val.val if @val.remove_paren?
|
195
247
|
end
|
196
248
|
if @val2.kind_of? ExpParen
|
197
249
|
@val2 = @val2.val
|
198
250
|
end
|
251
|
+
self
|
252
|
+
end
|
253
|
+
|
254
|
+
def add_paren
|
255
|
+
if @val.priority > PRIORITY_LEFT_HAND_SIDE
|
256
|
+
@val = ExpPare.new(@val)
|
257
|
+
end
|
258
|
+
self
|
199
259
|
end
|
200
260
|
end
|
201
261
|
#
|
@@ -212,7 +272,7 @@ module Minjs
|
|
212
272
|
end
|
213
273
|
|
214
274
|
def priority
|
215
|
-
|
275
|
+
PRIORITY_LEFT_HAND_SIDE
|
216
276
|
end
|
217
277
|
|
218
278
|
def traverse(parent, &block)
|
@@ -226,9 +286,17 @@ module Minjs
|
|
226
286
|
end
|
227
287
|
|
228
288
|
def remove_paren
|
229
|
-
if @val.kind_of? ExpParen and @val.val.priority <=
|
289
|
+
if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
|
230
290
|
@val = @val.val if @val.remove_paren?
|
231
291
|
end
|
292
|
+
self
|
293
|
+
end
|
294
|
+
|
295
|
+
def add_paren
|
296
|
+
if @val.priority > PRIORITY_LEFT_HAND_SIDE
|
297
|
+
@val = ExpPare.new(@val)
|
298
|
+
end
|
299
|
+
self
|
232
300
|
end
|
233
301
|
end
|
234
302
|
#11.2
|
@@ -244,7 +312,7 @@ module Minjs
|
|
244
312
|
end
|
245
313
|
|
246
314
|
def priority
|
247
|
-
|
315
|
+
PRIORITY_LEFT_HAND_SIDE
|
248
316
|
end
|
249
317
|
|
250
318
|
def deep_dup
|
@@ -275,18 +343,35 @@ module Minjs
|
|
275
343
|
end
|
276
344
|
|
277
345
|
def remove_paren
|
278
|
-
if @name.kind_of? ExpParen and @name.val.priority <=
|
346
|
+
if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
|
279
347
|
@name = @name.val if @name.remove_paren?
|
280
348
|
end
|
281
349
|
if @args
|
282
350
|
@args.map! do |arg|
|
283
|
-
if arg.kind_of? ExpParen and arg.val.priority <=
|
351
|
+
if arg.kind_of? ExpParen and arg.val.priority <= PRIORITY_ASSIGNMENT #AssignmentOperators
|
284
352
|
arg.val if arg.remove_paren?
|
285
353
|
else
|
286
354
|
arg
|
287
355
|
end
|
288
356
|
end
|
289
357
|
end
|
358
|
+
self
|
359
|
+
end
|
360
|
+
|
361
|
+
def add_paren
|
362
|
+
if @name.priority > PRIORITY_LEFT_HAND_SIDE
|
363
|
+
@name = ExpPare.new(@name)
|
364
|
+
end
|
365
|
+
if @args
|
366
|
+
@args.map! do |arg|
|
367
|
+
if arg.priority > PRIORITY_ASSIGNMENT
|
368
|
+
ExpParen.new(arg)
|
369
|
+
else
|
370
|
+
arg
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
self
|
290
375
|
end
|
291
376
|
|
292
377
|
end
|
@@ -302,7 +387,7 @@ module Minjs
|
|
302
387
|
end
|
303
388
|
|
304
389
|
def priority
|
305
|
-
|
390
|
+
PRIORITY_LEFT_HAND_SIDE
|
306
391
|
end
|
307
392
|
|
308
393
|
def deep_dup
|
@@ -338,18 +423,35 @@ module Minjs
|
|
338
423
|
end
|
339
424
|
|
340
425
|
def remove_paren
|
341
|
-
if @name.kind_of? ExpParen and @name.val.priority <=
|
426
|
+
if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
|
342
427
|
@name = @name.val if @name.remove_paren?
|
343
428
|
end
|
344
429
|
if @args
|
345
430
|
@args.map! do |arg|
|
346
|
-
if arg.kind_of? ExpParen and arg.val.priority <=
|
431
|
+
if arg.kind_of? ExpParen and arg.val.priority <= PRIORITY_ASSIGNMENT
|
347
432
|
arg.val if arg.remove_paren?
|
348
433
|
else
|
349
434
|
arg
|
350
435
|
end
|
351
436
|
end
|
352
437
|
end
|
438
|
+
self
|
439
|
+
end
|
440
|
+
|
441
|
+
def add_paren
|
442
|
+
if @name.priority > PRIORITY_LEFT_HAND_SIDE
|
443
|
+
@name = ExpParen.new(@name)
|
444
|
+
end
|
445
|
+
if @args
|
446
|
+
@args.map! do |arg|
|
447
|
+
if arg.priority > PRIORITY_ASSIGNMENT
|
448
|
+
ExpParen.new(arg)
|
449
|
+
else
|
450
|
+
arg
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
self
|
353
455
|
end
|
354
456
|
end
|
355
457
|
|
@@ -361,9 +463,11 @@ module Minjs
|
|
361
463
|
def sym
|
362
464
|
"++"
|
363
465
|
end
|
466
|
+
|
364
467
|
def priority
|
365
|
-
|
468
|
+
PRIORITY_POSTFIX
|
366
469
|
end
|
470
|
+
|
367
471
|
def to_js(options = {})
|
368
472
|
concat options, @val, sym
|
369
473
|
end
|
@@ -373,9 +477,11 @@ module Minjs
|
|
373
477
|
def sym
|
374
478
|
"--"
|
375
479
|
end
|
480
|
+
|
376
481
|
def priority
|
377
|
-
|
482
|
+
PRIORITY_POSTFIX
|
378
483
|
end
|
484
|
+
|
379
485
|
def to_js(options = {})
|
380
486
|
concat options, @val, sym
|
381
487
|
end
|
@@ -390,17 +496,24 @@ module Minjs
|
|
390
496
|
"delete"
|
391
497
|
end
|
392
498
|
def priority
|
393
|
-
|
499
|
+
PRIORITY_UNARY
|
394
500
|
end
|
395
501
|
end
|
396
502
|
class ExpVoid < ExpArg1
|
397
503
|
include UnaryOperation
|
504
|
+
|
398
505
|
def sym
|
399
506
|
"void"
|
400
507
|
end
|
508
|
+
|
401
509
|
def priority
|
402
|
-
|
510
|
+
PRIORITY_UNARY
|
511
|
+
end
|
512
|
+
|
513
|
+
def ecma262_typeof
|
514
|
+
:undefined
|
403
515
|
end
|
516
|
+
|
404
517
|
end
|
405
518
|
class ExpTypeof < ExpArg1
|
406
519
|
include UnaryOperation
|
@@ -408,7 +521,11 @@ module Minjs
|
|
408
521
|
"typeof"
|
409
522
|
end
|
410
523
|
def priority
|
411
|
-
|
524
|
+
PRIORITY_UNARY
|
525
|
+
end
|
526
|
+
|
527
|
+
def ecma262_typeof
|
528
|
+
:string
|
412
529
|
end
|
413
530
|
end
|
414
531
|
|
@@ -417,8 +534,9 @@ module Minjs
|
|
417
534
|
def sym
|
418
535
|
"++"
|
419
536
|
end
|
537
|
+
|
420
538
|
def priority
|
421
|
-
|
539
|
+
PRIORITY_UNARY
|
422
540
|
end
|
423
541
|
end
|
424
542
|
class ExpPreDec < ExpArg1
|
@@ -426,8 +544,9 @@ module Minjs
|
|
426
544
|
def sym
|
427
545
|
"--"
|
428
546
|
end
|
547
|
+
|
429
548
|
def priority
|
430
|
-
|
549
|
+
PRIORITY_UNARY
|
431
550
|
end
|
432
551
|
end
|
433
552
|
class ExpPositive < ExpArg1
|
@@ -435,8 +554,9 @@ module Minjs
|
|
435
554
|
def sym
|
436
555
|
"+"
|
437
556
|
end
|
557
|
+
|
438
558
|
def priority
|
439
|
-
|
559
|
+
PRIORITY_UNARY
|
440
560
|
end
|
441
561
|
|
442
562
|
def reduce(parent)
|
@@ -444,6 +564,10 @@ module Minjs
|
|
444
564
|
parent.replace(self, @val)
|
445
565
|
end
|
446
566
|
end
|
567
|
+
|
568
|
+
def ecma262_typeof
|
569
|
+
:number
|
570
|
+
end
|
447
571
|
end
|
448
572
|
|
449
573
|
class ExpNegative < ExpArg1
|
@@ -451,8 +575,9 @@ module Minjs
|
|
451
575
|
def sym
|
452
576
|
"-"
|
453
577
|
end
|
578
|
+
|
454
579
|
def priority
|
455
|
-
|
580
|
+
PRIORITY_UNARY
|
456
581
|
end
|
457
582
|
|
458
583
|
def reduce(parent)
|
@@ -466,14 +591,24 @@ module Minjs
|
|
466
591
|
parent.replace(self, val)
|
467
592
|
end
|
468
593
|
end
|
594
|
+
|
595
|
+
def ecma262_typeof
|
596
|
+
:number
|
597
|
+
end
|
469
598
|
end
|
599
|
+
|
470
600
|
class ExpBitwiseNot < ExpArg1
|
471
601
|
include UnaryOperation
|
472
602
|
def sym
|
473
603
|
"~"
|
474
604
|
end
|
605
|
+
|
475
606
|
def priority
|
476
|
-
|
607
|
+
PRIORITY_UNARY
|
608
|
+
end
|
609
|
+
|
610
|
+
def ecma262_typeof
|
611
|
+
:number
|
477
612
|
end
|
478
613
|
end
|
479
614
|
class ExpLogicalNot < ExpArg1
|
@@ -481,11 +616,47 @@ module Minjs
|
|
481
616
|
def sym
|
482
617
|
"!"
|
483
618
|
end
|
619
|
+
|
484
620
|
def priority
|
485
|
-
|
621
|
+
PRIORITY_UNARY
|
622
|
+
end
|
623
|
+
|
624
|
+
#feature
|
625
|
+
def reduce(parent)
|
626
|
+
if @val.kind_of? ECMA262Numeric and (@val.to_js == "0" || @val.to_js == "1")
|
627
|
+
return
|
628
|
+
end
|
629
|
+
|
630
|
+
if (e = ecma262_eval(:boolean)) != nil
|
631
|
+
if e
|
632
|
+
parent.replace(self, ExpLogicalNot.new(ECMA262Numeric.new(0)))
|
633
|
+
else
|
634
|
+
parent.replace(self, ExpLogicalNot.new(ECMA262Numeric.new(1)))
|
635
|
+
end
|
636
|
+
elsif @val.kind_of? ExpLogicalNot and
|
637
|
+
@val.val.respond_to?(:ecma262_typeof) and
|
638
|
+
@val.val.ecma262_typeof == :boolean
|
639
|
+
parent.replace(self, @val.val)
|
640
|
+
end
|
486
641
|
end
|
487
|
-
end
|
488
642
|
|
643
|
+
def ecma262_eval(type)
|
644
|
+
if @val.respond_to? :ecma262_eval
|
645
|
+
e = @val.ecma262_eval(type)
|
646
|
+
if e.nil?
|
647
|
+
return nil
|
648
|
+
else
|
649
|
+
return !e
|
650
|
+
end
|
651
|
+
else
|
652
|
+
nil
|
653
|
+
end
|
654
|
+
end
|
655
|
+
|
656
|
+
def ecma262_typeof
|
657
|
+
:boolean
|
658
|
+
end
|
659
|
+
end
|
489
660
|
#
|
490
661
|
# 11.5.1 Applying the * Operator
|
491
662
|
#
|
@@ -497,7 +668,13 @@ module Minjs
|
|
497
668
|
end
|
498
669
|
|
499
670
|
def priority
|
500
|
-
|
671
|
+
PRIORITY_MULTIPLICATIVE
|
672
|
+
end
|
673
|
+
|
674
|
+
def swap
|
675
|
+
t = @val
|
676
|
+
@val = @val2
|
677
|
+
@val2 = t
|
501
678
|
end
|
502
679
|
|
503
680
|
def reduce(parent)
|
@@ -537,7 +714,7 @@ module Minjs
|
|
537
714
|
"/"
|
538
715
|
end
|
539
716
|
def priority
|
540
|
-
|
717
|
+
PRIORITY_MULTIPLICATIVE
|
541
718
|
end
|
542
719
|
end
|
543
720
|
|
@@ -550,7 +727,7 @@ module Minjs
|
|
550
727
|
"%"
|
551
728
|
end
|
552
729
|
def priority
|
553
|
-
|
730
|
+
PRIORITY_MULTIPLICATIVE
|
554
731
|
end
|
555
732
|
end
|
556
733
|
|
@@ -564,7 +741,13 @@ module Minjs
|
|
564
741
|
end
|
565
742
|
|
566
743
|
def priority
|
567
|
-
|
744
|
+
PRIORITY_ADDITIVE
|
745
|
+
end
|
746
|
+
|
747
|
+
def swap
|
748
|
+
t = @val
|
749
|
+
@val = @val2
|
750
|
+
@val2 = t
|
568
751
|
end
|
569
752
|
|
570
753
|
def reduce(parent)
|
@@ -617,7 +800,7 @@ module Minjs
|
|
617
800
|
end
|
618
801
|
|
619
802
|
def priority
|
620
|
-
|
803
|
+
PRIORITY_ADDITIVE
|
621
804
|
end
|
622
805
|
|
623
806
|
def reduce(parent)
|
@@ -669,7 +852,7 @@ module Minjs
|
|
669
852
|
"<<"
|
670
853
|
end
|
671
854
|
def priority
|
672
|
-
|
855
|
+
PRIORITY_SHIFT
|
673
856
|
end
|
674
857
|
end
|
675
858
|
#
|
@@ -681,7 +864,7 @@ module Minjs
|
|
681
864
|
">>"
|
682
865
|
end
|
683
866
|
def priority
|
684
|
-
|
867
|
+
PRIORITY_SHIFT
|
685
868
|
end
|
686
869
|
end
|
687
870
|
#
|
@@ -693,7 +876,7 @@ module Minjs
|
|
693
876
|
">>>"
|
694
877
|
end
|
695
878
|
def priority
|
696
|
-
|
879
|
+
PRIORITY_SHIFT
|
697
880
|
end
|
698
881
|
end
|
699
882
|
#
|
@@ -705,7 +888,7 @@ module Minjs
|
|
705
888
|
"<"
|
706
889
|
end
|
707
890
|
def priority
|
708
|
-
|
891
|
+
PRIORITY_RELATIONAL
|
709
892
|
end
|
710
893
|
end
|
711
894
|
|
@@ -718,7 +901,7 @@ module Minjs
|
|
718
901
|
">"
|
719
902
|
end
|
720
903
|
def priority
|
721
|
-
|
904
|
+
PRIORITY_RELATIONAL
|
722
905
|
end
|
723
906
|
end
|
724
907
|
#
|
@@ -730,7 +913,7 @@ module Minjs
|
|
730
913
|
"<="
|
731
914
|
end
|
732
915
|
def priority
|
733
|
-
|
916
|
+
PRIORITY_RELATIONAL
|
734
917
|
end
|
735
918
|
end
|
736
919
|
#
|
@@ -742,7 +925,7 @@ module Minjs
|
|
742
925
|
">="
|
743
926
|
end
|
744
927
|
def priority
|
745
|
-
|
928
|
+
PRIORITY_RELATIONAL
|
746
929
|
end
|
747
930
|
end
|
748
931
|
#
|
@@ -754,7 +937,7 @@ module Minjs
|
|
754
937
|
"instanceof"
|
755
938
|
end
|
756
939
|
def priority
|
757
|
-
|
940
|
+
PRIORITY_RELATIONAL
|
758
941
|
end
|
759
942
|
end
|
760
943
|
#
|
@@ -766,7 +949,7 @@ module Minjs
|
|
766
949
|
"in"
|
767
950
|
end
|
768
951
|
def priority
|
769
|
-
|
952
|
+
PRIORITY_RELATIONAL
|
770
953
|
end
|
771
954
|
end
|
772
955
|
#
|
@@ -778,7 +961,7 @@ module Minjs
|
|
778
961
|
"=="
|
779
962
|
end
|
780
963
|
def priority
|
781
|
-
|
964
|
+
PRIORITY_EQUALITY
|
782
965
|
end
|
783
966
|
end
|
784
967
|
#
|
@@ -790,7 +973,7 @@ module Minjs
|
|
790
973
|
"!="
|
791
974
|
end
|
792
975
|
def priority
|
793
|
-
|
976
|
+
PRIORITY_EQUALITY
|
794
977
|
end
|
795
978
|
end
|
796
979
|
#
|
@@ -801,8 +984,16 @@ module Minjs
|
|
801
984
|
def sym
|
802
985
|
"==="
|
803
986
|
end
|
987
|
+
|
804
988
|
def priority
|
805
|
-
|
989
|
+
PRIORITY_EQUALITY
|
990
|
+
end
|
991
|
+
|
992
|
+
def reduce(parent)
|
993
|
+
if @val.respond_to?(:ecma262_typeof) and @val2.respond_to?(:ecma262_typeof) and
|
994
|
+
@val.ecma262_typeof == @val2.ecma262_typeof
|
995
|
+
parent.replace(self, ExpEq.new(@val, @val2))
|
996
|
+
end
|
806
997
|
end
|
807
998
|
end
|
808
999
|
#
|
@@ -813,8 +1004,16 @@ module Minjs
|
|
813
1004
|
def sym
|
814
1005
|
"!=="
|
815
1006
|
end
|
1007
|
+
|
816
1008
|
def priority
|
817
|
-
|
1009
|
+
PRIORITY_EQUALITY
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
def reduce(parent)
|
1013
|
+
if @val.respond_to?(:ecma262_typeof) and @val2.respond_to?(:ecma262_typeof) and
|
1014
|
+
@val.ecma262_typeof == @val2.ecma262_typeof
|
1015
|
+
parent.replace(self, ExpNotEq.new(@val, @val2))
|
1016
|
+
end
|
818
1017
|
end
|
819
1018
|
end
|
820
1019
|
#
|
@@ -825,8 +1024,15 @@ module Minjs
|
|
825
1024
|
def sym
|
826
1025
|
"&"
|
827
1026
|
end
|
1027
|
+
|
828
1028
|
def priority
|
829
|
-
|
1029
|
+
PRIORITY_BITWISE_AND
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
def swap
|
1033
|
+
t = @val
|
1034
|
+
@val = @val2
|
1035
|
+
@val2 = t
|
830
1036
|
end
|
831
1037
|
end
|
832
1038
|
# ^
|
@@ -835,8 +1041,15 @@ module Minjs
|
|
835
1041
|
def sym
|
836
1042
|
"^"
|
837
1043
|
end
|
1044
|
+
|
838
1045
|
def priority
|
839
|
-
|
1046
|
+
PRIORITY_BITWISE_XOR
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
def swap
|
1050
|
+
t = @val
|
1051
|
+
@val = @val2
|
1052
|
+
@val2 = t
|
840
1053
|
end
|
841
1054
|
end
|
842
1055
|
|
@@ -846,8 +1059,15 @@ module Minjs
|
|
846
1059
|
def sym
|
847
1060
|
"|"
|
848
1061
|
end
|
1062
|
+
|
849
1063
|
def priority
|
850
|
-
|
1064
|
+
PRIORITY_BITWISE_OR
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
def swap
|
1068
|
+
t = @val
|
1069
|
+
@val = @val2
|
1070
|
+
@val2 = t
|
851
1071
|
end
|
852
1072
|
end
|
853
1073
|
#
|
@@ -856,12 +1076,15 @@ module Minjs
|
|
856
1076
|
# &&
|
857
1077
|
class ExpLogicalAnd < ExpArg2
|
858
1078
|
include BinaryOperation
|
1079
|
+
|
859
1080
|
def sym
|
860
1081
|
"&&"
|
861
1082
|
end
|
1083
|
+
|
862
1084
|
def priority
|
863
|
-
|
1085
|
+
PRIORITY_LOGICAL_AND
|
864
1086
|
end
|
1087
|
+
|
865
1088
|
end
|
866
1089
|
# ||
|
867
1090
|
class ExpLogicalOr < ExpArg2
|
@@ -869,8 +1092,9 @@ module Minjs
|
|
869
1092
|
def sym
|
870
1093
|
"||"
|
871
1094
|
end
|
1095
|
+
|
872
1096
|
def priority
|
873
|
-
|
1097
|
+
PRIORITY_LOGICAL_OR
|
874
1098
|
end
|
875
1099
|
end
|
876
1100
|
#
|
@@ -886,19 +1110,33 @@ module Minjs
|
|
886
1110
|
end
|
887
1111
|
|
888
1112
|
def priority
|
889
|
-
|
1113
|
+
PRIORITY_CONDITIONAL
|
890
1114
|
end
|
891
1115
|
|
892
1116
|
def remove_paren
|
893
|
-
if @val.kind_of? ExpParen and @val.val.priority <
|
1117
|
+
if @val.kind_of? ExpParen and @val.val.priority < PRIORITY_CONDITIONAL
|
894
1118
|
@val = @val.val if @val.remove_paren?
|
895
1119
|
end
|
896
|
-
if @val2.kind_of? ExpParen and @val2.val.priority <=
|
1120
|
+
if @val2.kind_of? ExpParen and @val2.val.priority <= PRIORITY_ASSIGNMENT
|
897
1121
|
@val2 = @val2.val
|
898
1122
|
end
|
899
|
-
if @val3.kind_of? ExpParen and @val3.val.priority <=
|
1123
|
+
if @val3.kind_of? ExpParen and @val3.val.priority <= PRIORITY_ASSIGNMENT
|
900
1124
|
@val3 = @val3.val
|
901
1125
|
end
|
1126
|
+
self
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
def add_paren
|
1130
|
+
if @val.priority > PRIORITY_CONDITIONAL
|
1131
|
+
@val = ExpParen.new(@val)
|
1132
|
+
end
|
1133
|
+
if @val2.priority > PRIORITY_ASSIGNMENT
|
1134
|
+
@val2 = ExpParen.new(@val2)
|
1135
|
+
end
|
1136
|
+
if @val3.priority > PRIORITY_ASSIGNMENT
|
1137
|
+
@val3 = ExpParen.new(@val3)
|
1138
|
+
end
|
1139
|
+
self
|
902
1140
|
end
|
903
1141
|
|
904
1142
|
def deep_dup
|
@@ -934,8 +1172,60 @@ module Minjs
|
|
934
1172
|
def sym
|
935
1173
|
"="
|
936
1174
|
end
|
1175
|
+
|
937
1176
|
def priority
|
938
|
-
|
1177
|
+
PRIORITY_ASSIGNMENT
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
def reduce(parent)
|
1181
|
+
#
|
1182
|
+
# a = a / b => a /= b
|
1183
|
+
#
|
1184
|
+
if @val2.kind_of? ExpDiv and @val2.val == @val
|
1185
|
+
parent.replace(self,
|
1186
|
+
ExpParen.new(
|
1187
|
+
ExpDivAssign.new(@val, @val2.val2)))
|
1188
|
+
elsif @val2.kind_of? ExpMul and @val2.val == @val
|
1189
|
+
parent.replace(self,
|
1190
|
+
ExpParen.new(
|
1191
|
+
ExpMulAssign.new(@val, @val2.val2)))
|
1192
|
+
elsif @val2.kind_of? ExpMod and @val2.val == @val
|
1193
|
+
parent.replace(self,
|
1194
|
+
ExpParen.new(
|
1195
|
+
ExpModAssign.new(@val, @val2.val2)))
|
1196
|
+
elsif @val2.kind_of? ExpAdd and @val2.val == @val
|
1197
|
+
parent.replace(self,
|
1198
|
+
ExpParen.new(
|
1199
|
+
ExpAddAssign.new(@val, @val2.val2)))
|
1200
|
+
elsif @val2.kind_of? ExpSub and @val2.val == @val
|
1201
|
+
parent.replace(self,
|
1202
|
+
ExpParen.new(
|
1203
|
+
ExpSubAssign.new(@val, @val2.val2)))
|
1204
|
+
elsif @val2.kind_of? ExpLShift and @val2.val == @val
|
1205
|
+
parent.replace(self,
|
1206
|
+
ExpParen.new(
|
1207
|
+
ExpLShiftAssign.new(@val, @val2.val2)))
|
1208
|
+
elsif @val2.kind_of? ExpRShift and @val2.val == @val
|
1209
|
+
parent.replace(self,
|
1210
|
+
ExpParen.new(
|
1211
|
+
ExpRShiftAssign.new(@val, @val2.val2)))
|
1212
|
+
elsif @val2.kind_of? ExpURShift and @val2.val == @val
|
1213
|
+
parent.replace(self,
|
1214
|
+
ExpParen.new(
|
1215
|
+
ExpURShiftAssign.new(@val, @val2.val2)))
|
1216
|
+
elsif @val2.kind_of? ExpAnd and @val2.val == @val
|
1217
|
+
parent.replace(self,
|
1218
|
+
ExpParen.new(
|
1219
|
+
ExpAndAssign.new(@val, @val2.val2)))
|
1220
|
+
elsif @val2.kind_of? ExpOr and @val2.val == @val
|
1221
|
+
parent.replace(self,
|
1222
|
+
ExpParen.new(
|
1223
|
+
ExpOrAssign.new(@val, @val2.val2)))
|
1224
|
+
elsif @val2.kind_of? ExpXor and @val2.val == @val
|
1225
|
+
parent.replace(self,
|
1226
|
+
ExpParen.new(
|
1227
|
+
ExpXorAssign.new(@val, @val2.val2)))
|
1228
|
+
end
|
939
1229
|
end
|
940
1230
|
end
|
941
1231
|
class ExpDivAssign < ExpAssign
|
@@ -944,7 +1234,7 @@ module Minjs
|
|
944
1234
|
"/="
|
945
1235
|
end
|
946
1236
|
def priority
|
947
|
-
|
1237
|
+
PRIORITY_ASSIGNMENT
|
948
1238
|
end
|
949
1239
|
end
|
950
1240
|
class ExpMulAssign < ExpAssign
|
@@ -953,7 +1243,7 @@ module Minjs
|
|
953
1243
|
"*="
|
954
1244
|
end
|
955
1245
|
def priority
|
956
|
-
|
1246
|
+
PRIORITY_ASSIGNMENT
|
957
1247
|
end
|
958
1248
|
end
|
959
1249
|
class ExpModAssign < ExpAssign
|
@@ -962,7 +1252,7 @@ module Minjs
|
|
962
1252
|
"%="
|
963
1253
|
end
|
964
1254
|
def priority
|
965
|
-
|
1255
|
+
PRIORITY_ASSIGNMENT
|
966
1256
|
end
|
967
1257
|
end
|
968
1258
|
class ExpAddAssign < ExpAssign
|
@@ -971,7 +1261,7 @@ module Minjs
|
|
971
1261
|
"+="
|
972
1262
|
end
|
973
1263
|
def priority
|
974
|
-
|
1264
|
+
PRIORITY_ASSIGNMENT
|
975
1265
|
end
|
976
1266
|
end
|
977
1267
|
class ExpSubAssign < ExpAssign
|
@@ -980,7 +1270,7 @@ module Minjs
|
|
980
1270
|
"-="
|
981
1271
|
end
|
982
1272
|
def priority
|
983
|
-
|
1273
|
+
PRIORITY_ASSIGNMENT
|
984
1274
|
end
|
985
1275
|
end
|
986
1276
|
class ExpLShiftAssign < ExpAssign
|
@@ -989,7 +1279,7 @@ module Minjs
|
|
989
1279
|
"<<="
|
990
1280
|
end
|
991
1281
|
def priority
|
992
|
-
|
1282
|
+
PRIORITY_ASSIGNMENT
|
993
1283
|
end
|
994
1284
|
end
|
995
1285
|
class ExpRShiftAssign < ExpAssign
|
@@ -998,7 +1288,7 @@ module Minjs
|
|
998
1288
|
">>="
|
999
1289
|
end
|
1000
1290
|
def priority
|
1001
|
-
|
1291
|
+
PRIORITY_ASSIGNMENT
|
1002
1292
|
end
|
1003
1293
|
end
|
1004
1294
|
class ExpURShiftAssign < ExpAssign
|
@@ -1007,7 +1297,7 @@ module Minjs
|
|
1007
1297
|
">>>="
|
1008
1298
|
end
|
1009
1299
|
def priority
|
1010
|
-
|
1300
|
+
PRIORITY_ASSIGNMENT
|
1011
1301
|
end
|
1012
1302
|
end
|
1013
1303
|
class ExpAndAssign < ExpAssign
|
@@ -1016,7 +1306,7 @@ module Minjs
|
|
1016
1306
|
"&="
|
1017
1307
|
end
|
1018
1308
|
def priority
|
1019
|
-
|
1309
|
+
PRIORITY_ASSIGNMENT
|
1020
1310
|
end
|
1021
1311
|
end
|
1022
1312
|
class ExpOrAssign < ExpAssign
|
@@ -1025,7 +1315,7 @@ module Minjs
|
|
1025
1315
|
"|="
|
1026
1316
|
end
|
1027
1317
|
def priority
|
1028
|
-
|
1318
|
+
PRIORITY_ASSIGNMENT
|
1029
1319
|
end
|
1030
1320
|
end
|
1031
1321
|
class ExpXorAssign < ExpAssign
|
@@ -1034,7 +1324,7 @@ module Minjs
|
|
1034
1324
|
"^="
|
1035
1325
|
end
|
1036
1326
|
def priority
|
1037
|
-
|
1327
|
+
PRIORITY_ASSIGNMENT
|
1038
1328
|
end
|
1039
1329
|
end
|
1040
1330
|
#
|
@@ -1045,8 +1335,9 @@ module Minjs
|
|
1045
1335
|
def sym
|
1046
1336
|
","
|
1047
1337
|
end
|
1338
|
+
|
1048
1339
|
def priority
|
1049
|
-
|
1340
|
+
PRIORITY_COMMA
|
1050
1341
|
end
|
1051
1342
|
end
|
1052
1343
|
end
|