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.
@@ -0,0 +1,141 @@
1
+ module Minjs
2
+ module ECMA262
3
+ # ECMA262 punctuator element
4
+ #
5
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 7.7
6
+ class Punctuator < Literal
7
+ attr_reader :val
8
+
9
+ @@sym = {}
10
+
11
+ def initialize(val)
12
+ @val = val.to_sym
13
+ end
14
+
15
+ # Returns punctuator object representation of string.
16
+ #
17
+ # @param val [String] punctuator
18
+ def self.get(val)
19
+ @@sym[val] ||= self.new(val)
20
+ end
21
+
22
+ # Returns a string containg the representation of punctuator.
23
+ def to_s
24
+ val.to_s
25
+ end
26
+
27
+ # Returns a ECMAScript string containg the representation of element.
28
+ # @see Base#to_js
29
+ def to_js
30
+ val.to_s
31
+ end
32
+
33
+ # Return true if punctuator equals to other.
34
+ #
35
+ # @param obj other element.
36
+ def ==(obj)
37
+ self.class == obj.class and self.val == obj.val
38
+ end
39
+ end
40
+ #punctuator
41
+ PUNC_CONDIF = Punctuator.get('?')
42
+ #punctuator
43
+ PUNC_ASSIGN = Punctuator.get('=')
44
+ #punctuator
45
+ PUNC_DIVASSIGN = Punctuator.get('/=')
46
+ #punctuator
47
+ PUNC_MULASSIGN = Punctuator.get('*=')
48
+ #punctuator
49
+ PUNC_MODASSIGN = Punctuator.get('%=')
50
+ #punctuator
51
+ PUNC_ADDASSIGN = Punctuator.get('+=')
52
+ #punctuator
53
+ PUNC_SUBASSIGN = Punctuator.get('-=')
54
+ #punctuator
55
+ PUNC_LSHIFTASSIGN = Punctuator.get('<<=')
56
+ #punctuator
57
+ PUNC_RSHIFTASSIGN = Punctuator.get('>>=')
58
+ #punctuator
59
+ PUNC_URSHIFTASSIGN = Punctuator.get('>>>=')
60
+ #punctuator
61
+ PUNC_ANDASSIGN = Punctuator.get('&=')
62
+ #punctuator
63
+ PUNC_XORASSIGN = Punctuator.get('^=')
64
+ #punctuator
65
+ PUNC_ORASSIGN = Punctuator.get('|=')
66
+ #punctuator
67
+ PUNC_LOR = Punctuator.get('||')
68
+ #punctuator
69
+ PUNC_LAND = Punctuator.get('&&')
70
+ #punctuator
71
+ PUNC_OR = Punctuator.get('|')
72
+ #punctuator
73
+ PUNC_XOR = Punctuator.get('^')
74
+ #punctuator
75
+ PUNC_AND = Punctuator.get('&')
76
+ #punctuator
77
+ PUNC_EQ = Punctuator.get('==')
78
+ #punctuator
79
+ PUNC_NEQ = Punctuator.get('!=')
80
+ #punctuator
81
+ PUNC_SEQ = Punctuator.get('===')
82
+ #punctuator
83
+ PUNC_SNEQ = Punctuator.get('!==')
84
+ #punctuator
85
+ PUNC_LT = Punctuator.get('<')
86
+ #punctuator
87
+ PUNC_GT = Punctuator.get('>')
88
+ #punctuator
89
+ PUNC_LTEQ = Punctuator.get('<=')
90
+ #punctuator
91
+ PUNC_GTEQ = Punctuator.get('>=')
92
+ #punctuator
93
+ PUNC_LSHIFT = Punctuator.get('<<')
94
+ #punctuator
95
+ PUNC_RSHIFT = Punctuator.get('>>')
96
+ #punctuator
97
+ PUNC_URSHIFT = Punctuator.get('>>>')
98
+ #punctuator
99
+ PUNC_ADD = Punctuator.get('+')
100
+ #punctuator
101
+ PUNC_SUB = Punctuator.get('-')
102
+ #punctuator
103
+ PUNC_MUL = Punctuator.get('*')
104
+ #punctuator
105
+ PUNC_DIV = Punctuator.get('/')
106
+ #punctuator
107
+ PUNC_MOD = Punctuator.get('%')
108
+ #punctuator
109
+ PUNC_INC = Punctuator.get('++')
110
+ #punctuator
111
+ PUNC_DEC = Punctuator.get('--')
112
+ #punctuator
113
+ PUNC_NOT = Punctuator.get('~')
114
+ #punctuator
115
+ PUNC_LNOT = Punctuator.get('!')
116
+ #punctuator
117
+ PUNC_LPARENTHESIS = Punctuator.get('(')
118
+ #punctuator
119
+ PUNC_RPARENTHESIS = Punctuator.get(')')
120
+ #punctuator
121
+ PUNC_LSQBRAC = Punctuator.get('[')
122
+ #punctuator
123
+ PUNC_RSQBRAC = Punctuator.get(']')
124
+ #punctuator
125
+ PUNC_LCURLYBRAC = Punctuator.get('{')
126
+ #punctuator
127
+ PUNC_RCURLYBRAC = Punctuator.get('}')
128
+ #punctuator
129
+ PUNC_COMMA = Punctuator.get(',')
130
+ #punctuator
131
+ PUNC_COLON = Punctuator.get(':')
132
+ #punctuator
133
+ PUNC_SEMICOLON = Punctuator.get(';')
134
+ #punctuator
135
+ PUNC_PERIOD = Punctuator.get('.')
136
+
137
+ Punctuator.class_eval {
138
+ private_class_method :new
139
+ }
140
+ end
141
+ end
@@ -1,30 +1,37 @@
1
1
  module Minjs
2
2
  module ECMA262
3
- class St < Base
3
+ # Base class of ECMA262 statement element.
4
+ #
5
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12
6
+ class Statement < Base
7
+ # return true if statement can convert to expression.
4
8
  def to_exp?
5
9
  false
6
10
  end
7
11
 
12
+ # return true if statement can convert to return statement.
8
13
  def to_return?
9
14
  false
10
15
  end
11
16
 
17
+ # @return [Fixnum] expression priority
12
18
  def priority
13
19
  999
14
20
  end
15
21
 
22
+ # return true if statement can convert to empty statement.
16
23
  def empty?
17
24
  false
18
25
  end
19
26
  end
20
27
 
28
+ # Base class of ECMA262 Block element.
21
29
  #
22
- # 12.1
23
- #
24
- class StBlock < St
30
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.1
31
+ class StBlock < Statement
25
32
  attr_reader :statement_list
26
33
 
27
- #statement_list:StatementList
34
+ # @param statement_list [StatementList] statement list
28
35
  def initialize(statement_list)
29
36
  if statement_list.kind_of? Array
