minjs 0.3.0 → 0.4.0

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.
@@ -1,46 +1,70 @@
1
1
  module Minjs
2
2
  module ECMA262
3
+ #priority
3
4
  PRIORITY_PRIMARY = 10
5
+ #priority
4
6
  PRIORITY_LEFT_HAND_SIDE = 20
7
+ #priority
5
8
  PRIORITY_POSTFIX = 30
9
+ #priority
6
10
  PRIORITY_UNARY = 40
11
+ #priority
7
12
  PRIORITY_MULTIPLICATIVE = 50
13
+ #priority
8
14
  PRIORITY_ADDITIVE = 60
15
+ #priority
9
16
  PRIORITY_SHIFT = 70
17
+ #priority
10
18
  PRIORITY_RELATIONAL = 80
19
+ #priority
11
20
  PRIORITY_EQUALITY = 90
21
+ #priority
12
22
  PRIORITY_BITWISE_AND = 100
23
+ #priority
13
24
  PRIORITY_BITWISE_XOR = 106
25
+ #priority
14
26
  PRIORITY_BITWISE_OR = 108
27
+ #priority
15
28
  PRIORITY_LOGICAL_AND = 110
29
+ #priority
16
30
  PRIORITY_LOGICAL_OR = 116
31
+ #priority
17
32
  PRIORITY_CONDITIONAL = 120
33
+ #priority
18
34
  PRIORITY_ASSIGNMENT = 130
35
+ #priority
19
36
  PRIORITY_COMMA = 140
20
37
 
21
- class Exp < Base
22
- def traverse
23
- yield(self)
24
- end
25
-
26
- def to_js(options = {})
27
- raise "internal error"
28
- end
29
-
38
+ # Base class of ECMA262 expression element
39
+ class Expression < Base
40
+ # reduce expression if available
41
+ # @param parent [Base] parent element
30
42
  def reduce(parent)
31
43
  end
32
44
 
45
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
33
46
  def left_hand_side_exp?
34
47
  false
35
48
  end
36
49
 
50
+ # @return [Fixnum] expression priority
37
51
  def priority
38
- 9999
52
+ 999
39
53
  end
40
54
 
55
+ def side_effect?
56
+ return true
57
+ end
41
58
  end
42
59
 
60
+ # Module of typically binary operation expression.
61
+ #
62
+ # Typically binary operation expression has two
63
+ # values(val, val2) and operation symbol.
43
64
  module BinaryOperation
65
+ attr_reader :val, :val2
66
+
67
+ # remove parenthesis if possible
44
68
  def remove_paren
45
69
  if @val.kind_of? ExpParen and @val.val.priority <= self.priority
46
70
  @val = @val.val if @val.remove_paren?
@@ -51,6 +75,7 @@ module Minjs
51
75
  self
52
76
  end
53
77
 
78
+ # add parenthesis if need
54
79
  def add_paren
55
80
  if @val.priority > self.priority
56
81
  @val = ExpParen.new(@val)
@@ -62,19 +87,59 @@ module Minjs
62
87
  self
63
88
  end
64
89
 
90
+ # compare object
65
91
  def ==(obj)
66
92
  self.class == obj.class and self.val == obj.val and self.val2 == obj.val2
67
93
  end
94
+
95
+ # duplicate object
96
+ # @see Base#deep_dup
97
+ def deep_dup
98
+ self.class.new(@val.deep_dup, @val2.deep_dup)
99
+ end
100
+
101
+ # Replaces children object.
102
+ # @see Base#replace
103
+ def replace(from, to)
104
+ if @val .eql? from
105
+ @val = to
106
+ elsif @val2 .eql? from
107
+ @val2 = to
108
+ end
109
+ end
110
+
111
+ # Traverses this children and itself with given block.
112
+ # @see Base#traverse
113
+ def traverse(parent, &block)
114
+ @val.traverse(self, &block)
115
+ @val2.traverse(self, &block)
116
+ yield parent, self
117
+ end
118
+
119
+ # Returns a ECMAScript string containg the representation of element.
120
+ # @see Base#to_js
121
+ def to_js(options = {})
122
+ concat options, @val, sym, @val2
123
+ end
68
124
  end
69
125
 
126
+ # Module of typically unary operation expression.
127
+ #
128
+ # Typically unary operation expression has one
129
+ # values(val) and operation symbol.
130
+ #
70
131
  module UnaryOperation
132
+ attr_reader :val
133
+
134
+ # remove parenthesis if possible
71
135
  def remove_paren
72
136
  if @val.kind_of? ExpParen and @val.val.priority <= self.priority
73
- @val = @val.val if @val.remove_paren?
137
+ @val = @val.val
74
138
  end
75
139
  self
76
140
  end
77
141
 
142
+ # add parenthesis if need
78
143
  def add_paren
79
144
  if @val.priority > self.priority
80
145
  @val = ExpParen.new(@val)
@@ -83,12 +148,53 @@ module Minjs
83
148
  self
84
149
  end
85
150
 
151
+ # compare object
86
152
  def ==(obj)
87
153
  self.class == obj.class and self.val == obj.val
88
154
  end
155
+
156
+ # duplicate object
157
+ # @see Base#deep_dup
158
+ def deep_dup
159
+ self.class.new(@val.deep_dup)
160
+ end
161
+
162
+ # Replaces children object.
163
+ # @see Base#replace
164
+ def replace(from, to)
165
+ if @val .eql? from
166
+ @val = to
167
+ end
168
+ end
169
+
170
+ # Traverses this children and itself with given block.
171
+ # @see Base#traverse
172
+ def traverse(parent, &block)
173
+ @val.traverse(self, &block)
174
+ yield parent, self
175
+ end
176
+
177
+ # Returns a ECMAScript string containg the representation of element.
178
+ # @see Base#to_js
179
+ def to_js(options = {})
180
+ concat options, sym, @val
181
+ end
182
+
183
+ # Returns this element has side effect or not.
184
+ # @return [Boolean]
185
+ def side_effect?
186
+ @val.side_effect?
187
+ end
89
188
  end
90
189
 
190
+ # Module of typically Assignment operation.
191
+ #
192
+ # Typically unary operation expression has left-hand value(val)
193
+ # and right-hand value(val2)
91
194
  module AssignmentOperation
195
+ attr_reader :val, :val2
196
+
197
+ # remove parenthesis if possible
92
198
  def remove_paren
93
199
  if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
94
200
  @val = @val.val if @val.remove_paren?
@@ -99,6 +205,7 @@ module Minjs
99
205
  self
100
206
  end
101
207
 
208
+ # add parenthesis if need
102
209
  def add_paren
103
210
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
104
211
  @val = ExpParen.new(@val)
@@ -109,10 +216,15 @@ module Minjs
109
216
  self
110
217
  end
111
218
 
219
+ # compare object
112
220
  def ==(obj)
113
221
  self.class == obj.class and self.val == obj.val and self.val2 == obj.val2
114
222
  end
115
223
 
224
+ # return results of 'typeof' operator.
225
+ #
226
+ # @return [Symbol] type of right-side-hand expression
227
+ # or nil if typeof value is undetermined.
116
228
  def ecma262_typeof
117
229
  if @val2.respond_to? :ecma262_typeof
118
230
  @val2.ecma262_typeof
@@ -120,51 +232,14 @@ module Minjs
120
232
  nil
121
233
  end
122
234
  end
123
- end
124
-
125
- class ExpArg1 < Exp
126
- attr_reader :val
127
-
128
- def initialize(val)
129
- @val = val
130
- end
131
-
132
- def deep_dup
133
- self.class.new(@val.deep_dup)
134
- end
135
-
136
- def replace(from, to)
137
- if @val .eql? from
138
- @val = to
139
- end
140
- end
141
-
142
- def traverse(parent, &block)
143
- @val.traverse(self, &block)
144
- yield self, parent
145
- end
146
-
147
- def to_js(options = {})
148
- concat options, sym, @val
149
- end
150
-
151
- def left_hand_side_exp?
152
- true
153
- end
154
- end
155
-
156
- class ExpArg2 < Exp
157
- attr_reader :val, :val2
158
-
159
- def initialize(val, val2)
160
- @val = val
161
- @val2 = val2
162
- end
163
-
235
+ # duplicate object
236
+ # @see Base#deep_dup
164
237
  def deep_dup
165
238
  self.class.new(@val.deep_dup, @val2.deep_dup)
166
239
  end
167
240
 
241
+ # Replaces children object.
242
+ # @see Base#replace
168
243
  def replace(from, to)
169
244
  if @val .eql? from
170
245
  @val = to
@@ -173,58 +248,132 @@ module Minjs
173
248
  end
174
249
  end
175
250
 
251
+ # Traverses this children and itself with given block.
252
+ # @see Base#traverse
176
253
  def traverse(parent, &block)
177
254
  @val.traverse(self, &block)
178
255
  @val2.traverse(self, &block)
179
- yield self, parent
256
+ yield parent, self
180
257
  end
181
258
 
259
+ # Returns a ECMAScript string containg the representation of element.
260
+ # @see Base#to_js
182
261
  def to_js(options = {})
183
262
  concat options, @val, sym, @val2
184
263
  end
185
- end
186
264
 
