@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.
- package/README.md +3 -1
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/animations/shared.js +2 -1
- package/src/core/interpolate/interpolate.js +1 -18
- package/src/core/parser/ast-type.js +21 -20
- package/src/core/parser/ast.js +253 -93
- package/src/core/parser/interpreter.js +639 -174
- package/src/core/parser/lexer.js +22 -22
- package/src/core/parser/parse.js +51 -265
- package/src/core/parser/parse.md +0 -13
- package/src/core/parser/parse.spec.js +429 -444
- package/src/core/parser/parser.js +39 -11
- package/src/directive/csp.md +0 -26
- package/src/loader.js +5 -1
- package/src/shared/jqlite/jqlite.js +2 -2
- package/src/types.js +0 -10
- package/types/animations/shared.d.ts +1 -1
- package/types/core/parser/ast-type.d.ts +24 -20
- package/types/core/parser/ast.d.ts +266 -73
- package/types/core/parser/interpreter.d.ts +207 -53
- package/types/core/parser/lexer.d.ts +23 -19
- package/types/core/parser/parse.d.ts +50 -44
- package/types/core/parser/parser.d.ts +31 -16
- package/types/loader.d.ts +397 -0
- package/types/shared/jqlite/jqlite.d.ts +4 -4
- package/types/types.d.ts +0 -1
- package/src/core/parser/compiler.js +0 -561
- package/src/core/parser/shared.js +0 -228
- package/types/core/parser/compiler.d.ts +0 -49
- package/types/core/parser/shared.d.ts +0 -29
|
@@ -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({
|
|
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({
|
|
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:
|
|
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:
|
|
339
|
+
type: ASTType.Program,
|
|
341
340
|
body: [
|
|
342
341
|
{
|
|
343
|
-
type:
|
|
344
|
-
expression: { type:
|
|
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:
|
|
351
|
+
type: ASTType.Program,
|
|
353
352
|
body: [
|
|
354
353
|
{
|
|
355
|
-
type:
|
|
354
|
+
type: ASTType.ExpressionStatement,
|
|
356
355
|
expression: {
|
|
357
|
-
type:
|
|
358
|
-
object: { type:
|
|
359
|
-
property: { type:
|
|
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:
|
|
368
|
+
type: ASTType.Program,
|
|
370
369
|
body: [
|
|
371
370
|
{
|
|
372
|
-
type:
|
|
371
|
+
type: ASTType.ExpressionStatement,
|
|
373
372
|
expression: {
|
|
374
|
-
type:
|
|
373
|
+
type: ASTType.MemberExpression,
|
|
375
374
|
object: {
|
|
376
|
-
type:
|
|
377
|
-
object: { type:
|
|
378
|
-
property: { type:
|
|
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:
|
|
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:
|
|
390
|
+
type: ASTType.Program,
|
|
392
391
|
body: [
|
|
393
392
|
{
|
|
394
|
-
type:
|
|
393
|
+
type: ASTType.ExpressionStatement,
|
|
395
394
|
expression: {
|
|
396
|
-
type:
|
|
397
|
-
object: { type:
|
|
398
|
-
property: { type:
|
|
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:
|
|
407
|
+
type: ASTType.Program,
|
|
409
408
|
body: [
|
|
410
409
|
{
|
|
411
|
-
type:
|
|
410
|
+
type: ASTType.ExpressionStatement,
|
|
412
411
|
expression: {
|
|
413
|
-
type:
|
|
412
|
+
type: ASTType.MemberExpression,
|
|
414
413
|
object: {
|
|
415
|
-
type:
|
|
416
|
-
object: { type:
|
|
417
|
-
property: { type:
|
|
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:
|
|
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:
|
|
429
|
+
type: ASTType.Program,
|
|
431
430
|
body: [
|
|
432
431
|
{
|
|
433
|
-
type:
|
|
432
|
+
type: ASTType.ExpressionStatement,
|
|
434
433
|
expression: {
|
|
435
|
-
type:
|
|
436
|
-
callee: { type:
|
|
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:
|
|
445
|
+
type: ASTType.Program,
|
|
447
446
|
body: [
|
|
448
447
|
{
|
|
449
|
-
type:
|
|
448
|
+
type: ASTType.ExpressionStatement,
|
|
450
449
|
expression: {
|
|
451
|
-
type:
|
|
452
|
-
callee: { type:
|
|
450
|
+
type: ASTType.CallExpression,
|
|
451
|
+
callee: { type: ASTType.Identifier, name: "foo" },
|
|
453
452
|
arguments: [
|
|
454
|
-
{ type:
|
|
455
|
-
{ type:
|
|
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:
|
|
464
|
+
type: ASTType.Program,
|
|
466
465
|
body: [
|
|
467
466
|
{
|
|
468
|
-
type:
|
|
467
|
+
type: ASTType.ExpressionStatement,
|
|
469
468
|
expression: {
|
|
470
|
-
type:
|
|
469
|
+
type: ASTType.CallExpression,
|
|
471
470
|
callee: {
|
|
472
|
-
type:
|
|
473
|
-
callee: { type:
|
|
471
|
+
type: ASTType.CallExpression,
|
|
472
|
+
callee: { type: ASTType.Identifier, name: "foo" },
|
|
474
473
|
arguments: [
|
|
475
|
-
{ type:
|
|
476
|
-
{ type:
|
|
474
|
+
{ type: ASTType.Identifier, name: "bar" },
|
|
475
|
+
{ type: ASTType.Identifier, name: "baz" },
|
|
477
476
|
],
|
|
478
477
|
},
|
|
479
478
|
arguments: [
|
|
480
|
-
{ type:
|
|
481
|
-
{ type:
|
|
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:
|
|
490
|
+
type: ASTType.Program,
|
|
492
491
|
body: [
|
|
493
492
|
{
|
|
494
|
-
type:
|
|
493
|
+
type: ASTType.ExpressionStatement,
|
|
495
494
|
expression: {
|
|
496
|
-
type:
|
|
497
|
-
callee: { type:
|
|
495
|
+
type: ASTType.CallExpression,
|
|
496
|
+
callee: { type: ASTType.Identifier, name: "foo" },
|
|
498
497
|
arguments: [
|
|
499
|
-
{ type:
|
|
500
|
-
{ type:
|
|
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:
|
|
509
|
+
type: ASTType.Program,
|
|
511
510
|
body: [
|
|
512
511
|
{
|
|
513
|
-
type:
|
|
512
|
+
type: ASTType.ExpressionStatement,
|
|
514
513
|
expression: {
|
|
515
|
-
type:
|
|
514
|
+
type: ASTType.CallExpression,
|
|
516
515
|
callee: {
|
|
517
|
-
type:
|
|
516
|
+
type: ASTType.MemberExpression,
|
|
518
517
|
object: {
|
|
519
|
-
type:
|
|
520
|
-
object: { type:
|
|
521
|
-
property: { type:
|
|
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:
|
|
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:
|
|
532
|
+
type: ASTType.Program,
|
|
534
533
|
body: [
|
|
535
534
|
{
|
|
536
|
-
type:
|
|
535
|
+
type: ASTType.ExpressionStatement,
|
|
537
536
|
expression: {
|
|
538
|
-
type:
|
|
537
|
+
type: ASTType.MemberExpression,
|
|
539
538
|
object: {
|
|
540
|
-
type:
|
|
539
|
+
type: ASTType.CallExpression,
|
|
541
540
|
callee: {
|
|
542
|
-
type:
|
|
543
|
-
object: { type:
|
|
544
|
-
property: { type:
|
|
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:
|
|
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:
|
|
555
|
+
type: ASTType.Program,
|
|
557
556
|
body: [
|
|
558
557
|
{
|
|
559
|
-
type:
|
|
558
|
+
type: ASTType.ExpressionStatement,
|
|
560
559
|
expression: {
|
|
561
|
-
type:
|
|
560
|
+
type: ASTType.MemberExpression,
|
|
562
561
|
object: {
|
|
563
|
-
type:
|
|
562
|
+
type: ASTType.MemberExpression,
|
|
564
563
|
object: {
|
|
565
|
-
type:
|
|
566
|
-
callee: { type:
|
|
564
|
+
type: ASTType.CallExpression,
|
|
565
|
+
callee: { type: ASTType.Identifier, name: "foo" },
|
|
567
566
|
arguments: [],
|
|
568
567
|
},
|
|
569
|
-
property: { type:
|
|
568
|
+
property: { type: ASTType.Identifier, name: "bar" },
|
|
570
569
|
computed: false,
|
|
571
570
|
},
|
|
572
|
-
property: { type:
|
|
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:
|
|
592
|
+
type: ASTType.Program,
|
|
594
593
|
body: [
|
|
595
594
|
{
|
|
596
|
-
type:
|
|
597
|
-
expression: { type:
|
|
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:
|
|
606
|
+
type: ASTType.Program,
|
|
608
607
|
body: [
|
|
609
608
|
{
|
|
610
|
-
type:
|
|
611
|
-
expression: { type:
|
|
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:
|
|
618
|
+
type: ASTType.Program,
|
|
620
619
|
body: [
|
|
621
620
|
{
|
|
622
|
-
type:
|
|
623
|
-
expression: { type:
|
|
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:
|
|
633
|
+
type: ASTType.Program,
|
|
635
634
|
body: [
|
|
636
635
|
{
|
|
637
|
-
type:
|
|
636
|
+
type: ASTType.ExpressionStatement,
|
|
638
637
|
expression: {
|
|
639
|
-
type:
|
|
640
|
-
object: { type:
|
|
641
|
-
property: { type:
|
|
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:
|
|
665
|
+
type: ASTType.Program,
|
|
667
666
|
body: [
|
|
668
667
|
{
|
|
669
|
-
type:
|
|
668
|
+
type: ASTType.ExpressionStatement,
|
|
670
669
|
expression: {
|
|
671
|
-
type:
|
|
670
|
+
type: ASTType.UnaryExpression,
|
|
672
671
|
operator,
|
|
673
672
|
prefix: true,
|
|
674
|
-
argument: { type:
|
|
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:
|
|
690
|
+
type: ASTType.Program,
|
|
692
691
|
body: [
|
|
693
692
|
{
|
|
694
|
-
type:
|
|
693
|
+
type: ASTType.ExpressionStatement,
|
|
695
694
|
expression: {
|
|
696
|
-
type:
|
|
695
|
+
type: ASTType.UnaryExpression,
|
|
697
696
|
operator: operators[0],
|
|
698
697
|
prefix: true,
|
|
699
698
|
argument: {
|
|
700
|
-
type:
|
|
699
|
+
type: ASTType.UnaryExpression,
|
|
701
700
|
operator: operators[1],
|
|
702
701
|
prefix: true,
|
|
703
702
|
argument: {
|
|
704
|
-
type:
|
|
703
|
+
type: ASTType.UnaryExpression,
|
|
705
704
|
operator: operators[2],
|
|
706
705
|
prefix: true,
|
|
707
|
-
argument: { type:
|
|
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:
|
|
736
|
+
type: ASTType.Program,
|
|
738
737
|
body: [
|
|
739
738
|
{
|
|
740
|
-
type:
|
|
739
|
+
type: ASTType.ExpressionStatement,
|
|
741
740
|
expression: {
|
|
742
|
-
type:
|
|
741
|
+
type: ASTType.BinaryExpression,
|
|
743
742
|
operator,
|
|
744
|
-
left: { type:
|
|
745
|
-
right: { type:
|
|
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:
|
|
764
|
+
type: ASTType.Program,
|
|
766
765
|
body: [
|
|
767
766
|
{
|
|
768
|
-
type:
|
|
767
|
+
type: ASTType.ExpressionStatement,
|
|
769
768
|
expression: {
|
|
770
|
-
type:
|
|
769
|
+
type: ASTType.BinaryExpression,
|
|
771
770
|
operator: op2,
|
|
772
771
|
left: {
|
|
773
|
-
type:
|
|
772
|
+
type: ASTType.BinaryExpression,
|
|
774
773
|
operator: op1,
|
|
775
|
-
left: { type:
|
|
776
|
-
right: { type:
|
|
774
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
775
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
777
776
|
},
|
|
778
|
-
right: { type:
|
|
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:
|
|
790
|
+
type: ASTType.Program,
|
|
792
791
|
body: [
|
|
793
792
|
{
|
|
794
|
-
type:
|
|
793
|
+
type: ASTType.ExpressionStatement,
|
|
795
794
|
expression: {
|
|
796
|
-
type:
|
|
795
|
+
type: ASTType.UnaryExpression,
|
|
797
796
|
operator,
|
|
798
797
|
prefix: true,
|
|
799
798
|
argument: {
|
|
800
|
-
type:
|
|
801
|
-
callee: { type:
|
|
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:
|
|
808
|
+
type: ASTType.Program,
|
|
810
809
|
body: [
|
|
811
810
|
{
|
|
812
|
-
type:
|
|
811
|
+
type: ASTType.ExpressionStatement,
|
|
813
812
|
expression: {
|
|
814
|
-
type:
|
|
813
|
+
type: ASTType.UnaryExpression,
|
|
815
814
|
operator,
|
|
816
815
|
prefix: true,
|
|
817
816
|
argument: {
|
|
818
|
-
type:
|
|
819
|
-
object: { type:
|
|
820
|
-
property: { type:
|
|
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:
|
|
827
|
+
type: ASTType.Program,
|
|
829
828
|
body: [
|
|
830
829
|
{
|
|
831
|
-
type:
|
|
830
|
+
type: ASTType.ExpressionStatement,
|
|
832
831
|
expression: {
|
|
833
|
-
type:
|
|
832
|
+
type: ASTType.UnaryExpression,
|
|
834
833
|
operator,
|
|
835
834
|
prefix: true,
|
|
836
835
|
argument: {
|
|
837
|
-
type:
|
|
838
|
-
object: { type:
|
|
839
|
-
property: { type:
|
|
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:
|
|
852
|
+
type: ASTType.Program,
|
|
854
853
|
body: [
|
|
855
854
|
{
|
|
856
|
-
type:
|
|
855
|
+
type: ASTType.ExpressionStatement,
|
|
857
856
|
expression: {
|
|
858
|
-
type:
|
|
857
|
+
type: ASTType.BinaryExpression,
|
|
859
858
|
operator: op2,
|
|
860
859
|
left: {
|
|
861
|
-
type:
|
|
860
|
+
type: ASTType.UnaryExpression,
|
|
862
861
|
operator: op1,
|
|
863
862
|
prefix: true,
|
|
864
|
-
argument: { type:
|
|
863
|
+
argument: { type: ASTType.Identifier, name: "foo" },
|
|
865
864
|
},
|
|
866
865
|
right: {
|
|
867
|
-
type:
|
|
866
|
+
type: ASTType.UnaryExpression,
|
|
868
867
|
operator: op1,
|
|
869
868
|
prefix: true,
|
|
870
|
-
argument: { type:
|
|
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:
|
|
890
|
+
type: ASTType.Program,
|
|
892
891
|
body: [
|
|
893
892
|
{
|
|
894
|
-
type:
|
|
893
|
+
type: ASTType.ExpressionStatement,
|
|
895
894
|
expression: {
|
|
896
|
-
type:
|
|
895
|
+
type: ASTType.BinaryExpression,
|
|
897
896
|
operator: op2,
|
|
898
897
|
left: {
|
|
899
|
-
type:
|
|
898
|
+
type: ASTType.BinaryExpression,
|
|
900
899
|
operator: op1,
|
|
901
|
-
left: { type:
|
|
902
|
-
right: { type:
|
|
900
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
901
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
903
902
|
},
|
|
904
903
|
right: {
|
|
905
|
-
type:
|
|
904
|
+
type: ASTType.BinaryExpression,
|
|
906
905
|
operator: op1,
|
|
907
|
-
left: { type:
|
|
908
|
-
right: { type:
|
|
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:
|
|
921
|
+
type: ASTType.Program,
|
|
923
922
|
body: [
|
|
924
923
|
{
|
|
925
|
-
type:
|
|
924
|
+
type: ASTType.ExpressionStatement,
|
|
926
925
|
expression: {
|
|
927
|
-
type:
|
|
926
|
+
type: ASTType.LogicalExpression,
|
|
928
927
|
operator,
|
|
929
|
-
left: { type:
|
|
930
|
-
right: { type:
|
|
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:
|
|
940
|
+
type: ASTType.Program,
|
|
942
941
|
body: [
|
|
943
942
|
{
|
|
944
|
-
type:
|
|
943
|
+
type: ASTType.ExpressionStatement,
|
|
945
944
|
expression: {
|
|
946
|
-
type:
|
|
945
|
+
type: ASTType.LogicalExpression,
|
|
947
946
|
operator: op,
|
|
948
947
|
left: {
|
|
949
|
-
type:
|
|
948
|
+
type: ASTType.LogicalExpression,
|
|
950
949
|
operator: op,
|
|
951
|
-
left: { type:
|
|
952
|
-
right: { type:
|
|
950
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
951
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
953
952
|
},
|
|
954
|
-
right: { type:
|
|
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:
|
|
963
|
+
type: ASTType.Program,
|
|
965
964
|
body: [
|
|
966
965
|
{
|
|
967
|
-
type:
|
|
966
|
+
type: ASTType.ExpressionStatement,
|
|
968
967
|
expression: {
|
|
969
|
-
type:
|
|
970
|
-
test: { type:
|
|
971
|
-
alternate: { type:
|
|
972
|
-
consequent: { type:
|
|
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:
|
|
981
|
+
type: ASTType.Program,
|
|
983
982
|
body: [
|
|
984
983
|
{
|
|
985
|
-
type:
|
|
984
|
+
type: ASTType.ExpressionStatement,
|
|
986
985
|
expression: {
|
|
987
|
-
type:
|
|
988
|
-
test: { type:
|
|
989
|
-
alternate: { type:
|
|
986
|
+
type: ASTType.ConditionalExpression,
|
|
987
|
+
test: { type: ASTType.Identifier, name: "foo0" },
|
|
988
|
+
alternate: { type: ASTType.Identifier, name: "foo1" },
|
|
990
989
|
consequent: {
|
|
991
|
-
type:
|
|
992
|
-
test: { type:
|
|
990
|
+
type: ASTType.ConditionalExpression,
|
|
991
|
+
test: { type: ASTType.Identifier, name: "foo2" },
|
|
993
992
|
alternate: {
|
|
994
|
-
type:
|
|
995
|
-
test: { type:
|
|
996
|
-
alternate: { type:
|
|
997
|
-
consequent: { type:
|
|
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:
|
|
1001
|
-
test: { type:
|
|
1002
|
-
alternate: { type:
|
|
1003
|
-
consequent: { type:
|
|
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:
|
|
1015
|
+
type: ASTType.Program,
|
|
1017
1016
|
body: [
|
|
1018
1017
|
{
|
|
1019
|
-
type:
|
|
1018
|
+
type: ASTType.ExpressionStatement,
|
|
1020
1019
|
expression: {
|
|
1021
|
-
type:
|
|
1022
|
-
left: { type:
|
|
1023
|
-
right: { type:
|
|
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:
|
|
1033
|
+
type: ASTType.Program,
|
|
1035
1034
|
body: [
|
|
1036
1035
|
{
|
|
1037
|
-
type:
|
|
1036
|
+
type: ASTType.ExpressionStatement,
|
|
1038
1037
|
expression: {
|
|
1039
|
-
type:
|
|
1040
|
-
left: { type:
|
|
1038
|
+
type: ASTType.AssignmentExpression,
|
|
1039
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1041
1040
|
right: {
|
|
1042
|
-
type:
|
|
1043
|
-
left: { type:
|
|
1044
|
-
right: { type:
|
|
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:
|
|
1056
|
+
type: ASTType.Program,
|
|
1058
1057
|
body: [
|
|
1059
1058
|
{
|
|
1060
|
-
type:
|
|
1059
|
+
type: ASTType.ExpressionStatement,
|
|
1061
1060
|
expression: {
|
|
1062
|
-
type:
|
|
1061
|
+
type: ASTType.LogicalExpression,
|
|
1063
1062
|
operator: "&&",
|
|
1064
1063
|
left: {
|
|
1065
|
-
type:
|
|
1064
|
+
type: ASTType.BinaryExpression,
|
|
1066
1065
|
operator,
|
|
1067
|
-
left: { type:
|
|
1068
|
-
right: { type:
|
|
1066
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1067
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
1069
1068
|
},
|
|
1070
1069
|
right: {
|
|
1071
|
-
type:
|
|
1070
|
+
type: ASTType.BinaryExpression,
|
|
1072
1071
|
operator,
|
|
1073
|
-
left: { type:
|
|
1074
|
-
right: { type:
|
|
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:
|
|
1084
|
+
type: ASTType.Program,
|
|
1086
1085
|
body: [
|
|
1087
1086
|
{
|
|
1088
|
-
type:
|
|
1087
|
+
type: ASTType.ExpressionStatement,
|
|
1089
1088
|
expression: {
|
|
1090
|
-
type:
|
|
1089
|
+
type: ASTType.LogicalExpression,
|
|
1091
1090
|
operator: "||",
|
|
1092
1091
|
left: {
|
|
1093
|
-
type:
|
|
1092
|
+
type: ASTType.LogicalExpression,
|
|
1094
1093
|
operator: "&&",
|
|
1095
|
-
left: { type:
|
|
1096
|
-
right: { type:
|
|
1094
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1095
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
1097
1096
|
},
|
|
1098
1097
|
right: {
|
|
1099
|
-
type:
|
|
1098
|
+
type: ASTType.LogicalExpression,
|
|
1100
1099
|
operator: "&&",
|
|
1101
|
-
left: { type:
|
|
1102
|
-
right: { type:
|
|
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:
|
|
1111
|
+
type: ASTType.Program,
|
|
1113
1112
|
body: [
|
|
1114
1113
|
{
|
|
1115
|
-
type:
|
|
1114
|
+
type: ASTType.ExpressionStatement,
|
|
1116
1115
|
expression: {
|
|
1117
|
-
type:
|
|
1116
|
+
type: ASTType.ConditionalExpression,
|
|
1118
1117
|
test: {
|
|
1119
|
-
type:
|
|
1118
|
+
type: ASTType.LogicalExpression,
|
|
1120
1119
|
operator: "||",
|
|
1121
|
-
left: { type:
|
|
1122
|
-
right: { type:
|
|
1120
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1121
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
1123
1122
|
},
|
|
1124
|
-
alternate: { type:
|
|
1125
|
-
consequent: { type:
|
|
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:
|
|
1133
|
+
type: ASTType.Program,
|
|
1135
1134
|
body: [
|
|
1136
1135
|
{
|
|
1137
|
-
type:
|
|
1136
|
+
type: ASTType.ExpressionStatement,
|
|
1138
1137
|
expression: {
|
|
1139
|
-
type:
|
|
1140
|
-
left: { type:
|
|
1138
|
+
type: ASTType.AssignmentExpression,
|
|
1139
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1141
1140
|
right: {
|
|
1142
|
-
type:
|
|
1143
|
-
test: { type:
|
|
1144
|
-
alternate: { type:
|
|
1145
|
-
consequent: { type:
|
|
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:
|
|
1155
|
+
type: ASTType.Program,
|
|
1157
1156
|
body: [
|
|
1158
1157
|
{
|
|
1159
|
-
type:
|
|
1158
|
+
type: ASTType.ExpressionStatement,
|
|
1160
1159
|
expression: {
|
|
1161
|
-
type:
|
|
1160
|
+
type: ASTType.ArrayExpression,
|
|
1162
1161
|
elements: [],
|
|
1163
1162
|
},
|
|
1164
1163
|
},
|
|
1165
1164
|
],
|
|
1166
1165
|
});
|
|
1167
1166
|
expect(createAst("[foo]")).toEqual({
|
|
1168
|
-
type:
|
|
1167
|
+
type: ASTType.Program,
|
|
1169
1168
|
body: [
|
|
1170
1169
|
{
|
|
1171
|
-
type:
|
|
1170
|
+
type: ASTType.ExpressionStatement,
|
|
1172
1171
|
expression: {
|
|
1173
|
-
type:
|
|
1174
|
-
elements: [{ type:
|
|
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:
|
|
1179
|
+
type: ASTType.Program,
|
|
1181
1180
|
body: [
|
|
1182
1181
|
{
|
|
1183
|
-
type:
|
|
1182
|
+
type: ASTType.ExpressionStatement,
|
|
1184
1183
|
expression: {
|
|
1185
|
-
type:
|
|
1186
|
-
elements: [{ type:
|
|
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:
|
|
1191
|
+
type: ASTType.Program,
|
|
1193
1192
|
body: [
|
|
1194
1193
|
{
|
|
1195
|
-
type:
|
|
1194
|
+
type: ASTType.ExpressionStatement,
|
|
1196
1195
|
expression: {
|
|
1197
|
-
type:
|
|
1196
|
+
type: ASTType.ArrayExpression,
|
|
1198
1197
|
elements: [
|
|
1199
|
-
{ type:
|
|
1200
|
-
{ type:
|
|
1201
|
-
{ type:
|
|
1202
|
-
{ type:
|
|
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:
|
|
1208
|
+
type: ASTType.Program,
|
|
1210
1209
|
body: [
|
|
1211
1210
|
{
|
|
1212
|
-
type:
|
|
1211
|
+
type: ASTType.ExpressionStatement,
|
|
1213
1212
|
expression: {
|
|
1214
|
-
type:
|
|
1213
|
+
type: ASTType.ArrayExpression,
|
|
1215
1214
|
elements: [
|
|
1216
|
-
{ type:
|
|
1217
|
-
{ type:
|
|
1218
|
-
{ type:
|
|
1219
|
-
{ type:
|
|
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:
|
|
1228
|
+
type: ASTType.Program,
|
|
1230
1229
|
body: [
|
|
1231
1230
|
{
|
|
1232
|
-
type:
|
|
1231
|
+
type: ASTType.ExpressionStatement,
|
|
1233
1232
|
expression: {
|
|
1234
|
-
type:
|
|
1233
|
+
type: ASTType.ObjectExpression,
|
|
1235
1234
|
properties: [],
|
|
1236
1235
|
},
|
|
1237
1236
|
},
|
|
1238
1237
|
],
|
|
1239
1238
|
});
|
|
1240
1239
|
expect(createAst("{foo: bar}")).toEqual({
|
|
1241
|
-
type:
|
|
1240
|
+
type: ASTType.Program,
|
|
1242
1241
|
body: [
|
|
1243
1242
|
{
|
|
1244
|
-
type:
|
|
1243
|
+
type: ASTType.ExpressionStatement,
|
|
1245
1244
|
expression: {
|
|
1246
|
-
type:
|
|
1245
|
+
type: ASTType.ObjectExpression,
|
|
1247
1246
|
properties: [
|
|
1248
1247
|
{
|
|
1249
|
-
type:
|
|
1248
|
+
type: ASTType.Property,
|
|
1250
1249
|
kind: "init",
|
|
1251
|
-
key: { type:
|
|
1250
|
+
key: { type: ASTType.Identifier, name: "foo" },
|
|
1252
1251
|
computed: false,
|
|
1253
|
-
value: { type:
|
|
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:
|
|
1260
|
+
type: ASTType.Program,
|
|
1262
1261
|
body: [
|
|
1263
1262
|
{
|
|
1264
|
-
type:
|
|
1263
|
+
type: ASTType.ExpressionStatement,
|
|
1265
1264
|
expression: {
|
|
1266
|
-
type:
|
|
1265
|
+
type: ASTType.ObjectExpression,
|
|
1267
1266
|
properties: [
|
|
1268
1267
|
{
|
|
1269
|
-
type:
|
|
1268
|
+
type: ASTType.Property,
|
|
1270
1269
|
kind: "init",
|
|
1271
|
-
key: { type:
|
|
1270
|
+
key: { type: ASTType.Identifier, name: "foo" },
|
|
1272
1271
|
computed: false,
|
|
1273
|
-
value: { type:
|
|
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:
|
|
1280
|
+
type: ASTType.Program,
|
|
1282
1281
|
body: [
|
|
1283
1282
|
{
|
|
1284
|
-
type:
|
|
1283
|
+
type: ASTType.ExpressionStatement,
|
|
1285
1284
|
expression: {
|
|
1286
|
-
type:
|
|
1285
|
+
type: ASTType.ObjectExpression,
|
|
1287
1286
|
properties: [
|
|
1288
1287
|
{
|
|
1289
|
-
type:
|
|
1288
|
+
type: ASTType.Property,
|
|
1290
1289
|
kind: "init",
|
|
1291
|
-
key: { type:
|
|
1290
|
+
key: { type: ASTType.Identifier, name: "foo" },
|
|
1292
1291
|
computed: false,
|
|
1293
|
-
value: { type:
|
|
1292
|
+
value: { type: ASTType.Identifier, name: "bar" },
|
|
1294
1293
|
},
|
|
1295
1294
|
{
|
|
1296
|
-
type:
|
|
1295
|
+
type: ASTType.Property,
|
|
1297
1296
|
kind: "init",
|
|
1298
|
-
key: { type:
|
|
1297
|
+
key: { type: ASTType.Literal, value: "man" },
|
|
1299
1298
|
computed: false,
|
|
1300
|
-
value: { type:
|
|
1299
|
+
value: { type: ASTType.Literal, value: "shell" },
|
|
1301
1300
|
},
|
|
1302
1301
|
{
|
|
1303
|
-
type:
|
|
1302
|
+
type: ASTType.Property,
|
|
1304
1303
|
kind: "init",
|
|
1305
|
-
key: { type:
|
|
1304
|
+
key: { type: ASTType.Literal, value: 42 },
|
|
1306
1305
|
computed: false,
|
|
1307
|
-
value: { type:
|
|
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:
|
|
1314
|
+
type: ASTType.Program,
|
|
1316
1315
|
body: [
|
|
1317
1316
|
{
|
|
1318
|
-
type:
|
|
1317
|
+
type: ASTType.ExpressionStatement,
|
|
1319
1318
|
expression: {
|
|
1320
|
-
type:
|
|
1319
|
+
type: ASTType.ObjectExpression,
|
|
1321
1320
|
properties: [
|
|
1322
1321
|
{
|
|
1323
|
-
type:
|
|
1322
|
+
type: ASTType.Property,
|
|
1324
1323
|
kind: "init",
|
|
1325
|
-
key: { type:
|
|
1324
|
+
key: { type: ASTType.Identifier, name: "foo" },
|
|
1326
1325
|
computed: false,
|
|
1327
|
-
value: { type:
|
|
1326
|
+
value: { type: ASTType.Identifier, name: "bar" },
|
|
1328
1327
|
},
|
|
1329
1328
|
{
|
|
1330
|
-
type:
|
|
1329
|
+
type: ASTType.Property,
|
|
1331
1330
|
kind: "init",
|
|
1332
|
-
key: { type:
|
|
1331
|
+
key: { type: ASTType.Literal, value: "man" },
|
|
1333
1332
|
computed: false,
|
|
1334
|
-
value: { type:
|
|
1333
|
+
value: { type: ASTType.Literal, value: "shell" },
|
|
1335
1334
|
},
|
|
1336
1335
|
{
|
|
1337
|
-
type:
|
|
1336
|
+
type: ASTType.Property,
|
|
1338
1337
|
kind: "init",
|
|
1339
|
-
key: { type:
|
|
1338
|
+
key: { type: ASTType.Literal, value: 42 },
|
|
1340
1339
|
computed: false,
|
|
1341
|
-
value: { type:
|
|
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:
|
|
1352
|
+
type: ASTType.Program,
|
|
1354
1353
|
body: [
|
|
1355
1354
|
{
|
|
1356
|
-
type:
|
|
1355
|
+
type: ASTType.ExpressionStatement,
|
|
1357
1356
|
expression: {
|
|
1358
|
-
type:
|
|
1357
|
+
type: ASTType.ObjectExpression,
|
|
1359
1358
|
properties: [
|
|
1360
1359
|
{
|
|
1361
|
-
type:
|
|
1360
|
+
type: ASTType.Property,
|
|
1362
1361
|
kind: "init",
|
|
1363
|
-
key: { type:
|
|
1362
|
+
key: { type: ASTType.Identifier, name: "x" },
|
|
1364
1363
|
computed: false,
|
|
1365
|
-
value: { type:
|
|
1364
|
+
value: { type: ASTType.Identifier, name: "x" },
|
|
1366
1365
|
},
|
|
1367
1366
|
{
|
|
1368
|
-
type:
|
|
1367
|
+
type: ASTType.Property,
|
|
1369
1368
|
kind: "init",
|
|
1370
|
-
key: { type:
|
|
1369
|
+
key: { type: ASTType.Identifier, name: "y" },
|
|
1371
1370
|
computed: false,
|
|
1372
|
-
value: { type:
|
|
1371
|
+
value: { type: ASTType.Identifier, name: "y" },
|
|
1373
1372
|
},
|
|
1374
1373
|
{
|
|
1375
|
-
type:
|
|
1374
|
+
type: ASTType.Property,
|
|
1376
1375
|
kind: "init",
|
|
1377
|
-
key: { type:
|
|
1376
|
+
key: { type: ASTType.Identifier, name: "z" },
|
|
1378
1377
|
computed: false,
|
|
1379
|
-
value: { type:
|
|
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:
|
|
1391
|
+
type: ASTType.Program,
|
|
1393
1392
|
body: [
|
|
1394
1393
|
{
|
|
1395
|
-
type:
|
|
1394
|
+
type: ASTType.ExpressionStatement,
|
|
1396
1395
|
expression: {
|
|
1397
|
-
type:
|
|
1396
|
+
type: ASTType.ObjectExpression,
|
|
1398
1397
|
properties: [
|
|
1399
1398
|
{
|
|
1400
|
-
type:
|
|
1399
|
+
type: ASTType.Property,
|
|
1401
1400
|
kind: "init",
|
|
1402
|
-
key: { type:
|
|
1401
|
+
key: { type: ASTType.Identifier, name: "x" },
|
|
1403
1402
|
computed: true,
|
|
1404
|
-
value: { type:
|
|
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:
|
|
1411
|
+
type: ASTType.Program,
|
|
1413
1412
|
body: [
|
|
1414
1413
|
{
|
|
1415
|
-
type:
|
|
1414
|
+
type: ASTType.ExpressionStatement,
|
|
1416
1415
|
expression: {
|
|
1417
|
-
type:
|
|
1416
|
+
type: ASTType.ObjectExpression,
|
|
1418
1417
|
properties: [
|
|
1419
1418
|
{
|
|
1420
|
-
type:
|
|
1419
|
+
type: ASTType.Property,
|
|
1421
1420
|
kind: "init",
|
|
1422
1421
|
key: {
|
|
1423
|
-
type:
|
|
1422
|
+
type: ASTType.BinaryExpression,
|
|
1424
1423
|
operator: "+",
|
|
1425
|
-
left: { type:
|
|
1426
|
-
right: { type:
|
|
1424
|
+
left: { type: ASTType.Identifier, name: "x" },
|
|
1425
|
+
right: { type: ASTType.Literal, value: 1 },
|
|
1427
1426
|
},
|
|
1428
1427
|
computed: true,
|
|
1429
|
-
value: { type:
|
|
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:
|
|
1439
|
+
type: ASTType.Program,
|
|
1441
1440
|
body: [
|
|
1442
1441
|
{
|
|
1443
|
-
type:
|
|
1442
|
+
type: ASTType.ExpressionStatement,
|
|
1444
1443
|
expression: {
|
|
1445
|
-
type:
|
|
1446
|
-
left: { type:
|
|
1447
|
-
right: { type:
|
|
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:
|
|
1451
|
+
type: ASTType.ExpressionStatement,
|
|
1453
1452
|
expression: {
|
|
1454
|
-
type:
|
|
1455
|
-
left: { type:
|
|
1456
|
-
right: { type:
|
|
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:
|
|
1466
|
+
type: ASTType.Program,
|
|
1468
1467
|
body: [
|
|
1469
1468
|
{
|
|
1470
|
-
type:
|
|
1469
|
+
type: ASTType.ExpressionStatement,
|
|
1471
1470
|
expression: {
|
|
1472
|
-
type:
|
|
1473
|
-
callee: { type:
|
|
1474
|
-
arguments: [{ type:
|
|
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:
|
|
1483
|
+
type: ASTType.Program,
|
|
1485
1484
|
body: [
|
|
1486
1485
|
{
|
|
1487
|
-
type:
|
|
1486
|
+
type: ASTType.ExpressionStatement,
|
|
1488
1487
|
expression: {
|
|
1489
|
-
type:
|
|
1490
|
-
callee: { type:
|
|
1488
|
+
type: ASTType.CallExpression,
|
|
1489
|
+
callee: { type: ASTType.Identifier, name: "bar" },
|
|
1491
1490
|
arguments: [
|
|
1492
|
-
{ type:
|
|
1493
|
-
{ type:
|
|
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:
|
|
1503
|
+
type: ASTType.Program,
|
|
1505
1504
|
body: [
|
|
1506
1505
|
{
|
|
1507
|
-
type:
|
|
1506
|
+
type: ASTType.ExpressionStatement,
|
|
1508
1507
|
expression: {
|
|
1509
|
-
type:
|
|
1510
|
-
callee: { type:
|
|
1508
|
+
type: ASTType.CallExpression,
|
|
1509
|
+
callee: { type: ASTType.Identifier, name: "shell" },
|
|
1511
1510
|
arguments: [
|
|
1512
1511
|
{
|
|
1513
|
-
type:
|
|
1514
|
-
callee: { type:
|
|
1512
|
+
type: ASTType.CallExpression,
|
|
1513
|
+
callee: { type: ASTType.Identifier, name: "bar" },
|
|
1515
1514
|
arguments: [
|
|
1516
|
-
{ type:
|
|
1517
|
-
{ type:
|
|
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:
|
|
1530
|
+
type: ASTType.Program,
|
|
1532
1531
|
body: [
|
|
1533
1532
|
{
|
|
1534
|
-
type:
|
|
1533
|
+
type: ASTType.ExpressionStatement,
|
|
1535
1534
|
expression: {
|
|
1536
|
-
type:
|
|
1537
|
-
callee: { type:
|
|
1535
|
+
type: ASTType.CallExpression,
|
|
1536
|
+
callee: { type: ASTType.Identifier, name: "man" },
|
|
1538
1537
|
arguments: [
|
|
1539
1538
|
{
|
|
1540
|
-
type:
|
|
1541
|
-
left: { type:
|
|
1542
|
-
right: { type:
|
|
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:
|
|
1554
|
+
type: ASTType.Program,
|
|
1556
1555
|
body: [
|
|
1557
1556
|
{
|
|
1558
|
-
type:
|
|
1557
|
+
type: ASTType.ExpressionStatement,
|
|
1559
1558
|
expression: {
|
|
1560
|
-
type:
|
|
1561
|
-
callee: { type:
|
|
1559
|
+
type: ASTType.CallExpression,
|
|
1560
|
+
callee: { type: ASTType.Identifier, name: "bar" },
|
|
1562
1561
|
arguments: [
|
|
1563
|
-
{ type:
|
|
1562
|
+
{ type: ASTType.Identifier, name: "foo" },
|
|
1564
1563
|
{
|
|
1565
|
-
type:
|
|
1566
|
-
left: { type:
|
|
1567
|
-
right: { type:
|
|
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:
|
|
1579
|
+
type: ASTType.Program,
|
|
1581
1580
|
body: [
|
|
1582
1581
|
{
|
|
1583
|
-
type:
|
|
1582
|
+
type: ASTType.ExpressionStatement,
|
|
1584
1583
|
expression: {
|
|
1585
|
-
type:
|
|
1586
|
-
object: { type:
|
|
1584
|
+
type: ASTType.MemberExpression,
|
|
1585
|
+
object: { type: ASTType.Identifier, name: "foo" },
|
|
1587
1586
|
property: {
|
|
1588
|
-
type:
|
|
1589
|
-
left: { type:
|
|
1590
|
-
right: { type:
|
|
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:
|
|
1601
|
+
type: ASTType.Program,
|
|
1603
1602
|
body: [
|
|
1604
1603
|
{
|
|
1605
|
-
type:
|
|
1604
|
+
type: ASTType.ExpressionStatement,
|
|
1606
1605
|
expression: {
|
|
1607
|
-
type:
|
|
1608
|
-
callee: { type:
|
|
1606
|
+
type: ASTType.CallExpression,
|
|
1607
|
+
callee: { type: ASTType.Identifier, name: "foo" },
|
|
1609
1608
|
arguments: [
|
|
1610
1609
|
{
|
|
1611
|
-
type:
|
|
1612
|
-
left: { type:
|
|
1613
|
-
right: { type:
|
|
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:
|
|
1624
|
+
type: ASTType.Program,
|
|
1626
1625
|
body: [
|
|
1627
1626
|
{
|
|
1628
|
-
type:
|
|
1627
|
+
type: ASTType.ExpressionStatement,
|
|
1629
1628
|
expression: {
|
|
1630
|
-
type:
|
|
1629
|
+
type: ASTType.ConditionalExpression,
|
|
1631
1630
|
test: {
|
|
1632
|
-
type:
|
|
1631
|
+
type: ASTType.LogicalExpression,
|
|
1633
1632
|
operator: "||",
|
|
1634
|
-
left: { type:
|
|
1635
|
-
right: { type:
|
|
1633
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1634
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
1636
1635
|
},
|
|
1637
1636
|
alternate: {
|
|
1638
|
-
type:
|
|
1639
|
-
left: { type:
|
|
1640
|
-
right: { type:
|
|
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:
|
|
1645
|
-
left: { type:
|
|
1646
|
-
right: { type:
|
|
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:
|
|
1656
|
+
type: ASTType.Program,
|
|
1658
1657
|
body: [
|
|
1659
1658
|
{
|
|
1660
|
-
type:
|
|
1659
|
+
type: ASTType.ExpressionStatement,
|
|
1661
1660
|
expression: {
|
|
1662
|
-
type:
|
|
1661
|
+
type: ASTType.ArrayExpression,
|
|
1663
1662
|
elements: [
|
|
1664
1663
|
{
|
|
1665
|
-
type:
|
|
1666
|
-
left: { type:
|
|
1667
|
-
right: { type:
|
|
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:
|
|
1678
|
+
type: ASTType.Program,
|
|
1680
1679
|
body: [
|
|
1681
1680
|
{
|
|
1682
|
-
type:
|
|
1681
|
+
type: ASTType.ExpressionStatement,
|
|
1683
1682
|
expression: {
|
|
1684
|
-
type:
|
|
1683
|
+
type: ASTType.ObjectExpression,
|
|
1685
1684
|
properties: [
|
|
1686
1685
|
{
|
|
1687
|
-
type:
|
|
1686
|
+
type: ASTType.Property,
|
|
1688
1687
|
kind: "init",
|
|
1689
|
-
key: { type:
|
|
1688
|
+
key: { type: ASTType.Identifier, name: "foo" },
|
|
1690
1689
|
computed: false,
|
|
1691
1690
|
value: {
|
|
1692
|
-
type:
|
|
1693
|
-
left: { type:
|
|
1694
|
-
right: { type:
|
|
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:
|
|
1706
|
+
type: ASTType.Program,
|
|
1708
1707
|
body: [
|
|
1709
1708
|
{
|
|
1710
|
-
type:
|
|
1709
|
+
type: ASTType.ExpressionStatement,
|
|
1711
1710
|
expression: {
|
|
1712
|
-
type:
|
|
1711
|
+
type: ASTType.MemberExpression,
|
|
1713
1712
|
object: {
|
|
1714
|
-
type:
|
|
1713
|
+
type: ASTType.BinaryExpression,
|
|
1715
1714
|
operator: "+",
|
|
1716
|
-
left: { type:
|
|
1717
|
-
right: { type:
|
|
1715
|
+
left: { type: ASTType.Identifier, name: "foo" },
|
|
1716
|
+
right: { type: ASTType.Identifier, name: "bar" },
|
|
1718
1717
|
},
|
|
1719
|
-
property: { type:
|
|
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:
|
|
1728
|
+
type: ASTType.Program,
|
|
1730
1729
|
body: [
|
|
1731
1730
|
{
|
|
1732
|
-
type:
|
|
1733
|
-
expression: { type:
|
|
1731
|
+
type: ASTType.ExpressionStatement,
|
|
1732
|
+
expression: { type: ASTType.Identifier, name: "foo" },
|
|
1734
1733
|
},
|
|
1735
1734
|
{
|
|
1736
|
-
type:
|
|
1737
|
-
expression: { type:
|
|
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:
|
|
1741
|
+
type: ASTType.Program,
|
|
1743
1742
|
body: [
|
|
1744
1743
|
{
|
|
1745
|
-
type:
|
|
1746
|
-
expression: { type:
|
|
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:
|
|
1750
|
+
type: ASTType.Program,
|
|
1752
1751
|
body: [
|
|
1753
1752
|
{
|
|
1754
|
-
type:
|
|
1755
|
-
expression: { type:
|
|
1753
|
+
type: ASTType.ExpressionStatement,
|
|
1754
|
+
expression: { type: ASTType.Identifier, name: "foo" },
|
|
1756
1755
|
},
|
|
1757
1756
|
],
|
|
1758
1757
|
});
|
|
1759
|
-
expect(createAst(";;;;")).toEqual({ type:
|
|
1760
|
-
expect(createAst("")).toEqual({ type:
|
|
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
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
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_;
|