minjs 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,10 @@ module Minjs
23
23
  def traverse(parent, &block)
24
24
  end
25
25
 
26
+ def ==(obj)
27
+ self.class == obj.class and self.val == obj.val
28
+ end
29
+
26
30
  def to_js(options = {})
27
31
  "??"
28
32
  end
@@ -43,6 +47,10 @@ module Minjs
43
47
  true
44
48
  end
45
49
 
50
+ def ==(obj)
51
+ self.class == obj.class
52
+ end
53
+
46
54
  def to_js(options = {})
47
55
  " "
48
56
  end
@@ -61,6 +69,10 @@ module Minjs
61
69
  true
62
70
  end
63
71
 
72
+ def ==(obj)
73
+ self.class == obj.class
74
+ end
75
+
64
76
  def to_js(options = {})
65
77
  "\n"
66
78
  end
@@ -90,6 +102,10 @@ module Minjs
90
102
  "null"
91
103
  end
92
104
 
105
+ def ==(obj)
106
+ self.class == obj.class
107
+ end
108
+
93
109
  def to_js(options = {})
94
110
  "null"
95
111
  end
@@ -127,6 +143,11 @@ module Minjs
127
143
  yield self, parent
128
144
  end
129
145
 
146
+ def ==(obj)
147
+ self.class == obj.class and
148
+ @val == obj.val
149
+ end
150
+
130
151
  def to_js(options = {})
131
152
  @val.to_s
132
153
  end
@@ -135,6 +156,18 @@ module Minjs
135
156
  @val == :true
136
157
  end
137
158
 
159
+ def to_ecma262_boolean
160
+ if @val == :false
161
+ false
162
+ else
163
+ true
164
+ end
165
+ end
166
+
167
+ def ecma262_typeof
168
+ :boolean
169
+ end
170
+
138
171
  @@true = self.new(:true)
139
172
  @@false = self.new(:false)
140
173
  def self.get(val)
@@ -160,6 +193,11 @@ module Minjs
160
193
  def traverse(parent)
161
194
  yield self, parent
162
195
  end
196
+
197
+ def ==(obj)
198
+ self.class == obj.class and @val == obj.val
199
+ end
200
+
163
201
  def to_js(options = {})
164
202
  t = "\""
165
203
  @val.to_s.each_codepoint do |c|
@@ -238,6 +276,10 @@ module Minjs
238
276
  yield self, parent
239
277
  end
240
278
 
279
+ def ==(obj)
280
+ self.class == obj.class and self.to_ecma262_string == obj.to_ecma262_string
281
+ end
282
+
241
283
  def to_js(options = {})
242
284
  if @nan
243
285
  return "NaN"
@@ -289,6 +331,7 @@ module Minjs
289
331
  end
290
332
  "#{@integer}.#{d}e#{@exp}".to_f
291
333
  end
334
+
292
335
  #
293
336
  # 9.8.1
294
337
  #
@@ -352,6 +395,8 @@ module Minjs
352
395
  NUMERIC_NAN = ECMA262Numeric.new(:nan)
353
396
 
354
397
  class ECMA262RegExp < Literal
398
+ attr_reader :body, :flags
399
+
355
400
  def initialize(body, flags)
356
401
  @body = body
357
402
  @flags = flags
@@ -365,6 +410,10 @@ module Minjs
365
410
  yield self, parent
366
411
  end
367
412
 
413
+ def ==(obj)
414
+ self.class == obj.class and @body == obj.body and @flags == obj.flags
415
+ end
416
+
368
417
  def to_js(options = {})
369
418
  "/#{@body}/#{@flags}"
370
419
  end
@@ -374,6 +423,8 @@ module Minjs
374
423
  LITERAL_FALSE = Boolean.new(:false)
375
424
 
376
425
  class ECMA262Array < Literal
426
+ attr_reader :val
427
+
377
428
  def initialize(val)
378
429
  @val = val # val is Array
379
430
  end
@@ -385,9 +436,14 @@ module Minjs
385
436
  def traverse(parent, &block)
386
437
  yield self, parent
387
438
  @val.each do |k|
388
- k.traverse(parent, &block)
439
+ k.traverse(parent, &block) if k
389
440
  end
390
441
  end
442
+
443
+ def ==(obj)
444
+ self.class == obj.class and @val == obj.val
445
+ end
446
+
391
447
  def to_js(options = {})
392
448
  "[" + @val.collect{|x| x.to_s}.join(",") + "]"
393
449
  end
@@ -411,6 +467,8 @@ module Minjs
411
467
  end
412
468
 
413
469
  public
470
+ attr_reader :val
471
+
414
472
  def initialize(val)
415
473
  @val = val
416
474
  end
@@ -426,6 +484,11 @@ module Minjs
426
484
  v.traverse(parent, &block)
427
485
  end
428
486
  end
487
+
488
+ def ==(obj)
489
+ self.class == obj.class and @val == obj.val
490
+ end
491
+
429
492
  def to_js(options = {})
430
493
  "{" + @val.collect{|x, y|
431
494
  if y.kind_of? StFunc and (y.getter? || y.setter?)
@@ -474,6 +537,11 @@ module Minjs
474
537
  def traverse(parent, &block)
475
538
  end
476
539
 
540
+ def ==(obj)
541
+ self.class == obj.class and
542
+ @comment == obj.comment
543
+ end
544
+
477
545
  def to_js(options)
478
546
  "//#{@comment}"
479
547
  end
@@ -484,6 +552,8 @@ module Minjs
484
552
  end
485
553
 
486
554
  class MultiLineComment < Literal
555
+ attr_reader :comment, :has_lf
556
+
487
557
  def initialize(comment, has_lf)
488
558
  @comment = comment
489
559
  @has_lf = has_lf
@@ -492,6 +562,12 @@ module Minjs
492
562
  def traverse(parent, &block)
493
563
  end
494
564
 
565
+ def ==(obj)
566
+ self.class == obj.class and
567
+ @comment == obj.comment and
568
+ @has_lf == obj.has_lf
569
+ end
570
+
495
571
  def to_js(options)
496
572
  if lt?
497
573
  "/*#{@comment}*/"
@@ -550,13 +626,13 @@ module Minjs
550
626
  self.class.new(@context, @val)
551
627
  end
552
628
 
553
- def to_js(options = {})
554
- val.to_s
555
- end
556
-
557
629
  def ==(obj)
558
630
  self.class == obj.class and self.val == obj.val
559
631
  end
632
+
633
+ def to_js(options = {})
634
+ val.to_s
635
+ end
560
636
  end
561
637
 
562
638
  ID_THIS = IdentifierName.get(nil, :this)
@@ -30,6 +30,10 @@ module Minjs
30
30
  def to_s
31
31
  val.to_s
32
32
  end
33
+
34
+ def ==(obj)
35
+ self.class == obj.class and self.val == obj.val
36
+ end
33
37
  end
34
38
  PUNC_CONDIF = Punctuator.get('?')
35
39
  PUNC_CONDELSE = Punctuator.get(':')