| 1 |
package parser |
| 2 |
|
| 3 |
import ( |
| 4 |
"bytes" |
| 5 |
"encoding/json" |
| 6 |
"fmt" |
| 7 |
"os" |
| 8 |
"reflect" |
| 9 |
"strings" |
| 10 |
"testing" |
| 11 |
|
| 12 |
"github.com/robertkrimen/otto/ast" |
| 13 |
"github.com/stretchr/testify/require" |
| 14 |
) |
| 15 |
|
| 16 |
func marshal(name string, children ...interface{}) interface{} { |
| 17 |
if len(children) == 1 { |
| 18 |
if name == "" { |
| 19 |
return testMarshalNode(children[0]) |
| 20 |
} |
| 21 |
return map[string]interface{}{ |
| 22 |
name: children[0], |
| 23 |
} |
| 24 |
} |
| 25 |
ret := map[string]interface{}{} |
| 26 |
length := len(children) / 2 |
| 27 |
for i := range length { |
| 28 |
name := children[i*2].(string) |
| 29 |
value := children[i*2+1] |
| 30 |
ret[name] = value |
| 31 |
} |
| 32 |
if name == "" { |
| 33 |
return ret |
| 34 |
} |
| 35 |
return map[string]interface{}{ |
| 36 |
name: ret, |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
func testMarshalNode(node interface{}) interface{} { |
| 41 |
switch node := node.(type) { |
| 42 |
|
| 43 |
|
| 44 |
case *ast.ArrayLiteral: |
| 45 |
return marshal("Array", testMarshalNode(node.Value)) |
| 46 |
|
| 47 |
case *ast.AssignExpression: |
| 48 |
return marshal("Assign", |
| 49 |
"Left", testMarshalNode(node.Left), |
| 50 |
"Right", testMarshalNode(node.Right), |
| 51 |
) |
| 52 |
|
| 53 |
case *ast.BinaryExpression: |
| 54 |
return marshal("BinaryExpression", |
| 55 |
"Operator", node.Operator.String(), |
| 56 |
"Left", testMarshalNode(node.Left), |
| 57 |
"Right", testMarshalNode(node.Right), |
| 58 |
) |
| 59 |
|
| 60 |
case *ast.BooleanLiteral: |
| 61 |
return marshal("Literal", node.Value) |
| 62 |
|
| 63 |
case *ast.CallExpression: |
| 64 |
return marshal("Call", |
| 65 |
"Callee", testMarshalNode(node.Callee), |
| 66 |
"ArgumentList", testMarshalNode(node.ArgumentList), |
| 67 |
) |
| 68 |
|
| 69 |
case *ast.ConditionalExpression: |
| 70 |
return marshal("Conditional", |
| 71 |
"Test", testMarshalNode(node.Test), |
| 72 |
"Consequent", testMarshalNode(node.Consequent), |
| 73 |
"Alternate", testMarshalNode(node.Alternate), |
| 74 |
) |
| 75 |
|
| 76 |
case *ast.DotExpression: |
| 77 |
return marshal("Dot", |
| 78 |
"Left", testMarshalNode(node.Left), |
| 79 |
"Member", node.Identifier.Name, |
| 80 |
) |
| 81 |
|
| 82 |
case *ast.NewExpression: |
| 83 |
return marshal("New", |
| 84 |
"Callee", testMarshalNode(node.Callee), |
| 85 |
"ArgumentList", testMarshalNode(node.ArgumentList), |
| 86 |
) |
| 87 |
|
| 88 |
case *ast.NullLiteral: |
| 89 |
return marshal("Literal", nil) |
| 90 |
|
| 91 |
case *ast.NumberLiteral: |
| 92 |
return marshal("Literal", node.Value) |
| 93 |
|
| 94 |
case *ast.ObjectLiteral: |
| 95 |
return marshal("Object", testMarshalNode(node.Value)) |
| 96 |
|
| 97 |
case *ast.RegExpLiteral: |
| 98 |
return marshal("Literal", node.Literal) |
| 99 |
|
| 100 |
case *ast.StringLiteral: |
| 101 |
return marshal("Literal", node.Literal) |
| 102 |
|
| 103 |
case *ast.VariableExpression: |
| 104 |
return []interface{}{node.Name, testMarshalNode(node.Initializer)} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
case *ast.Program: |
| 109 |
return testMarshalNode(node.Body) |
| 110 |
|
| 111 |
case *ast.BlockStatement: |
| 112 |
return marshal("BlockStatement", testMarshalNode(node.List)) |
| 113 |
|
| 114 |
case *ast.EmptyStatement: |
| 115 |
return "EmptyStatement" |
| 116 |
|
| 117 |
case *ast.ExpressionStatement: |
| 118 |
return testMarshalNode(node.Expression) |
| 119 |
|
| 120 |
case *ast.ForInStatement: |
| 121 |
return marshal("ForIn", |
| 122 |
"Into", marshal("", node.Into), |
| 123 |
"Source", marshal("", node.Source), |
| 124 |
"Body", marshal("", node.Body), |
| 125 |
) |
| 126 |
|
| 127 |
case *ast.FunctionLiteral: |
| 128 |
return marshal("Function", testMarshalNode(node.Body)) |
| 129 |
|
| 130 |
case *ast.Identifier: |
| 131 |
return marshal("Identifier", node.Name) |
| 132 |
|
| 133 |
case *ast.IfStatement: |
| 134 |
ret := marshal("", |
| 135 |
"Test", testMarshalNode(node.Test), |
| 136 |
"Consequent", testMarshalNode(node.Consequent), |
| 137 |
).(map[string]interface{}) |
| 138 |
if node.Alternate != nil { |
| 139 |
ret["Alternate"] = testMarshalNode(node.Alternate) |
| 140 |
} |
| 141 |
return marshal("If", ret) |
| 142 |
|
| 143 |
case *ast.LabelledStatement: |
| 144 |
return marshal("Label", |
| 145 |
"Name", node.Label.Name, |
| 146 |
"Statement", testMarshalNode(node.Statement), |
| 147 |
) |
| 148 |
case ast.Property: |
| 149 |
return marshal("", |
| 150 |
"Key", node.Key, |
| 151 |
"Value", testMarshalNode(node.Value), |
| 152 |
) |
| 153 |
|
| 154 |
case *ast.ReturnStatement: |
| 155 |
return marshal("Return", testMarshalNode(node.Argument)) |
| 156 |
|
| 157 |
case *ast.SequenceExpression: |
| 158 |
return marshal("Sequence", testMarshalNode(node.Sequence)) |
| 159 |
|
| 160 |
case *ast.ThrowStatement: |
| 161 |
return marshal("Throw", testMarshalNode(node.Argument)) |
| 162 |
|
| 163 |
case *ast.VariableStatement: |
| 164 |
return marshal("Var", testMarshalNode(node.List)) |
| 165 |
} |
| 166 |
|
| 167 |
{ |
| 168 |
value := reflect.ValueOf(node) |
| 169 |
if value.Kind() == reflect.Slice { |
| 170 |
tmp0 := []interface{}{} |
| 171 |
for index := range value.Len() { |
| 172 |
tmp0 = append(tmp0, testMarshalNode(value.Index(index).Interface())) |
| 173 |
} |
| 174 |
return tmp0 |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
if node != nil { |
| 179 |
fmt.Fprintf(os.Stderr, "testMarshalNode(%T)\n", node) |
| 180 |
} |
| 181 |
|
| 182 |
return nil |
| 183 |
} |
| 184 |
|
| 185 |
func testMarshal(node interface{}) string { |
| 186 |
value, err := json.Marshal(testMarshalNode(node)) |
| 187 |
if err != nil { |
| 188 |
panic(err) |
| 189 |
} |
| 190 |
return string(value) |
| 191 |
} |
| 192 |
|
| 193 |
func TestParserAST(t *testing.T) { |
| 194 |
tt(t, func() { |
| 195 |
test := func(inputOutput string) { |
| 196 |
match := matchBeforeAfterSeparator.FindStringIndex(inputOutput) |
| 197 |
input := strings.TrimSpace(inputOutput[0:match[0]]) |
| 198 |
wantOutput := strings.TrimSpace(inputOutput[match[1]:]) |
| 199 |
_, program, err := testParse(input) |
| 200 |
is(err, nil) |
| 201 |
haveOutput := testMarshal(program) |
| 202 |
tmp0, tmp1 := bytes.Buffer{}, bytes.Buffer{} |
| 203 |
err = json.Indent(&tmp0, []byte(haveOutput), "\t\t", " ") |
| 204 |
require.NoError(t, err) |
| 205 |
err = json.Indent(&tmp1, []byte(wantOutput), "\t\t", " ") |
| 206 |
require.NoError(t, err) |
| 207 |
is("\n\t\t"+tmp0.String(), "\n\t\t"+tmp1.String()) |
| 208 |
} |
| 209 |
|
| 210 |
test(` |
| 211 |
--- |
| 212 |
[] |
| 213 |
`) |
| 214 |
|
| 215 |
test(` |
| 216 |
; |
| 217 |
--- |
| 218 |
[ |
| 219 |
"EmptyStatement" |
| 220 |
] |
| 221 |
`) |
| 222 |
|
| 223 |
test(` |
| 224 |
;;; |
| 225 |
--- |
| 226 |
[ |
| 227 |
"EmptyStatement", |
| 228 |
"EmptyStatement", |
| 229 |
"EmptyStatement" |
| 230 |
] |
| 231 |
`) |
| 232 |
|
| 233 |
test(` |
| 234 |
1; true; abc; "abc"; null; |
| 235 |
--- |
| 236 |
[ |
| 237 |
{ |
| 238 |
"Literal": 1 |
| 239 |
}, |
| 240 |
{ |
| 241 |
"Literal": true |
| 242 |
}, |
| 243 |
{ |
| 244 |
"Identifier": "abc" |
| 245 |
}, |
| 246 |
{ |
| 247 |
"Literal": "\"abc\"" |
| 248 |
}, |
| 249 |
{ |
| 250 |
"Literal": null |
| 251 |
} |
| 252 |
] |
| 253 |
`) |
| 254 |
|
| 255 |
test(` |
| 256 |
{ 1; null; 3.14159; ; } |
| 257 |
--- |
| 258 |
[ |
| 259 |
{ |
| 260 |
"BlockStatement": [ |
| 261 |
{ |
| 262 |
"Literal": 1 |
| 263 |
}, |
| 264 |
{ |
| 265 |
"Literal": null |
| 266 |
}, |
| 267 |
{ |
| 268 |
"Literal": 3.14159 |
| 269 |
}, |
| 270 |
"EmptyStatement" |
| 271 |
] |
| 272 |
} |
| 273 |
] |
| 274 |
`) |
| 275 |
|
| 276 |
test(` |
| 277 |
new abc(); |
| 278 |
--- |
| 279 |
[ |
| 280 |
{ |
| 281 |
"New": { |
| 282 |
"ArgumentList": [], |
| 283 |
"Callee": { |
| 284 |
"Identifier": "abc" |
| 285 |
} |
| 286 |
} |
| 287 |
} |
| 288 |
] |
| 289 |
`) |
| 290 |
|
| 291 |
test(` |
| 292 |
new abc(1, 3.14159) |
| 293 |
--- |
| 294 |
[ |
| 295 |
{ |
| 296 |
"New": { |
| 297 |
"ArgumentList": [ |
| 298 |
{ |
| 299 |
"Literal": 1 |
| 300 |
}, |
| 301 |
{ |
| 302 |
"Literal": 3.14159 |
| 303 |
} |
| 304 |
], |
| 305 |
"Callee": { |
| 306 |
"Identifier": "abc" |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
] |
| 311 |
`) |
| 312 |
|
| 313 |
test(` |
| 314 |
true ? false : true |
| 315 |
--- |
| 316 |
[ |
| 317 |
{ |
| 318 |
"Conditional": { |
| 319 |
"Alternate": { |
| 320 |
"Literal": true |
| 321 |
}, |
| 322 |
"Consequent": { |
| 323 |
"Literal": false |
| 324 |
}, |
| 325 |
"Test": { |
| 326 |
"Literal": true |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
] |
| 331 |
`) |
| 332 |
|
| 333 |
test(` |
| 334 |
true || false |
| 335 |
--- |
| 336 |
[ |
| 337 |
{ |
| 338 |
"BinaryExpression": { |
| 339 |
"Left": { |
| 340 |
"Literal": true |
| 341 |
}, |
| 342 |
"Operator": "||", |
| 343 |
"Right": { |
| 344 |
"Literal": false |
| 345 |
} |
| 346 |
} |
| 347 |
} |
| 348 |
] |
| 349 |
`) |
| 350 |
|
| 351 |
test(` |
| 352 |
0 + { abc: true } |
| 353 |
--- |
| 354 |
[ |
| 355 |
{ |
| 356 |
"BinaryExpression": { |
| 357 |
"Left": { |
| 358 |
"Literal": 0 |
| 359 |
}, |
| 360 |
"Operator": "+", |
| 361 |
"Right": { |
| 362 |
"Object": [ |
| 363 |
{ |
| 364 |
"Key": "abc", |
| 365 |
"Value": { |
| 366 |
"Literal": true |
| 367 |
} |
| 368 |
} |
| 369 |
] |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
] |
| 374 |
`) |
| 375 |
|
| 376 |
test(` |
| 377 |
1 == "1" |
| 378 |
--- |
| 379 |
[ |
| 380 |
{ |
| 381 |
"BinaryExpression": { |
| 382 |
"Left": { |
| 383 |
"Literal": 1 |
| 384 |
}, |
| 385 |
"Operator": "==", |
| 386 |
"Right": { |
| 387 |
"Literal": "\"1\"" |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
] |
| 392 |
`) |
| 393 |
|
| 394 |
test(` |
| 395 |
abc(1) |
| 396 |
--- |
| 397 |
[ |
| 398 |
{ |
| 399 |
"Call": { |
| 400 |
"ArgumentList": [ |
| 401 |
{ |
| 402 |
"Literal": 1 |
| 403 |
} |
| 404 |
], |
| 405 |
"Callee": { |
| 406 |
"Identifier": "abc" |
| 407 |
} |
| 408 |
} |
| 409 |
} |
| 410 |
] |
| 411 |
`) |
| 412 |
|
| 413 |
test(` |
| 414 |
Math.pow(3, 2) |
| 415 |
--- |
| 416 |
[ |
| 417 |
{ |
| 418 |
"Call": { |
| 419 |
"ArgumentList": [ |
| 420 |
{ |
| 421 |
"Literal": 3 |
| 422 |
}, |
| 423 |
{ |
| 424 |
"Literal": 2 |
| 425 |
} |
| 426 |
], |
| 427 |
"Callee": { |
| 428 |
"Dot": { |
| 429 |
"Left": { |
| 430 |
"Identifier": "Math" |
| 431 |
}, |
| 432 |
"Member": "pow" |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
} |
| 437 |
] |
| 438 |
`) |
| 439 |
|
| 440 |
test(` |
| 441 |
1, 2, 3 |
| 442 |
--- |
| 443 |
[ |
| 444 |
{ |
| 445 |
"Sequence": [ |
| 446 |
{ |
| 447 |
"Literal": 1 |
| 448 |
}, |
| 449 |
{ |
| 450 |
"Literal": 2 |
| 451 |
}, |
| 452 |
{ |
| 453 |
"Literal": 3 |
| 454 |
} |
| 455 |
] |
| 456 |
} |
| 457 |
] |
| 458 |
`) |
| 459 |
|
| 460 |
test(` |
| 461 |
/ abc / gim; |
| 462 |
--- |
| 463 |
[ |
| 464 |
{ |
| 465 |
"Literal": "/ abc / gim" |
| 466 |
} |
| 467 |
] |
| 468 |
`) |
| 469 |
|
| 470 |
test(` |
| 471 |
if (0) |
| 472 |
1; |
| 473 |
--- |
| 474 |
[ |
| 475 |
{ |
| 476 |
"If": { |
| 477 |
"Consequent": { |
| 478 |
"Literal": 1 |
| 479 |
}, |
| 480 |
"Test": { |
| 481 |
"Literal": 0 |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
] |
| 486 |
`) |
| 487 |
|
| 488 |
test(` |
| 489 |
0+function(){ |
| 490 |
return; |
| 491 |
} |
| 492 |
--- |
| 493 |
[ |
| 494 |
{ |
| 495 |
"BinaryExpression": { |
| 496 |
"Left": { |
| 497 |
"Literal": 0 |
| 498 |
}, |
| 499 |
"Operator": "+", |
| 500 |
"Right": { |
| 501 |
"Function": { |
| 502 |
"BlockStatement": [ |
| 503 |
{ |
| 504 |
"Return": null |
| 505 |
} |
| 506 |
] |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
} |
| 511 |
] |
| 512 |
`) |
| 513 |
|
| 514 |
test(` |
| 515 |
xyzzy // Ignore it |
| 516 |
// Ignore this |
| 517 |
// And this |
| 518 |
/* And all.. |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
... of this! |
| 523 |
*/ |
| 524 |
"Nothing happens." |
| 525 |
// And finally this |
| 526 |
--- |
| 527 |
[ |
| 528 |
{ |
| 529 |
"Identifier": "xyzzy" |
| 530 |
}, |
| 531 |
{ |
| 532 |
"Literal": "\"Nothing happens.\"" |
| 533 |
} |
| 534 |
] |
| 535 |
`) |
| 536 |
|
| 537 |
test(` |
| 538 |
((x & (x = 1)) !== 0) |
| 539 |
--- |
| 540 |
[ |
| 541 |
{ |
| 542 |
"BinaryExpression": { |
| 543 |
"Left": { |
| 544 |
"BinaryExpression": { |
| 545 |
"Left": { |
| 546 |
"Identifier": "x" |
| 547 |
}, |
| 548 |
"Operator": "\u0026", |
| 549 |
"Right": { |
| 550 |
"Assign": { |
| 551 |
"Left": { |
| 552 |
"Identifier": "x" |
| 553 |
}, |
| 554 |
"Right": { |
| 555 |
"Literal": 1 |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
}, |
| 561 |
"Operator": "!==", |
| 562 |
"Right": { |
| 563 |
"Literal": 0 |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
] |
| 568 |
`) |
| 569 |
|
| 570 |
test(` |
| 571 |
{ abc: 'def' } |
| 572 |
--- |
| 573 |
[ |
| 574 |
{ |
| 575 |
"BlockStatement": [ |
| 576 |
{ |
| 577 |
"Label": { |
| 578 |
"Name": "abc", |
| 579 |
"Statement": { |
| 580 |
"Literal": "'def'" |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
] |
| 585 |
} |
| 586 |
] |
| 587 |
`) |
| 588 |
|
| 589 |
test(` |
| 590 |
// This is not an object, this is a string literal with a label! |
| 591 |
({ abc: 'def' }) |
| 592 |
--- |
| 593 |
[ |
| 594 |
{ |
| 595 |
"Object": [ |
| 596 |
{ |
| 597 |
"Key": "abc", |
| 598 |
"Value": { |
| 599 |
"Literal": "'def'" |
| 600 |
} |
| 601 |
} |
| 602 |
] |
| 603 |
} |
| 604 |
] |
| 605 |
`) |
| 606 |
|
| 607 |
test(` |
| 608 |
[,] |
| 609 |
--- |
| 610 |
[ |
| 611 |
{ |
| 612 |
"Array": [ |
| 613 |
null |
| 614 |
] |
| 615 |
} |
| 616 |
] |
| 617 |
`) |
| 618 |
|
| 619 |
test(` |
| 620 |
[,,] |
| 621 |
--- |
| 622 |
[ |
| 623 |
{ |
| 624 |
"Array": [ |
| 625 |
null, |
| 626 |
null |
| 627 |
] |
| 628 |
} |
| 629 |
] |
| 630 |
`) |
| 631 |
|
| 632 |
test(` |
| 633 |
({ get abc() {} }) |
| 634 |
--- |
| 635 |
[ |
| 636 |
{ |
| 637 |
"Object": [ |
| 638 |
{ |
| 639 |
"Key": "abc", |
| 640 |
"Value": { |
| 641 |
"Function": { |
| 642 |
"BlockStatement": [] |
| 643 |
} |
| 644 |
} |
| 645 |
} |
| 646 |
] |
| 647 |
} |
| 648 |
] |
| 649 |
`) |
| 650 |
|
| 651 |
test(` |
| 652 |
/abc/.source |
| 653 |
--- |
| 654 |
[ |
| 655 |
{ |
| 656 |
"Dot": { |
| 657 |
"Left": { |
| 658 |
"Literal": "/abc/" |
| 659 |
}, |
| 660 |
"Member": "source" |
| 661 |
} |
| 662 |
} |
| 663 |
] |
| 664 |
`) |
| 665 |
|
| 666 |
test(` |
| 667 |
xyzzy |
| 668 |
|
| 669 |
throw new TypeError("Nothing happens.") |
| 670 |
--- |
| 671 |
[ |
| 672 |
{ |
| 673 |
"Identifier": "xyzzy" |
| 674 |
}, |
| 675 |
{ |
| 676 |
"Throw": { |
| 677 |
"New": { |
| 678 |
"ArgumentList": [ |
| 679 |
{ |
| 680 |
"Literal": "\"Nothing happens.\"" |
| 681 |
} |
| 682 |
], |
| 683 |
"Callee": { |
| 684 |
"Identifier": "TypeError" |
| 685 |
} |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
] |
| 690 |
`) |
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
test(` |
| 698 |
var abc = 1 |
| 699 |
(function(){ |
| 700 |
})() |
| 701 |
--- |
| 702 |
[ |
| 703 |
{ |
| 704 |
"Var": [ |
| 705 |
[ |
| 706 |
"abc", |
| 707 |
{ |
| 708 |
"Call": { |
| 709 |
"ArgumentList": [], |
| 710 |
"Callee": { |
| 711 |
"Call": { |
| 712 |
"ArgumentList": [ |
| 713 |
{ |
| 714 |
"Function": { |
| 715 |
"BlockStatement": [] |
| 716 |
} |
| 717 |
} |
| 718 |
], |
| 719 |
"Callee": { |
| 720 |
"Literal": 1 |
| 721 |
} |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
} |
| 726 |
] |
| 727 |
] |
| 728 |
} |
| 729 |
] |
| 730 |
`) |
| 731 |
|
| 732 |
test(` |
| 733 |
"use strict" |
| 734 |
--- |
| 735 |
[ |
| 736 |
{ |
| 737 |
"Literal": "\"use strict\"" |
| 738 |
} |
| 739 |
] |
| 740 |
`) |
| 741 |
|
| 742 |
test(` |
| 743 |
"use strict" |
| 744 |
abc = 1 + 2 + 11 |
| 745 |
--- |
| 746 |
[ |
| 747 |
{ |
| 748 |
"Literal": "\"use strict\"" |
| 749 |
}, |
| 750 |
{ |
| 751 |
"Assign": { |
| 752 |
"Left": { |
| 753 |
"Identifier": "abc" |
| 754 |
}, |
| 755 |
"Right": { |
| 756 |
"BinaryExpression": { |
| 757 |
"Left": { |
| 758 |
"BinaryExpression": { |
| 759 |
"Left": { |
| 760 |
"Literal": 1 |
| 761 |
}, |
| 762 |
"Operator": "+", |
| 763 |
"Right": { |
| 764 |
"Literal": 2 |
| 765 |
} |
| 766 |
} |
| 767 |
}, |
| 768 |
"Operator": "+", |
| 769 |
"Right": { |
| 770 |
"Literal": 11 |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
} |
| 776 |
] |
| 777 |
`) |
| 778 |
|
| 779 |
test(` |
| 780 |
abc = function() { 'use strict' } |
| 781 |
--- |
| 782 |
[ |
| 783 |
{ |
| 784 |
"Assign": { |
| 785 |
"Left": { |
| 786 |
"Identifier": "abc" |
| 787 |
}, |
| 788 |
"Right": { |
| 789 |
"Function": { |
| 790 |
"BlockStatement": [ |
| 791 |
{ |
| 792 |
"Literal": "'use strict'" |
| 793 |
} |
| 794 |
] |
| 795 |
} |
| 796 |
} |
| 797 |
} |
| 798 |
} |
| 799 |
] |
| 800 |
`) |
| 801 |
|
| 802 |
test(` |
| 803 |
for (var abc in def) { |
| 804 |
} |
| 805 |
--- |
| 806 |
[ |
| 807 |
{ |
| 808 |
"ForIn": { |
| 809 |
"Body": { |
| 810 |
"BlockStatement": [] |
| 811 |
}, |
| 812 |
"Into": [ |
| 813 |
"abc", |
| 814 |
null |
| 815 |
], |
| 816 |
"Source": { |
| 817 |
"Identifier": "def" |
| 818 |
} |
| 819 |
} |
| 820 |
} |
| 821 |
] |
| 822 |
`) |
| 823 |
|
| 824 |
test(` |
| 825 |
abc = { |
| 826 |
'"': "'", |
| 827 |
"'": '"', |
| 828 |
} |
| 829 |
--- |
| 830 |
[ |
| 831 |
{ |
| 832 |
"Assign": { |
| 833 |
"Left": { |
| 834 |
"Identifier": "abc" |
| 835 |
}, |
| 836 |
"Right": { |
| 837 |
"Object": [ |
| 838 |
{ |
| 839 |
"Key": "\"", |
| 840 |
"Value": { |
| 841 |
"Literal": "\"'\"" |
| 842 |
} |
| 843 |
}, |
| 844 |
{ |
| 845 |
"Key": "'", |
| 846 |
"Value": { |
| 847 |
"Literal": "'\"'" |
| 848 |
} |
| 849 |
} |
| 850 |
] |
| 851 |
} |
| 852 |
} |
| 853 |
} |
| 854 |
] |
| 855 |
`) |
| 856 |
|
| 857 |
test(` |
| 858 |
if (!abc && abc.jkl(def) && abc[0] === +abc[0] && abc.length < ghi) { |
| 859 |
} |
| 860 |
--- |
| 861 |
[ |
| 862 |
{ |
| 863 |
"If": { |
| 864 |
"Consequent": { |
| 865 |
"BlockStatement": [] |
| 866 |
}, |
| 867 |
"Test": { |
| 868 |
"BinaryExpression": { |
| 869 |
"Left": { |
| 870 |
"BinaryExpression": { |
| 871 |
"Left": { |
| 872 |
"BinaryExpression": { |
| 873 |
"Left": null, |
| 874 |
"Operator": "\u0026\u0026", |
| 875 |
"Right": { |
| 876 |
"Call": { |
| 877 |
"ArgumentList": [ |
| 878 |
{ |
| 879 |
"Identifier": "def" |
| 880 |
} |
| 881 |
], |
| 882 |
"Callee": { |
| 883 |
"Dot": { |
| 884 |
"Left": { |
| 885 |
"Identifier": "abc" |
| 886 |
}, |
| 887 |
"Member": "jkl" |
| 888 |
} |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
}, |
| 894 |
"Operator": "\u0026\u0026", |
| 895 |
"Right": { |
| 896 |
"BinaryExpression": { |
| 897 |
"Left": null, |
| 898 |
"Operator": "===", |
| 899 |
"Right": null |
| 900 |
} |
| 901 |
} |
| 902 |
} |
| 903 |
}, |
| 904 |
"Operator": "\u0026\u0026", |
| 905 |
"Right": { |
| 906 |
"BinaryExpression": { |
| 907 |
"Left": { |
| 908 |
"Dot": { |
| 909 |
"Left": { |
| 910 |
"Identifier": "abc" |
| 911 |
}, |
| 912 |
"Member": "length" |
| 913 |
} |
| 914 |
}, |
| 915 |
"Operator": "\u003c", |
| 916 |
"Right": { |
| 917 |
"Identifier": "ghi" |
| 918 |
} |
| 919 |
} |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
} |
| 925 |
] |
| 926 |
`) |
| 927 |
}) |
| 928 |
} |