265
+ # reduce expression if available
266
+ # @param parent [Base] parent element
267
+ def reduce(parent)
268
+ #
269
+ # a = a / b => a /= b
270
+ #
271
+ if @val2.kind_of? ExpDiv and @val2.val == @val
272
+ parent.replace(self,
273
+ ExpParen.new(
274
+ ExpDivAssign.new(@val, @val2.val2)))
275
+ elsif @val2.kind_of? ExpMul and @val2.val == @val
276
+ parent.replace(self,
277
+ ExpParen.new(
278
+ ExpMulAssign.new(@val, @val2.val2)))
279
+ elsif @val2.kind_of? ExpMod and @val2.val == @val
280
+ parent.replace(self,
281
+ ExpParen.new(
282
+ ExpModAssign.new(@val, @val2.val2)))
283
+ elsif @val2.kind_of? ExpAdd and @val2.val == @val
284
+ parent.replace(self,
285
+ ExpParen.new(
286
+ ExpAddAssign.new(@val, @val2.val2)))
287
+ elsif @val2.kind_of? ExpSub and @val2.val == @val
288
+ parent.replace(self,
289
+ ExpParen.new(
290
+ ExpSubAssign.new(@val, @val2.val2)))
291
+ elsif @val2.kind_of? ExpLShift and @val2.val == @val
292
+ parent.replace(self,
293
+ ExpParen.new(
294
+ ExpLShiftAssign.new(@val, @val2.val2)))
295
+ elsif @val2.kind_of? ExpRShift and @val2.val == @val
296
+ parent.replace(self,
297
+ ExpParen.new(
298
+ ExpRShiftAssign.new(@val, @val2.val2)))
299
+ elsif @val2.kind_of? ExpURShift and @val2.val == @val
300
+ parent.replace(self,
301
+ ExpParen.new(
302
+ ExpURShiftAssign.new(@val, @val2.val2)))
303
+ elsif @val2.kind_of? ExpAnd and @val2.val == @val
304
+ parent.replace(self,
305
+ ExpParen.new(
306
+ ExpAndAssign.new(@val, @val2.val2)))
307
+ elsif @val2.kind_of? ExpOr and @val2.val == @val
308
+ parent.replace(self,
309
+ ExpParen.new(
310
+ ExpOrAssign.new(@val, @val2.val2)))
311
+ elsif @val2.kind_of? ExpXor and @val2.val == @val
312
+ parent.replace(self,
313
+ ExpParen.new(
314
+ ExpXorAssign.new(@val, @val2.val2)))
315
+ end
316
+ end
317
+ end
318
+ # Class of the Grouping operator expression element.
187
319
  #
188
- # 11.1 primary expression
189
- #
190
- class ExpParen < Exp
320
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.1.6
321
+ class ExpParen < Expression
191
322
  attr_reader :val
192
323
 
193
324
  def initialize(val)
194
325
  @val = val
195
326
  end
196
327
 
328
+ # @return [Fixnum] expression priority
197
329
  def priority
198
330
  PRIORITY_PRIMARY
199
331
  end
200
332
 
333
+ # duplicate object
334
+ # @see Base#deep_dup
201
335
  def deep_dup
202
336
  self.class.new(@val.deep_dup)
203
337
  end
204
338
 
339
+ # Replaces children object.
340
+ # @see Base#replace
205
341
  def replace(from, to)
206
342
  if @val .eql? from
207
343
  @val = to
208
344
  end
209
345
  end
210
346
 
347
+ # Traverses this children and itself with given block.
348
+ # @see Base#traverse
211
349
  def traverse(parent, &block)
212
350
  @val.traverse(self, &block)
213
- yield self, parent
351
+ yield parent, self
214
352
  end
215
353
 
354
+ # compare object
216
355
  def ==(obj)
217
356
  self.class == obj.class and @val == obj.val
218
357
  end
219
358
 
359
+ # Returns a ECMAScript string containg the representation of element.
360
+ # @see Base#to_js
220
361
  def to_js(options = {})
221
362
  "(#{@val.to_js(options)})"
222
363
  end
223
364
 
365
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
224
366
  def left_hand_side_exp?
225
367
  true
226
368
  end
227
369
 
370
+ # returns removing parenthesis is possible or not
371
+ #
372
+ # ECMA262 expression-statement should not start with
373
+ # "function" or "{".
374
+ # This method checks inner of the parenthesis' first literal.
375
+ #
376
+ # @return [Boolean] true if possible
228
377
  def remove_paren?
229
378
  js = @val.to_js
