minjs 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/minjs/compressor.rb +130 -121
- data/lib/minjs/ctype.rb +2 -0
- data/lib/minjs/ecma262/base.rb +172 -34
- data/lib/minjs/ecma262/exp.rb +644 -388
- data/lib/minjs/ecma262/lit.rb +39 -3
- data/lib/minjs/ecma262/st.rb +388 -157
- data/lib/minjs/exceptions.rb +1 -1
- data/lib/minjs/expression.rb +88 -76
- data/lib/minjs/func.rb +1 -2
- data/lib/minjs/lex.rb +7 -7
- data/lib/minjs/minjs_compressor.rb +8 -4
- data/lib/minjs/program.rb +1 -1
- data/lib/minjs/statement.rb +32 -15
- data/lib/minjs/version.rb +1 -1
- metadata +2 -2
data/lib/minjs/ecma262/exp.rb
CHANGED
@@ -12,16 +12,50 @@ module Minjs
|
|
12
12
|
def reduce(parent)
|
13
13
|
end
|
14
14
|
|
15
|
-
def priority
|
15
|
+
def priority
|
16
16
|
9999
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
module BinaryOperation
|
21
|
+
def remove_paren
|
22
|
+
if @val.kind_of? ExpParen and @val.val.priority <= self.priority
|
23
|
+
@val = @val.val if @val.remove_paren?
|
24
|
+
end
|
25
|
+
if @val2.kind_of? ExpParen and @val2.val.priority < self.priority
|
26
|
+
@val2 = @val2.val
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module UnaryOperation
|
32
|
+
def remove_paren
|
33
|
+
if @val.kind_of? ExpParen and @val.val.priority <= self.priority
|
34
|
+
@val = @val.val if @val.remove_paren?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module AssignmentOperation
|
40
|
+
def remove_paren
|
41
|
+
if @val.kind_of? ExpParen and @val.val.priority <= 20
|
42
|
+
@val = @val.val if @val.remove_paren?
|
43
|
+
end
|
44
|
+
if @val2.kind_of? ExpParen and @val2.val.priority <= 130
|
45
|
+
@val2 = @val2.val
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
20
50
|
class ExpArg1 < Exp
|
21
51
|
def initialize(val)
|
22
52
|
@val = val
|
23
53
|
end
|
24
54
|
|
55
|
+
def deep_dup
|
56
|
+
self.class.new(@val.deep_dup)
|
57
|
+
end
|
58
|
+
|
25
59
|
def replace(from, to)
|
26
60
|
if @val == from
|
27
61
|
@val = to
|
@@ -46,6 +80,10 @@ module Minjs
|
|
46
80
|
@val2 = val2
|
47
81
|
end
|
48
82
|
|
83
|
+
def deep_dup
|
84
|
+
self.class.new(@val.deep_dup, @val2.deep_dup)
|
85
|
+
end
|
86
|
+
|
49
87
|
def replace(from, to)
|
50
88
|
if @val == from
|
51
89
|
@val = to
|
@@ -65,16 +103,25 @@ module Minjs
|
|
65
103
|
end
|
66
104
|
end
|
67
105
|
|
106
|
+
#
|
68
107
|
# ""
|
108
|
+
#
|
69
109
|
class ExpEmpty < Exp
|
110
|
+
def deep_dup
|
111
|
+
self.class.new
|
112
|
+
end
|
113
|
+
|
70
114
|
def traverse(parent, &block)
|
71
115
|
end
|
116
|
+
|
72
117
|
def to_js(options = {})
|
73
118
|
""
|
74
119
|
end
|
75
120
|
end
|
76
121
|
|
77
|
-
#
|
122
|
+
#
|
123
|
+
# 11.1 primary expression
|
124
|
+
#
|
78
125
|
class ExpParen < Exp
|
79
126
|
attr_reader :val
|
80
127
|
|
@@ -82,8 +129,12 @@ module Minjs
|
|
82
129
|
@val = val
|
83
130
|
end
|
84
131
|
|
85
|
-
def priority
|
86
|
-
|
132
|
+
def priority
|
133
|
+
10
|
134
|
+
end
|
135
|
+
|
136
|
+
def deep_dup
|
137
|
+
self.class.new(@val.deep_dup)
|
87
138
|
end
|
88
139
|
|
89
140
|
def replace(from, to)
|
@@ -100,270 +151,419 @@ module Minjs
|
|
100
151
|
def to_js(options = {})
|
101
152
|
"(#{@val.to_js(options)})"
|
102
153
|
end
|
103
|
-
end
|
104
154
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
114
|
-
class ExpDivAssign < ExpAssign
|
115
|
-
def sym
|
116
|
-
"/="
|
155
|
+
def remove_paren?
|
156
|
+
js = @val.to_js
|
157
|
+
if js.match(/^function/) or js.match(/^{/)
|
158
|
+
false
|
159
|
+
else
|
160
|
+
true
|
161
|
+
end
|
117
162
|
end
|
118
|
-
|
119
|
-
|
163
|
+
|
164
|
+
def remove_paren
|
165
|
+
if @val.kind_of? ExpParen
|
166
|
+
@val = @val.val if @val.remove_paren?
|
167
|
+
end
|
120
168
|
end
|
121
169
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
170
|
+
#
|
171
|
+
# 11.2 Left-Hand-Side Expressions
|
172
|
+
#
|
173
|
+
# function expression: see st.rb:StFunc
|
174
|
+
#
|
175
|
+
# 11.2.1 Property Accessors val[val2]
|
176
|
+
#
|
177
|
+
class ExpPropBrac < ExpArg2
|
178
|
+
def priority
|
179
|
+
20
|
125
180
|
end
|
126
|
-
|
127
|
-
|
181
|
+
|
182
|
+
def traverse(parent, &block)
|
183
|
+
@val.traverse(self, &block)
|
184
|
+
@val2.traverse(self, &block)
|
185
|
+
yield self, parent
|
128
186
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
"%="
|
187
|
+
|
188
|
+
def to_js(options = {})
|
189
|
+
"#{@val.to_js(options)}[#{@val2.to_js(options)}]"
|
133
190
|
end
|
134
|
-
|
135
|
-
|
191
|
+
|
192
|
+
def remove_paren
|
193
|
+
if @val.kind_of? ExpParen and @val.val.priority <= 20
|
194
|
+
@val = @val.val if @val.remove_paren?
|
195
|
+
end
|
196
|
+
if @val2.kind_of? ExpParen
|
197
|
+
@val2 = @val2.val
|
198
|
+
end
|
136
199
|
end
|
137
200
|
end
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
def
|
143
|
-
|
201
|
+
#
|
202
|
+
# => val.val2
|
203
|
+
#
|
204
|
+
class ExpProp < ExpArg2
|
205
|
+
def initialize(val, val2)
|
206
|
+
@val = val
|
207
|
+
if val2.kind_of? IdentifierName
|
208
|
+
@val2 = ECMA262::ECMA262String.new(val2.val)
|
209
|
+
elsif val2.kind_of? ECMA262String
|
210
|
+
@val2 = val2
|
211
|
+
end
|
144
212
|
end
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
"-="
|
213
|
+
|
214
|
+
def priority
|
215
|
+
20
|
149
216
|
end
|
150
|
-
|
151
|
-
|
217
|
+
|
218
|
+
def traverse(parent, &block)
|
219
|
+
@val.traverse(self, &block)
|
220
|
+
@val2.traverse(self, &block)
|
221
|
+
yield self, parent
|
152
222
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
"<<="
|
223
|
+
|
224
|
+
def to_js(options = {})
|
225
|
+
"#{@val.to_js(options)}.#{@val2.val}"
|
157
226
|
end
|
158
|
-
|
159
|
-
|
227
|
+
|
228
|
+
def remove_paren
|
229
|
+
if @val.kind_of? ExpParen and @val.val.priority <= 20
|
230
|
+
@val = @val.val if @val.remove_paren?
|
231
|
+
end
|
160
232
|
end
|
161
233
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
234
|
+
#11.2
|
235
|
+
# => name(args)
|
236
|
+
#
|
237
|
+
class ExpCall < Exp
|
238
|
+
attr_reader :name
|
239
|
+
attr_reader :args
|
240
|
+
|
241
|
+
def initialize(name, args)
|
242
|
+
@name = name
|
243
|
+
@args = args
|
168
244
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
">>>="
|
245
|
+
|
246
|
+
def priority
|
247
|
+
20
|
173
248
|
end
|
174
|
-
|
175
|
-
|
249
|
+
|
250
|
+
def deep_dup
|
251
|
+
self.class.new(@name.deep_dup, @args.collect{|x| x.deep_dup})
|
176
252
|
end
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
253
|
+
|
254
|
+
def replace(from, to)
|
255
|
+
@args.each_index do |i|
|
256
|
+
arg = @args[i]
|
257
|
+
if arg == from
|
258
|
+
@args[i] = to
|
259
|
+
break
|
260
|
+
end
|
261
|
+
end
|
181
262
|
end
|
182
|
-
|
183
|
-
|
263
|
+
|
264
|
+
def traverse(parent, &block)
|
265
|
+
@name.traverse(self, &block)
|
266
|
+
@args.each do |x|
|
267
|
+
x.traverse(self, &block)
|
268
|
+
end
|
269
|
+
yield self, parent
|
184
270
|
end
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
"
|
271
|
+
|
272
|
+
def to_js(options = {})
|
273
|
+
args = @args.collect{|x| x.to_js(options)}.join(",")
|
274
|
+
"#{@name.to_js(options)}(#{args})"
|
189
275
|
end
|
190
|
-
|
191
|
-
|
276
|
+
|
277
|
+
def remove_paren
|
278
|
+
if @name.kind_of? ExpParen and @name.val.priority <= 20
|
279
|
+
@name = @name.val if @name.remove_paren?
|
280
|
+
end
|
281
|
+
if @args
|
282
|
+
@args.map! do |arg|
|
283
|
+
if arg.kind_of? ExpParen and arg.val.priority <= 130 #AssignmentOperators
|
284
|
+
arg.val if arg.remove_paren?
|
285
|
+
else
|
286
|
+
arg
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
192
290
|
end
|
291
|
+
|
193
292
|
end
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
293
|
+
|
294
|
+
#
|
295
|
+
# new M
|
296
|
+
# new M(a,b,c...)
|
297
|
+
#
|
298
|
+
class ExpNew < Exp
|
299
|
+
def initialize(name, args)
|
300
|
+
@name = name
|
301
|
+
@args = args
|
200
302
|
end
|
201
|
-
end
|
202
303
|
|
203
|
-
|
204
|
-
|
205
|
-
def initialize(val, val2, val3)
|
206
|
-
@val = val
|
207
|
-
@val2 = val2
|
208
|
-
@val3 = val3
|
304
|
+
def priority
|
305
|
+
20
|
209
306
|
end
|
210
307
|
|
211
|
-
def
|
212
|
-
|
308
|
+
def deep_dup
|
309
|
+
self.class.new(@name,
|
310
|
+
@args.collect{|x| x.deep_dup})
|
213
311
|
end
|
214
312
|
|
215
313
|
def replace(from, to)
|
216
|
-
if
|
217
|
-
@
|
218
|
-
elsif
|
219
|
-
@
|
220
|
-
elsif from == @val3
|
221
|
-
@val3 = to
|
314
|
+
if @name == from
|
315
|
+
@name = from
|
316
|
+
elsif @args and (idx = @args.index(from))
|
317
|
+
@args[idx] = to
|
222
318
|
end
|
223
319
|
end
|
224
320
|
|
225
321
|
def traverse(parent, &block)
|
226
|
-
@
|
227
|
-
@
|
228
|
-
|
322
|
+
@name.traverse(self, &block)
|
323
|
+
if @args
|
324
|
+
@args.each do |arg|
|
325
|
+
arg.traverse(self, &block)
|
326
|
+
end
|
327
|
+
end
|
229
328
|
yield self, parent
|
230
329
|
end
|
231
330
|
|
232
331
|
def to_js(options = {})
|
233
|
-
|
332
|
+
if @args
|
333
|
+
args = @args.collect{|x| x.to_js(options)}.join(",")
|
334
|
+
concat options, :new, @name, '(', args, ')'
|
335
|
+
else
|
336
|
+
concat options, :new, @name
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def remove_paren
|
341
|
+
if @name.kind_of? ExpParen and @name.val.priority <= 20
|
342
|
+
@name = @name.val if @name.remove_paren?
|
343
|
+
end
|
344
|
+
if @args
|
345
|
+
@args.map! do |arg|
|
346
|
+
if arg.kind_of? ExpParen and arg.val.priority <= 130 #AssignmentOperators
|
347
|
+
arg.val if arg.remove_paren?
|
348
|
+
else
|
349
|
+
arg
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
234
353
|
end
|
235
354
|
end
|
236
355
|
|
237
|
-
#
|
238
|
-
|
356
|
+
#
|
357
|
+
# 11.3 Postfix Expressions
|
358
|
+
#
|
359
|
+
class ExpPostInc < ExpArg1
|
360
|
+
include UnaryOperation
|
239
361
|
def sym
|
240
|
-
"
|
362
|
+
"++"
|
363
|
+
end
|
364
|
+
def priority
|
365
|
+
30
|
241
366
|
end
|
242
|
-
def
|
243
|
-
|
367
|
+
def to_js(options = {})
|
368
|
+
concat options, @val, sym
|
244
369
|
end
|
245
370
|
end
|
246
|
-
|
247
|
-
|
248
|
-
class ExpLogicalAnd < ExpArg2
|
371
|
+
class ExpPostDec < ExpArg1
|
372
|
+
include UnaryOperation
|
249
373
|
def sym
|
250
|
-
"
|
374
|
+
"--"
|
251
375
|
end
|
252
|
-
def priority
|
253
|
-
|
376
|
+
def priority
|
377
|
+
30
|
378
|
+
end
|
379
|
+
def to_js(options = {})
|
380
|
+
concat options, @val, sym
|
254
381
|
end
|
255
382
|
end
|
256
|
-
|
257
|
-
#
|
258
|
-
|
383
|
+
#
|
384
|
+
# 11.4
|
385
|
+
# unary expression
|
386
|
+
#
|
387
|
+
class ExpDelete < ExpArg1
|
388
|
+
include UnaryOperation
|
259
389
|
def sym
|
260
|
-
"
|
390
|
+
"delete"
|
261
391
|
end
|
262
|
-
def priority
|
263
|
-
|
392
|
+
def priority
|
393
|
+
40
|
264
394
|
end
|
265
395
|
end
|
266
|
-
|
267
|
-
|
268
|
-
class ExpXor < ExpArg2
|
396
|
+
class ExpVoid < ExpArg1
|
397
|
+
include UnaryOperation
|
269
398
|
def sym
|
270
|
-
"
|
399
|
+
"void"
|
271
400
|
end
|
272
|
-
def priority
|
273
|
-
|
401
|
+
def priority
|
402
|
+
40
|
274
403
|
end
|
275
404
|
end
|
276
|
-
|
277
|
-
|
278
|
-
class ExpAnd < ExpArg2
|
405
|
+
class ExpTypeof < ExpArg1
|
406
|
+
include UnaryOperation
|
279
407
|
def sym
|
280
|
-
"
|
408
|
+
"typeof"
|
281
409
|
end
|
282
|
-
def priority
|
283
|
-
|
410
|
+
def priority
|
411
|
+
40
|
284
412
|
end
|
285
413
|
end
|
286
414
|
|
287
|
-
|
288
|
-
|
289
|
-
class ExpEq < ExpArg2
|
415
|
+
class ExpPreInc < ExpArg1
|
416
|
+
include UnaryOperation
|
290
417
|
def sym
|
291
|
-
"
|
418
|
+
"++"
|
292
419
|
end
|
293
|
-
def priority
|
294
|
-
|
420
|
+
def priority
|
421
|
+
40
|
295
422
|
end
|
296
423
|
end
|
297
|
-
|
298
|
-
|
424
|
+
class ExpPreDec < ExpArg1
|
425
|
+
include UnaryOperation
|
299
426
|
def sym
|
300
|
-
"
|
427
|
+
"--"
|
301
428
|
end
|
302
|
-
def priority
|
303
|
-
|
429
|
+
def priority
|
430
|
+
40
|
304
431
|
end
|
305
432
|
end
|
306
|
-
|
307
|
-
|
433
|
+
class ExpPositive < ExpArg1
|
434
|
+
include UnaryOperation
|
308
435
|
def sym
|
309
|
-
"
|
436
|
+
"+"
|
310
437
|
end
|
311
|
-
def priority
|
312
|
-
|
438
|
+
def priority
|
439
|
+
40
|
440
|
+
end
|
441
|
+
|
442
|
+
def reduce(parent)
|
443
|
+
if @val.kind_of? ECMA262Numeric
|
444
|
+
parent.replace(self, @val)
|
445
|
+
end
|
313
446
|
end
|
314
447
|
end
|
315
|
-
|
316
|
-
class
|
448
|
+
|
449
|
+
class ExpNegative < ExpArg1
|
450
|
+
include UnaryOperation
|
317
451
|
def sym
|
318
|
-
"
|
452
|
+
"-"
|
319
453
|
end
|
320
|
-
def priority
|
321
|
-
|
454
|
+
def priority
|
455
|
+
40
|
322
456
|
end
|
323
|
-
end
|
324
457
|
|
325
|
-
|
458
|
+
def reduce(parent)
|
459
|
+
if @val.kind_of? ECMA262Numeric
|
460
|
+
if @val.integer.match(/^\-/)
|
461
|
+
integer = $'
|
462
|
+
else
|
463
|
+
integer = "-#{@val.integer}"
|
464
|
+
end
|
465
|
+
val = ECMA262Numeric.new(integer, @val.decimal, @val.exp)
|
466
|
+
parent.replace(self, val)
|
467
|
+
end
|
468
|
+
end
|
469
|
+
end
|
470
|
+
class ExpBitwiseNot < ExpArg1
|
471
|
+
include UnaryOperation
|
326
472
|
def sym
|
327
|
-
"
|
473
|
+
"~"
|
328
474
|
end
|
329
|
-
def priority
|
330
|
-
|
475
|
+
def priority
|
476
|
+
40
|
477
|
+
end
|
478
|
+
end
|
479
|
+
class ExpLogicalNot < ExpArg1
|
480
|
+
include UnaryOperation
|
481
|
+
def sym
|
482
|
+
"!"
|
483
|
+
end
|
484
|
+
def priority
|
485
|
+
40
|
331
486
|
end
|
332
487
|
end
|
333
488
|
|
334
|
-
|
489
|
+
#
|
490
|
+
# 11.5.1 Applying the * Operator
|
491
|
+
#
|
492
|
+
class ExpMul < ExpArg2
|
493
|
+
include BinaryOperation
|
494
|
+
|
335
495
|
def sym
|
336
|
-
"
|
496
|
+
"*"
|
337
497
|
end
|
338
|
-
|
339
|
-
|
498
|
+
|
499
|
+
def priority
|
500
|
+
50
|
501
|
+
end
|
502
|
+
|
503
|
+
def reduce(parent)
|
504
|
+
# a * 1 => a
|
505
|
+
if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.to_num == 1
|
506
|
+
parent.replace(self, @val2)
|
507
|
+
end
|
508
|
+
# 1 * b => b
|
509
|
+
if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val2.to_num == 1
|
510
|
+
parent.replace(self, @val)
|
511
|
+
end
|
512
|
+
# N * M => (N * M)
|
513
|
+
if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.integer? and @val2.integer?
|
514
|
+
parent.replace(self, ECMA262Numeric.new(@val.to_num * @val2.to_num))
|
515
|
+
end
|
516
|
+
=begin
|
517
|
+
# ((a * N) * M) or ((N * a) * M)
|
518
|
+
if @val2.kind_of? ECMA262Numeric and @val2.integer? and @val.kind_of? ExpMul
|
519
|
+
if @val.val2.kind_of? ECMA262Numeric and @val.val2.integer?
|
520
|
+
@val2 = ECMA262Numeric.new(@val.val2.to_num * @val2.to_num)
|
521
|
+
@val = @val.val
|
522
|
+
elsif @val.val.kind_of? ECMA262Numeric and @val.val.integer?
|
523
|
+
@val2 = ECMA262Numeric.new(@val.val.to_num * @val2.to_num)
|
524
|
+
@val = @val.val2
|
525
|
+
end
|
526
|
+
end
|
527
|
+
=end
|
340
528
|
end
|
341
529
|
end
|
342
530
|
|
343
|
-
|
531
|
+
#
|
532
|
+
# 11.5.2 Applying the / Operator
|
533
|
+
#
|
534
|
+
class ExpDiv < ExpArg2
|
535
|
+
include BinaryOperation
|
344
536
|
def sym
|
345
|
-
"
|
537
|
+
"/"
|
346
538
|
end
|
347
|
-
def priority
|
348
|
-
|
539
|
+
def priority
|
540
|
+
50
|
349
541
|
end
|
350
542
|
end
|
351
543
|
|
352
|
-
|
544
|
+
#
|
545
|
+
# 11.5.3 Applying the % Operator
|
546
|
+
#
|
547
|
+
class ExpMod < ExpArg2
|
548
|
+
include BinaryOperation
|
353
549
|
def sym
|
354
|
-
"
|
550
|
+
"%"
|
355
551
|
end
|
356
|
-
def priority
|
357
|
-
|
552
|
+
def priority
|
553
|
+
50
|
358
554
|
end
|
359
555
|
end
|
360
556
|
|
361
|
-
|
557
|
+
#
|
558
|
+
#11.6.1 The Addition operator ( + )
|
559
|
+
#
|
362
560
|
class ExpAdd < ExpArg2
|
561
|
+
include BinaryOperation
|
363
562
|
def sym
|
364
563
|
"+"
|
365
564
|
end
|
366
|
-
|
565
|
+
|
566
|
+
def priority
|
367
567
|
60
|
368
568
|
end
|
369
569
|
|
@@ -380,6 +580,7 @@ module Minjs
|
|
380
580
|
if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.integer? and @val2.integer?
|
381
581
|
parent.replace(self, ECMA262Numeric.new(@val.to_num + @val2.to_num))
|
382
582
|
end
|
583
|
+
=begin
|
383
584
|
if @val2.kind_of? ECMA262Numeric and @val2.integer?
|
384
585
|
# ((a + N) + M) or ((N + a) + M)
|
385
586
|
if @val.kind_of? ExpAdd
|
@@ -401,15 +602,21 @@ module Minjs
|
|
401
602
|
end
|
402
603
|
end
|
403
604
|
end
|
605
|
+
=end
|
404
606
|
end
|
405
607
|
|
406
608
|
end
|
407
|
-
|
609
|
+
#
|
610
|
+
# 11.6.2 The Subtraction Operator ( - )
|
611
|
+
#
|
408
612
|
class ExpSub < ExpArg2
|
613
|
+
include BinaryOperation
|
614
|
+
|
409
615
|
def sym
|
410
616
|
"-"
|
411
617
|
end
|
412
|
-
|
618
|
+
|
619
|
+
def priority
|
413
620
|
60
|
414
621
|
end
|
415
622
|
|
@@ -426,6 +633,7 @@ module Minjs
|
|
426
633
|
if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.integer? and @val2.integer?
|
427
634
|
parent.replace(self, ECMA262Numeric.new(@val.to_num - @val2.to_num))
|
428
635
|
end
|
636
|
+
=begin
|
429
637
|
if @val2.kind_of? ECMA262Numeric and @val2.integer?
|
430
638
|
# ((a - N) - M) or ((N - a) - M)
|
431
639
|
if @val.kind_of? ExpSub
|
@@ -447,349 +655,397 @@ module Minjs
|
|
447
655
|
end
|
448
656
|
end
|
449
657
|
end
|
658
|
+
=end
|
450
659
|
end
|
451
660
|
|
452
661
|
end
|
453
662
|
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
end
|
458
|
-
def priority(exp)
|
459
|
-
80
|
460
|
-
end
|
461
|
-
end
|
462
|
-
|
463
|
-
class ExpIn < ExpArg2
|
464
|
-
def sym
|
465
|
-
"in"
|
466
|
-
end
|
467
|
-
def priority(exp)
|
468
|
-
80
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
663
|
+
#
|
664
|
+
# 11.7.1 The Left Shift Operator ( << )
|
665
|
+
#
|
472
666
|
class ExpLShift < ExpArg2
|
667
|
+
include BinaryOperation
|
473
668
|
def sym
|
474
669
|
"<<"
|
475
670
|
end
|
476
|
-
def priority
|
671
|
+
def priority
|
477
672
|
70
|
478
673
|
end
|
479
674
|
end
|
675
|
+
#
|
676
|
+
# 11.7.2 The Signed Right Shift Operator ( >> )
|
677
|
+
#
|
480
678
|
class ExpRShift < ExpArg2
|
679
|
+
include BinaryOperation
|
481
680
|
def sym
|
482
681
|
">>"
|
483
682
|
end
|
484
|
-
def priority
|
683
|
+
def priority
|
485
684
|
70
|
486
685
|
end
|
487
686
|
end
|
687
|
+
#
|
688
|
+
# 11.7.3 The Unsigned Right Shift Operator ( >>> )
|
689
|
+
#
|
488
690
|
class ExpURShift < ExpArg2
|
691
|
+
include BinaryOperation
|
489
692
|
def sym
|
490
693
|
">>>"
|
491
694
|
end
|
492
|
-
def priority
|
695
|
+
def priority
|
493
696
|
70
|
494
697
|
end
|
495
698
|
end
|
496
|
-
|
497
|
-
|
699
|
+
#
|
700
|
+
# 11.8.1 The Less-than Operator ( < )
|
701
|
+
#
|
702
|
+
class ExpLt < ExpArg2
|
703
|
+
include BinaryOperation
|
498
704
|
def sym
|
499
|
-
"
|
705
|
+
"<"
|
500
706
|
end
|
501
|
-
def priority
|
502
|
-
|
707
|
+
def priority
|
708
|
+
80
|
503
709
|
end
|
710
|
+
end
|
504
711
|
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
if @val.kind_of? ECMA262Numeric and @val2.kind_of? ECMA262Numeric and @val.integer? and @val2.integer?
|
516
|
-
parent.replace(self, ECMA262Numeric.new(@val.to_num * @val2.to_num))
|
517
|
-
end
|
518
|
-
# ((a * N) * M) or ((N * a) * M)
|
519
|
-
if @val2.kind_of? ECMA262Numeric and @val2.integer? and @val.kind_of? ExpMul
|
520
|
-
if @val.val2.kind_of? ECMA262Numeric and @val.val2.integer?
|
521
|
-
@val2 = ECMA262Numeric.new(@val.val2.to_num * @val2.to_num)
|
522
|
-
@val = @val.val
|
523
|
-
elsif @val.val.kind_of? ECMA262Numeric and @val.val.integer?
|
524
|
-
@val2 = ECMA262Numeric.new(@val.val.to_num * @val2.to_num)
|
525
|
-
@val = @val.val2
|
526
|
-
end
|
527
|
-
end
|
712
|
+
#
|
713
|
+
# 11.8.2 The Greater-than Operator ( > )
|
714
|
+
#
|
715
|
+
class ExpGt < ExpArg2
|
716
|
+
include BinaryOperation
|
717
|
+
def sym
|
718
|
+
">"
|
719
|
+
end
|
720
|
+
def priority
|
721
|
+
80
|
528
722
|
end
|
529
723
|
end
|
530
|
-
|
724
|
+
#
|
725
|
+
# 11.8.3 The Less-than-or-equal Operator ( <= )
|
726
|
+
#
|
727
|
+
class ExpLtEq < ExpArg2
|
728
|
+
include BinaryOperation
|
531
729
|
def sym
|
532
|
-
"
|
730
|
+
"<="
|
533
731
|
end
|
534
|
-
def priority
|
535
|
-
|
732
|
+
def priority
|
733
|
+
80
|
536
734
|
end
|
537
735
|
end
|
538
|
-
|
736
|
+
#
|
737
|
+
# 11.8.4 The Greater-than-or-equal Operator ( >= )
|
738
|
+
#
|
739
|
+
class ExpGtEq < ExpArg2
|
740
|
+
include BinaryOperation
|
539
741
|
def sym
|
540
|
-
"
|
742
|
+
">="
|
541
743
|
end
|
542
|
-
def priority
|
543
|
-
|
744
|
+
def priority
|
745
|
+
80
|
544
746
|
end
|
545
747
|
end
|
546
748
|
#
|
547
|
-
# 11.
|
548
|
-
# unary expression
|
749
|
+
# 11.8.6 The instanceof operator
|
549
750
|
#
|
550
|
-
class
|
751
|
+
class ExpInstanceOf < ExpArg2
|
752
|
+
include BinaryOperation
|
551
753
|
def sym
|
552
|
-
"
|
754
|
+
"instanceof"
|
553
755
|
end
|
554
|
-
def priority
|
555
|
-
|
756
|
+
def priority
|
757
|
+
80
|
556
758
|
end
|
557
759
|
end
|
558
|
-
|
760
|
+
#
|
761
|
+
# 11.8.7 The in operator
|
762
|
+
#
|
763
|
+
class ExpIn < ExpArg2
|
764
|
+
include BinaryOperation
|
559
765
|
def sym
|
560
|
-
"
|
766
|
+
"in"
|
561
767
|
end
|
562
|
-
def priority
|
563
|
-
|
768
|
+
def priority
|
769
|
+
80
|
564
770
|
end
|
565
771
|
end
|
566
|
-
|
772
|
+
#
|
773
|
+
# 11.9.1 The Equals Operator ( == )
|
774
|
+
#
|
775
|
+
class ExpEq < ExpArg2
|
776
|
+
include BinaryOperation
|
567
777
|
def sym
|
568
|
-
"
|
778
|
+
"=="
|
569
779
|
end
|
570
|
-
def priority
|
571
|
-
|
780
|
+
def priority
|
781
|
+
90
|
572
782
|
end
|
573
783
|
end
|
574
|
-
|
784
|
+
#
|
785
|
+
# 11.9.2 The Does-not-equals Operator ( != )
|
786
|
+
#
|
787
|
+
class ExpNotEq < ExpArg2
|
788
|
+
include BinaryOperation
|
575
789
|
def sym
|
576
|
-
"
|
577
|
-
end
|
578
|
-
def priority(exp)
|
579
|
-
30
|
790
|
+
"!="
|
580
791
|
end
|
581
|
-
def
|
582
|
-
|
792
|
+
def priority
|
793
|
+
90
|
583
794
|
end
|
584
795
|
end
|
585
|
-
|
796
|
+
#
|
797
|
+
# 11.9.4 The Strict Equals Operator ( === )
|
798
|
+
#
|
799
|
+
class ExpStrictEq < ExpArg2
|
800
|
+
include BinaryOperation
|
586
801
|
def sym
|
587
|
-
"
|
588
|
-
end
|
589
|
-
def priority(exp)
|
590
|
-
30
|
802
|
+
"==="
|
591
803
|
end
|
592
|
-
def
|
593
|
-
|
804
|
+
def priority
|
805
|
+
90
|
594
806
|
end
|
595
807
|
end
|
596
|
-
|
808
|
+
#
|
809
|
+
# 11.9.5 The Strict Does-not-equal Operator ( !== )
|
810
|
+
#
|
811
|
+
class ExpStrictNotEq < ExpArg2
|
812
|
+
include BinaryOperation
|
597
813
|
def sym
|
598
|
-
"
|
814
|
+
"!=="
|
599
815
|
end
|
600
|
-
def priority
|
601
|
-
|
816
|
+
def priority
|
817
|
+
90
|
602
818
|
end
|
603
819
|
end
|
604
|
-
|
820
|
+
#
|
821
|
+
# 11.10 Binary Bitwise Operators
|
822
|
+
#
|
823
|
+
class ExpAnd < ExpArg2
|
824
|
+
include BinaryOperation
|
605
825
|
def sym
|
606
|
-
"
|
826
|
+
"&"
|
607
827
|
end
|
608
|
-
def priority
|
609
|
-
|
828
|
+
def priority
|
829
|
+
100
|
610
830
|
end
|
611
831
|
end
|
612
|
-
|
832
|
+
# ^
|
833
|
+
class ExpXor < ExpArg2
|
834
|
+
include BinaryOperation
|
613
835
|
def sym
|
614
|
-
"
|
615
|
-
end
|
616
|
-
def priority(exp)
|
617
|
-
40
|
836
|
+
"^"
|
618
837
|
end
|
619
|
-
|
620
|
-
|
621
|
-
if @val.kind_of? ECMA262Numeric
|
622
|
-
parent.replace(self, @val)
|
623
|
-
end
|
838
|
+
def priority
|
839
|
+
106
|
624
840
|
end
|
625
841
|
end
|
626
842
|
|
627
|
-
|
843
|
+
# |
|
844
|
+
class ExpOr < ExpArg2
|
845
|
+
include BinaryOperation
|
628
846
|
def sym
|
629
|
-
"
|
630
|
-
end
|
631
|
-
def priority(exp)
|
632
|
-
40
|
847
|
+
"|"
|
633
848
|
end
|
634
|
-
|
635
|
-
|
636
|
-
if @val.kind_of? ECMA262Numeric
|
637
|
-
if @val.integer.match(/^\-/)
|
638
|
-
integer = $'
|
639
|
-
else
|
640
|
-
integer = "-#{@val.integer}"
|
641
|
-
end
|
642
|
-
val = ECMA262Numeric.new(integer, @val.decimal, @val.exp)
|
643
|
-
parent.replace(self, val)
|
644
|
-
end
|
849
|
+
def priority
|
850
|
+
108
|
645
851
|
end
|
646
852
|
end
|
647
|
-
|
853
|
+
#
|
854
|
+
# 11.11 Binary Logical Operators
|
855
|
+
#
|
856
|
+
# &&
|
857
|
+
class ExpLogicalAnd < ExpArg2
|
858
|
+
include BinaryOperation
|
648
859
|
def sym
|
649
|
-
"
|
860
|
+
"&&"
|
650
861
|
end
|
651
|
-
def priority
|
652
|
-
|
862
|
+
def priority
|
863
|
+
110
|
653
864
|
end
|
654
865
|
end
|
655
|
-
|
866
|
+
# ||
|
867
|
+
class ExpLogicalOr < ExpArg2
|
868
|
+
include BinaryOperation
|
656
869
|
def sym
|
657
|
-
"
|
870
|
+
"||"
|
658
871
|
end
|
659
|
-
def priority
|
660
|
-
|
872
|
+
def priority
|
873
|
+
116
|
661
874
|
end
|
662
875
|
end
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
876
|
+
#
|
877
|
+
# 11.12 Conditional Operator ( ? : )
|
878
|
+
#
|
879
|
+
# val ? val2 : val3
|
880
|
+
#
|
881
|
+
class ExpCond < Exp
|
882
|
+
def initialize(val, val2, val3)
|
883
|
+
@val = val
|
884
|
+
@val2 = val2
|
885
|
+
@val3 = val3
|
668
886
|
end
|
669
887
|
|
670
|
-
def priority
|
671
|
-
|
888
|
+
def priority
|
889
|
+
120
|
672
890
|
end
|
673
891
|
|
674
|
-
def
|
675
|
-
if @
|
676
|
-
@
|
677
|
-
elsif @args and (idx = @args.index(from))
|
678
|
-
@args[idx] = to
|
892
|
+
def remove_paren
|
893
|
+
if @val.kind_of? ExpParen and @val.val.priority < 120
|
894
|
+
@val = @val.val if @val.remove_paren?
|
679
895
|
end
|
680
|
-
|
681
|
-
|
682
|
-
def traverse(parent, &block)
|
683
|
-
@name.traverse(self, &block)
|
684
|
-
if @args
|
685
|
-
@args.each do |arg|
|
686
|
-
arg.traverse(self, &block)
|
687
|
-
end
|
896
|
+
if @val2.kind_of? ExpParen and @val2.val.priority <= 130
|
897
|
+
@val2 = @val2.val
|
688
898
|
end
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
def to_js(options = {})
|
693
|
-
if @args
|
694
|
-
args = @args.collect{|x| x.to_js(options)}.join(",")
|
695
|
-
concat options, :new, @name, '(', args, ')'
|
696
|
-
else
|
697
|
-
concat options, :new, @name
|
899
|
+
if @val3.kind_of? ExpParen and @val3.val.priority <= 130
|
900
|
+
@val3 = @val3.val
|
698
901
|
end
|
699
902
|
end
|
700
|
-
end
|
701
|
-
#11.2
|
702
|
-
# => name(args)
|
703
|
-
#
|
704
|
-
class ExpCall < Exp
|
705
|
-
attr_reader :name
|
706
|
-
attr_reader :args
|
707
|
-
|
708
|
-
def initialize(name, args)
|
709
|
-
@name = name
|
710
|
-
@args = args
|
711
|
-
end
|
712
903
|
|
713
|
-
def
|
714
|
-
|
715
|
-
999
|
716
|
-
else
|
717
|
-
20
|
718
|
-
end
|
904
|
+
def deep_dup
|
905
|
+
self.class.new(@val.deep_dup, @val2.deep_dup, @val3.deep_dup)
|
719
906
|
end
|
720
907
|
|
721
908
|
def replace(from, to)
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
909
|
+
if from == @val
|
910
|
+
@val = to
|
911
|
+
elsif from == @val2
|
912
|
+
@val2 = to
|
913
|
+
elsif from == @val3
|
914
|
+
@val3 = to
|
728
915
|
end
|
729
916
|
end
|
730
917
|
|
731
918
|
def traverse(parent, &block)
|
732
|
-
@
|
733
|
-
@
|
734
|
-
|
735
|
-
end
|
919
|
+
@val.traverse(self, &block)
|
920
|
+
@val2.traverse(self, &block)
|
921
|
+
@val3.traverse(self, &block)
|
736
922
|
yield self, parent
|
737
923
|
end
|
738
924
|
|
739
925
|
def to_js(options = {})
|
740
|
-
|
741
|
-
"#{@name.to_js(options)}(#{args})"
|
926
|
+
"#{@val.to_js(options)}?#{@val2.to_js(options)}:#{@val3.to_js(options)}"
|
742
927
|
end
|
743
928
|
end
|
744
929
|
#
|
745
|
-
#
|
930
|
+
# 11.13 Assignment Operators
|
746
931
|
#
|
747
|
-
class
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
@val2 = ECMA262::ECMA262String.new(val2.val)
|
752
|
-
else
|
753
|
-
raise "internal error: val2 must be kind_of ItentiferName"
|
754
|
-
end
|
932
|
+
class ExpAssign < ExpArg2
|
933
|
+
include AssignmentOperation
|
934
|
+
def sym
|
935
|
+
"="
|
755
936
|
end
|
756
|
-
|
757
|
-
|
758
|
-
20
|
937
|
+
def priority
|
938
|
+
130
|
759
939
|
end
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
940
|
+
end
|
941
|
+
class ExpDivAssign < ExpAssign
|
942
|
+
include AssignmentOperation
|
943
|
+
def sym
|
944
|
+
"/="
|
765
945
|
end
|
766
|
-
def
|
767
|
-
|
946
|
+
def priority
|
947
|
+
130
|
768
948
|
end
|
769
949
|
end
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
def priority(exp)
|
775
|
-
20
|
950
|
+
class ExpMulAssign < ExpAssign
|
951
|
+
include AssignmentOperation
|
952
|
+
def sym
|
953
|
+
"*="
|
776
954
|
end
|
777
|
-
|
778
|
-
|
779
|
-
@val.traverse(self, &block)
|
780
|
-
@val2.traverse(self, &block)
|
781
|
-
yield self, parent
|
955
|
+
def priority
|
956
|
+
130
|
782
957
|
end
|
783
|
-
|
784
|
-
|
958
|
+
end
|
959
|
+
class ExpModAssign < ExpAssign
|
960
|
+
include AssignmentOperation
|
961
|
+
def sym
|
962
|
+
"%="
|
963
|
+
end
|
964
|
+
def priority
|
965
|
+
130
|
785
966
|
end
|
786
967
|
end
|
787
|
-
|
968
|
+
class ExpAddAssign < ExpAssign
|
969
|
+
include AssignmentOperation
|
970
|
+
def sym
|
971
|
+
"+="
|
972
|
+
end
|
973
|
+
def priority
|
974
|
+
130
|
975
|
+
end
|
976
|
+
end
|
977
|
+
class ExpSubAssign < ExpAssign
|
978
|
+
include AssignmentOperation
|
979
|
+
def sym
|
980
|
+
"-="
|
981
|
+
end
|
982
|
+
def priority
|
983
|
+
130
|
984
|
+
end
|
985
|
+
end
|
986
|
+
class ExpLShiftAssign < ExpAssign
|
987
|
+
include AssignmentOperation
|
988
|
+
def sym
|
989
|
+
"<<="
|
990
|
+
end
|
991
|
+
def priority
|
992
|
+
130
|
993
|
+
end
|
994
|
+
end
|
995
|
+
class ExpRShiftAssign < ExpAssign
|
996
|
+
include AssignmentOperation
|
997
|
+
def sym
|
998
|
+
">>="
|
999
|
+
end
|
1000
|
+
def priority
|
1001
|
+
130
|
1002
|
+
end
|
1003
|
+
end
|
1004
|
+
class ExpURShiftAssign < ExpAssign
|
1005
|
+
include AssignmentOperation
|
1006
|
+
def sym
|
1007
|
+
">>>="
|
1008
|
+
end
|
1009
|
+
def priority
|
1010
|
+
130
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
class ExpAndAssign < ExpAssign
|
1014
|
+
include AssignmentOperation
|
1015
|
+
def sym
|
1016
|
+
"&="
|
1017
|
+
end
|
1018
|
+
def priority
|
1019
|
+
130
|
1020
|
+
end
|
1021
|
+
end
|
1022
|
+
class ExpOrAssign < ExpAssign
|
1023
|
+
include AssignmentOperation
|
1024
|
+
def sym
|
1025
|
+
"|="
|
1026
|
+
end
|
1027
|
+
def priority
|
1028
|
+
130
|
1029
|
+
end
|
1030
|
+
end
|
1031
|
+
class ExpXorAssign < ExpAssign
|
1032
|
+
include AssignmentOperation
|
1033
|
+
def sym
|
1034
|
+
"^="
|
1035
|
+
end
|
1036
|
+
def priority
|
1037
|
+
130
|
1038
|
+
end
|
1039
|
+
end
|
1040
|
+
#
|
1041
|
+
# Comma Operator ( , )
|
1042
|
+
#
|
788
1043
|
class ExpComma < ExpArg2
|
1044
|
+
include BinaryOperation
|
789
1045
|
def sym
|
790
1046
|
","
|
791
1047
|
end
|
792
|
-
def priority
|
1048
|
+
def priority
|
793
1049
|
140
|
794
1050
|
end
|
795
1051
|
end
|