30
37
  @statement_list = StatementList.new(statement_list)
@@ -33,30 +40,41 @@ module Minjs
33
40
  end
34
41
  end
35
42
 
43
+ # duplicate object
44
+ # @see Base#deep_dup
36
45
  def deep_dup
37
46
  self.class.new(@statement_list.deep_dup)
38
47
  end
39
48
 
49
+ # Replaces children object.
50
+ # @see Base#replace
40
51
  def replace(from, to)
41
52
  if from == @statement_list
42
53
  @statement_list = to
43
54
  end
44
55
  end
45
56
 
57
+ # Traverses this children and itself with given block.
58
+ #
59
+ # @see Base#traverse
46
60
  def traverse(parent, &block)
47
61
  @statement_list.traverse(self, &block)
48
- yield self, parent
62
+ yield parent, self
49
63
  end
50
64
 
65
+ # compare object
51
66
  def ==(obj)
52
67
  self.class == obj.class and
53
68
  @statement_list == obj.statement_list
54
69
  end
55
70
 
71
+ # Returns a ECMAScript string containg the representation of element.
72
+ # @see Base#to_js
56
73
  def to_js(options = {})
57
74
  concat(options, "{", @statement_list, "}")
58
75
  end
59
76
 
77
+ # true if block can convert to expression
60
78
  def to_exp?