230
379
  if js.match(/^function/) or js.match(/^{/)
@@ -234,6 +383,7 @@ module Minjs
234
383
  end
235
384
  end
236
385
 
386
+ # remove parenthesis if possible
237
387
  def remove_paren
238
388
  if @val.kind_of? ExpParen
239
389
  @val = @val.val if @val.remove_paren?
@@ -241,16 +391,28 @@ module Minjs
241
391
  self
242
392
  end
243
393
 
394
+ # add parenthesis if need
244
395
  def add_paren
245
396
  self
246
397
  end
247
398
 
399
+ # Returns results of ToBoolean()
400
+ #
401
+ # Returns _true_ or _false_ if trivial,
402
+ # otherwise nil.
403
+ #
404
+ # @return [Boolean]
405
+ #
406
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 9.2
248
407
  def to_ecma262_boolean
249
408
  return nil unless @val.respond_to? :to_ecma262_boolean
250
409
  return nil if @val.to_ecma262_boolean.nil?
251
410
  @val.to_ecma262_boolean
252
411
  end
253
412
 
413
+ # return results of 'typeof' operator.
414
+ #
415
+ # @return [Symbol] type of val
254
416
  def ecma262_typeof
255
417
  if @val.respond_to? :ecma262_typeof
256
418
  @val.ecma262_typeof
@@ -259,38 +421,69 @@ module Minjs
259
421
  end
260
422
  end
261
423
  end
424
+ # Class of the Property Accessors expression element.
262
425
  #
263
- # 11.2 Left-Hand-Side Expressions
264
- #
265
- # function expression: see st.rb:StFunc
426
+ # This is another expression of ExpProp.
427
+ # This class uses bracket instead of period.
266
428
  #
267
- # 11.2.1 Property Accessors val[val2]
268
- #
269
- class ExpPropBrac < ExpArg2
429
+ # @see ExpProp
430
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.2.1
431
+ class ExpPropBrac < Expression
432
+ attr_reader :val, :val2
433
+
434
+ def initialize(val, val2)
435
+ @val = val
436
+ @val2 = val2
437
+ end
438
+
439
+ # duplicate object
440
+ # @see Base#deep_dup
441
+ def deep_dup
442
+ self.class.new(@val.deep_dup, @val2.deep_dup)
443
+ end
444
+
445
+ # Replaces children object.
446
+ # @see Base#replace
447
+ def replace(from, to)
448
+ if @val .eql? from
449
+ @val = to
450
+ elsif @val2 .eql? from
451
+ @val2 = to
452
+ end
453
+ end
454
+
455
+ # @return [Fixnum] expression priority
270
456
  def priority
271
457
  PRIORITY_LEFT_HAND_SIDE
272
458
  end
273
459
 
460
+ # Traverses this children and itself with given block.
461
+ # @see Base#traverse
274
462
  def traverse(parent, &block)
275
463
  @val.traverse(self, &block)
276
464
  @val2.traverse(self, &block)
277
- yield self, parent
465
+ yield parent, self
278
466
  end
279
467
 
468
+ # compare object
280
469
  def ==(obj)
281
470
  self.class == obj.class and
282
471
  @val == obj.val and
283
472
  @val2 == obj.val2
284
473
  end
285
474
 
475
+ # Returns a ECMAScript string containg the representation of element.
476
+ # @see Base#to_js
286
477
  def to_js(options = {})
287
478
  "#{@val.to_js(options)}[#{@val2.to_js(options)}]"
288
479
  end
289
480
 
481
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
290
482
  def left_hand_side_exp?
291
483
  true
292
484
  end
293
485
 
486
+ # remove parenthesis if possible
294
487
  def remove_paren
295
488
  if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
296
489
  @val = @val.val if @val.remove_paren?
@@ -301,6 +494,7 @@ module Minjs
301
494
  self
302
495
  end
303
496
 
497
+ # add parenthesis if need
304
498
  def add_paren
305
499
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
306
500
  @val = ExpParen.new(@val)
@@ -308,10 +502,16 @@ module Minjs
308
502
  self
309
503
  end
310
504
  end
505
+ # Class of the Property Accessors expression element.
311
506
  #
312
- # => val.val2
507
+ # This is another expression of ExpPropBrac.
508
+ # This class uses period insted of bracket.
313
509
  #
314
- class ExpProp < ExpArg2
510
+ # @see ExpPropBrac
511
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.2.1
512
+ class ExpProp < Expression
513
+ attr_reader :val, :val2
514
+
315
515
  def initialize(val, val2)
316
516
  @val = val
317
517
  if val2.kind_of? IdentifierName
@@ -321,30 +521,54 @@ module Minjs
321
521
  end
322
522
  end
323
523
 
524
+ # duplicate object
525
+ # @see Base#deep_dup
526
+ def deep_dup
527
+ self.class.new(@val.deep_dup, @val2.deep_dup)
528
+ end
529
+
530
+ # @return [Fixnum] expression priority
324
531
  def priority
325
532
  PRIORITY_LEFT_HAND_SIDE
326
533
  end
327
534
 
535
+ # Replaces children object.
536
+ # @see Base#replace
537
+ def replace(from, to)
538
+ if @val .eql? from
539
+ @val = to
540
+ elsif @val2 .eql? from
541
+ @val2 = to
542
+ end
543
+ end
544
+
545
+ # Traverses this children and itself with given block.
546
+ # @see Base#traverse
328
547
  def traverse(parent, &block)
329
548
  @val.traverse(self, &block)
330
549
  @val2.traverse(self, &block)
331
- yield self, parent
550
+ yield parent, self
332
551
  end
333
552
 
553
+ # compare object
334
554
  def ==(obj)
335
555
  self.class == obj.class and
336
556
  @val == obj.val and
337
557
  @val2 == obj.val2
338
558
  end
339
559
 
560
+ # Returns a ECMAScript string containg the representation of element.
561
+ # @see Base#to_js
340
562
  def to_js(options = {})
341
563
  "#{@val.to_js(options)}.#{@val2.val}"
342
564
  end
343
565
 
566
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
344
567
  def left_hand_side_exp?
345
568
  true
346
569
  end
347
570
 
571
+ # remove parenthesis if possible
348
572
  def remove_paren
349
573
  if @val.kind_of? ExpParen and @val.val.priority <= PRIORITY_LEFT_HAND_SIDE
350
574
  @val = @val.val if @val.remove_paren?
@@ -352,6 +576,7 @@ module Minjs
352
576
  self
353
577
  end
354
578
 
579
+ # add parenthesis if need
355
580
  def add_paren
356
581
  if @val.priority > PRIORITY_LEFT_HAND_SIDE
357
582
  @val = ExpParen.new(@val)
@@ -359,10 +584,10 @@ module Minjs
359
584
  self
360
585
  end
361
586
  end
362
- #11.2
363
- # => name(args)
587
+ # Class of the Call expression element.
364
588
  #
365
- class ExpCall < Exp
589
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.2
590
+ class ExpCall < Expression
366
591
  attr_reader :name
367
592
  attr_reader :args
368
593
 
@@ -371,15 +596,20 @@ module Minjs
371
596
  @args = args
372
597
  end
373
598
 
599
+ # @return [Fixnum] expression priority
374
600
  def priority
375
601
  PRIORITY_LEFT_HAND_SIDE
376
602
  end
377
603
 
604
+ # duplicate object
605
+ # @see Base#deep_dup
378
606
  def deep_dup
379
607
  self.class.new(@name.deep_dup,
380
608
  @args ? @args.collect{|x| x.deep_dup} : nil)
381
609
  end
382
610
 
611
+ # Replaces children object.
612
+ # @see Base#replace
383
613
  def replace(from, to)
384
614
  if @name .eql? from
385
615
  @name = to
@@ -394,27 +624,33 @@ module Minjs
394
624
  end
395
625
  end
396
626
 
627
+ # Traverses this children and itself with given block.
397
628
  def traverse(parent, &block)
398
629
  @name.traverse(self, &block)
399
630
  @args.each do |x|
400
631
  x.traverse(self, &block)
401
632
  end
402
- yield self, parent
633
+ yield parent, self
403
634
  end
404
635
 
636
+ # compare object
405
637
  def ==(obj)
406
638
  self.class == obj.class and @name == obj.name and @args == obj.args
407
639
  end
408
640
 
641
+ # Returns a ECMAScript string containg the representation of element.
642
+ # @see Base#to_js
409
643
  def to_js(options = {})
410
644
  args = @args.collect{|x| x.to_js(options)}.join(",")
411
645
  "#{@name.to_js(options)}(#{args})"
412
646
  end
413
647
 
648
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
414
649
  def left_hand_side_exp?
415
650
  true
416
651
  end
417
652
 
653
+ # remove parenthesis if possible
418
654
  def remove_paren
419
655
  if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
420
656
  @name = @name.val if @name.remove_paren?
@@ -431,6 +667,7 @@ module Minjs
431
667
  self
432
668
  end
433
669
 
670
+ # add parenthesis if need
434
671
  def add_paren
435
672
  if @name.priority > PRIORITY_LEFT_HAND_SIDE
436
673
  @name = ExpParen.new(@name)
@@ -449,11 +686,10 @@ module Minjs
449
686
 
450
687
  end
451
688
 
689
+ # Class of the New expression element.
452
690
  #
453
- # new M
454
- # new M(a,b,c...)
455
- #
456
- class ExpNew < Exp
691
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.2
692
+ class ExpNew < Expression
457
693
  attr_reader :name, :args
458
694
 
459
695
  def initialize(name, args)
@@ -461,15 +697,20 @@ module Minjs
461
697
  @args = args
462
698
  end
463
699
 
700
+ # @return [Fixnum] expression priority
464
701
  def priority
465
702
  PRIORITY_LEFT_HAND_SIDE + ((args == nil) ? 1 : 0)
466
703
  end
467
704
 
705
+ # duplicate object
706
+ # @see Base#deep_dup
468
707
  def deep_dup
469
708
  self.class.new(@name,
470
709
  @args ? @args.collect{|x| x.deep_dup} : nil)
471
710
  end
472
711
 
712
+ # Replaces children object.
713
+ # @see Base#replace
473
714
  def replace(from, to)
474
715
  if @name .eql? from
475
716
  @name = from
@@ -480,6 +721,8 @@ module Minjs
480
721
  end
481
722
  end
482
723
 
724
+ # Traverses this children and itself with given block.
725
+ # @see Base#traverse
483
726
  def traverse(parent, &block)
484
727
  @name.traverse(self, &block)
485
728
  if @args
@@ -487,13 +730,16 @@ module Minjs
487
730
  arg.traverse(self, &block)
488
731
  end
489
732
  end
490
- yield self, parent
733
+ yield parent, self
491
734
  end
492
735
 
736
+ # compare object
493
737
  def ==(obj)
494
738
  self.class == obj.class and @name == obj.name and @args == obj.args
495
739
  end
496
740
 
741
+ # Returns a ECMAScript string containg the representation of element.
742
+ # @see Base#to_js
497
743
  def to_js(options = {})
498
744
  if @args
499
745
  args = @args.collect{|x| x.to_js(options)}.join(",")
@@ -503,10 +749,12 @@ module Minjs
503
749
  end
504
750
  end
505
751
 
752
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
506
753
  def left_hand_side_exp?
507
754
  true
508
755
  end
509
756
 
757
+ # remove parenthesis if possible
510
758
  def remove_paren
511
759
  if @name.kind_of? ExpParen and @name.val.priority <= PRIORITY_LEFT_HAND_SIDE
512
760
  @name = @name.val if @name.remove_paren?
@@ -523,6 +771,7 @@ module Minjs
523
771
  self
524
772
  end
525
773
 
774
+ # add parenthesis if need
526
775
  def add_paren
527
776
  if @name.priority > PRIORITY_LEFT_HAND_SIDE
528
777
  @name = ExpParen.new(@name)
@@ -540,139 +789,238 @@ module Minjs
540
789
  end
541
790
  end
542
791
 
792
+ # Class of the Postfix increment operator expression element.
543
793
  #
544
- # 11.3 Postfix Expressions
545
- #
546
- class ExpPostInc < ExpArg1
794
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.3.1
795
+ class ExpPostInc < Expression
547
796
  include UnaryOperation
797
+ def initialize(val)
798
+ @val = val
799
+ end
800
+
801
+ # symbol of expression
548
802
  def sym
549
803
  "++"
550
804
  end
551
805
 
806
+ # @return [Fixnum] expression priority
552
807
  def priority
553
808
  PRIORITY_POSTFIX
554
809
  end
555
810
 
811
+ # Returns a ECMAScript string containg the representation of element.
812
+ # @see Base#to_js
556
813
  def to_js(options = {})
557
814
  concat options, @val, sym
558
815
  end
559
816
  end
560
- class ExpPostDec < ExpArg1
817
+
818
+ # Class of the Postfix decrement operator expression element.
819
+ #
820
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.3.2
821
+ class ExpPostDec < Expression
561
822
  include UnaryOperation
823
+ def initialize(val)
824
+ @val = val
825
+ end
826
+
827
+ # symbol of expression
562
828
  def sym
563
829
  "--"
564
830
  end
565
831
 
832
+ # @return [Fixnum] expression priority
566
833
  def priority
567
834
  PRIORITY_POSTFIX
568
835
  end
569
836
 
837
+ # Returns a ECMAScript string containg the representation of element.
838
+ # @see Base#to_js
570
839
  def to_js(options = {})
571
840
  concat options, @val, sym
572
841
  end
573
842
  end
843
+ # Class of the Delete operator expression element.
574
844
  #
575
- # 11.4
576
- # unary expression
577
- #
578
- class ExpDelete < ExpArg1
845
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
846
+ class ExpDelete < Expression
579
847
  include UnaryOperation
848
+ def initialize(val)
849
+ @val = val
850
+ end
851
+
852
+ # symbol of expression
580
853
  def sym
581
854
  "delete"
582
855
  end
856
+ # @return [Fixnum] expression priority
583
857
  def priority
584
858
  PRIORITY_UNARY
585
859
  end
586
860
  end
587
- class ExpVoid < ExpArg1
861
+ # Class of the Void operator expression element.
862
+ #
863
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
864
+ class ExpVoid < Expression
588
865
  include UnaryOperation
589
866
 
867
+ def initialize(val)
868
+ @val = val
869
+ end
870
+ # symbol of expression
590
871
  def sym
591
872
  "void"
592
873
  end
593
874
 
875
+ # @return [Fixnum] expression priority
594
876
  def priority
595
877
  PRIORITY_UNARY
596
878
  end
597
879
 
880
+ # return results of 'typeof' operator.
881
+ #
882
+ # @return [Symbol] :undefined
598
883
  def ecma262_typeof
599
884
  :undefined
600
885
  end
601
-
602
886
  end
603
- class ExpTypeof < ExpArg1
887
+
888
+ # Class of the Typeof operator expression element.
889
+ #
890
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
891
+ class ExpTypeof < Expression
604
892
  include UnaryOperation
893
+ def initialize(val)
894
+ @val = val
895
+ end
896
+
897
+ # symbol of expression
605
898
  def sym
606
899
  "typeof"
607
900
  end
901
+ # @return [Fixnum] expression priority
608
902
  def priority
609
903
  PRIORITY_UNARY
610
904
  end
611
905
 
906
+ # return results of 'typeof' operator.
907
+ #
908
+ # @return [Symbol] :string
612
909
  def ecma262_typeof
613
910
  :string
614
911
  end
615
912
  end
616
913
 
617
- class ExpPreInc < ExpArg1
914
+ # Class of the Prefix Increment operator expression element.
915
+ #
916
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
917
+ class ExpPreInc < Expression
618
918
  include UnaryOperation
919
+ def initialize(val)
920
+ @val = val
921
+ end
922
+
923
+ # symbol of expression
619
924
  def sym
620
925
  "++"
621
926
  end
622
927
 
928
+ # @return [Fixnum] expression priority
623
929
  def priority
624
930
  PRIORITY_UNARY
625
931
  end
626
932
 
933
+ # return results of 'typeof' operator.
934
+ #
935
+ # @return [Symbol] :number
627
936
  def ecma262_typeof
628
937
  :number
629
938
  end
630
939
  end
631
- class ExpPreDec < ExpArg1
940
+
941
+ # Class of the Prefix Decrement operator expression element.
942
+ #
943
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
944
+ class ExpPreDec < Expression
632
945
  include UnaryOperation
946
+ def initialize(val)
947
+ @val = val
948
+ end
949
+
950
+ # symbol of expression
633
951
  def sym
634
952
  "--"
635
953
  end
636
954
 
955
+ # @return [Fixnum] expression priority
637
956
  def priority
638
957
  PRIORITY_UNARY
639
958
  end
640
959
 
960
+ # return results of 'typeof' operator.
961
+ #
962
+ # @return [Symbol] :number
641
963
  def ecma262_typeof
642
964
  :number
643
965
  end
644
966
  end
645
- class ExpPositive < ExpArg1
967
+
968
+ # Class of the Positive operator expression element.
969
+ #
970
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
971
+ class ExpPositive < Expression
646
972
  include UnaryOperation
973
+ def initialize(val)
974
+ @val = val
975
+ end
976
+
977
+ # symbol of expression
647
978
  def sym
648
979
  "+"
649
980
  end
650
981
 
982
+ # @return [Fixnum] expression priority
651
983
  def priority
652
984
  PRIORITY_UNARY
653
985
  end
654
986
 
987
+ # reduce expression if available
988
+ # @param parent [Base] parent element
655
989
  def reduce(parent)
656
990
  if @val.kind_of? ECMA262Numeric
657
991
  parent.replace(self, @val)
658
992
  end
659
993
  end
660
994
 
995
+ # return results of 'typeof' operator.
996
+ #
997
+ # @return [Symbol] :number
661
998
  def ecma262_typeof
662
999
  :number
663
1000
  end
664
1001
  end
665
1002
 
666
- class ExpNegative < ExpArg1
1003
+ # Class of the Negative operator expression element.
1004
+ #
1005
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
1006
+ class ExpNegative < Expression
667
1007
  include UnaryOperation
1008
+ def initialize(val)
1009
+ @val = val
1010
+ end
1011
+
1012
+ # symbol of expression
668
1013
  def sym
669
1014
  "-"
670
1015
  end
671
1016
 
1017
+ # @return [Fixnum] expression priority
672
1018
  def priority
673
1019
  PRIORITY_UNARY
674
1020
  end
675
1021
 
1022
+ # reduce expression if available
1023
+ # @param parent [Base] parent element
676
1024
  def reduce(parent)
677
1025
  if @val.kind_of? ECMA262Numeric
678
1026
  if @val.integer.match(/^\-/)
@@ -685,41 +1033,68 @@ module Minjs
685
1033
  end
686
1034
  end
687
1035
 
1036
+ # return results of 'typeof' operator.
1037
+ #
1038
+ # @return [Symbol] :number
688
1039
  def ecma262_typeof
689
1040
  :number
690
1041
  end
691
1042
  end
692
1043
 
693
- class ExpBitwiseNot < ExpArg1
1044
+ # Class of the Bitwise Not operator expression element.
1045
+ #
1046
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
1047
+ class ExpBitwiseNot < Expression
694
1048
  include UnaryOperation
1049
+ def initialize(val)
1050
+ @val = val
1051
+ end
1052
+
1053
+ # symbol of expression
695
1054
  def sym
696
1055
  "~"
697
1056
  end
698
1057
 
1058
+ # @return [Fixnum] expression priority
699
1059
  def priority
700
1060
  PRIORITY_UNARY
701
1061
  end
702
1062
 
1063
+ # return results of 'typeof' operator.
1064
+ #
1065
+ # @return [Symbol] :number
703
1066
  def ecma262_typeof
704
1067
  :number
705
1068
  end
706
1069
  end
707
- class ExpLogicalNot < ExpArg1
1070
+
1071
+ # Class of the Logical Not operator expression element.
1072
+ #
1073
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.4
1074
+ class ExpLogicalNot < Expression
708
1075
  include UnaryOperation
1076
+ def initialize(val)
1077
+ @val = val
1078
+ end
1079
+
1080
+ # symbol of expression
709
1081
  def sym
710
1082
  "!"
711
1083
  end
712
1084
 
1085
+ # @return [Fixnum] expression priority
713
1086
  def priority
714
1087
  PRIORITY_UNARY
715
1088
  end
716
1089
 
1090
+ # reduce expression if available
1091
+ # @param parent [Base] parent element
717
1092
  def reduce(parent)
718
1093
  if @val.kind_of? ECMA262Numeric and (@val.to_js == "0" || @val.to_js == "1")
719
1094
  return
720
1095
  end
721
1096
 
722
- if (e = ecma262_eval(:boolean)) != nil
1097
+ if (e = to_ecma262_boolean) != nil and @val.side_effect? == false
723
1098
  if e
724
1099
  parent.replace(self, ExpLogicalNot.new(ECMA262Numeric.new(0)))
725
1100
  else
@@ -732,12 +1107,28 @@ module Minjs
732
1107
  end
733
1108
  end
734
1109
 
1110
+ # Returns results of ToBoolean()
1111
+ #
1112
+ # Returns _true_ or _false_ if trivial,
1113
+ # otherwise nil.
1114
+ #
1115
+ # @return [Boolean]
1116
+ #
1117
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 9.2
735
1118
  def to_ecma262_boolean
736
1119
  return nil unless @val.respond_to? :to_ecma262_boolean
737
1120
  return nil if @val.to_ecma262_boolean.nil?
738
1121
  !@val.to_ecma262_boolean
739
1122
  end
740
1123
 
1124
+ # Returns results of ToNumber()
1125
+ #
1126
+ # Returns number if value is trivial,
1127
+ # otherwise nil.
1128
+ #
1129
+ # @return [Numeric]
1130
+ #
1131
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 9.3
741
1132
  def to_ecma262_number
742
1133
  if @val.respond_to? :to_ecma262_number
743
1134
  v = @val.to_ecma262_number
@@ -746,43 +1137,37 @@ module Minjs
746
1137
  end
747
1138
  end
748
1139
 
749
- def ecma262_eval(type)
750
- if @val.respond_to? :ecma262_eval
751
- e = @val.ecma262_eval(type)
752
- if e.nil?
753
- return nil
754
- else
755
- return !e
756
- end
757
- else
758
- nil
759
- end
760
- end
761
-
1140
+ # return results of 'typeof' operator.
1141
+ #
1142
+ # @return [Symbol] :boolean
762
1143
  def ecma262_typeof
763
1144
  :boolean
764
1145
  end
765
1146
  end
1147
+
1148
+ # Class of the Multiprication operator expression element.
766
1149
  #
767
- # 11.5.1 Applying the * Operator
768
- #
769
- class ExpMul < ExpArg2
1150
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.5
1151
+ class ExpMul < Expression
770
1152
  include BinaryOperation
771
1153
 
772
- def sym
773
- "*"
1154
+ def initialize(val, val2)
1155
+ @val = val
1156
+ @val2 = val2
774
1157
  end
775
1158
 
776
- def priority
777
- PRIORITY_MULTIPLICATIVE
1159
+ # symbol of expression
1160
+ def sym
1161
+ "*"
778
1162
  end
779
1163
 
780
- def swap
781
- t = @val
782
- @val = @val2
783
- @val2 = t
1164
+ # @return [Fixnum] expression priority
1165
+ def priority
1166
+ PRIORITY_MULTIPLICATIVE
784
1167
  end
785
1168
 
1169
+ # reduce expression if available
1170
+ # @param parent [Base] parent element
786
1171
  def reduce(parent)
787
1172
  # A * B
788
1173
  if @val.respond_to? :to_ecma262_number and @val2.respond_to? :to_ecma262_number
@@ -794,61 +1179,85 @@ module Minjs
794
1179
  end
795
1180
  end
796
1181
 
1182
+ # return results of 'typeof' operator.
1183
+ #
1184
+ # @return [Symbol] :number
797
1185
  def ecma262_typeof
798
1186
  :number
799
1187
  end
800
1188
  end
801
1189
 
1190
+ # Class of the Division operator expression element.
802
1191
  #
803
- # 11.5.2 Applying the / Operator
804
- #
805
- class ExpDiv < ExpArg2
1192
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.5
1193
+ class ExpDiv < Expression
806
1194
  include BinaryOperation
1195
+
1196
+ def initialize(val, val2)
1197
+ @val = val
1198
+ @val2 = val2
1199
+ end
1200
+
1201
+ # symbol of expression
807
1202
  def sym
808
1203
  "/"
809
1204
  end
1205
+ # @return [Fixnum] expression priority
810
1206
  def priority
811
1207
  PRIORITY_MULTIPLICATIVE
812
1208
  end
813
1209
  end
814
1210
 
1211
+ # Class of the Remainder operator expression element.
815
1212
  #
816
- # 11.5.3 Applying the % Operator
817
- #
818
- class ExpMod < ExpArg2
1213
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.5
1214
+ class ExpMod < Expression
819
1215
  include BinaryOperation
1216
+ def initialize(val, val2)
1217
+ @val = val
1218
+ @val2 = val2
1219
+ end
1220
+
1221
+ # symbol of expression
820
1222
  def sym
821
1223
  "%"
822
1224
  end
823
1225
 
1226
+ # @return [Fixnum] expression priority
824
1227
  def priority
825
1228
  PRIORITY_MULTIPLICATIVE
826
1229
  end
827
1230
 
1231
+ # return results of 'typeof' operator.
1232
+ #
1233
+ # @return [Symbol] :number
828
1234
  def ecma262_typeof
829
1235
  :number
830
1236
  end
831
1237
  end
832
1238
 
1239
+ # Class of the Additionr operator expression element.
833
1240
  #
834
- #11.6.1 The Addition operator ( + )
835
- #
836
- class ExpAdd < ExpArg2
1241
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.6
1242
+ class ExpAdd < Expression
837
1243
  include BinaryOperation
1244
+ def initialize(val, val2)
1245
+ @val = val
1246
+ @val2 = val2
1247
+ end
1248
+
1249
+ # symbol of expression
838
1250
  def sym
839
1251
  "+"
840
1252
  end
841
1253
 
1254
+ # @return [Fixnum] expression priority
842
1255
  def priority
843
1256
  PRIORITY_ADDITIVE
844
1257
  end
845
1258
 
846
- def swap
847
- t = @val
848
- @val = @val2
849
- @val2 = t
850
- end
851
-
1259
+ # reduce expression if available
1260
+ # @param parent [Base] parent element
852
1261
  def reduce(parent)
853
1262
  #
854
1263
  # String + String/
@@ -878,20 +1287,28 @@ module Minjs
878
1287
  end
879
1288
  end
880
1289
  end
1290
+ # Class of the Subtraction operator expression element.
881
1291
  #
882
- # 11.6.2 The Subtraction Operator ( - )
883
- #
884
- class ExpSub < ExpArg2
1292
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.6
1293
+ class ExpSub < Expression
885
1294
  include BinaryOperation
1295
+ def initialize(val, val2)
1296
+ @val = val
1297
+ @val2 = val2
1298
+ end
886
1299
 
1300
+ # symbol of expression
887
1301
  def sym
888
1302
  "-"
889
1303
  end
890
1304
 
1305
+ # @return [Fixnum] expression priority
891
1306
  def priority
892
1307
  PRIORITY_ADDITIVE
893
1308
  end
894
1309
 
1310
+ # reduce expression if available
1311
+ # @param parent [Base] parent element
895
1312
  def reduce(parent)
896
1313
  # A - B
897
1314
  if @val.respond_to? :to_ecma262_number and @val2.respond_to? :to_ecma262_number
@@ -903,212 +1320,334 @@ module Minjs
903
1320
  end
904
1321
  end
905
1322
 
1323
+ # return results of 'typeof' operator.
1324
+ #
1325
+ # @return [Symbol] :number
906
1326
  def ecma262_typeof
907
1327
  :number
908
1328
  end
909
1329
  end
910
1330
 
1331
+ # Class of the Left Shift operator expression element.
911
1332
  #
912
- # 11.7.1 The Left Shift Operator ( << )
913
- #
914
- class ExpLShift < ExpArg2
1333
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.7
1334
+ class ExpLShift < Expression
915
1335
  include BinaryOperation
1336
+ def initialize(val, val2)
1337
+ @val = val
1338
+ @val2 = val2
1339
+ end
1340
+
1341
+ # symbol of expression
916
1342
  def sym
917
1343
  "<<"
918
1344
  end
919
1345
 
1346
+ # @return [Fixnum] expression priority
920
1347
  def priority
921
1348
  PRIORITY_SHIFT
922
1349
  end
923
1350
 
1351
+ # return results of 'typeof' operator.
1352
+ #
1353
+ # @return [Symbol] :number
924
1354
  def ecma262_typeof
925
1355
  :number
926
1356
  end
927
1357
  end
1358
+ # Class of the Right Shift operator expression element.
928
1359
  #
929
- # 11.7.2 The Signed Right Shift Operator ( >> )
930
- #
931
- class ExpRShift < ExpArg2
1360
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.7
1361
+ class ExpRShift < Expression
932
1362
  include BinaryOperation
1363
+ def initialize(val, val2)
1364
+ @val = val
1365
+ @val2 = val2
1366
+ end
1367
+
1368
+ # symbol of expression
933
1369
  def sym
934
1370
  ">>"
935
1371
  end
936
1372
 
1373
+ # @return [Fixnum] expression priority
937
1374
  def priority
938
1375
  PRIORITY_SHIFT
939
1376
  end
940
1377
 
1378
+ # return results of 'typeof' operator.
1379
+ #
1380
+ # @return [Symbol] :number
941
1381
  def ecma262_typeof
942
1382
  :number
943
1383
  end
944
1384
  end
1385
+ # Class of the Unsigned Right Shift operator expression element.
945
1386
  #
946
- # 11.7.3 The Unsigned Right Shift Operator ( >>> )
947
- #
948
- class ExpURShift < ExpArg2
1387
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.7
1388
+ class ExpURShift < Expression
949
1389
  include BinaryOperation
1390
+ def initialize(val, val2)
1391
+ @val = val
1392
+ @val2 = val2
1393
+ end
1394
+
1395
+ # symbol of expression
950
1396
  def sym
951
1397
  ">>>"
952
1398
  end
953
1399
 
1400
+ # @return [Fixnum] expression priority
954
1401
  def priority
955
1402
  PRIORITY_SHIFT
956
1403
  end
957
1404
 
1405
+ # return results of 'typeof' operator.
1406
+ #
1407
+ # @return [Symbol] :number
958
1408
  def ecma262_typeof
959
1409
  :number
960
1410
  end
961
1411
  end
1412
+ # Class of the Less-than operator expression element.
962
1413
  #
963
- # 11.8.1 The Less-than Operator ( < )
964
- #
965
- class ExpLt < ExpArg2
1414
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.8
1415
+ class ExpLt < Expression
966
1416
  include BinaryOperation
1417
+ def initialize(val, val2)
1418
+ @val = val
1419
+ @val2 = val2
1420
+ end
1421
+
1422
+ # symbol of expression
967
1423
  def sym
968
1424
  "<"
969
1425
  end
970
1426
 
1427
+ # @return [Fixnum] expression priority
971
1428
  def priority
972
1429
  PRIORITY_RELATIONAL
973
1430
  end
974
1431
 
1432
+ # return results of 'typeof' operator.
1433
+ #
1434
+ # @return [Symbol] :boolean
975
1435
  def ecma262_typeof
976
1436
  :boolean
977
1437
  end
978
1438
  end
979
1439
 
1440
+ # Class of the Greater-than operator expression element.
980
1441
  #
981
- # 11.8.2 The Greater-than Operator ( > )
982
- #
983
- class ExpGt < ExpArg2
1442
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.8
1443
+ class ExpGt < Expression
984
1444
  include BinaryOperation
1445
+ def initialize(val, val2)
1446
+ @val = val
1447
+ @val2 = val2
1448
+ end
1449
+
1450
+ # symbol of expression
985
1451
  def sym
986
1452
  ">"
987
1453
  end
988
1454
 
1455
+ # @return [Fixnum] expression priority
989
1456
  def priority
990
1457
  PRIORITY_RELATIONAL
991
1458
  end
992
1459
 
1460
+ # return results of 'typeof' operator.
1461
+ #
1462
+ # @return [Symbol] :boolean
993
1463
  def ecma262_typeof
994
1464
  :boolean
995
1465
  end
996
1466
  end
1467
+ # Class of the Less-than-or-equal operator expression element.
997
1468
  #
998
- # 11.8.3 The Less-than-or-equal Operator ( <= )
999
- #
1000
- class ExpLtEq < ExpArg2
1469
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.8
1470
+ class ExpLtEq < Expression
1001
1471
  include BinaryOperation
1472
+ def initialize(val, val2)
1473
+ @val = val
1474
+ @val2 = val2
1475
+ end
1476
+
1477
+ # symbol of expression
1002
1478
  def sym
1003
1479
  "<="
1004
1480
  end
1005
1481
 
1482
+ # @return [Fixnum] expression priority
1006
1483
  def priority
1007
1484
  PRIORITY_RELATIONAL
1008
1485
  end
1009
1486
 
1487
+ # return results of 'typeof' operator.
1488
+ #
1489
+ # @return [Symbol] :boolean
1010
1490
  def ecma262_typeof
1011
1491
  :boolean
1012
1492
  end
1013
1493
  end
1494
+ # Class of the Greater-than-or-equal operator expression element.
1014
1495
  #
1015
- # 11.8.4 The Greater-than-or-equal Operator ( >= )
1016
- #
1017
- class ExpGtEq < ExpArg2
1496
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.8
1497
+ class ExpGtEq < Expression
1018
1498
  include BinaryOperation
1499
+ def initialize(val, val2)
1500
+ @val = val
1501
+ @val2 = val2
1502
+ end
1503
+
1504
+ # symbol of expression
1019
1505
  def sym
1020
1506
  ">="
1021
1507
  end
1022
1508
 
1509
+ # @return [Fixnum] expression priority
1023
1510
  def priority
1024
1511
  PRIORITY_RELATIONAL
1025
1512
  end
1026
1513
 
1514
+ # return results of 'typeof' operator.
1515
+ #
1516
+ # @return [Symbol] :boolean
1027
1517
  def ecma262_typeof
1028
1518
  :boolean
1029
1519
  end
1030
1520
  end
1521
+ # Class of the instanceof operator expression element.
1031
1522
  #
1032
- # 11.8.6 The instanceof operator
1033
- #
1034
- class ExpInstanceOf < ExpArg2
1523
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.8
1524
+ class ExpInstanceOf < Expression
1035
1525
  include BinaryOperation
1526
+ def initialize(val, val2)
1527
+ @val = val
1528
+ @val2 = val2
1529
+ end
1530
+
1531
+ # symbol of expression
1036
1532
  def sym
1037
1533
  "instanceof"
1038
1534
  end
1039
1535
 
1536
+ # @return [Fixnum] expression priority
1040
1537
  def priority
1041
1538
  PRIORITY_RELATIONAL
1042
1539
  end
1043
1540
 
1541
+ # return results of 'typeof' operator.
1542
+ #
1543
+ # @return [Symbol] :boolean
1044
1544
  def ecma262_typeof
1045
1545
  :boolean
1046
1546
  end
1047
1547
  end
1548
+ # Class of the in operator expression element.
1048
1549
  #
1049
- # 11.8.7 The in operator
1050
- #
1051
- class ExpIn < ExpArg2
1550
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.8
1551
+ class ExpIn < Expression
1052
1552
  include BinaryOperation
1553
+ def initialize(val, val2)
1554
+ @val = val
1555
+ @val2 = val2
1556
+ end
1557
+
1558
+ # symbol of expression
1053
1559
  def sym
1054
1560
  "in"
1055
1561
  end
1056
1562
 
1563
+ # @return [Fixnum] expression priority
1057
1564
  def priority
1058
1565
  PRIORITY_RELATIONAL
1059
1566
  end
1060
1567
 
1568
+ # return results of 'typeof' operator.
1569
+ #
1570
+ # @return [Symbol] :boolean
1061
1571
  def ecma262_typeof
1062
1572
  :boolean
1063
1573
  end
1064
1574
  end
1575
+ # Class of the Equals operator expression element.
1065
1576
  #
1066
- # 11.9.1 The Equals Operator ( == )
1067
- #
1068
- class ExpEq < ExpArg2
1577
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.9
1578
+ class ExpEq < Expression
1069
1579
  include BinaryOperation
1580
+ def initialize(val, val2)
1581
+ @val = val
1582
+ @val2 = val2
1583
+ end
1584
+
1585
+ # symbol of expression
1070
1586
  def sym
1071
1587
  "=="
1072
1588
  end
1073
1589
 
1590
+ # @return [Fixnum] expression priority
1074
1591
  def priority
1075
1592
  PRIORITY_EQUALITY
1076
1593
  end
1077
1594
 
1595
+ # return results of 'typeof' operator.
1596
+ #
1597
+ # @return [Symbol] :boolean
1078
1598
  def ecma262_typeof
1079
1599
  :boolean
1080
1600
  end
1081
1601
  end
1602
+ # Class of the Does-not-equals operator expression element.
1082
1603
  #
1083
- # 11.9.2 The Does-not-equals Operator ( != )
1084
- #
1085
- class ExpNotEq < ExpArg2
1604
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.9
1605
+ class ExpNotEq < Expression
1086
1606
  include BinaryOperation
1607
+ def initialize(val, val2)
1608
+ @val = val
1609
+ @val2 = val2
1610
+ end
1611
+
1612
+ # symbol of expression
1087
1613
  def sym
1088
1614
  "!="
1089
1615
  end
1090
1616
 
1617
+ # @return [Fixnum] expression priority
1091
1618
  def priority
1092
1619
  PRIORITY_EQUALITY
1093
1620
  end
1094
1621
 
1622
+ # return results of 'typeof' operator.
1623
+ #
1624
+ # @return [Symbol] :boolean
1095
1625
  def ecma262_typeof
1096
1626
  :boolean
1097
1627
  end
1098
1628
  end
1629
+ # Class of the Strict Equals operator expression element.
1099
1630
  #
1100
- # 11.9.4 The Strict Equals Operator ( === )
1101
- #
1102
- class ExpStrictEq < ExpArg2
1631
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.9
1632
+ class ExpStrictEq < Expression
1103
1633
  include BinaryOperation
1634
+ def initialize(val, val2)
1635
+ @val = val
1636
+ @val2 = val2
1637
+ end
1638
+
1639
+ # symbol of expression
1104
1640
  def sym
1105
1641
  "==="
1106
1642
  end
1107
1643
 
1644
+ # @return [Fixnum] expression priority
1108
1645
  def priority
1109
1646
  PRIORITY_EQUALITY
1110
1647
  end
1111
1648
 
1649
+ # reduce expression if available
1650
+ # @param parent [Base] parent element
1112
1651
  def reduce(parent)
1113
1652
  if @val.respond_to?(:ecma262_typeof) and @val2.respond_to?(:ecma262_typeof) and
1114
1653
  (t = @val.ecma262_typeof) == @val2.ecma262_typeof and !t.nil?
@@ -1116,23 +1655,35 @@ module Minjs
1116
1655
  end
1117
1656
  end
1118
1657
 
1658
+ # return results of 'typeof' operator.
1659
+ #
1660
+ # @return [Symbol] :boolean
1119
1661
  def ecma262_typeof
1120
1662
  :boolean
1121
1663
  end
1122
1664
  end
1665
+ # Class of the Strict Does-not-equals operator expression element.
1123
1666
  #
1124
- # 11.9.5 The Strict Does-not-equal Operator ( !== )
1125
- #
1126
- class ExpStrictNotEq < ExpArg2
1667
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.9
1668
+ class ExpStrictNotEq < Expression
1127
1669
  include BinaryOperation
1670
+ def initialize(val, val2)
1671
+ @val = val
1672
+ @val2 = val2
1673
+ end
1674
+
1675
+ # symbol of expression
1128
1676
  def sym
1129
1677
  "!=="
1130
1678
  end
1131
1679
 
1680
+ # @return [Fixnum] expression priority
1132
1681
  def priority
1133
1682
  PRIORITY_EQUALITY
1134
1683
  end
1135
1684
 
1685
+ # reduce expression if available
1686
+ # @param parent [Base] parent element
1136
1687
  def reduce(parent)
1137
1688
  if @val.respond_to?(:ecma262_typeof) and @val2.respond_to?(:ecma262_typeof) and
1138
1689
  (t = @val.ecma262_typeof) == @val2.ecma262_typeof and !t.nil?
@@ -1140,91 +1691,126 @@ module Minjs
1140
1691
  end
1141
1692
  end
1142
1693
 
1694
+ # return results of 'typeof' operator.
1695
+ #
1696
+ # @return [Symbol] :boolean
1143
1697
  def ecma262_typeof
1144
1698
  :boolean
1145
1699
  end
1146
1700
  end
1701
+ # Class of the Bitwise And operator expression element.
1147
1702
  #
1148
- # 11.10 Binary Bitwise Operators
1149
- #
1150
- class ExpAnd < ExpArg2
1703
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.10
1704
+ class ExpAnd < Expression
1151
1705
  include BinaryOperation
1706
+ def initialize(val, val2)
1707
+ @val = val
1708
+ @val2 = val2
1709
+ end
1710
+
1711
+ # symbol of expression
1152
1712
  def sym
1153
1713
  "&"
1154
1714
  end
1155
1715
 
1716
+ # @return [Fixnum] expression priority
1156
1717
  def priority
1157
1718
  PRIORITY_BITWISE_AND
1158
1719
  end
1159
1720
 
1160
- def swap
1161
- t = @val
1162
- @val = @val2
1163
- @val2 = t
1164
- end
1165
-
1721
+ # return results of 'typeof' operator.
1722
+ #
1723
+ # @return [Symbol] :number
1166
1724
  def ecma262_typeof
1167
1725
  :number
1168
1726
  end
1169
1727
  end
1170
- # ^
1171
- class ExpXor < ExpArg2
1728
+
1729
+ # Class of the Bitwise Xor operator expression element.
1730
+ #
1731
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.10
1732
+ class ExpXor < Expression
1172
1733
  include BinaryOperation
1734
+ def initialize(val, val2)
1735
+ @val = val
1736
+ @val2 = val2
1737
+ end
1738
+
1739
+ # symbol of expression
1173
1740
  def sym
1174
1741
  "^"
1175
1742
  end
1176
1743
 
1744
+ # @return [Fixnum] expression priority
1177
1745
  def priority
1178
1746
  PRIORITY_BITWISE_XOR
1179
1747
  end
1180
1748
 
1181
- def swap
1182
- t = @val
1183
- @val = @val2
1184
- @val2 = t
1185
- end
1186
-
1749
+ # return results of 'typeof' operator.
1750
+ #
1751
+ # @return [Symbol] :number
1187
1752
  def ecma262_typeof
1188
1753
  :number
1189
1754
  end
1190
1755
  end
1191
1756
 
1192
- # |
1193
- class ExpOr < ExpArg2
1757
+ # Class of the Bitwise Or operator expression element.
1758
+ #
1759
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.10
1760
+ class ExpOr < Expression
1194
1761
  include BinaryOperation
1762
+ def initialize(val, val2)
1763
+ @val = val
1764
+ @val2 = val2
1765
+ end
1766
+
1767
+ # symbol of expression
1195
1768
  def sym
1196
1769
  "|"
1197
1770
  end
1198
1771
 
1772
+ # @return [Fixnum] expression priority
1199
1773
  def priority
1200
1774
  PRIORITY_BITWISE_OR
1201
1775
  end
1202
1776
 
1203
- def swap
1204
- t = @val
1205
- @val = @val2
1206
- @val2 = t
1207
- end
1208
-
1777
+ # return results of 'typeof' operator.
1778
+ #
1779
+ # @return [Symbol] :number
1209
1780
  def ecma262_typeof
1210
1781
  :number
1211
1782
  end
1212
1783
  end
1784
+
1785
+ # Class of the Bitwise Logical And operator expression element.
1213
1786
  #
1214
- # 11.11 Binary Logical Operators
1215
- #
1216
- # &&
1217
- class ExpLogicalAnd < ExpArg2
1787
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.11
1788
+ class ExpLogicalAnd < Expression
1218
1789
  include BinaryOperation
1219
1790
 
1791
+ def initialize(val, val2)
1792
+ @val = val
1793
+ @val2 = val2
1794
+ end
1795
+
1796
+ # symbol of expression
1220
1797
  def sym
1221
1798
  "&&"
1222
1799
  end
1223
1800
 
1801
+ # @return [Fixnum] expression priority
1224
1802
  def priority
1225
1803
  PRIORITY_LOGICAL_AND
1226
1804
  end
1227
1805
 
1806
+ # Returns results of ToBoolean()
1807
+ #
1808
+ # Returns _true_ or _false_ if trivial,
1809
+ # otherwise nil.
1810
+ #
1811
+ # @return [Boolean]
1812
+ #
1813
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 9.2
1228
1814
  def to_ecma262_boolean
1229
1815
  return nil if !(@val.respond_to? :to_ecma262_boolean)
1230
1816
  return nil if @val.to_ecma262_boolean == nil
@@ -1235,6 +1821,9 @@ module Minjs
1235
1821
  true
1236
1822
  end
1237
1823
 
1824
+ # return results of 'typeof' operator.
1825
+ #
1826
+ # @return [Symbol] typeof val if typeof val equals to val2
1238
1827
  def ecma262_typeof
1239
1828
  if @val.respond_to? :ecma262_typeof and @val2.respond_to? :ecma262_typeof
1240
1829
  if @val.ecma262_typeof == @val2.ecma262_typeof
@@ -1244,17 +1833,34 @@ module Minjs
1244
1833
  nil
1245
1834
  end
1246
1835
  end
1247
- # ||
1248
- class ExpLogicalOr < ExpArg2
1836
+ # Class of the Bitwise Logical Or operator expression element.
1837
+ #
1838
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.11
1839
+ class ExpLogicalOr < Expression
1249
1840
  include BinaryOperation
1841
+ def initialize(val, val2)
1842
+ @val = val
1843
+ @val2 = val2
1844
+ end
1845
+
1846
+ # symbol of expression
1250
1847
  def sym
1251
1848
  "||"
1252
1849
  end
1253
1850
 
1851
+ # @return [Fixnum] expression priority
1254
1852
  def priority
1255
1853
  PRIORITY_LOGICAL_OR
1256
1854
  end
1257
1855
 
1856
+ # Returns results of ToBoolean()
1857
+ #
1858
+ # Returns _true_ or _false_ if trivial,
1859
+ # otherwise nil.
1860
+ #
1861
+ # @return [Boolean]
1862
+ #
1863
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 9.2
1258
1864
  def to_ecma262_boolean
1259
1865
  return nil if !(@val.respond_to? :to_ecma262_boolean)
1260
1866
  return nil if @val.to_ecma262_boolean == nil
@@ -1265,6 +1871,9 @@ module Minjs
1265
1871
  false
1266
1872
  end
1267
1873
 
1874
+ # return results of 'typeof' operator.
1875
+ #
1876
+ # @return [Symbol] typeof val if typeof val equals to val2
1268
1877
  def ecma262_typeof
1269
1878
  if @val.respond_to? :ecma262_typeof and @val2.respond_to? :ecma262_typeof
1270
1879
  if @val.ecma262_typeof == @val2.ecma262_typeof
@@ -1274,12 +1883,10 @@ module Minjs
1274
1883
  nil
1275
1884
  end
1276
1885
  end
1886
+ # Class of the Conditional operator expression element.
1277
1887
  #
1278
- # 11.12 Conditional Operator ( ? : )
1279
- #
1280
- # val ? val2 : val3
1281
- #
1282
- class ExpCond < Exp
1888
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.12
1889
+ class ExpCond < Expression
1283
1890
  attr_reader :val, :val2, :val3
1284
1891
  alias :cond :val
1285
1892
 
@@ -1289,10 +1896,12 @@ module Minjs
1289
1896
  @val3 = val3
1290
1897
  end
1291
1898
 
1899
+ # @return [Fixnum] expression priority
1292
1900
  def priority
1293
1901
  PRIORITY_CONDITIONAL
1294
1902
  end
1295
1903
 
1904
+ # remove parenthesis if possible
1296
1905
  def remove_paren
1297
1906
  if @val.kind_of? ExpParen and @val.val.priority < PRIORITY_CONDITIONAL
1298
1907
  @val = @val.val if @val.remove_paren?
@@ -1306,6 +1915,7 @@ module Minjs
1306
1915
  self
1307
1916
  end
1308
1917
 
1918
+ # add parenthesis if need
1309
1919
  def add_paren
1310
1920
  if @val.priority > PRIORITY_CONDITIONAL
1311
1921
  @val = ExpParen.new(@val)
@@ -1319,10 +1929,14 @@ module Minjs
1319
1929
  self
1320
1930
  end
1321
1931
 
1932
+ # duplicate object
1933
+ # @see Base#deep_dup
1322
1934
  def deep_dup
1323
1935
  self.class.new(@val.deep_dup, @val2.deep_dup, @val3.deep_dup)
1324
1936
  end
1325
1937
 
1938
+ # Replaces children object.
1939
+ # @see Base#replace
1326
1940
  def replace(from, to)
1327
1941
  if from .eql? @val
1328
1942
  @val = to
@@ -1333,13 +1947,16 @@ module Minjs
1333
1947
  end
1334
1948
  end
1335
1949
 
1950
+ # Traverses this children and itself with given block.
1951
+ # @see Base#traverse
1336
1952
  def traverse(parent, &block)
1337
1953
  @val.traverse(self, &block)
1338
1954
  @val2.traverse(self, &block)
1339
1955
  @val3.traverse(self, &block)
1340
- yield self, parent
1956
+ yield parent, self
1341
1957
  end
1342
1958
 
1959
+ # compare object
1343
1960
  def ==(obj)
1344
1961
  self.class == obj.class and
1345
1962
  @val == obj.val and
@@ -1347,10 +1964,15 @@ module Minjs
1347
1964
  @val3 == obj.val3
1348
1965
  end
1349
1966
 
1967
+ # Returns a ECMAScript string containg the representation of element.
1968
+ # @see Base#to_js
1350
1969
  def to_js(options = {})
1351
1970
  "#{@val.to_js(options)}?#{@val2.to_js(options)}:#{@val3.to_js(options)}"
1352
1971
  end
1353
1972
 
1973
+ # return results of 'typeof' operator.
1974
+ #
1975
+ # @return [Symbol] typeof val2 if typeof val2 equals to val3
1354
1976
  def ecma262_typeof
1355
1977
  if @val2.respond_to? :ecma262_typeof and @val3.respond_to? :ecma262_typeof
1356
1978
  if @val2.ecma262_typeof == @val3.ecma262_typeof
@@ -1360,178 +1982,263 @@ module Minjs
1360
1982
  nil
1361
1983
  end
1362
1984
  end
1985
+
1986
+ # Class of '=' operator
1363
1987
  #
1364
- # 11.13 Assignment Operators
1365
- #
1366
- class ExpAssign < ExpArg2
1988
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
1989
+ class ExpAssign < Expression
1367
1990
  include AssignmentOperation
1991
+ def initialize(val, val2)
1992
+ @val = val
1993
+ @val2 = val2
1994
+ end
1995
+
1996
+ # symbol of expression
1368
1997
  def sym
1369
1998
  "="
1370
1999
  end
1371
2000
 
2001
+ # @return [Fixnum] expression priority
1372
2002
  def priority
1373
2003
  PRIORITY_ASSIGNMENT
1374
2004
  end
1375
-
1376
- def reduce(parent)
1377
- #
1378
- # a = a / b => a /= b
1379
- #
1380
- if @val2.kind_of? ExpDiv and @val2.val == @val
1381
- parent.replace(self,
1382
- ExpParen.new(
1383
- ExpDivAssign.new(@val, @val2.val2)))
1384
- elsif @val2.kind_of? ExpMul and @val2.val == @val
1385
- parent.replace(self,
1386
- ExpParen.new(
1387
- ExpMulAssign.new(@val, @val2.val2)))
1388
- elsif @val2.kind_of? ExpMod and @val2.val == @val
1389
- parent.replace(self,
1390
- ExpParen.new(
1391
- ExpModAssign.new(@val, @val2.val2)))
1392
- elsif @val2.kind_of? ExpAdd and @val2.val == @val
1393
- parent.replace(self,
1394
- ExpParen.new(
1395
- ExpAddAssign.new(@val, @val2.val2)))
1396
- elsif @val2.kind_of? ExpSub and @val2.val == @val
1397
- parent.replace(self,
1398
- ExpParen.new(
1399
- ExpSubAssign.new(@val, @val2.val2)))
1400
- elsif @val2.kind_of? ExpLShift and @val2.val == @val
1401
- parent.replace(self,
1402
- ExpParen.new(
1403
- ExpLShiftAssign.new(@val, @val2.val2)))
1404
- elsif @val2.kind_of? ExpRShift and @val2.val == @val
1405
- parent.replace(self,
1406
- ExpParen.new(
1407
- ExpRShiftAssign.new(@val, @val2.val2)))
1408
- elsif @val2.kind_of? ExpURShift and @val2.val == @val
1409
- parent.replace(self,
1410
- ExpParen.new(
1411
- ExpURShiftAssign.new(@val, @val2.val2)))
1412
- elsif @val2.kind_of? ExpAnd and @val2.val == @val
1413
- parent.replace(self,
1414
- ExpParen.new(
1415
- ExpAndAssign.new(@val, @val2.val2)))
1416
- elsif @val2.kind_of? ExpOr and @val2.val == @val
1417
- parent.replace(self,
1418
- ExpParen.new(
1419
- ExpOrAssign.new(@val, @val2.val2)))
1420
- elsif @val2.kind_of? ExpXor and @val2.val == @val
1421
- parent.replace(self,
1422
- ExpParen.new(
1423
- ExpXorAssign.new(@val, @val2.val2)))
1424
- end
1425
- end
1426
2005
  end
1427
- class ExpDivAssign < ExpAssign
2006
+
2007
+ # Class of '/=' operator
2008
+ #
2009
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2010
+ class ExpDivAssign < Expression
1428
2011
  include AssignmentOperation
2012
+ def initialize(val, val2)
2013
+ @val = val
2014
+ @val2 = val2
2015
+ end
2016
+
2017
+ # symbol of expression
1429
2018
  def sym
1430
2019
  "/="
1431
2020
  end
2021
+ # @return [Fixnum] expression priority
1432
2022
  def priority
1433
2023
  PRIORITY_ASSIGNMENT
1434
2024
  end
1435
2025
  end
1436
- class ExpMulAssign < ExpAssign
2026
+
2027
+ # Class of '*=' operator
2028
+ #
2029
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2030
+ class ExpMulAssign < Expression
1437
2031
  include AssignmentOperation
2032
+ def initialize(val, val2)
2033
+ @val = val
2034
+ @val2 = val2
2035
+ end
2036
+
2037
+ # symbol of expression
1438
2038
  def sym
1439
2039
  "*="
1440
2040
  end
2041
+ # @return [Fixnum] expression priority
1441
2042
  def priority
1442
2043
  PRIORITY_ASSIGNMENT
1443
2044
  end
1444
2045
  end
1445
- class ExpModAssign < ExpAssign
2046
+
2047
+ # Class of '%=' operator
2048
+ #
2049
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2050
+ class ExpModAssign < Expression
1446
2051
  include AssignmentOperation
2052
+ def initialize(val, val2)
2053
+ @val = val
2054
+ @val2 = val2
2055
+ end
2056
+
2057
+ # symbol of expression
1447
2058
  def sym
1448
2059
  "%="
1449
2060
  end
2061
+ # @return [Fixnum] expression priority
1450
2062
  def priority
1451
2063
  PRIORITY_ASSIGNMENT
1452
2064
  end
1453
2065
  end
1454
- class ExpAddAssign < ExpAssign
2066
+
2067
+ # Class of '+=' operator
2068
+ #
2069
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2070
+ class ExpAddAssign < Expression
1455
2071
  include AssignmentOperation
2072
+ def initialize(val, val2)
2073
+ @val = val
2074
+ @val2 = val2
2075
+ end
2076
+
2077
+ # symbol of expression
1456
2078
  def sym
1457
2079
  "+="
1458
2080
  end
2081
+ # @return [Fixnum] expression priority
1459
2082
  def priority
1460
2083
  PRIORITY_ASSIGNMENT
1461
2084
  end
1462
2085
  end
1463
- class ExpSubAssign < ExpAssign
2086
+
2087
+ # Class of '-=' operator
2088
+ #
2089
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2090
+ class ExpSubAssign < Expression
1464
2091
  include AssignmentOperation
2092
+ def initialize(val, val2)
2093
+ @val = val
2094
+ @val2 = val2
2095
+ end
2096
+
2097
+ # symbol of expression
1465
2098
  def sym
1466
2099
  "-="
1467
2100
  end
2101
+ # @return [Fixnum] expression priority
1468
2102
  def priority
1469
2103
  PRIORITY_ASSIGNMENT
1470
2104
  end
1471
2105
  end
1472
- class ExpLShiftAssign < ExpAssign
2106
+
2107
+ # Class of '<<=' operator
2108
+ #
2109
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2110
+ class ExpLShiftAssign < Expression
1473
2111
  include AssignmentOperation
2112
+ def initialize(val, val2)
2113
+ @val = val
2114
+ @val2 = val2
2115
+ end
2116
+
2117
+ # symbol of expression
1474
2118
  def sym
1475
2119
  "<<="
1476
2120
  end
2121
+ # @return [Fixnum] expression priority
1477
2122
  def priority
1478
2123
  PRIORITY_ASSIGNMENT
1479
2124
  end
1480
2125
  end
1481
- class ExpRShiftAssign < ExpAssign
2126
+
2127
+ # Class of '>>=' operator
2128
+ #
2129
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2130
+ class ExpRShiftAssign < Expression
1482
2131
  include AssignmentOperation
2132
+ def initialize(val, val2)
2133
+ @val = val
2134
+ @val2 = val2
2135
+ end
2136
+
2137
+ # symbol of expression
1483
2138
  def sym
1484
2139
  ">>="
1485
2140
  end
2141
+ # @return [Fixnum] expression priority
1486
2142
  def priority
1487
2143
  PRIORITY_ASSIGNMENT
1488
2144
  end
1489
2145
  end
1490
- class ExpURShiftAssign < ExpAssign
2146
+
2147
+ # Class of '>>>=' operator
2148
+ #
2149
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2150
+ class ExpURShiftAssign < Expression
1491
2151
  include AssignmentOperation
2152
+ def initialize(val, val2)
2153
+ @val = val
2154
+ @val2 = val2
2155
+ end
2156
+
2157
+ # symbol of expression
1492
2158
  def sym
1493
2159
  ">>>="
1494
2160
  end
2161
+ # @return [Fixnum] expression priority
1495
2162
  def priority
1496
2163
  PRIORITY_ASSIGNMENT
1497
2164
  end
1498
2165
  end
1499
- class ExpAndAssign < ExpAssign
2166
+
2167
+ # Class of '&=' operator
2168
+ #
2169
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2170
+ class ExpAndAssign < Expression
1500
2171
  include AssignmentOperation
2172
+ def initialize(val, val2)
2173
+ @val = val
2174
+ @val2 = val2
2175
+ end
2176
+
2177
+ # symbol of expression
1501
2178
  def sym
1502
2179
  "&="
1503
2180
  end
2181
+ # @return [Fixnum] expression priority
1504
2182
  def priority
1505
2183
  PRIORITY_ASSIGNMENT
1506
2184
  end
1507
2185
  end
1508
- class ExpOrAssign < ExpAssign
2186
+
2187
+ # Class of '|=' operator
2188
+ #
2189
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2190
+ class ExpOrAssign < Expression
1509
2191
  include AssignmentOperation
2192
+ def initialize(val, val2)
2193
+ @val = val
2194
+ @val2 = val2
2195
+ end
2196
+
2197
+ # symbol of expression
1510
2198
  def sym
1511
2199
  "|="
1512
2200
  end
2201
+ # @return [Fixnum] expression priority
1513
2202
  def priority
1514
2203
  PRIORITY_ASSIGNMENT
1515
2204
  end
1516
2205
  end
1517
- class ExpXorAssign < ExpAssign
2206
+
2207
+ # Class of '^=' operator
2208
+ #
2209
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.13
2210
+ class ExpXorAssign < Expression
1518
2211
  include AssignmentOperation
2212
+ def initialize(val, val2)
2213
+ @val = val
2214
+ @val2 = val2
2215
+ end
2216
+
2217
+ # symbol of expression
1519
2218
  def sym
1520
2219
  "^="
1521
2220
  end
2221
+ # @return [Fixnum] expression priority
1522
2222
  def priority
1523
2223
  PRIORITY_ASSIGNMENT
1524
2224
  end
1525
2225
  end
2226
+ # Class of comma operator ( , )
1526
2227
  #
1527
- # Comma Operator ( , )
1528
- #
1529
- class ExpComma < ExpArg2
2228
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 11.14
2229
+ class ExpComma < Expression
1530
2230
  include BinaryOperation
2231
+ def initialize(val, val2)
2232
+ @val = val
2233
+ @val2 = val2
2234
+ end
2235
+
2236
+ # symbol of expression
1531
2237
  def sym
1532
2238
  ","
1533
2239
  end
1534
2240
 
2241
+ # @return [Fixnum] expression priority
1535
2242
  def priority
1536
2243
  PRIORITY_COMMA
1537
2244
  end