@angular-wave/angular.ts 0.0.49 → 0.0.51

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.
@@ -11,6 +11,7 @@ import {
11
11
  } from "../../shared/utils";
12
12
  import { publishExternalAPI } from "../../public";
13
13
  import { createInjector } from "../../injector";
14
+ import { ASTType } from "./ast-type";
14
15
 
15
16
  describe("parser", () => {
16
17
  let $rootScope;
@@ -35,7 +36,7 @@ describe("parser", () => {
35
36
 
36
37
  beforeEach(() => {
37
38
  lex = function () {
38
- const lexer = new Lexer({ csp: false });
39
+ const lexer = new Lexer({});
39
40
  return lexer.lex.apply(lexer, arguments);
40
41
  };
41
42
  });
@@ -132,7 +133,6 @@ describe("parser", () => {
132
133
  const isIdentifierContinue = jasmine.createSpy("continue");
133
134
  isIdentifierStart.and.returnValue(true);
134
135
  const lex = new Lexer({
135
- csp: false,
136
136
  isIdentifierStart,
137
137
  isIdentifierContinue,
138
138
  });
@@ -155,7 +155,6 @@ describe("parser", () => {
155
155
  isIdentifierStart.and.returnValue(true);
156
156
  isIdentifierContinue.and.returnValue(true);
157
157
  const lex = new Lexer({
158
- csp: false,
159
158
  isIdentifierStart,
160
159
  isIdentifierContinue,
161
160
  });
@@ -317,7 +316,7 @@ describe("parser", () => {
317
316
  beforeEach(() => {
318
317
  /* global AST: false */
319
318
  createAst = function () {
320
- const lexer = new Lexer({ csp: false });
319
+ const lexer = new Lexer({});
321
320
  const ast = new AST(lexer, {
322
321
  csp: false,
323
322
  literals: {
@@ -332,16 +331,16 @@ describe("parser", () => {
332
331
  });
333
332
 
334
333
  it("should handle an empty list of tokens", () => {
335
- expect(createAst("")).toEqual({ type: "Program", body: [] });
334
+ expect(createAst("")).toEqual({ type: ASTType.Program, body: [] });
336
335
  });
337
336
 
338
337
  it("should understand identifiers", () => {
339
338
  expect(createAst("foo")).toEqual({
340
- type: "Program",
339
+ type: ASTType.Program,
341
340
  body: [
342
341
  {
343
- type: "ExpressionStatement",
344
- expression: { type: "Identifier", name: "foo" },
342
+ type: ASTType.ExpressionStatement,
343
+ expression: { type: ASTType.Identifier, name: "foo" },
345
344
  },
346
345
  ],
347
346
  });
@@ -349,14 +348,14 @@ describe("parser", () => {
349
348
 
350
349
  it("should understand non-computed member expressions", () => {
351
350
  expect(createAst("foo.bar")).toEqual({
352
- type: "Program",
351
+ type: ASTType.Program,
353
352
  body: [
354
353
  {
355
- type: "ExpressionStatement",
354
+ type: ASTType.ExpressionStatement,
356
355
  expression: {
357
- type: "MemberExpression",
358
- object: { type: "Identifier", name: "foo" },
359
- property: { type: "Identifier", name: "bar" },
356
+ type: ASTType.MemberExpression,
357
+ object: { type: ASTType.Identifier, name: "foo" },
358
+ property: { type: ASTType.Identifier, name: "bar" },
360
359
  computed: false,
361
360
  },
362
361
  },
@@ -366,19 +365,19 @@ describe("parser", () => {
366
365
 
367
366
  it("should associate non-computed member expressions left-to-right", () => {
368
367
  expect(createAst("foo.bar.baz")).toEqual({
369
- type: "Program",
368
+ type: ASTType.Program,
370
369
  body: [
371
370
  {
372
- type: "ExpressionStatement",
371
+ type: ASTType.ExpressionStatement,
373
372
  expression: {
374
- type: "MemberExpression",
373
+ type: ASTType.MemberExpression,
375
374
  object: {
376
- type: "MemberExpression",
377
- object: { type: "Identifier", name: "foo" },
378
- property: { type: "Identifier", name: "bar" },
375
+ type: ASTType.MemberExpression,
376
+ object: { type: ASTType.Identifier, name: "foo" },
377
+ property: { type: ASTType.Identifier, name: "bar" },
379
378
  computed: false,
380
379
  },
381
- property: { type: "Identifier", name: "baz" },
380
+ property: { type: ASTType.Identifier, name: "baz" },
382
381
  computed: false,
383
382
  },
384
383
  },
@@ -388,14 +387,14 @@ describe("parser", () => {
388
387
 
389
388
  it("should understand computed member expressions", () => {
390
389
  expect(createAst("foo[bar]")).toEqual({
391
- type: "Program",
390
+ type: ASTType.Program,
392
391
  body: [
393
392
  {
394
- type: "ExpressionStatement",
393
+ type: ASTType.ExpressionStatement,
395
394
  expression: {
396
- type: "MemberExpression",
397
- object: { type: "Identifier", name: "foo" },
398
- property: { type: "Identifier", name: "bar" },
395
+ type: ASTType.MemberExpression,
396
+ object: { type: ASTType.Identifier, name: "foo" },
397
+ property: { type: ASTType.Identifier, name: "bar" },
399
398
  computed: true,
400
399
  },
401
400
  },
@@ -405,19 +404,19 @@ describe("parser", () => {
405
404
 
406
405
  it("should associate computed member expressions left-to-right", () => {
407
406
  expect(createAst("foo[bar][baz]")).toEqual({
408
- type: "Program",
407
+ type: ASTType.Program,
409
408
  body: [
410
409
  {
411
- type: "ExpressionStatement",
410
+ type: ASTType.ExpressionStatement,
412
411
  expression: {
413
- type: "MemberExpression",
412
+ type: ASTType.MemberExpression,
414
413
  object: {
415
- type: "MemberExpression",
416
- object: { type: "Identifier", name: "foo" },
417
- property: { type: "Identifier", name: "bar" },
414
+ type: ASTType.MemberExpression,
415
+ object: { type: ASTType.Identifier, name: "foo" },
416
+ property: { type: ASTType.Identifier, name: "bar" },
418
417
  computed: true,
419
418
  },
420
- property: { type: "Identifier", name: "baz" },
419
+ property: { type: ASTType.Identifier, name: "baz" },
421
420
  computed: true,
422
421
  },
423
422
  },
@@ -427,13 +426,13 @@ describe("parser", () => {
427
426
 
428
427
  it("should understand call expressions", () => {
429
428
  expect(createAst("foo()")).toEqual({
430
- type: "Program",
429
+ type: ASTType.Program,
431
430
  body: [
432
431
  {
433
- type: "ExpressionStatement",
432
+ type: ASTType.ExpressionStatement,
434
433
  expression: {
435
- type: "CallExpression",
436
- callee: { type: "Identifier", name: "foo" },
434
+ type: ASTType.CallExpression,
435
+ callee: { type: ASTType.Identifier, name: "foo" },
437
436
  arguments: [],
438
437
  },
439
438
  },
@@ -443,16 +442,16 @@ describe("parser", () => {
443
442
 
444
443
  it("should parse call expression arguments", () => {
445
444
  expect(createAst("foo(bar, baz)")).toEqual({
446
- type: "Program",
445
+ type: ASTType.Program,
447
446
  body: [
448
447
  {
449
- type: "ExpressionStatement",
448
+ type: ASTType.ExpressionStatement,
450
449
  expression: {
451
- type: "CallExpression",
452
- callee: { type: "Identifier", name: "foo" },
450
+ type: ASTType.CallExpression,
451
+ callee: { type: ASTType.Identifier, name: "foo" },
453
452
  arguments: [
454
- { type: "Identifier", name: "bar" },
455
- { type: "Identifier", name: "baz" },
453
+ { type: ASTType.Identifier, name: "bar" },
454
+ { type: ASTType.Identifier, name: "baz" },
456
455
  ],
457
456
  },
458
457
  },
@@ -462,23 +461,23 @@ describe("parser", () => {
462
461
 
463
462
  it("should parse call expression left-to-right", () => {
464
463
  expect(createAst("foo(bar, baz)(man, shell)")).toEqual({
465
- type: "Program",
464
+ type: ASTType.Program,
466
465
  body: [
467
466
  {
468
- type: "ExpressionStatement",
467
+ type: ASTType.ExpressionStatement,
469
468
  expression: {
470
- type: "CallExpression",
469
+ type: ASTType.CallExpression,
471
470
  callee: {
472
- type: "CallExpression",
473
- callee: { type: "Identifier", name: "foo" },
471
+ type: ASTType.CallExpression,
472
+ callee: { type: ASTType.Identifier, name: "foo" },
474
473
  arguments: [
475
- { type: "Identifier", name: "bar" },
476
- { type: "Identifier", name: "baz" },
474
+ { type: ASTType.Identifier, name: "bar" },
475
+ { type: ASTType.Identifier, name: "baz" },
477
476
  ],
478
477
  },
479
478
  arguments: [
480
- { type: "Identifier", name: "man" },
481
- { type: "Identifier", name: "shell" },
479
+ { type: ASTType.Identifier, name: "man" },
480
+ { type: ASTType.Identifier, name: "shell" },
482
481
  ],
483
482
  },
484
483
  },
@@ -488,16 +487,16 @@ describe("parser", () => {
488
487
 
489
488
  it("should keep the context when having superfluous parenthesis", () => {
490
489
  expect(createAst("(foo)(bar, baz)")).toEqual({
491
- type: "Program",
490
+ type: ASTType.Program,
492
491
  body: [
493
492
  {
494
- type: "ExpressionStatement",
493
+ type: ASTType.ExpressionStatement,
495
494
  expression: {
496
- type: "CallExpression",
497
- callee: { type: "Identifier", name: "foo" },
495
+ type: ASTType.CallExpression,
496
+ callee: { type: ASTType.Identifier, name: "foo" },
498
497
  arguments: [
499
- { type: "Identifier", name: "bar" },
500
- { type: "Identifier", name: "baz" },
498
+ { type: ASTType.Identifier, name: "bar" },
499
+ { type: ASTType.Identifier, name: "baz" },
501
500
  ],
502
501
  },
503
502
  },
@@ -507,21 +506,21 @@ describe("parser", () => {
507
506
 
508
507
  it("should treat member expressions and call expression with the same precedence", () => {
509
508
  expect(createAst("foo.bar[baz]()")).toEqual({
510
- type: "Program",
509
+ type: ASTType.Program,
511
510
  body: [
512
511
  {
513
- type: "ExpressionStatement",
512
+ type: ASTType.ExpressionStatement,
514
513
  expression: {
515
- type: "CallExpression",
514
+ type: ASTType.CallExpression,
516
515
  callee: {
517
- type: "MemberExpression",
516
+ type: ASTType.MemberExpression,
518
517
  object: {
519
- type: "MemberExpression",
520
- object: { type: "Identifier", name: "foo" },
521
- property: { type: "Identifier", name: "bar" },
518
+ type: ASTType.MemberExpression,
519
+ object: { type: ASTType.Identifier, name: "foo" },
520
+ property: { type: ASTType.Identifier, name: "bar" },
522
521
  computed: false,
523
522
  },
524
- property: { type: "Identifier", name: "baz" },
523
+ property: { type: ASTType.Identifier, name: "baz" },
525
524
  computed: true,
526
525
  },
527
526
  arguments: [],
@@ -530,46 +529,46 @@ describe("parser", () => {
530
529
  ],
531
530
  });
532
531
  expect(createAst("foo[bar]().baz")).toEqual({
533
- type: "Program",
532
+ type: ASTType.Program,
534
533
  body: [
535
534
  {
536
- type: "ExpressionStatement",
535
+ type: ASTType.ExpressionStatement,
537
536
  expression: {
538
- type: "MemberExpression",
537
+ type: ASTType.MemberExpression,
539
538
  object: {
540
- type: "CallExpression",
539
+ type: ASTType.CallExpression,
541
540
  callee: {
542
- type: "MemberExpression",
543
- object: { type: "Identifier", name: "foo" },
544
- property: { type: "Identifier", name: "bar" },
541
+ type: ASTType.MemberExpression,
542
+ object: { type: ASTType.Identifier, name: "foo" },
543
+ property: { type: ASTType.Identifier, name: "bar" },
545
544
  computed: true,
546
545
  },
547
546
  arguments: [],
548
547
  },
549
- property: { type: "Identifier", name: "baz" },
548
+ property: { type: ASTType.Identifier, name: "baz" },
550
549
  computed: false,
551
550
  },
552
551
  },
553
552
  ],
554
553
  });
555
554
  expect(createAst("foo().bar[baz]")).toEqual({
556
- type: "Program",
555
+ type: ASTType.Program,
557
556
  body: [
558
557
  {
559
- type: "ExpressionStatement",
558
+ type: ASTType.ExpressionStatement,
560
559
  expression: {
561
- type: "MemberExpression",
560
+ type: ASTType.MemberExpression,
562
561
  object: {
563
- type: "MemberExpression",
562
+ type: ASTType.MemberExpression,
564
563
  object: {
565
- type: "CallExpression",
566
- callee: { type: "Identifier", name: "foo" },
564
+ type: ASTType.CallExpression,
565
+ callee: { type: ASTType.Identifier, name: "foo" },
567
566
  arguments: [],
568
567
  },
569
- property: { type: "Identifier", name: "bar" },
568
+ property: { type: ASTType.Identifier, name: "bar" },
570
569
  computed: false,
571
570
  },
572
- property: { type: "Identifier", name: "baz" },
571
+ property: { type: ASTType.Identifier, name: "baz" },
573
572
  computed: true,
574
573
  },
575
574
  },
@@ -590,11 +589,11 @@ describe("parser", () => {
590
589
  },
591
590
  (value, expression) => {
592
591
  expect(createAst(expression)).toEqual({
593
- type: "Program",
592
+ type: ASTType.Program,
594
593
  body: [
595
594
  {
596
- type: "ExpressionStatement",
597
- expression: { type: "Literal", value },
595
+ type: ASTType.ExpressionStatement,
596
+ expression: { type: ASTType.Literal, value },
598
597
  },
599
598
  ],
600
599
  });
@@ -604,11 +603,11 @@ describe("parser", () => {
604
603
 
605
604
  it("should understand the `this` expression", () => {
606
605
  expect(createAst("this")).toEqual({
607
- type: "Program",
606
+ type: ASTType.Program,
608
607
  body: [
609
608
  {
610
- type: "ExpressionStatement",
611
- expression: { type: "ThisExpression" },
609
+ type: ASTType.ExpressionStatement,
610
+ expression: { type: ASTType.ThisExpression },
612
611
  },
613
612
  ],
614
613
  });
@@ -616,11 +615,11 @@ describe("parser", () => {
616
615
 
617
616
  it("should understand the `$locals` expression", () => {
618
617
  expect(createAst("$locals")).toEqual({
619
- type: "Program",
618
+ type: ASTType.Program,
620
619
  body: [
621
620
  {
622
- type: "ExpressionStatement",
623
- expression: { type: "LocalsExpression" },
621
+ type: ASTType.ExpressionStatement,
622
+ expression: { type: ASTType.LocalsExpression },
624
623
  },
625
624
  ],
626
625
  });
@@ -631,14 +630,14 @@ describe("parser", () => {
631
630
  ["this", "$locals", "undefined", "true", "false", "null"],
632
631
  (identifier) => {
633
632
  expect(createAst(`foo.${identifier}`)).toEqual({
634
- type: "Program",
633
+ type: ASTType.Program,
635
634
  body: [
636
635
  {
637
- type: "ExpressionStatement",
636
+ type: ASTType.ExpressionStatement,
638
637
  expression: {
639
- type: "MemberExpression",
640
- object: { type: "Identifier", name: "foo" },
641
- property: { type: "Identifier", name: identifier },
638
+ type: ASTType.MemberExpression,
639
+ object: { type: ASTType.Identifier, name: "foo" },
640
+ property: { type: ASTType.Identifier, name: identifier },
642
641
  computed: false,
643
642
  },
644
643
  },
@@ -663,15 +662,15 @@ describe("parser", () => {
663
662
  it("should understand the unary operators `-`, `+` and `!`", () => {
664
663
  forEach(["-", "+", "!"], (operator) => {
665
664
  expect(createAst(`${operator}foo`)).toEqual({
666
- type: "Program",
665
+ type: ASTType.Program,
667
666
  body: [
668
667
  {
669
- type: "ExpressionStatement",
668
+ type: ASTType.ExpressionStatement,
670
669
  expression: {
671
- type: "UnaryExpression",
670
+ type: ASTType.UnaryExpression,
672
671
  operator,
673
672
  prefix: true,
674
- argument: { type: "Identifier", name: "foo" },
673
+ argument: { type: ASTType.Identifier, name: "foo" },
675
674
  },
676
675
  },
677
676
  ],
@@ -688,23 +687,23 @@ describe("parser", () => {
688
687
  ],
689
688
  (operators) => {
690
689
  expect(createAst(`${operators.join("")}foo`)).toEqual({
691
- type: "Program",
690
+ type: ASTType.Program,
692
691
  body: [
693
692
  {
694
- type: "ExpressionStatement",
693
+ type: ASTType.ExpressionStatement,
695
694
  expression: {
696
- type: "UnaryExpression",
695
+ type: ASTType.UnaryExpression,
697
696
  operator: operators[0],
698
697
  prefix: true,
699
698
  argument: {
700
- type: "UnaryExpression",
699
+ type: ASTType.UnaryExpression,
701
700
  operator: operators[1],
702
701
  prefix: true,
703
702
  argument: {
704
- type: "UnaryExpression",
703
+ type: ASTType.UnaryExpression,
705
704
  operator: operators[2],
706
705
  prefix: true,
707
- argument: { type: "Identifier", name: "foo" },
706
+ argument: { type: ASTType.Identifier, name: "foo" },
708
707
  },
709
708
  },
710
709
  },
@@ -734,15 +733,15 @@ describe("parser", () => {
734
733
  ],
735
734
  (operator) => {
736
735
  expect(createAst(`foo${operator}bar`)).toEqual({
737
- type: "Program",
736
+ type: ASTType.Program,
738
737
  body: [
739
738
  {
740
- type: "ExpressionStatement",
739
+ type: ASTType.ExpressionStatement,
741
740
  expression: {
742
- type: "BinaryExpression",
741
+ type: ASTType.BinaryExpression,
743
742
  operator,
744
- left: { type: "Identifier", name: "foo" },
745
- right: { type: "Identifier", name: "bar" },
743
+ left: { type: ASTType.Identifier, name: "foo" },
744
+ right: { type: ASTType.Identifier, name: "bar" },
746
745
  },
747
746
  },
748
747
  ],
@@ -762,20 +761,20 @@ describe("parser", () => {
762
761
  forEach(operators, (op1) => {
763
762
  forEach(operators, (op2) => {
764
763
  expect(createAst(`foo${op1}bar${op2}baz`)).toEqual({
765
- type: "Program",
764
+ type: ASTType.Program,
766
765
  body: [
767
766
  {
768
- type: "ExpressionStatement",
767
+ type: ASTType.ExpressionStatement,
769
768
  expression: {
770
- type: "BinaryExpression",
769
+ type: ASTType.BinaryExpression,
771
770
  operator: op2,
772
771
  left: {
773
- type: "BinaryExpression",
772
+ type: ASTType.BinaryExpression,
774
773
  operator: op1,
775
- left: { type: "Identifier", name: "foo" },
776
- right: { type: "Identifier", name: "bar" },
774
+ left: { type: ASTType.Identifier, name: "foo" },
775
+ right: { type: ASTType.Identifier, name: "bar" },
777
776
  },
778
- right: { type: "Identifier", name: "baz" },
777
+ right: { type: ASTType.Identifier, name: "baz" },
779
778
  },
780
779
  },
781
780
  ],
@@ -788,17 +787,17 @@ describe("parser", () => {
788
787
  it("should give higher precedence to member calls than to unary expressions", () => {
789
788
  forEach(["!", "+", "-"], (operator) => {
790
789
  expect(createAst(`${operator}foo()`)).toEqual({
791
- type: "Program",
790
+ type: ASTType.Program,
792
791
  body: [
793
792
  {
794
- type: "ExpressionStatement",
793
+ type: ASTType.ExpressionStatement,
795
794
  expression: {
796
- type: "UnaryExpression",
795
+ type: ASTType.UnaryExpression,
797
796
  operator,
798
797
  prefix: true,
799
798
  argument: {
800
- type: "CallExpression",
801
- callee: { type: "Identifier", name: "foo" },
799
+ type: ASTType.CallExpression,
800
+ callee: { type: ASTType.Identifier, name: "foo" },
802
801
  arguments: [],
803
802
  },
804
803
  },
@@ -806,18 +805,18 @@ describe("parser", () => {
806
805
  ],
807
806
  });
808
807
  expect(createAst(`${operator}foo.bar`)).toEqual({
809
- type: "Program",
808
+ type: ASTType.Program,
810
809
  body: [
811
810
  {
812
- type: "ExpressionStatement",
811
+ type: ASTType.ExpressionStatement,
813
812
  expression: {
814
- type: "UnaryExpression",
813
+ type: ASTType.UnaryExpression,
815
814
  operator,
816
815
  prefix: true,
817
816
  argument: {
818
- type: "MemberExpression",
819
- object: { type: "Identifier", name: "foo" },
820
- property: { type: "Identifier", name: "bar" },
817
+ type: ASTType.MemberExpression,
818
+ object: { type: ASTType.Identifier, name: "foo" },
819
+ property: { type: ASTType.Identifier, name: "bar" },
821
820
  computed: false,
822
821
  },
823
822
  },
@@ -825,18 +824,18 @@ describe("parser", () => {
825
824
  ],
826
825
  });
827
826
  expect(createAst(`${operator}foo[bar]`)).toEqual({
828
- type: "Program",
827
+ type: ASTType.Program,
829
828
  body: [
830
829
  {
831
- type: "ExpressionStatement",
830
+ type: ASTType.ExpressionStatement,
832
831
  expression: {
833
- type: "UnaryExpression",
832
+ type: ASTType.UnaryExpression,
834
833
  operator,
835
834
  prefix: true,
836
835
  argument: {
837
- type: "MemberExpression",
838
- object: { type: "Identifier", name: "foo" },
839
- property: { type: "Identifier", name: "bar" },
836
+ type: ASTType.MemberExpression,
837
+ object: { type: ASTType.Identifier, name: "foo" },
838
+ property: { type: ASTType.Identifier, name: "bar" },
840
839
  computed: true,
841
840
  },
842
841
  },
@@ -850,24 +849,24 @@ describe("parser", () => {
850
849
  forEach(["!", "+", "-"], (op1) => {
851
850
  forEach(["*", "/", "%"], (op2) => {
852
851
  expect(createAst(`${op1}foo${op2}${op1}bar`)).toEqual({
853
- type: "Program",
852
+ type: ASTType.Program,
854
853
  body: [
855
854
  {
856
- type: "ExpressionStatement",
855
+ type: ASTType.ExpressionStatement,
857
856
  expression: {
858
- type: "BinaryExpression",
857
+ type: ASTType.BinaryExpression,
859
858
  operator: op2,
860
859
  left: {
861
- type: "UnaryExpression",
860
+ type: ASTType.UnaryExpression,
862
861
  operator: op1,
863
862
  prefix: true,
864
- argument: { type: "Identifier", name: "foo" },
863
+ argument: { type: ASTType.Identifier, name: "foo" },
865
864
  },
866
865
  right: {
867
- type: "UnaryExpression",
866
+ type: ASTType.UnaryExpression,
868
867
  operator: op1,
869
868
  prefix: true,
870
- argument: { type: "Identifier", name: "bar" },
869
+ argument: { type: ASTType.Identifier, name: "bar" },
871
870
  },
872
871
  },
873
872
  },
@@ -888,24 +887,24 @@ describe("parser", () => {
888
887
  forEach(operatorsByPrecedence[i], (op1) => {
889
888
  forEach(operatorsByPrecedence[i + 1], (op2) => {
890
889
  expect(createAst(`foo${op1}bar${op2}baz${op1}man`)).toEqual({
891
- type: "Program",
890
+ type: ASTType.Program,
892
891
  body: [
893
892
  {
894
- type: "ExpressionStatement",
893
+ type: ASTType.ExpressionStatement,
895
894
  expression: {
896
- type: "BinaryExpression",
895
+ type: ASTType.BinaryExpression,
897
896
  operator: op2,
898
897
  left: {
899
- type: "BinaryExpression",
898
+ type: ASTType.BinaryExpression,
900
899
  operator: op1,
901
- left: { type: "Identifier", name: "foo" },
902
- right: { type: "Identifier", name: "bar" },
900
+ left: { type: ASTType.Identifier, name: "foo" },
901
+ right: { type: ASTType.Identifier, name: "bar" },
903
902
  },
904
903
  right: {
905
- type: "BinaryExpression",
904
+ type: ASTType.BinaryExpression,
906
905
  operator: op1,
907
- left: { type: "Identifier", name: "baz" },
908
- right: { type: "Identifier", name: "man" },
906
+ left: { type: ASTType.Identifier, name: "baz" },
907
+ right: { type: ASTType.Identifier, name: "man" },
909
908
  },
910
909
  },
911
910
  },
@@ -919,15 +918,15 @@ describe("parser", () => {
919
918
  it("should understand logical operators", () => {
920
919
  forEach(["||", "&&"], (operator) => {
921
920
  expect(createAst(`foo${operator}bar`)).toEqual({
922
- type: "Program",
921
+ type: ASTType.Program,
923
922
  body: [
924
923
  {
925
- type: "ExpressionStatement",
924
+ type: ASTType.ExpressionStatement,
926
925
  expression: {
927
- type: "LogicalExpression",
926
+ type: ASTType.LogicalExpression,
928
927
  operator,
929
- left: { type: "Identifier", name: "foo" },
930
- right: { type: "Identifier", name: "bar" },
928
+ left: { type: ASTType.Identifier, name: "foo" },
929
+ right: { type: ASTType.Identifier, name: "bar" },
931
930
  },
932
931
  },
933
932
  ],
@@ -938,20 +937,20 @@ describe("parser", () => {
938
937
  it("should associate logical operators left-to-right", () => {
939
938
  forEach(["||", "&&"], (op) => {
940
939
  expect(createAst(`foo${op}bar${op}baz`)).toEqual({
941
- type: "Program",
940
+ type: ASTType.Program,
942
941
  body: [
943
942
  {
944
- type: "ExpressionStatement",
943
+ type: ASTType.ExpressionStatement,
945
944
  expression: {
946
- type: "LogicalExpression",
945
+ type: ASTType.LogicalExpression,
947
946
  operator: op,
948
947
  left: {
949
- type: "LogicalExpression",
948
+ type: ASTType.LogicalExpression,
950
949
  operator: op,
951
- left: { type: "Identifier", name: "foo" },
952
- right: { type: "Identifier", name: "bar" },
950
+ left: { type: ASTType.Identifier, name: "foo" },
951
+ right: { type: ASTType.Identifier, name: "bar" },
953
952
  },
954
- right: { type: "Identifier", name: "baz" },
953
+ right: { type: ASTType.Identifier, name: "baz" },
955
954
  },
956
955
  },
957
956
  ],
@@ -961,15 +960,15 @@ describe("parser", () => {
961
960
 
962
961
  it("should understand ternary operators", () => {
963
962
  expect(createAst("foo?bar:baz")).toEqual({
964
- type: "Program",
963
+ type: ASTType.Program,
965
964
  body: [
966
965
  {
967
- type: "ExpressionStatement",
966
+ type: ASTType.ExpressionStatement,
968
967
  expression: {
969
- type: "ConditionalExpression",
970
- test: { type: "Identifier", name: "foo" },
971
- alternate: { type: "Identifier", name: "bar" },
972
- consequent: { type: "Identifier", name: "baz" },
968
+ type: ASTType.ConditionalExpression,
969
+ test: { type: ASTType.Identifier, name: "foo" },
970
+ alternate: { type: ASTType.Identifier, name: "bar" },
971
+ consequent: { type: ASTType.Identifier, name: "baz" },
973
972
  },
974
973
  },
975
974
  ],
@@ -979,28 +978,28 @@ describe("parser", () => {
979
978
  it("should associate the conditional operator right-to-left", () => {
980
979
  expect(createAst("foo0?foo1:foo2?bar0?bar1:bar2:man0?man1:man2")).toEqual(
981
980
  {
982
- type: "Program",
981
+ type: ASTType.Program,
983
982
  body: [
984
983
  {
985
- type: "ExpressionStatement",
984
+ type: ASTType.ExpressionStatement,
986
985
  expression: {
987
- type: "ConditionalExpression",
988
- test: { type: "Identifier", name: "foo0" },
989
- alternate: { type: "Identifier", name: "foo1" },
986
+ type: ASTType.ConditionalExpression,
987
+ test: { type: ASTType.Identifier, name: "foo0" },
988
+ alternate: { type: ASTType.Identifier, name: "foo1" },
990
989
  consequent: {
991
- type: "ConditionalExpression",
992
- test: { type: "Identifier", name: "foo2" },
990
+ type: ASTType.ConditionalExpression,
991
+ test: { type: ASTType.Identifier, name: "foo2" },
993
992
  alternate: {
994
- type: "ConditionalExpression",
995
- test: { type: "Identifier", name: "bar0" },
996
- alternate: { type: "Identifier", name: "bar1" },
997
- consequent: { type: "Identifier", name: "bar2" },
993
+ type: ASTType.ConditionalExpression,
994
+ test: { type: ASTType.Identifier, name: "bar0" },
995
+ alternate: { type: ASTType.Identifier, name: "bar1" },
996
+ consequent: { type: ASTType.Identifier, name: "bar2" },
998
997
  },
999
998
  consequent: {
1000
- type: "ConditionalExpression",
1001
- test: { type: "Identifier", name: "man0" },
1002
- alternate: { type: "Identifier", name: "man1" },
1003
- consequent: { type: "Identifier", name: "man2" },
999
+ type: ASTType.ConditionalExpression,
1000
+ test: { type: ASTType.Identifier, name: "man0" },
1001
+ alternate: { type: ASTType.Identifier, name: "man1" },
1002
+ consequent: { type: ASTType.Identifier, name: "man2" },
1004
1003
  },
1005
1004
  },
1006
1005
  },
@@ -1013,14 +1012,14 @@ describe("parser", () => {
1013
1012
  it("should understand assignment operator", () => {
1014
1013
  // Currently, only `=` is supported
1015
1014
  expect(createAst("foo=bar")).toEqual({
1016
- type: "Program",
1015
+ type: ASTType.Program,
1017
1016
  body: [
1018
1017
  {
1019
- type: "ExpressionStatement",
1018
+ type: ASTType.ExpressionStatement,
1020
1019
  expression: {
1021
- type: "AssignmentExpression",
1022
- left: { type: "Identifier", name: "foo" },
1023
- right: { type: "Identifier", name: "bar" },
1020
+ type: ASTType.AssignmentExpression,
1021
+ left: { type: ASTType.Identifier, name: "foo" },
1022
+ right: { type: ASTType.Identifier, name: "bar" },
1024
1023
  operator: "=",
1025
1024
  },
1026
1025
  },
@@ -1031,17 +1030,17 @@ describe("parser", () => {
1031
1030
  it("should associate assignments right-to-left", () => {
1032
1031
  // Currently, only `=` is supported
1033
1032
  expect(createAst("foo=bar=man")).toEqual({
1034
- type: "Program",
1033
+ type: ASTType.Program,
1035
1034
  body: [
1036
1035
  {
1037
- type: "ExpressionStatement",
1036
+ type: ASTType.ExpressionStatement,
1038
1037
  expression: {
1039
- type: "AssignmentExpression",
1040
- left: { type: "Identifier", name: "foo" },
1038
+ type: ASTType.AssignmentExpression,
1039
+ left: { type: ASTType.Identifier, name: "foo" },
1041
1040
  right: {
1042
- type: "AssignmentExpression",
1043
- left: { type: "Identifier", name: "bar" },
1044
- right: { type: "Identifier", name: "man" },
1041
+ type: ASTType.AssignmentExpression,
1042
+ left: { type: ASTType.Identifier, name: "bar" },
1043
+ right: { type: ASTType.Identifier, name: "man" },
1045
1044
  operator: "=",
1046
1045
  },
1047
1046
  operator: "=",
@@ -1054,24 +1053,24 @@ describe("parser", () => {
1054
1053
  it("should give higher precedence to equality than to the logical `and` operator", () => {
1055
1054
  forEach(["==", "!=", "===", "!=="], (operator) => {
1056
1055
  expect(createAst(`foo${operator}bar && man${operator}shell`)).toEqual({
1057
- type: "Program",
1056
+ type: ASTType.Program,
1058
1057
  body: [
1059
1058
  {
1060
- type: "ExpressionStatement",
1059
+ type: ASTType.ExpressionStatement,
1061
1060
  expression: {
1062
- type: "LogicalExpression",
1061
+ type: ASTType.LogicalExpression,
1063
1062
  operator: "&&",
1064
1063
  left: {
1065
- type: "BinaryExpression",
1064
+ type: ASTType.BinaryExpression,
1066
1065
  operator,
1067
- left: { type: "Identifier", name: "foo" },
1068
- right: { type: "Identifier", name: "bar" },
1066
+ left: { type: ASTType.Identifier, name: "foo" },
1067
+ right: { type: ASTType.Identifier, name: "bar" },
1069
1068
  },
1070
1069
  right: {
1071
- type: "BinaryExpression",
1070
+ type: ASTType.BinaryExpression,
1072
1071
  operator,
1073
- left: { type: "Identifier", name: "man" },
1074
- right: { type: "Identifier", name: "shell" },
1072
+ left: { type: ASTType.Identifier, name: "man" },
1073
+ right: { type: ASTType.Identifier, name: "shell" },
1075
1074
  },
1076
1075
  },
1077
1076
  },
@@ -1082,24 +1081,24 @@ describe("parser", () => {
1082
1081
 
1083
1082
  it("should give higher precedence to logical `and` than to logical `or`", () => {
1084
1083
  expect(createAst("foo&&bar||man&&shell")).toEqual({
1085
- type: "Program",
1084
+ type: ASTType.Program,
1086
1085
  body: [
1087
1086
  {
1088
- type: "ExpressionStatement",
1087
+ type: ASTType.ExpressionStatement,
1089
1088
  expression: {
1090
- type: "LogicalExpression",
1089
+ type: ASTType.LogicalExpression,
1091
1090
  operator: "||",
1092
1091
  left: {
1093
- type: "LogicalExpression",
1092
+ type: ASTType.LogicalExpression,
1094
1093
  operator: "&&",
1095
- left: { type: "Identifier", name: "foo" },
1096
- right: { type: "Identifier", name: "bar" },
1094
+ left: { type: ASTType.Identifier, name: "foo" },
1095
+ right: { type: ASTType.Identifier, name: "bar" },
1097
1096
  },
1098
1097
  right: {
1099
- type: "LogicalExpression",
1098
+ type: ASTType.LogicalExpression,
1100
1099
  operator: "&&",
1101
- left: { type: "Identifier", name: "man" },
1102
- right: { type: "Identifier", name: "shell" },
1100
+ left: { type: ASTType.Identifier, name: "man" },
1101
+ right: { type: ASTType.Identifier, name: "shell" },
1103
1102
  },
1104
1103
  },
1105
1104
  },
@@ -1109,20 +1108,20 @@ describe("parser", () => {
1109
1108
 
1110
1109
  it("should give higher precedence to the logical `or` than to the conditional operator", () => {
1111
1110
  expect(createAst("foo||bar?man:shell")).toEqual({
1112
- type: "Program",
1111
+ type: ASTType.Program,
1113
1112
  body: [
1114
1113
  {
1115
- type: "ExpressionStatement",
1114
+ type: ASTType.ExpressionStatement,
1116
1115
  expression: {
1117
- type: "ConditionalExpression",
1116
+ type: ASTType.ConditionalExpression,
1118
1117
  test: {
1119
- type: "LogicalExpression",
1118
+ type: ASTType.LogicalExpression,
1120
1119
  operator: "||",
1121
- left: { type: "Identifier", name: "foo" },
1122
- right: { type: "Identifier", name: "bar" },
1120
+ left: { type: ASTType.Identifier, name: "foo" },
1121
+ right: { type: ASTType.Identifier, name: "bar" },
1123
1122
  },
1124
- alternate: { type: "Identifier", name: "man" },
1125
- consequent: { type: "Identifier", name: "shell" },
1123
+ alternate: { type: ASTType.Identifier, name: "man" },
1124
+ consequent: { type: ASTType.Identifier, name: "shell" },
1126
1125
  },
1127
1126
  },
1128
1127
  ],
@@ -1131,18 +1130,18 @@ describe("parser", () => {
1131
1130
 
1132
1131
  it("should give higher precedence to the conditional operator than to assignment operators", () => {
1133
1132
  expect(createAst("foo=bar?man:shell")).toEqual({
1134
- type: "Program",
1133
+ type: ASTType.Program,
1135
1134
  body: [
1136
1135
  {
1137
- type: "ExpressionStatement",
1136
+ type: ASTType.ExpressionStatement,
1138
1137
  expression: {
1139
- type: "AssignmentExpression",
1140
- left: { type: "Identifier", name: "foo" },
1138
+ type: ASTType.AssignmentExpression,
1139
+ left: { type: ASTType.Identifier, name: "foo" },
1141
1140
  right: {
1142
- type: "ConditionalExpression",
1143
- test: { type: "Identifier", name: "bar" },
1144
- alternate: { type: "Identifier", name: "man" },
1145
- consequent: { type: "Identifier", name: "shell" },
1141
+ type: ASTType.ConditionalExpression,
1142
+ test: { type: ASTType.Identifier, name: "bar" },
1143
+ alternate: { type: ASTType.Identifier, name: "man" },
1144
+ consequent: { type: ASTType.Identifier, name: "shell" },
1146
1145
  },
1147
1146
  operator: "=",
1148
1147
  },
@@ -1153,70 +1152,70 @@ describe("parser", () => {
1153
1152
 
1154
1153
  it("should understand array literals", () => {
1155
1154
  expect(createAst("[]")).toEqual({
1156
- type: "Program",
1155
+ type: ASTType.Program,
1157
1156
  body: [
1158
1157
  {
1159
- type: "ExpressionStatement",
1158
+ type: ASTType.ExpressionStatement,
1160
1159
  expression: {
1161
- type: "ArrayExpression",
1160
+ type: ASTType.ArrayExpression,
1162
1161
  elements: [],
1163
1162
  },
1164
1163
  },
1165
1164
  ],
1166
1165
  });
1167
1166
  expect(createAst("[foo]")).toEqual({
1168
- type: "Program",
1167
+ type: ASTType.Program,
1169
1168
  body: [
1170
1169
  {
1171
- type: "ExpressionStatement",
1170
+ type: ASTType.ExpressionStatement,
1172
1171
  expression: {
1173
- type: "ArrayExpression",
1174
- elements: [{ type: "Identifier", name: "foo" }],
1172
+ type: ASTType.ArrayExpression,
1173
+ elements: [{ type: ASTType.Identifier, name: "foo" }],
1175
1174
  },
1176
1175
  },
1177
1176
  ],
1178
1177
  });
1179
1178
  expect(createAst("[foo,]")).toEqual({
1180
- type: "Program",
1179
+ type: ASTType.Program,
1181
1180
  body: [
1182
1181
  {
1183
- type: "ExpressionStatement",
1182
+ type: ASTType.ExpressionStatement,
1184
1183
  expression: {
1185
- type: "ArrayExpression",
1186
- elements: [{ type: "Identifier", name: "foo" }],
1184
+ type: ASTType.ArrayExpression,
1185
+ elements: [{ type: ASTType.Identifier, name: "foo" }],
1187
1186
  },
1188
1187
  },
1189
1188
  ],
1190
1189
  });
1191
1190
  expect(createAst("[foo,bar,man,shell]")).toEqual({
1192
- type: "Program",
1191
+ type: ASTType.Program,
1193
1192
  body: [
1194
1193
  {
1195
- type: "ExpressionStatement",
1194
+ type: ASTType.ExpressionStatement,
1196
1195
  expression: {
1197
- type: "ArrayExpression",
1196
+ type: ASTType.ArrayExpression,
1198
1197
  elements: [
1199
- { type: "Identifier", name: "foo" },
1200
- { type: "Identifier", name: "bar" },
1201
- { type: "Identifier", name: "man" },
1202
- { type: "Identifier", name: "shell" },
1198
+ { type: ASTType.Identifier, name: "foo" },
1199
+ { type: ASTType.Identifier, name: "bar" },
1200
+ { type: ASTType.Identifier, name: "man" },
1201
+ { type: ASTType.Identifier, name: "shell" },
1203
1202
  ],
1204
1203
  },
1205
1204
  },
1206
1205
  ],
1207
1206
  });
1208
1207
  expect(createAst("[foo,bar,man,shell,]")).toEqual({
1209
- type: "Program",
1208
+ type: ASTType.Program,
1210
1209
  body: [
1211
1210
  {
1212
- type: "ExpressionStatement",
1211
+ type: ASTType.ExpressionStatement,
1213
1212
  expression: {
1214
- type: "ArrayExpression",
1213
+ type: ASTType.ArrayExpression,
1215
1214
  elements: [
1216
- { type: "Identifier", name: "foo" },
1217
- { type: "Identifier", name: "bar" },
1218
- { type: "Identifier", name: "man" },
1219
- { type: "Identifier", name: "shell" },
1215
+ { type: ASTType.Identifier, name: "foo" },
1216
+ { type: ASTType.Identifier, name: "bar" },
1217
+ { type: ASTType.Identifier, name: "man" },
1218
+ { type: ASTType.Identifier, name: "shell" },
1220
1219
  ],
1221
1220
  },
1222
1221
  },
@@ -1226,31 +1225,31 @@ describe("parser", () => {
1226
1225
 
1227
1226
  it("should understand objects", () => {
1228
1227
  expect(createAst("{}")).toEqual({
1229
- type: "Program",
1228
+ type: ASTType.Program,
1230
1229
  body: [
1231
1230
  {
1232
- type: "ExpressionStatement",
1231
+ type: ASTType.ExpressionStatement,
1233
1232
  expression: {
1234
- type: "ObjectExpression",
1233
+ type: ASTType.ObjectExpression,
1235
1234
  properties: [],
1236
1235
  },
1237
1236
  },
1238
1237
  ],
1239
1238
  });
1240
1239
  expect(createAst("{foo: bar}")).toEqual({
1241
- type: "Program",
1240
+ type: ASTType.Program,
1242
1241
  body: [
1243
1242
  {
1244
- type: "ExpressionStatement",
1243
+ type: ASTType.ExpressionStatement,
1245
1244
  expression: {
1246
- type: "ObjectExpression",
1245
+ type: ASTType.ObjectExpression,
1247
1246
  properties: [
1248
1247
  {
1249
- type: "Property",
1248
+ type: ASTType.Property,
1250
1249
  kind: "init",
1251
- key: { type: "Identifier", name: "foo" },
1250
+ key: { type: ASTType.Identifier, name: "foo" },
1252
1251
  computed: false,
1253
- value: { type: "Identifier", name: "bar" },
1252
+ value: { type: ASTType.Identifier, name: "bar" },
1254
1253
  },
1255
1254
  ],
1256
1255
  },
@@ -1258,19 +1257,19 @@ describe("parser", () => {
1258
1257
  ],
1259
1258
  });
1260
1259
  expect(createAst("{foo: bar,}")).toEqual({
1261
- type: "Program",
1260
+ type: ASTType.Program,
1262
1261
  body: [
1263
1262
  {
1264
- type: "ExpressionStatement",
1263
+ type: ASTType.ExpressionStatement,
1265
1264
  expression: {
1266
- type: "ObjectExpression",
1265
+ type: ASTType.ObjectExpression,
1267
1266
  properties: [
1268
1267
  {
1269
- type: "Property",
1268
+ type: ASTType.Property,
1270
1269
  kind: "init",
1271
- key: { type: "Identifier", name: "foo" },
1270
+ key: { type: ASTType.Identifier, name: "foo" },
1272
1271
  computed: false,
1273
- value: { type: "Identifier", name: "bar" },
1272
+ value: { type: ASTType.Identifier, name: "bar" },
1274
1273
  },
1275
1274
  ],
1276
1275
  },
@@ -1278,33 +1277,33 @@ describe("parser", () => {
1278
1277
  ],
1279
1278
  });
1280
1279
  expect(createAst('{foo: bar, "man": "shell", 42: 23}')).toEqual({
1281
- type: "Program",
1280
+ type: ASTType.Program,
1282
1281
  body: [
1283
1282
  {
1284
- type: "ExpressionStatement",
1283
+ type: ASTType.ExpressionStatement,
1285
1284
  expression: {
1286
- type: "ObjectExpression",
1285
+ type: ASTType.ObjectExpression,
1287
1286
  properties: [
1288
1287
  {
1289
- type: "Property",
1288
+ type: ASTType.Property,
1290
1289
  kind: "init",
1291
- key: { type: "Identifier", name: "foo" },
1290
+ key: { type: ASTType.Identifier, name: "foo" },
1292
1291
  computed: false,
1293
- value: { type: "Identifier", name: "bar" },
1292
+ value: { type: ASTType.Identifier, name: "bar" },
1294
1293
  },
1295
1294
  {
1296
- type: "Property",
1295
+ type: ASTType.Property,
1297
1296
  kind: "init",
1298
- key: { type: "Literal", value: "man" },
1297
+ key: { type: ASTType.Literal, value: "man" },
1299
1298
  computed: false,
1300
- value: { type: "Literal", value: "shell" },
1299
+ value: { type: ASTType.Literal, value: "shell" },
1301
1300
  },
1302
1301
  {
1303
- type: "Property",
1302
+ type: ASTType.Property,
1304
1303
  kind: "init",
1305
- key: { type: "Literal", value: 42 },
1304
+ key: { type: ASTType.Literal, value: 42 },
1306
1305
  computed: false,
1307
- value: { type: "Literal", value: 23 },
1306
+ value: { type: ASTType.Literal, value: 23 },
1308
1307
  },
1309
1308
  ],
1310
1309
  },
@@ -1312,33 +1311,33 @@ describe("parser", () => {
1312
1311
  ],
1313
1312
  });
1314
1313
  expect(createAst('{foo: bar, "man": "shell", 42: 23,}')).toEqual({
1315
- type: "Program",
1314
+ type: ASTType.Program,
1316
1315
  body: [
1317
1316
  {
1318
- type: "ExpressionStatement",
1317
+ type: ASTType.ExpressionStatement,
1319
1318
  expression: {
1320
- type: "ObjectExpression",
1319
+ type: ASTType.ObjectExpression,
1321
1320
  properties: [
1322
1321
  {
1323
- type: "Property",
1322
+ type: ASTType.Property,
1324
1323
  kind: "init",
1325
- key: { type: "Identifier", name: "foo" },
1324
+ key: { type: ASTType.Identifier, name: "foo" },
1326
1325
  computed: false,
1327
- value: { type: "Identifier", name: "bar" },
1326
+ value: { type: ASTType.Identifier, name: "bar" },
1328
1327
  },
1329
1328
  {
1330
- type: "Property",
1329
+ type: ASTType.Property,
1331
1330
  kind: "init",
1332
- key: { type: "Literal", value: "man" },
1331
+ key: { type: ASTType.Literal, value: "man" },
1333
1332
  computed: false,
1334
- value: { type: "Literal", value: "shell" },
1333
+ value: { type: ASTType.Literal, value: "shell" },
1335
1334
  },
1336
1335
  {
1337
- type: "Property",
1336
+ type: ASTType.Property,
1338
1337
  kind: "init",
1339
- key: { type: "Literal", value: 42 },
1338
+ key: { type: ASTType.Literal, value: 42 },
1340
1339
  computed: false,
1341
- value: { type: "Literal", value: 23 },
1340
+ value: { type: ASTType.Literal, value: 23 },
1342
1341
  },
1343
1342
  ],
1344
1343
  },
@@ -1350,33 +1349,33 @@ describe("parser", () => {
1350
1349
  it("should understand ES6 object initializer", () => {
1351
1350
  // Shorthand properties definitions.
1352
1351
  expect(createAst("{x, y, z}")).toEqual({
1353
- type: "Program",
1352
+ type: ASTType.Program,
1354
1353
  body: [
1355
1354
  {
1356
- type: "ExpressionStatement",
1355
+ type: ASTType.ExpressionStatement,
1357
1356
  expression: {
1358
- type: "ObjectExpression",
1357
+ type: ASTType.ObjectExpression,
1359
1358
  properties: [
1360
1359
  {
1361
- type: "Property",
1360
+ type: ASTType.Property,
1362
1361
  kind: "init",
1363
- key: { type: "Identifier", name: "x" },
1362
+ key: { type: ASTType.Identifier, name: "x" },
1364
1363
  computed: false,
1365
- value: { type: "Identifier", name: "x" },
1364
+ value: { type: ASTType.Identifier, name: "x" },
1366
1365
  },
1367
1366
  {
1368
- type: "Property",
1367
+ type: ASTType.Property,
1369
1368
  kind: "init",
1370
- key: { type: "Identifier", name: "y" },
1369
+ key: { type: ASTType.Identifier, name: "y" },
1371
1370
  computed: false,
1372
- value: { type: "Identifier", name: "y" },
1371
+ value: { type: ASTType.Identifier, name: "y" },
1373
1372
  },
1374
1373
  {
1375
- type: "Property",
1374
+ type: ASTType.Property,
1376
1375
  kind: "init",
1377
- key: { type: "Identifier", name: "z" },
1376
+ key: { type: ASTType.Identifier, name: "z" },
1378
1377
  computed: false,
1379
- value: { type: "Identifier", name: "z" },
1378
+ value: { type: ASTType.Identifier, name: "z" },
1380
1379
  },
1381
1380
  ],
1382
1381
  },
@@ -1389,19 +1388,19 @@ describe("parser", () => {
1389
1388
 
1390
1389
  // Computed properties
1391
1390
  expect(createAst("{[x]: x}")).toEqual({
1392
- type: "Program",
1391
+ type: ASTType.Program,
1393
1392
  body: [
1394
1393
  {
1395
- type: "ExpressionStatement",
1394
+ type: ASTType.ExpressionStatement,
1396
1395
  expression: {
1397
- type: "ObjectExpression",
1396
+ type: ASTType.ObjectExpression,
1398
1397
  properties: [
1399
1398
  {
1400
- type: "Property",
1399
+ type: ASTType.Property,
1401
1400
  kind: "init",
1402
- key: { type: "Identifier", name: "x" },
1401
+ key: { type: ASTType.Identifier, name: "x" },
1403
1402
  computed: true,
1404
- value: { type: "Identifier", name: "x" },
1403
+ value: { type: ASTType.Identifier, name: "x" },
1405
1404
  },
1406
1405
  ],
1407
1406
  },
@@ -1409,24 +1408,24 @@ describe("parser", () => {
1409
1408
  ],
1410
1409
  });
1411
1410
  expect(createAst("{[x + 1]: x}")).toEqual({
1412
- type: "Program",
1411
+ type: ASTType.Program,
1413
1412
  body: [
1414
1413
  {
1415
- type: "ExpressionStatement",
1414
+ type: ASTType.ExpressionStatement,
1416
1415
  expression: {
1417
- type: "ObjectExpression",
1416
+ type: ASTType.ObjectExpression,
1418
1417
  properties: [
1419
1418
  {
1420
- type: "Property",
1419
+ type: ASTType.Property,
1421
1420
  kind: "init",
1422
1421
  key: {
1423
- type: "BinaryExpression",
1422
+ type: ASTType.BinaryExpression,
1424
1423
  operator: "+",
1425
- left: { type: "Identifier", name: "x" },
1426
- right: { type: "Literal", value: 1 },
1424
+ left: { type: ASTType.Identifier, name: "x" },
1425
+ right: { type: ASTType.Literal, value: 1 },
1427
1426
  },
1428
1427
  computed: true,
1429
- value: { type: "Identifier", name: "x" },
1428
+ value: { type: ASTType.Identifier, name: "x" },
1430
1429
  },
1431
1430
  ],
1432
1431
  },
@@ -1437,23 +1436,23 @@ describe("parser", () => {
1437
1436
 
1438
1437
  it("should understand multiple expressions", () => {
1439
1438
  expect(createAst("foo = bar; man = shell")).toEqual({
1440
- type: "Program",
1439
+ type: ASTType.Program,
1441
1440
  body: [
1442
1441
  {
1443
- type: "ExpressionStatement",
1442
+ type: ASTType.ExpressionStatement,
1444
1443
  expression: {
1445
- type: "AssignmentExpression",
1446
- left: { type: "Identifier", name: "foo" },
1447
- right: { type: "Identifier", name: "bar" },
1444
+ type: ASTType.AssignmentExpression,
1445
+ left: { type: ASTType.Identifier, name: "foo" },
1446
+ right: { type: ASTType.Identifier, name: "bar" },
1448
1447
  operator: "=",
1449
1448
  },
1450
1449
  },
1451
1450
  {
1452
- type: "ExpressionStatement",
1451
+ type: ASTType.ExpressionStatement,
1453
1452
  expression: {
1454
- type: "AssignmentExpression",
1455
- left: { type: "Identifier", name: "man" },
1456
- right: { type: "Identifier", name: "shell" },
1453
+ type: ASTType.AssignmentExpression,
1454
+ left: { type: ASTType.Identifier, name: "man" },
1455
+ right: { type: ASTType.Identifier, name: "shell" },
1457
1456
  operator: "=",
1458
1457
  },
1459
1458
  },
@@ -1464,14 +1463,14 @@ describe("parser", () => {
1464
1463
  // This is non-standard syntax
1465
1464
  it("should understand filters", () => {
1466
1465
  expect(createAst("foo | bar")).toEqual({
1467
- type: "Program",
1466
+ type: ASTType.Program,
1468
1467
  body: [
1469
1468
  {
1470
- type: "ExpressionStatement",
1469
+ type: ASTType.ExpressionStatement,
1471
1470
  expression: {
1472
- type: "CallExpression",
1473
- callee: { type: "Identifier", name: "bar" },
1474
- arguments: [{ type: "Identifier", name: "foo" }],
1471
+ type: ASTType.CallExpression,
1472
+ callee: { type: ASTType.Identifier, name: "bar" },
1473
+ arguments: [{ type: ASTType.Identifier, name: "foo" }],
1475
1474
  filter: true,
1476
1475
  },
1477
1476
  },
@@ -1481,16 +1480,16 @@ describe("parser", () => {
1481
1480
 
1482
1481
  it("should understand filters with extra parameters", () => {
1483
1482
  expect(createAst("foo | bar:baz")).toEqual({
1484
- type: "Program",
1483
+ type: ASTType.Program,
1485
1484
  body: [
1486
1485
  {
1487
- type: "ExpressionStatement",
1486
+ type: ASTType.ExpressionStatement,
1488
1487
  expression: {
1489
- type: "CallExpression",
1490
- callee: { type: "Identifier", name: "bar" },
1488
+ type: ASTType.CallExpression,
1489
+ callee: { type: ASTType.Identifier, name: "bar" },
1491
1490
  arguments: [
1492
- { type: "Identifier", name: "foo" },
1493
- { type: "Identifier", name: "baz" },
1491
+ { type: ASTType.Identifier, name: "foo" },
1492
+ { type: ASTType.Identifier, name: "baz" },
1494
1493
  ],
1495
1494
  filter: true,
1496
1495
  },
@@ -1501,20 +1500,20 @@ describe("parser", () => {
1501
1500
 
1502
1501
  it("should associate filters right-to-left", () => {
1503
1502
  expect(createAst("foo | bar:man | shell")).toEqual({
1504
- type: "Program",
1503
+ type: ASTType.Program,
1505
1504
  body: [
1506
1505
  {
1507
- type: "ExpressionStatement",
1506
+ type: ASTType.ExpressionStatement,
1508
1507
  expression: {
1509
- type: "CallExpression",
1510
- callee: { type: "Identifier", name: "shell" },
1508
+ type: ASTType.CallExpression,
1509
+ callee: { type: ASTType.Identifier, name: "shell" },
1511
1510
  arguments: [
1512
1511
  {
1513
- type: "CallExpression",
1514
- callee: { type: "Identifier", name: "bar" },
1512
+ type: ASTType.CallExpression,
1513
+ callee: { type: ASTType.Identifier, name: "bar" },
1515
1514
  arguments: [
1516
- { type: "Identifier", name: "foo" },
1517
- { type: "Identifier", name: "man" },
1515
+ { type: ASTType.Identifier, name: "foo" },
1516
+ { type: ASTType.Identifier, name: "man" },
1518
1517
  ],
1519
1518
  filter: true,
1520
1519
  },
@@ -1528,18 +1527,18 @@ describe("parser", () => {
1528
1527
 
1529
1528
  it("should give higher precedence to assignments over filters", () => {
1530
1529
  expect(createAst("foo=bar | man")).toEqual({
1531
- type: "Program",
1530
+ type: ASTType.Program,
1532
1531
  body: [
1533
1532
  {
1534
- type: "ExpressionStatement",
1533
+ type: ASTType.ExpressionStatement,
1535
1534
  expression: {
1536
- type: "CallExpression",
1537
- callee: { type: "Identifier", name: "man" },
1535
+ type: ASTType.CallExpression,
1536
+ callee: { type: ASTType.Identifier, name: "man" },
1538
1537
  arguments: [
1539
1538
  {
1540
- type: "AssignmentExpression",
1541
- left: { type: "Identifier", name: "foo" },
1542
- right: { type: "Identifier", name: "bar" },
1539
+ type: ASTType.AssignmentExpression,
1540
+ left: { type: ASTType.Identifier, name: "foo" },
1541
+ right: { type: ASTType.Identifier, name: "bar" },
1543
1542
  operator: "=",
1544
1543
  },
1545
1544
  ],
@@ -1552,19 +1551,19 @@ describe("parser", () => {
1552
1551
 
1553
1552
  it("should accept expression as filters parameters", () => {
1554
1553
  expect(createAst("foo | bar:baz=man")).toEqual({
1555
- type: "Program",
1554
+ type: ASTType.Program,
1556
1555
  body: [
1557
1556
  {
1558
- type: "ExpressionStatement",
1557
+ type: ASTType.ExpressionStatement,
1559
1558
  expression: {
1560
- type: "CallExpression",
1561
- callee: { type: "Identifier", name: "bar" },
1559
+ type: ASTType.CallExpression,
1560
+ callee: { type: ASTType.Identifier, name: "bar" },
1562
1561
  arguments: [
1563
- { type: "Identifier", name: "foo" },
1562
+ { type: ASTType.Identifier, name: "foo" },
1564
1563
  {
1565
- type: "AssignmentExpression",
1566
- left: { type: "Identifier", name: "baz" },
1567
- right: { type: "Identifier", name: "man" },
1564
+ type: ASTType.AssignmentExpression,
1565
+ left: { type: ASTType.Identifier, name: "baz" },
1566
+ right: { type: ASTType.Identifier, name: "man" },
1568
1567
  operator: "=",
1569
1568
  },
1570
1569
  ],
@@ -1577,17 +1576,17 @@ describe("parser", () => {
1577
1576
 
1578
1577
  it("should accept expression as computer members", () => {
1579
1578
  expect(createAst("foo[a = 1]")).toEqual({
1580
- type: "Program",
1579
+ type: ASTType.Program,
1581
1580
  body: [
1582
1581
  {
1583
- type: "ExpressionStatement",
1582
+ type: ASTType.ExpressionStatement,
1584
1583
  expression: {
1585
- type: "MemberExpression",
1586
- object: { type: "Identifier", name: "foo" },
1584
+ type: ASTType.MemberExpression,
1585
+ object: { type: ASTType.Identifier, name: "foo" },
1587
1586
  property: {
1588
- type: "AssignmentExpression",
1589
- left: { type: "Identifier", name: "a" },
1590
- right: { type: "Literal", value: 1 },
1587
+ type: ASTType.AssignmentExpression,
1588
+ left: { type: ASTType.Identifier, name: "a" },
1589
+ right: { type: ASTType.Literal, value: 1 },
1591
1590
  operator: "=",
1592
1591
  },
1593
1592
  computed: true,
@@ -1599,18 +1598,18 @@ describe("parser", () => {
1599
1598
 
1600
1599
  it("should accept expression in function arguments", () => {
1601
1600
  expect(createAst("foo(a = 1)")).toEqual({
1602
- type: "Program",
1601
+ type: ASTType.Program,
1603
1602
  body: [
1604
1603
  {
1605
- type: "ExpressionStatement",
1604
+ type: ASTType.ExpressionStatement,
1606
1605
  expression: {
1607
- type: "CallExpression",
1608
- callee: { type: "Identifier", name: "foo" },
1606
+ type: ASTType.CallExpression,
1607
+ callee: { type: ASTType.Identifier, name: "foo" },
1609
1608
  arguments: [
1610
1609
  {
1611
- type: "AssignmentExpression",
1612
- left: { type: "Identifier", name: "a" },
1613
- right: { type: "Literal", value: 1 },
1610
+ type: ASTType.AssignmentExpression,
1611
+ left: { type: ASTType.Identifier, name: "a" },
1612
+ right: { type: ASTType.Literal, value: 1 },
1614
1613
  operator: "=",
1615
1614
  },
1616
1615
  ],
@@ -1622,28 +1621,28 @@ describe("parser", () => {
1622
1621
 
1623
1622
  it("should accept expression as part of ternary operators", () => {
1624
1623
  expect(createAst("foo || bar ? man = 1 : shell = 1")).toEqual({
1625
- type: "Program",
1624
+ type: ASTType.Program,
1626
1625
  body: [
1627
1626
  {
1628
- type: "ExpressionStatement",
1627
+ type: ASTType.ExpressionStatement,
1629
1628
  expression: {
1630
- type: "ConditionalExpression",
1629
+ type: ASTType.ConditionalExpression,
1631
1630
  test: {
1632
- type: "LogicalExpression",
1631
+ type: ASTType.LogicalExpression,
1633
1632
  operator: "||",
1634
- left: { type: "Identifier", name: "foo" },
1635
- right: { type: "Identifier", name: "bar" },
1633
+ left: { type: ASTType.Identifier, name: "foo" },
1634
+ right: { type: ASTType.Identifier, name: "bar" },
1636
1635
  },
1637
1636
  alternate: {
1638
- type: "AssignmentExpression",
1639
- left: { type: "Identifier", name: "man" },
1640
- right: { type: "Literal", value: 1 },
1637
+ type: ASTType.AssignmentExpression,
1638
+ left: { type: ASTType.Identifier, name: "man" },
1639
+ right: { type: ASTType.Literal, value: 1 },
1641
1640
  operator: "=",
1642
1641
  },
1643
1642
  consequent: {
1644
- type: "AssignmentExpression",
1645
- left: { type: "Identifier", name: "shell" },
1646
- right: { type: "Literal", value: 1 },
1643
+ type: ASTType.AssignmentExpression,
1644
+ left: { type: ASTType.Identifier, name: "shell" },
1645
+ right: { type: ASTType.Literal, value: 1 },
1647
1646
  operator: "=",
1648
1647
  },
1649
1648
  },
@@ -1654,17 +1653,17 @@ describe("parser", () => {
1654
1653
 
1655
1654
  it("should accept expression as part of array literals", () => {
1656
1655
  expect(createAst("[foo = 1]")).toEqual({
1657
- type: "Program",
1656
+ type: ASTType.Program,
1658
1657
  body: [
1659
1658
  {
1660
- type: "ExpressionStatement",
1659
+ type: ASTType.ExpressionStatement,
1661
1660
  expression: {
1662
- type: "ArrayExpression",
1661
+ type: ASTType.ArrayExpression,
1663
1662
  elements: [
1664
1663
  {
1665
- type: "AssignmentExpression",
1666
- left: { type: "Identifier", name: "foo" },
1667
- right: { type: "Literal", value: 1 },
1664
+ type: ASTType.AssignmentExpression,
1665
+ left: { type: ASTType.Identifier, name: "foo" },
1666
+ right: { type: ASTType.Literal, value: 1 },
1668
1667
  operator: "=",
1669
1668
  },
1670
1669
  ],
@@ -1676,22 +1675,22 @@ describe("parser", () => {
1676
1675
 
1677
1676
  it("should accept expression as part of object literals", () => {
1678
1677
  expect(createAst("{foo: bar = 1}")).toEqual({
1679
- type: "Program",
1678
+ type: ASTType.Program,
1680
1679
  body: [
1681
1680
  {
1682
- type: "ExpressionStatement",
1681
+ type: ASTType.ExpressionStatement,
1683
1682
  expression: {
1684
- type: "ObjectExpression",
1683
+ type: ASTType.ObjectExpression,
1685
1684
  properties: [
1686
1685
  {
1687
- type: "Property",
1686
+ type: ASTType.Property,
1688
1687
  kind: "init",
1689
- key: { type: "Identifier", name: "foo" },
1688
+ key: { type: ASTType.Identifier, name: "foo" },
1690
1689
  computed: false,
1691
1690
  value: {
1692
- type: "AssignmentExpression",
1693
- left: { type: "Identifier", name: "bar" },
1694
- right: { type: "Literal", value: 1 },
1691
+ type: ASTType.AssignmentExpression,
1692
+ left: { type: ASTType.Identifier, name: "bar" },
1693
+ right: { type: ASTType.Literal, value: 1 },
1695
1694
  operator: "=",
1696
1695
  },
1697
1696
  },
@@ -1704,19 +1703,19 @@ describe("parser", () => {
1704
1703
 
1705
1704
  it("should be possible to use parenthesis to indicate precedence", () => {
1706
1705
  expect(createAst("(foo + bar).man")).toEqual({
1707
- type: "Program",
1706
+ type: ASTType.Program,
1708
1707
  body: [
1709
1708
  {
1710
- type: "ExpressionStatement",
1709
+ type: ASTType.ExpressionStatement,
1711
1710
  expression: {
1712
- type: "MemberExpression",
1711
+ type: ASTType.MemberExpression,
1713
1712
  object: {
1714
- type: "BinaryExpression",
1713
+ type: ASTType.BinaryExpression,
1715
1714
  operator: "+",
1716
- left: { type: "Identifier", name: "foo" },
1717
- right: { type: "Identifier", name: "bar" },
1715
+ left: { type: ASTType.Identifier, name: "foo" },
1716
+ right: { type: ASTType.Identifier, name: "bar" },
1718
1717
  },
1719
- property: { type: "Identifier", name: "man" },
1718
+ property: { type: ASTType.Identifier, name: "man" },
1720
1719
  computed: false,
1721
1720
  },
1722
1721
  },
@@ -1726,64 +1725,51 @@ describe("parser", () => {
1726
1725
 
1727
1726
  it("should skip empty expressions", () => {
1728
1727
  expect(createAst("foo;;;;bar")).toEqual({
1729
- type: "Program",
1728
+ type: ASTType.Program,
1730
1729
  body: [
1731
1730
  {
1732
- type: "ExpressionStatement",
1733
- expression: { type: "Identifier", name: "foo" },
1731
+ type: ASTType.ExpressionStatement,
1732
+ expression: { type: ASTType.Identifier, name: "foo" },
1734
1733
  },
1735
1734
  {
1736
- type: "ExpressionStatement",
1737
- expression: { type: "Identifier", name: "bar" },
1735
+ type: ASTType.ExpressionStatement,
1736
+ expression: { type: ASTType.Identifier, name: "bar" },
1738
1737
  },
1739
1738
  ],
1740
1739
  });
1741
1740
  expect(createAst(";foo")).toEqual({
1742
- type: "Program",
1741
+ type: ASTType.Program,
1743
1742
  body: [
1744
1743
  {
1745
- type: "ExpressionStatement",
1746
- expression: { type: "Identifier", name: "foo" },
1744
+ type: ASTType.ExpressionStatement,
1745
+ expression: { type: ASTType.Identifier, name: "foo" },
1747
1746
  },
1748
1747
  ],
1749
1748
  });
1750
1749
  expect(createAst("foo;")).toEqual({
1751
- type: "Program",
1750
+ type: ASTType.Program,
1752
1751
  body: [
1753
1752
  {
1754
- type: "ExpressionStatement",
1755
- expression: { type: "Identifier", name: "foo" },
1753
+ type: ASTType.ExpressionStatement,
1754
+ expression: { type: ASTType.Identifier, name: "foo" },
1756
1755
  },
1757
1756
  ],
1758
1757
  });
1759
- expect(createAst(";;;;")).toEqual({ type: "Program", body: [] });
1760
- expect(createAst("")).toEqual({ type: "Program", body: [] });
1758
+ expect(createAst(";;;;")).toEqual({ type: ASTType.Program, body: [] });
1759
+ expect(createAst("")).toEqual({ type: ASTType.Program, body: [] });
1761
1760
  });
1762
1761
  });
1763
1762
 
1764
1763
  let filterProvider;
1765
1764
 
1766
- forEach([true, false], (cspEnabled) => {
1767
- beforeEach(() => {
1768
- createInjector([
1769
- "ng",
1770
- function ($filterProvider, $parseProvider) {
1771
- filterProvider = $filterProvider;
1772
- $parseProvider.addLiteral("Infinity", Infinity);
1773
- csp().noUnsafeEval = cspEnabled;
1774
- },
1775
- ]).invoke((_$rootScope_) => {
1776
- $rootScope = _$rootScope_;
1777
- });
1778
- });
1779
-
1780
- it(`should allow extending literals with csp ${cspEnabled}`, () => {
1781
- expect($rootScope.$eval("Infinity")).toEqual(Infinity);
1782
- expect($rootScope.$eval("-Infinity")).toEqual(-Infinity);
1783
- expect(() => {
1784
- $rootScope.$eval("Infinity = 1");
1785
- }).toThrow();
1786
- expect($rootScope.$eval("Infinity")).toEqual(Infinity);
1765
+ beforeEach(() => {
1766
+ createInjector([
1767
+ "ng",
1768
+ function ($filterProvider) {
1769
+ filterProvider = $filterProvider;
1770
+ },
1771
+ ]).invoke((_$rootScope_) => {
1772
+ $rootScope = _$rootScope_;
1787
1773
  });
1788
1774
  });
1789
1775
 
@@ -1794,7 +1780,6 @@ describe("parser", () => {
1794
1780
  "ng",
1795
1781
  function ($filterProvider) {
1796
1782
  filterProvider = $filterProvider;
1797
- csp().noUnsafeEval = cspEnabled;
1798
1783
  },
1799
1784
  ]).invoke((_$rootScope_) => {
1800
1785
  scope = _$rootScope_;