61
79
  t = @statement_list.statement_list.select{|s|
62
80
  s.class != StEmpty
@@ -64,6 +82,7 @@ module Minjs
64
82
  t.length == 1 and t[0].to_exp?
65
83
  end
66
84
 
85
+ # Converts block to expression and returns it.
67
86
  def to_exp(options = {})
68
87
  @statement_list.statement_list.select{|s|
69
88
  s.class != StEmpty
@@ -71,6 +90,7 @@ module Minjs
71
90
 
72
91
  end
73
92
 
93
+ # @return true if block can convert to single statement.
74
94
  def to_statement?
75
95
  t = @statement_list.statement_list.select{|s|
76
96
  s.class != StEmpty
@@ -78,6 +98,7 @@ module Minjs
78
98
  t.length == 1 || t.length == 0
79
99
  end
80
100
 
101
+ # Converts block to single statement and return it.
81
102
  def to_statement
82
103
  t = @statement_list.statement_list.select{|s|
83
104
  s.class != StEmpty
@@ -90,32 +111,39 @@ module Minjs
90
111
  end
91
112
  end
92
113
 
114
+ # @return true if block can convert to 'return statement'
93
115
  def to_return?
94
116
  to_statement? and to_statement.to_return?
95
117
  end
96
118
 
119
+ # Converts block to 'return statement' and returns it
97
120
  def to_return
98
121
  to_statement.to_return
99
122
  end
100
123
 
124
+ # @return true if block is empty
101
125
  def empty?
102
126
  @statement_list.statement_list.select{|s|
103
127
  s.class != StEmpty
104
128
  }.length == 0
105
129
  end
106
130
 
131
+ # Returns the statement at index
132
+ # @param i index
133
+ # @return [Statement] statement
107
134
  def [](i)
108
135
  @statement_list[i]
109
136
  end
110
137
 
138
+ # Removes empty statement in this block.
111
139
  def remove_empty_statement
112
140
  statement_list.remove_empty_statement
113
141
  end
114
142
  end
143
+ # Base class of ECMA262 VariableStatement element.
115
144
  #
116
- # 12.2
117
- #
118
- class StVar < St
145
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.2
146
+ class StVar < Statement
119
147
  attr_reader :vars
120
148
  attr_reader :context
121
149
  #
@@ -127,6 +155,8 @@ module Minjs
127
155
  @context = context
128
156
  end
129
157
 
158
+ # duplicate object
159
+ # @see Base#deep_dup
130
160
  def deep_dup
131
161
  self.class.new(@context,
132
162
  @vars.collect{|x,y|
@@ -134,6 +164,8 @@ module Minjs
134
164
  })
135
165
  end
136
166
 
167
+ # Replaces children object.
168
+ # @see Base#replace
137
169
  def replace(from, to)
138
170
  @vars.each do |x|
139
171
  if x[0] .eql? from
@@ -146,6 +178,7 @@ module Minjs
146
178
  end
147
179
  end
148
180
 
181
+ # Traverses this children and itself with given block.
149
182
  def traverse(parent, &block)
150
183
  @vars.each do |x|
151
184
  x[0].traverse(self, &block)
@@ -153,13 +186,16 @@ module Minjs
153
186
  x[1].traverse(self, &block)
154
187
  end
155
188
  end
156
- yield self, parent
189
+ yield parent, self
157
190
  end
158
191
 
192
+ # compare object
159
193
  def ==(obj)
160
194
  self.class == obj.class and @vars == obj.vars
161
195
  end
162
196
 
197
+ # Returns a ECMAScript string containg the representation of element.
198
+ # @see Base#to_js
163
199
  def to_js(options = {})
164
200
  t = concat(options, :var, @vars.collect{|x|
165
201
  if x[1]
@@ -175,8 +211,8 @@ module Minjs
175
211
  end
176
212
  end
177
213
 
214
+ # If variable has no initializer, this method moves it to latter
178
215
  def normalization
179
- # if var has no initializer, move it to latter
180
216
  v1 = []
181
217
  v2 = []
182
218
  @vars.each do |x|
@@ -189,6 +225,7 @@ module Minjs
189
225
  @vars = v1.concat(v2)
190
226
  end
191
227
 
228
+ # remove parenthesis if possible
192
229
  def remove_paren
193
230
  @vars.each do |x|
194
231
  if x[1] and x[1].kind_of? ExpParen and x[1].val.priority <= PRIORITY_ASSIGNMENT
@@ -198,6 +235,7 @@ module Minjs
198
235
  self
199
236
  end
200
237
 
238
+ # add parenthesis if need
201
239
  def add_paren
202
240
  @vars.each do |x|
203
241
  if x[1] and x[1].priority > PRIORITY_ASSIGNMENT
@@ -208,71 +246,93 @@ module Minjs
208
246
  end
209
247
  end
210
248
 
211
- #12.3 empty
212
- class StEmpty < St
249
+ # Base class of ECMA262 EmptyStatement element.
250
+ #
251
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.2
252
+ class StEmpty < Statement
213
253
  def initialize()
214
254
  end
215
255
 
256
+ # duplicate object
257
+ # @see Base#deep_dup
216
258
  def deep_dup
217
259
  self.class.new()
218
260
  end
219
261
 
262
+ # Traverses this children and itself with given block.
220
263
  def traverse(parent, &block)
221
- yield self, parent
264
+ yield parent, self
222
265
  end
223
266
 
267
+ # compare object
224
268
  def ==(obj)
225
269
  self.class == obj.class
226
270
  end
227
271
 
272
+ # Returns a ECMAScript string containg the representation of element.
273
+ # @see Base#to_js
228
274
  def to_js(options = {})
229
275
  ";;"
230
276
  end
231
277
 
278
+ # return true if statement can convert to empty statement.
232
279
  def empty?
233
280
  true
234
281
  end
235
282
  end
236
283
 
237
- #12.4
238
- class StExp < St
284
+ # Base class of ECMA262 ExpressionStatement element.
285
+ #
286
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.4
287
+ class StExp < Statement
239
288
  attr_reader :exp
240
289
 
241
290
  def initialize(exp)
242
291
  @exp = exp
243
292
  end
244
293
 
294
+ # duplicate object
295
+ # @see Base#deep_dup
245
296
  def deep_dup
246
297
  self.class.new(@exp.deep_dup)
247
298
  end
248
299
 
300
+ # Replaces children object.
301
+ # @see Base#replace
249
302
  def replace(from, to)
250
303
  if @exp .eql? from
251
304
  @exp = to
252
305
  end
253
306
  end
254
307
 
308
+ # Traverses this children and itself with given block.
255
309
  def traverse(parent, &block)
256
310
  @exp.traverse(self, &block)
257
- yield self, parent
311
+ yield parent, self
258
312
  end
259
313
 
314
+ # compare object
260
315
  def ==(obj)
261
316
  self.class == obj.class and @exp == obj.exp
262
317
  end
263
318
 
319
+ # Returns a ECMAScript string containg the representation of element.
320
+ # @see Base#to_js
264
321
  def to_js(options = {})
265
322
  concat(options, @exp, ";")
266
323
  end
267
324
 
325
+ # Converts statement to expression and returns it.
268
326
  def to_exp(options = {})
269
327
  @exp.deep_dup
270
328
  end
271
329
 
330
+ # true if statement can convert to expression
272
331
  def to_exp?
273
332
  true
274
333
  end
275
334
 
335
+ # remove parenthesis if possible
276
336
  def remove_paren
277
337
  if @exp.kind_of? ExpParen
278
338
  @exp = @exp.val if @exp.remove_paren?
@@ -280,13 +340,16 @@ module Minjs
280
340
  self
281
341
  end
282
342
 
343
+ # add parenthesis if need
283
344
  def add_paren
284
345
  self
285
346
  end
286
347
  end
287
348
 
288
- #12.5
289
- class StIf < St
349
+ # Base class of ECMA262 IfStatement element.
350
+ #
351
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.5
352
+ class StIf < Statement
290
353
  attr_reader :then_st, :else_st, :cond
291
354
 
292
355
  def initialize(cond, then_st, else_st)
@@ -295,6 +358,8 @@ module Minjs
295
358
  @else_st = else_st
296
359
  end
297
360
 
361
+ # Replaces children object.
362
+ # @see Base#replace
298
363
  def replace(from, to)
299
364
  if from .eql? @cond
300
365
  @cond = to
@@ -305,19 +370,23 @@ module Minjs
305
370
  end
306
371
  end
307
372
 
373
+ # Traverses this children and itself with given block.
308
374
  def traverse(parent, &block)
309
375
  @cond.traverse(self, &block)
310
376
  @then_st.traverse(self, &block)
311
377
  if @else_st
312
378
  @else_st.traverse(self, &block)
313
379
  end
314
- yield self, parent
380
+ yield parent, self
315
381
  end
316
382
 
383
+ # duplicate object
384
+ # @see Base#deep_dup
317
385
  def deep_dup
318
386
  self.class.new(@cond.deep_dup, @then_st.deep_dup, @else_st ? @else_st.deep_dup : nil)
319
387
  end
320
388
 
389
+ # compare object
321
390
  def ==(obj)
322
391
  self.class == obj.class and
323
392
  @cond == obj.cond and
@@ -325,6 +394,8 @@ module Minjs
325
394
  @else_st == obj.else_st
326
395
  end
327
396
 
397
+ # Returns a ECMAScript string containg the representation of element.
398
+ # @see Base#to_js
328
399
  def to_js(options = {})
329
400
  if @else_st
330
401
  concat options, :if, "(", @cond, ")", @then_st, :else, @else_st
@@ -333,6 +404,7 @@ module Minjs
333
404
  end
334
405
  end
335
406
 
407
+ # return true if statement can convert to return statement.
336
408
  def to_return?
337
409
  if !@else_st
338
410
  return false
@@ -341,6 +413,7 @@ module Minjs
341
413
  end
342
414
  end
343
415
 
416
+ # Converts block to 'return statement' and returns it
344
417
  def to_return
345
418
  then_exp = then_st.exp;
346
419
  if @else_st
@@ -361,6 +434,7 @@ module Minjs
361
434
  ret
362
435
  end
363
436
 
437
+ # true if statement can convert to expression
364
438
  def to_exp?
365
439
  if !@else_st
366
440
  return false if @then_st.to_exp? == false
@@ -371,6 +445,7 @@ module Minjs
371
445
  return true
372
446
  end
373
447
 
448
+ # Converts statement to expression and returns it.
374
449
  def to_exp(options = {})
375
450
  cond = @cond.deep_dup
376
451
  if !@else_st
@@ -400,6 +475,7 @@ module Minjs
400
475
  end
401
476
  end
402
477
 
478
+ # remove parenthesis if possible
403
479
  def remove_paren
404
480
  if @cond.kind_of? ExpParen
405
481
  @cond = @cond.val
@@ -407,10 +483,12 @@ module Minjs
407
483
  self
408
484
  end
409
485
 
486
+ # add parenthesis if need
410
487
  def add_paren
411
488
  self
412
489
  end
413
490
 
491
+ # Removes empty statement in this then-clause or else-clause
414
492
  def remove_empty_statement
415
493
  if @then_st.kind_of? StBlock
416
494
  @then_st.remove_empty_statement
@@ -421,36 +499,46 @@ module Minjs
421
499
  end
422
500
  end
423
501
 
424
- #12.6
425
- class StWhile < St
502
+ # Base class of ECMA262 'while' IterationStatement element.
503
+ #
504
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.6.2
505
+ class StWhile < Statement
426
506
  attr_reader :exp, :statement
427
507
 
428
508
  def initialize(exp, statement)
429
509
  @exp, @statement = exp, statement
430
510
  end
431
511
 
512
+ # duplicate object
513
+ # @see Base#deep_dup
432
514
  def deep_dup
433
515
  self.class.new(@exp.deep_dup, @statement.deep_dup)
434
516
  end
435
517
 
518
+ # Replaces children object.
519
+ # @see Base#replace
436
520
  def replace(from, to)
437
521
  if from .eql? @statement
438
522
  @statement = to
439
523
  end
440
524
  end
441
525
 
526
+ # Traverses this children and itself with given block.
442
527
  def traverse(parent, &block)
443
528
  @exp.traverse(self, &block)
444
529
  @statement.traverse(self, &block)
445
- yield self, parent
530
+ yield parent, self
446
531
  end
447
532
 
533
+ # compare object
448
534
  def ==(obj)
449
535
  self.class == obj.class and
450
536
  @exp == obj.exp and
451
537
  @statement == obj.statement
452
538
  end
453
539
 
540
+ # Returns a ECMAScript string containg the representation of element.
541
+ # @see Base#to_js
454
542
  def to_js(options = {})
455
543
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
456
544
  statement = @statement.statement_list.statement_list[0]
@@ -461,6 +549,7 @@ module Minjs
461
549
  concat(options, :while, "(", @exp, ")", statement)
462
550
  end
463
551
 
552
+ # remove parenthesis if possible
464
553
  def remove_paren
465
554
  if @exp.kind_of? ExpParen
466
555
  @exp = @exp.val
@@ -468,40 +557,52 @@ module Minjs
468
557
  self
469
558
  end
470
559
 
560
+ # add parenthesis if need
471
561
  def add_paren
472
562
  self
473
563
  end
474
564
  end
475
565
 
476
- class StDoWhile < St
566
+ # Base class of ECMA262 'do-while' IterationStatement element.
567
+ #
568
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.6.1
569
+ class StDoWhile < Statement
477
570
  attr_reader :exp, :statement
478
571
 
479
572
  def initialize(exp, statement)
480
573
  @exp, @statement = exp, statement
481
574
  end
482
575
 
576
+ # duplicate object
577
+ # @see Base#deep_dup
483
578
  def deep_dup
484
579
  self.class.new(@exp.deep_dup, @statement.deep_dup)
485
580
  end
486
581
 
582
+ # Replaces children object.
583
+ # @see Base#replace
487
584
  def replace(from, to)
488
585
  if from .eql? @statement
489
586
  @statement = to
490
587
  end
491
588
  end
492
589
 
590
+ # Traverses this children and itself with given block.
493
591
  def traverse(parent, &block)
494
592
  @exp.traverse(self, &block)
495
593
  @statement.traverse(self, &block)
496
- yield self, parent
594
+ yield parent, self
497
595
  end
498
596
 
597
+ # compare object
499
598
  def ==(obj)
500
599
  self.class == obj.class and
501
600
  @exp == obj.exp and
502
601
  @statement == obj.statement
503
602
  end
504
603
 
604
+ # Returns a ECMAScript string containg the representation of element.
605
+ # @see Base#to_js
505
606
  def to_js(options = {})
506
607
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
507
608
  statement = @statement.statement_list.statement_list[0]
@@ -512,6 +613,7 @@ module Minjs
512
613
  concat options, :do, statement, :while, "(", @exp, ")", ";"
513
614
  end
514
615
 
616
+ # remove parenthesis if possible
515
617
  def remove_paren
516
618
  if @exp.kind_of? ExpParen
517
619
  @exp = @exp.val
@@ -519,15 +621,16 @@ module Minjs
519
621
  self
520
622
  end
521
623
 
624
+ # add parenthesis if need
522
625
  def add_paren
523
626
  self
524
627
  end
525
628
  end
526
629
 
630
+ # Base class of ECMA262 'for(;;)' IterationStatement element.
527
631
  #
528
- # 12.6.3 the for statement
529
- #
530
- class StFor < St
632
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.6.3
633
+ class StFor < Statement
531
634
  attr_reader :exp1, :exp2, :exp3, :statement
532
635
 
533
636
  def initialize(exp1, exp2, exp3, statement)
@@ -537,6 +640,8 @@ module Minjs
537
640
  @statement = statement
538
641
  end
539
642
 
643
+ # duplicate object
644
+ # @see Base#deep_dup
540
645
  def deep_dup
541
646
  self.class.new(@exp1 && @exp1.deep_dup,
542
647
  @exp2 && @exp2.deep_dup,
@@ -544,6 +649,8 @@ module Minjs
544
649
  @statement.deep_dup)
545
650
  end
546
651
 
652
+ # Replaces children object.
653
+ # @see Base#replace
547
654
  def replace(from, to)
548
655
  if from .eql? @exp1
549
656
  @exp1 = to
@@ -556,14 +663,16 @@ module Minjs
556
663
  end
557
664
  end
558
665
 
666
+ # Traverses this children and itself with given block.
559
667
  def traverse(parent, &block)
560
668
  @exp1.traverse(self, &block) if @exp1
561
669
  @exp2.traverse(self, &block) if @exp2
562
670
  @exp3.traverse(self, &block) if @exp3
563
671
  @statement.traverse(self, &block)
564
- yield self, parent
672
+ yield parent, self
565
673
  end
566
674
 
675
+ # compare object
567
676
  def ==(obj)
568
677
  self.class == obj.class and
569
678
  @exp1 == obj.exp1 and
@@ -572,6 +681,8 @@ module Minjs
572
681
  @statement == obj.statement
573
682
  end
574
683
 
684
+ # Returns a ECMAScript string containg the representation of element.
685
+ # @see Base#to_js
575
686
  def to_js(options = {})
576
687
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
577
688
  statement = @statement.statement_list.statement_list[0]
@@ -579,9 +690,10 @@ module Minjs
579
690
  statement = @statement
580
691
  end
581
692
 
582
- concat options, :for, "(", @exp1, ";", @exp2, ";", @exp3, ")", statement
693
+ concat options, :for, "(", @exp1, ";;", @exp2, ";;", @exp3, ")", statement
583
694
  end
584
695
 
696
+ # remove parenthesis if possible
585
697
  def remove_paren
586
698
  if @exp1.kind_of? ExpParen
587
699
  @exp1 = @exp1.val
@@ -595,15 +707,16 @@ module Minjs
595
707
  self
596
708
  end
597
709
 
710
+ # add parenthesis if need
598
711
  def add_paren
599
712
  self
600
713
  end
601
714
  end
602
715
 
716
+ # Base class of ECMA262 'for(var;;)' IterationStatement element.
603
717
  #
604
- # for(var i=0,... ; ; )
605
- #
606
- class StForVar < St
718
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.6.3
719
+ class StForVar < Statement
607
720
  attr_reader :context
608
721
  attr_reader :var_decl_list, :exp2, :exp3, :statement
609
722
 
@@ -619,6 +732,8 @@ module Minjs
619
732
  @statement = statement
620
733
  end
621
734
 
735
+ # duplicate object
736
+ # @see Base#deep_dup
622
737
  def deep_dup
623
738
  self.class.new(@context,
624
739
  @var_decl_list.collect{|x,y|
@@ -629,12 +744,15 @@ module Minjs
629
744
  @statement.deep_dup)
630
745
  end
631
746
 
747
+ # Replaces children object.
748
+ # @see Base#replace
632
749
  def replace(from, to)
633
750
  if from .eql? @statement
634
751
  @statement = to
635
752
  end
636
753
  end
637
754
 
755
+ # Traverses this children and itself with given block.
638
756
  def traverse(parent, &block)
639
757
  @var_decl_list.each do |x|
640
758
  x[0].traverse(self, &block)
@@ -645,12 +763,10 @@ module Minjs
645
763
  @exp2.traverse(self, &block) if @exp2
646
764
  @exp3.traverse(self, &block) if @exp3
647
765
  @statement.traverse(self, &block)
648
- yield self, parent
766
+ yield parent, self
649
767
  end
650
768
 
651
- #
652
- # for(var ...; ; ) => for(...; ; )
653
- #
769
+ # converts for-var-statement to for-statement
654
770
  def to_st_for
655
771
  tt = nil
656
772
  @var_decl_list.each{|x|
@@ -668,6 +784,7 @@ module Minjs
668
784
  StFor.new(tt, @exp2, @exp3, @statement)
669
785
  end
670
786
 
787
+ # compare object
671
788
  def ==(obj)
672
789
  self.class == obj.class and
673
790
  @var_decl_list == obj.var_decl_list and
@@ -676,6 +793,8 @@ module Minjs
676
793
  @statement == obj.statement
677
794
  end
678
795
 
796
+ # Returns a ECMAScript string containg the representation of element.
797
+ # @see Base#to_js
679
798
  def to_js(options = {})
680
799
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
681
800
  statement = @statement.statement_list.statement_list[0]
@@ -690,10 +809,11 @@ module Minjs
690
809
  concat options, x[0]
691
810
  end
692
811
  }.join(",")
693
- t = concat({:for_args => true}.merge(options), :for, "(var", _var_decl_list, ";", @exp2, ";", @exp3, ")")
812
+ t = concat(options, :for, "(var", _var_decl_list, ";;", @exp2, ";;", @exp3, ")")
694
813
  concat options, t, statement
695
814
  end
696
815
 
816
+ # remove parenthesis if possible
697
817
  def remove_paren
698
818
  @var_decl_list.each do|x|
699
819
  if x[1] and x[1].kind_of? ExpParen
@@ -709,12 +829,16 @@ module Minjs
709
829
  self
710
830
  end
711
831
 
832
+ # add parenthesis if need
712
833
  def add_paren
713
834
  self
714
835
  end
715
836
  end
716
837
 
717
- class StForIn < St
838
+ # Base class of ECMA262 'for(in)' IterationStatement element.
839
+ #
840
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.6.4
841
+ class StForIn < Statement
718
842
  attr_reader :exp1, :exp2, :statement
719
843
 
720
844
  def initialize(exp1, exp2, statement)
@@ -723,23 +847,29 @@ module Minjs
723
847
  @statement = statement
724
848
  end
725
849
 
850
+ # duplicate object
851
+ # @see Base#deep_dup
726
852
  def deep_dup
727
853
  self.class.new(@exp1.deep_dup, @exp2.deep_dup, @statement.deep_dup)
728
854
  end
729
855
 
856
+ # Replaces children object.
857
+ # @see Base#replace
730
858
  def replace(from, to)
731
859
  if from .eql? @statement
732
860
  @statement = to
733
861
  end
734
862
  end
735
863
 
864
+ # Traverses this children and itself with given block.
736
865
  def traverse(parent, &block)
737
866
  @exp1.traverse(self, &block)
738
867
  @exp2.traverse(self, &block)
739
868
  @statement.traverse(self, &block)
740
- yield self, parent
869
+ yield parent, self
741
870
  end
742
871
 
872
+ # compare object
743
873
  def ==(obj)
744
874
  self.class == obj.class and
745
875
  @exp1 == obj.exp1 and
@@ -747,6 +877,8 @@ module Minjs
747
877
  @statement == obj.statement
748
878
  end
749
879
 
880
+ # Returns a ECMAScript string containg the representation of element.
881
+ # @see Base#to_js
750
882
  def to_js(options = {})
751
883
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
752
884
  statement = @statement.statement_list.statement_list[0]
@@ -757,6 +889,7 @@ module Minjs
757
889
  concat options, :for, '(', @exp1, :in, @exp2, ')', statement
758
890
  end
759
891
 
892
+ # remove parenthesis if possible
760
893
  def remove_paren
761
894
  if @exp1.kind_of? ExpParen and @exp1.val.priority <= PRIORITY_LEFT_HAND_SIDE
762
895
  @exp1 = @exp1.val
@@ -767,6 +900,7 @@ module Minjs
767
900
  self
768
901
  end
769
902
 
903
+ # add parenthesis if need
770
904
  def add_paren
771
905
  if @exp1.priority > PRIORITY_LEFT_HAND_SIDE
772
906
  @exp1 = ExpParen.new(@exp1)
@@ -775,7 +909,10 @@ module Minjs
775
909
  end
776
910
  end
777
911
 
778
- class StForInVar < St
912
+ # Base class of ECMA262 'for(var in)' IterationStatement element.
913
+ #
914
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.6.4
915
+ class StForInVar < Statement
779
916
  attr_reader :context
780
917
  attr_reader :var_decl, :exp2, :statement
781
918
 
@@ -786,6 +923,8 @@ module Minjs
786
923
  @statement = statement
787
924
  end
788
925
 
926
+ # duplicate object
927
+ # @see Base#deep_dup
789
928
  def deep_dup
790
929
  self.class.new(@context,
791
930
  [@var_decl[0].deep_dup, @var_decl[1] ? @var_decl[1].deep_dup : nil],
@@ -793,20 +932,24 @@ module Minjs
793
932
  @statement.deep_dup)
794
933
  end
795
934
 
935
+ # Traverses this children and itself with given block.
796
936
  def traverse(parent, &block)
797
937
  @var_decl[0].traverse(self, &block)
798
938
  @var_decl[1].traverse(self, &block) if @var_decl[1]
799
939
  @exp2.traverse(self, &block)
800
940
  @statement.traverse(self, &block)
801
- yield self, parent
941
+ yield parent, self
802
942
  end
803
943
 
944
+ # Replaces children object.
945
+ # @see Base#replace
804
946
  def replace(from, to)
805
947
  if from .eql? @statement
806
948
  @statement = to
807
949
  end
808
950
  end
809
951
 
952
+ # converts for-in-var-statement to for-var-statement
810
953
  def to_st_for_in
811
954
  if @var_decl[1]
812
955
  t = ExpAssign.new(@var_decl[0], @var_decl[1])
@@ -816,6 +959,7 @@ module Minjs
816
959
  StForIn.new(t, @exp2, @statement)
817
960
  end
818
961
 
962
+ # compare object
819
963
  def ==(obj)
820
964
  self.class == obj.class and
821
965
  @var_decl == obj.var_decl and
@@ -823,6 +967,8 @@ module Minjs
823
967
  @statement == obj.statement
824
968
  end
825
969
 
970
+ # Returns a ECMAScript string containg the representation of element.
971
+ # @see Base#to_js
826
972
  def to_js(options = {})
827
973
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
828
974
  statement = @statement.statement_list.statement_list[0]
@@ -839,6 +985,7 @@ module Minjs
839
985
  concat options, :for, "(", :var, _var_decl, :in, @exp2, ")", statement
840
986
  end
841
987
 
988
+ # remove parenthesis if possible
842
989
  def remove_paren
843
990
  if @var_decl[1] and @var_decl[1].kind_of? ExpParen
844
991
  @var_decl[1] = @var_decl[1].val
@@ -849,34 +996,43 @@ module Minjs
849
996
  self
850
997
  end
851
998
 
999
+ # add parenthesis if need
852
1000
  def add_paren
853
1001
  self
854
1002
  end
855
1003
  end
856
1004
 
857
1005
 
858
- #12.7
859
- class StContinue < St
1006
+ # Base class of ECMA262 ContinueStatement element.
1007
+ #
1008
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.7
1009
+ class StContinue < Statement
860
1010
  attr_reader :exp
861
1011
 
862
1012
  def initialize(exp = nil)
863
1013
  @exp = exp
864
1014
  end
865
1015
 
1016
+ # duplicate object
1017
+ # @see Base#deep_dup
866
1018
  def deep_dup
867
1019
  self.class.new(@exp ? @exp.deep_dup : nil)
868
1020
  end
869
1021
 
1022
+ # Traverses this children and itself with given block.
870
1023
  def traverse(parent, &block)
871
1024
  @exp.traverse(self, &block) if @exp
872
- yield self, parent
1025
+ yield parent, self
873
1026
  end
874
1027
 
1028
+ # compare object
875
1029
  def ==(obj)
876
1030
  self.class == obj.class and
877
1031
  @exp == obj.exp
878
1032
  end
879
1033
 
1034
+ # Returns a ECMAScript string containg the representation of element.
1035
+ # @see Base#to_js
880
1036
  def to_js(options = {})
881
1037
  if @exp
882
1038
  concat options, :continue, @exp, ";"
@@ -886,28 +1042,36 @@ module Minjs
886
1042
  end
887
1043
  end
888
1044
 
889
- #12.8
890
- class StBreak < St
1045
+ # Base class of ECMA262 BreakStatement element.
1046
+ #
1047
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.8
1048
+ class StBreak < Statement
891
1049
  attr_reader :exp
892
1050
 
893
1051
  def initialize(exp = nil)
894
1052
  @exp = exp
895
1053
  end
896
1054
 
1055
+ # duplicate object
1056
+ # @see Base#deep_dup
897
1057
  def deep_dup
898
1058
  self.class.new(@exp ? @exp.deep_dup : nil)
899
1059
  end
900
1060
 
1061
+ # Traverses this children and itself with given block.
901
1062
  def traverse(parent, &block)
902
1063
  @exp.traverse(self, &block) if @exp
903
- yield self, parent
1064
+ yield parent, self
904
1065
  end
905
1066
 
1067
+ # compare object
906
1068
  def ==(obj)
907
1069
  self.class == obj.class and
908
1070
  @exp == obj.exp
909
1071
  end
910
1072
 
1073
+ # Returns a ECMAScript string containg the representation of element.
1074
+ # @see Base#to_js
911
1075
  def to_js(options = {})
912
1076
  if @exp
913
1077
  concat options, :break, @exp, ";"
@@ -917,41 +1081,53 @@ module Minjs
917
1081
  end
918
1082
  end
919
1083
 
920
- #12.9
921
- class StReturn < St
1084
+ # Base class of ECMA262 ReturnStatement element.
1085
+ #
1086
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.9
1087
+ class StReturn < Statement
922
1088
  attr_reader :exp
923
1089
 
924
1090
  def initialize(exp = nil)
925
1091
  @exp = exp
926
1092
  end
927
1093
 
1094
+ # duplicate object
1095
+ # @see Base#deep_dup
928
1096
  def deep_dup
929
1097
  self.class.new(exp ? exp.deep_dup : nil)
930
1098
  end
931
1099
 
1100
+ # Replaces children object.
1101
+ # @see Base#replace
932
1102
  def replace(from, to)
933
1103
  if from .eql? @exp
934
1104
  @exp = to
935
1105
  end
936
1106
  end
937
1107
 
1108
+ # Traverses this children and itself with given block.
938
1109
  def traverse(parent, &block)
939
1110
  @exp.traverse(self, &block) if @exp
940
- yield self, parent
1111
+ yield parent, self
941
1112
  end
942
1113
 
1114
+ # return true if statement can convert to return statement.
943
1115
  def to_return?
944
1116
  true
945
1117
  end
946
1118
 
1119
+ # Converts block to 'return statement' and returns it
947
1120
  def to_return
948
1121
  self
949
1122
  end
950
1123
 
1124
+ # compare object
951
1125
  def ==(obj)
952
1126
  self.class == obj.class and @exp == obj.exp
953
1127
  end
954
1128
 
1129
+ # Returns a ECMAScript string containg the representation of element.
1130
+ # @see Base#to_js
955
1131
  def to_js(options = {})
956
1132
  if @exp
957
1133
  concat options, :return, @exp, ";"
@@ -960,6 +1136,7 @@ module Minjs
960
1136
  end
961
1137
  end
962
1138
 
1139
+ # remove parenthesis if possible
963
1140
  def remove_paren
964
1141
  if @exp.kind_of? ExpParen
965
1142
  @exp = @exp.val
@@ -967,12 +1144,16 @@ module Minjs
967
1144
  self
968
1145
  end
969
1146
 
1147
+ # add parenthesis if need
970
1148
  def add_paren
971
1149
  self
972
1150
  end
973
1151
  end
974
- #12.10
975
- class StWith < St
1152
+
1153
+ # Base class of ECMA262 WithStatement element.
1154
+ #
1155
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.10
1156
+ class StWith < Statement
976
1157
  attr_reader :exp, :statement, :context
977
1158
 
978
1159
  def initialize(context, exp, statement)
@@ -981,10 +1162,14 @@ module Minjs
981
1162
  @statement = statement
982
1163
  end
983
1164
 
1165
+ # duplicate object
1166
+ # @see Base#deep_dup
984
1167
  def deep_dup
985
1168
  self.class.new(@context, @exp.deep_dup, @statement.deep_dup)
986
1169
  end
987
1170
 
1171
+ # Replaces children object.
1172
+ # @see Base#replace
988
1173
  def replace(from, to)
989
1174
  if @exp .eql? from
990
1175
  @exp = to
@@ -993,22 +1178,27 @@ module Minjs
993
1178
  end
994
1179
  end
995
1180
 
1181
+ # Traverses this children and itself with given block.
996
1182
  def traverse(parent, &block)
997
1183
  @exp.traverse(self, &block)
998
1184
  @statement.traverse(self, &block)
999
- yield self, parent
1185
+ yield parent, self
1000
1186
  end
1001
1187
 
1188
+ # compare object
1002
1189
  def ==(obj)
1003
1190
  self.class == obj.class and
1004
1191
  @exp == obj.exp and
1005
1192
  @statement == obj.statement
1006
1193
  end
1007
1194
 
1195
+ # Returns a ECMAScript string containg the representation of element.
1196
+ # @see Base#to_js
1008
1197
  def to_js(options = {})
1009
1198
  concat options, :with, "(", @exp, ")", @statement
1010
1199
  end
1011
1200
 
1201
+ # remove parenthesis if possible
1012
1202
  def remove_paren
1013
1203
  if @exp.kind_of? ExpParen
1014
1204
  @exp = @exp.val
@@ -1016,12 +1206,16 @@ module Minjs
1016
1206
  self
1017
1207
  end
1018
1208
 
1209
+ # add parenthesis if need
1019
1210
  def add_paren
1020
1211
  self
1021
1212
  end
1022
1213
  end
1023
- #12.11
1024
- class StSwitch < St
1214
+
1215
+ # Base class of ECMA262 SwitchStatement element.
1216
+ #
1217
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.11
1218
+ class StSwitch < Statement
1025
1219
  attr_reader :exp, :blocks
1026
1220
 
1027
1221
  #
@@ -1032,6 +1226,8 @@ module Minjs
1032
1226
  @blocks = blocks
1033
1227
  end
1034
1228
 
1229
+ # duplicate object
1230
+ # @see Base#deep_dup
1035
1231
  def deep_dup
1036
1232
  self.class.new(@exp.deep_dup,
1037
1233
  @blocks.collect{|x, y|
@@ -1042,6 +1238,8 @@ module Minjs
1042
1238
  })
1043
1239
  end
1044
1240
 
1241
+ # Replaces children object.
1242
+ # @see Base#replace
1045
1243
  def replace(from, to)
1046
1244
  if @exp .eql? from
1047
1245
  @exp = to
@@ -1050,6 +1248,7 @@ module Minjs
1050
1248
  end
1051
1249
  end
1052
1250
 
1251
+ # Traverses this children and itself with given block.
1053
1252
  def traverse(parent, &blocks)
1054
1253
  @exp.traverse(self, &blocks)
1055
1254
  @blocks.each do |b|
@@ -1058,14 +1257,18 @@ module Minjs
1058
1257
  end
1059
1258
  b[1].traverse(self, &blocks)
1060
1259
  end
1061
- yield self, parent
1260
+ yield parent, self
1062
1261
  end
1063
1262
 
1263
+ # compare object
1064
1264
  def ==(obj)
1065
1265
  self.class == obj.class and
1066
1266
  @exp == obj.exp and
1067
1267
  @blocks == obj.blocks
1068
1268
  end
1269
+
1270
+ # Returns a ECMAScript string containg the representation of element.
1271
+ # @see Base#to_js
1069
1272
  def to_js(options = {})
1070
1273
  t = concat(options, :switch, "(", @exp, ")", "{")
1071
1274
  @blocks.each do |b|
@@ -1078,6 +1281,7 @@ module Minjs
1078
1281
  t = concat(options, t, "}")
1079
1282
  end
1080
1283
 
1284
+ # remove parenthesis if possible
1081
1285
  def remove_paren
1082
1286
  if @exp.kind_of? ExpParen
1083
1287
  @exp = @exp.val
@@ -1090,12 +1294,15 @@ module Minjs
1090
1294
  self
1091
1295
  end
1092
1296
 
1297
+ # add parenthesis if need
1093
1298
  def add_paren
1094
1299
  self
1095
1300
  end
1096
1301
  end
1097
- #12.12
1098
- class StLabelled < St
1302
+ # Base class of ECMA262 LabelledStatement element.
1303
+ #
1304
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.12
1305
+ class StLabelled < Statement
1099
1306
  attr_reader :label, :statement
1100
1307
 
1101
1308
  def initialize(label, statement)
@@ -1103,10 +1310,14 @@ module Minjs
1103
1310
  @statement = statement
1104
1311
  end
1105
1312
 
1313
+ # duplicate object
1314
+ # @see Base#deep_dup
1106
1315
  def deep_dup
1107
1316
  self.class.new(@label.deep_dup, @statement.deep_dup)
1108
1317
  end
1109
1318
 
1319
+ # Replaces children object.
1320
+ # @see Base#replace
1110
1321
  def replace(from, to)
1111
1322
  if from .eql? @label
1112
1323
  @label = to
@@ -1115,51 +1326,66 @@ module Minjs
1115
1326
  end
1116
1327
  end
1117
1328
 
1329
+ # Traverses this children and itself with given block.
1118
1330
  def traverse(parent, &block)
1119
1331
  @label.traverse(self, &block)
1120
1332
  @statement.traverse(self, &block)
1121
- yield self, parent
1333
+ yield parent, self
1122
1334
  end
1123
1335
 
1336
+ # compare object
1124
1337
  def ==(obj)
1125
1338
  self.class == obj.class and
1126
1339
  @label == obj.label and
1127
1340
  @statement == obj.statement
1128
1341
  end
1342
+
1343
+ # Returns a ECMAScript string containg the representation of element.
1344
+ # @see Base#to_js
1129
1345
  def to_js(options = {})
1130
1346
  concat options, @label, ":", @statement
1131
1347
  end
1132
1348
  end
1133
1349
 
1134
- #12.13
1135
- class StThrow < St
1350
+ # Base class of ECMA262 ThrowStatement element.
1351
+ #
1352
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.13
1353
+ class StThrow < Statement
1136
1354
  attr_reader :exp
1137
1355
 
1138
1356
  def initialize(exp)
1139
1357
  @exp = exp
1140
1358
  end
1141
1359
 
1360
+ # duplicate object
1361
+ # @see Base#deep_dup
1142
1362
  def deep_dup
1143
1363
  self.class.new(@exp.deep_dup)
1144
1364
  end
1145
1365
 
1366
+ # Traverses this children and itself with given block.
1146
1367
  def traverse(parent, &block)
1147
1368
  @exp.traverse(self, &block)
1148
- yield self, parent
1369
+ yield parent, self
1149
1370
  end
1150
1371
 
1372
+ # compare object
1151
1373
  def ==(obj)
1152
1374
  self.class == obj.class and
1153
1375
  @exp == obj.exp
1154
1376
  end
1155
1377
 
1378
+ # Returns a ECMAScript string containg the representation of element.
1379
+ # @see Base#to_js
1156
1380
  def to_js(options = {})
1157
1381
  concat options, :throw, @exp, ";"
1158
1382
  end
1159
1383
  end
1160
1384
 
1161
- #12.14
1162
- class StTry < St
1385
+ # Base class of ECMA262 TryStatement element.
1386
+ #
1387
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.14
1388
+ class StTry < Statement
1163
1389
  attr_reader :context
1164
1390
  attr_reader :try, :catch, :finally
1165
1391
 
@@ -1170,6 +1396,8 @@ module Minjs
1170
1396
  @finally = finally
1171
1397
  end
1172
1398
 
1399
+ # duplicate object
1400
+ # @see Base#deep_dup
1173
1401
  def deep_dup
1174
1402
  self.class.new(@context,
1175
1403
  @try.deep_dup,
@@ -1177,6 +1405,8 @@ module Minjs
1177
1405
  @finally ? @finally.deep_dup : nil)
1178
1406
  end
1179
1407
 
1408
+ # Replaces children object.
1409
+ # @see Base#replace
1180
1410
  def replace(from, to)
1181
1411
  if from .eql? @try
1182
1412
  @try = to
@@ -1189,6 +1419,7 @@ module Minjs
1189
1419
  end
1190
1420
  end
1191
1421
 
1422
+ # Traverses this children and itself with given block.
1192
1423
  def traverse(parent, &block)
1193
1424
  @try.traverse(self, &block)
1194
1425
  if @catch
@@ -1196,9 +1427,10 @@ module Minjs
1196
1427
  @catch[1].traverse(self, &block)
1197
1428
  end
1198
1429
  @finally.traverse(self, &block) if @finally
1199
- yield self, parent
1430
+ yield parent, self
1200
1431
  end
1201
1432
 
1433
+ # compare object
1202
1434
  def ==(obj)
1203
1435
  self.class == obj.class and
1204
1436
  self.try == obj.try and
@@ -1206,6 +1438,8 @@ module Minjs
1206
1438
  self.finally == obj.finally
1207
1439
  end
1208
1440
 
1441
+ # Returns a ECMAScript string containg the representation of element.
1442
+ # @see Base#to_js
1209
1443
  def to_js(options = {})
1210
1444
  if @catch and @finally
1211
1445
  concat(options, :try, @try, :catch, "(", @catch[0], ")", @catch[1], :finally, @finally)
@@ -1217,31 +1451,38 @@ module Minjs
1217
1451
  end
1218
1452
  end
1219
1453
 
1220
- #12.15
1221
- class StDebugger < St
1454
+ # Base class of ECMA262 DebuggerStatement element.
1455
+ #
1456
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 12.15
1457
+ class StDebugger < Statement
1458
+ # duplicate object
1459
+ # @see Base#deep_dup
1222
1460
  def deep_dup
1223
1461
  self.class.new
1224
1462
  end
1225
1463
 
1464
+ # Traverses this children and itself with given block.
1226
1465
  def traverse(parent, &block)
1227
- yield self, parent
1466
+ yield parent, self
1228
1467
  end
1229
1468
 
1469
+ # compare object
1230
1470
  def ==(obj)
1231
1471
  self.class == obj.class
1232
1472
  end
1233
1473
 
1474
+ # Returns a ECMAScript string containg the representation of element.
1475
+ # @see Base#to_js
1234
1476
  def to_js(options = {})
1235
1477
  concat options, :debugger, ";"
1236
1478
  end
1237
1479
  end
1238
1480
 
1481
+ # Base class of ECMA262 FunctionDeclaration / FunctionExpression
1482
+ # element
1239
1483
  #
1240
- # 13 function declaration
1241
- # 13 function expression
1242
- # 11.1.5 getter/setter
1243
- #
1244
- class StFunc < St
1484
+ # @see http://www.ecma-international.org/ecma-262 ECMA262 13, 11.1.5
1485
+ class StFunc < Statement
1245
1486
  attr_reader :name
1246
1487
  attr_reader :args
1247
1488
  attr_reader :statements
@@ -1257,10 +1498,13 @@ module Minjs
1257
1498
  @setter = options[:setter]
1258
1499
  end
1259
1500
 
1501
+ # @return [Fixnum] expression priority
1260
1502
  def priority
1261
- 10
1503
+ PRIORITY_PRIMARY
1262
1504
  end
1263
1505
 
1506
+ # duplicate object
1507
+ # @see Base#deep_dup
1264
1508
  def deep_dup
1265
1509
  self.class.new(@context, @name ? @name.deep_dup : nil,
1266
1510
  @args.collect{|args|args.deep_dup},
@@ -1268,15 +1512,17 @@ module Minjs
1268
1512
  {decl: @decl, getter: @getter, setter: @setter})
1269
1513
  end
1270
1514
 
1515
+ # Traverses this children and itself with given block.
1271
1516
  def traverse(parent, &block)
1272
1517
  @name.traverse(self, &block) if @name
1273
1518
  @args.each do |arg|
1274
1519
  arg.traverse(self, &block)
1275
1520
  end
1276
1521
  @statements.traverse(self, &block)
1277
- yield self, parent
1522
+ yield parent, self
1278
1523
  end
1279
1524
 
1525
+ # compare object
1280
1526
  def ==(obj)
1281
1527
  self.class == obj.class and
1282
1528
  @name == obj.name and
@@ -1284,6 +1530,8 @@ module Minjs
1284
1530
  @statements == obj.statements
1285
1531
  end
1286
1532
 
1533
+ # Returns a ECMAScript string containg the representation of element.
1534
+ # @see Base#to_js
1287
1535
  def to_js(options = {})
1288
1536
  _args = @args.collect{|x|x.to_js(options)}.join(",")
1289
1537
  if @getter
@@ -1295,18 +1543,22 @@ module Minjs
1295
1543
  end
1296
1544
  end
1297
1545
 
1546
+ # @return [Boolean] true if expression is kind of LeftHandSideExpression.
1298
1547
  def left_hand_side_exp?
1299
1548
  true
1300
1549
  end
1301
1550
 
1551
+ # Returns true if this object is setter in object
1302
1552
  def getter?
1303
1553
  @getter
1304
1554
  end
1305
1555
 
1556
+ # Returns true if this object is setter in object
1306
1557
  def setter?
1307
1558
  @setter
1308
1559
  end
1309
1560
 
1561
+ # Returns true if this object is function declaration
1310
1562
  def decl?
1311
1563
  @decl
1312
1564
  end