mancha 0.16.6 → 0.17.0
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 +22 -19
- package/dist/browser.d.ts +40 -3
- package/dist/browser.js +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/cli.js +7 -1
- package/dist/cli.js.map +1 -1
- package/dist/dome.d.ts +1 -2
- package/dist/dome.js +2 -0
- package/dist/dome.js.map +1 -1
- package/dist/expressions/ast.d.ts +79 -0
- package/dist/expressions/ast.js +6 -0
- package/dist/expressions/ast.js.map +1 -0
- package/dist/expressions/ast.test.d.ts +1 -0
- package/dist/expressions/ast.test.js +122 -0
- package/dist/expressions/ast.test.js.map +1 -0
- package/dist/expressions/ast_factory.d.ts +37 -0
- package/dist/expressions/ast_factory.js +119 -0
- package/dist/expressions/ast_factory.js.map +1 -0
- package/dist/expressions/ast_factory.test.d.ts +1 -0
- package/dist/expressions/ast_factory.test.js +88 -0
- package/dist/expressions/ast_factory.test.js.map +1 -0
- package/dist/expressions/constants.d.ts +6 -0
- package/dist/expressions/constants.js +72 -0
- package/dist/expressions/constants.js.map +1 -0
- package/dist/expressions/constants.test.d.ts +1 -0
- package/dist/expressions/constants.test.js +84 -0
- package/dist/expressions/constants.test.js.map +1 -0
- package/dist/expressions/eval.d.ts +101 -0
- package/dist/expressions/eval.js +375 -0
- package/dist/expressions/eval.js.map +1 -0
- package/dist/expressions/eval.test.d.ts +1 -0
- package/dist/expressions/eval.test.js +141 -0
- package/dist/expressions/eval.test.js.map +1 -0
- package/dist/expressions/expressions.test.d.ts +6 -0
- package/dist/expressions/expressions.test.js +7 -0
- package/dist/expressions/expressions.test.js.map +1 -0
- package/dist/expressions/index.d.ts +6 -0
- package/dist/expressions/index.js +7 -0
- package/dist/expressions/index.js.map +1 -0
- package/dist/expressions/parser.d.ts +32 -0
- package/dist/expressions/parser.js +336 -0
- package/dist/expressions/parser.js.map +1 -0
- package/dist/expressions/parser.test.d.ts +1 -0
- package/dist/expressions/parser.test.js +132 -0
- package/dist/expressions/parser.test.js.map +1 -0
- package/dist/expressions/tokenizer.d.ts +49 -0
- package/dist/expressions/tokenizer.js +253 -0
- package/dist/expressions/tokenizer.js.map +1 -0
- package/dist/expressions/tokenizer.test.d.ts +1 -0
- package/dist/expressions/tokenizer.test.js +99 -0
- package/dist/expressions/tokenizer.test.js.map +1 -0
- package/dist/mancha.d.ts +1 -1
- package/dist/mancha.js +1 -1
- package/dist/mancha.js.map +1 -1
- package/dist/renderer.d.ts +5 -2
- package/dist/renderer.js +2 -0
- package/dist/renderer.js.map +1 -1
- package/dist/safe_browser.d.ts +4 -3
- package/dist/safe_browser.js +1 -1
- package/dist/safe_browser.js.map +1 -1
- package/dist/store.d.ts +51 -11
- package/dist/store.js +89 -31
- package/dist/store.js.map +1 -1
- package/dist/trusted_attributes.d.ts +4 -0
- package/dist/trusted_attributes.js +28 -0
- package/dist/trusted_attributes.js.map +1 -0
- package/dist/type_checker.d.ts +1 -0
- package/dist/type_checker.js +92 -30
- package/dist/type_checker.js.map +1 -1
- package/docs/quickstart.md +36 -0
- package/gulpfile.js +5 -1
- package/package.json +18 -5
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type Expression = Literal | Empty | ID | Unary | Binary | Getter | Invoke | Paren | Index | Ternary | Map | List | ArrowFunction | SpreadProperty | SpreadElement | Property;
|
|
2
|
+
export type LiteralValue = string | number | boolean | null | undefined;
|
|
3
|
+
export interface Literal {
|
|
4
|
+
type: 'Literal';
|
|
5
|
+
value: LiteralValue;
|
|
6
|
+
}
|
|
7
|
+
export interface Empty {
|
|
8
|
+
type: 'Empty';
|
|
9
|
+
}
|
|
10
|
+
export interface ID {
|
|
11
|
+
type: 'ID';
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
14
|
+
export interface Unary {
|
|
15
|
+
type: 'Unary';
|
|
16
|
+
operator: string;
|
|
17
|
+
child: Expression;
|
|
18
|
+
}
|
|
19
|
+
export interface Binary {
|
|
20
|
+
type: 'Binary';
|
|
21
|
+
operator: string;
|
|
22
|
+
left: Expression;
|
|
23
|
+
right: Expression;
|
|
24
|
+
}
|
|
25
|
+
export interface Getter {
|
|
26
|
+
type: 'Getter';
|
|
27
|
+
receiver: Expression;
|
|
28
|
+
name: string;
|
|
29
|
+
optional?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface Invoke {
|
|
32
|
+
type: 'Invoke';
|
|
33
|
+
receiver: Expression;
|
|
34
|
+
method?: string;
|
|
35
|
+
arguments?: Array<Expression>;
|
|
36
|
+
optional?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface Paren {
|
|
39
|
+
type: 'Paren';
|
|
40
|
+
child: Expression;
|
|
41
|
+
}
|
|
42
|
+
export interface Index {
|
|
43
|
+
type: 'Index';
|
|
44
|
+
receiver: Expression;
|
|
45
|
+
argument?: Expression;
|
|
46
|
+
optional?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface Ternary {
|
|
49
|
+
type: 'Ternary';
|
|
50
|
+
condition: Expression;
|
|
51
|
+
trueExpr: Expression;
|
|
52
|
+
falseExpr: Expression;
|
|
53
|
+
}
|
|
54
|
+
export interface Map {
|
|
55
|
+
type: 'Map';
|
|
56
|
+
properties?: Array<Property | SpreadProperty>;
|
|
57
|
+
}
|
|
58
|
+
export interface Property {
|
|
59
|
+
type: 'Property';
|
|
60
|
+
key: string;
|
|
61
|
+
value: Expression;
|
|
62
|
+
}
|
|
63
|
+
export interface List {
|
|
64
|
+
type: 'List';
|
|
65
|
+
items?: Array<Expression>;
|
|
66
|
+
}
|
|
67
|
+
export interface ArrowFunction {
|
|
68
|
+
type: 'ArrowFunction';
|
|
69
|
+
params: Array<string>;
|
|
70
|
+
body: Expression;
|
|
71
|
+
}
|
|
72
|
+
export interface SpreadProperty {
|
|
73
|
+
type: 'SpreadProperty';
|
|
74
|
+
expression: Expression;
|
|
75
|
+
}
|
|
76
|
+
export interface SpreadElement {
|
|
77
|
+
type: 'SpreadElement';
|
|
78
|
+
expression: Expression;
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/expressions/ast.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { assert } from "../test_utils.js";
|
|
2
|
+
describe("AST Node Interfaces", () => {
|
|
3
|
+
it("should define Literal node correctly", () => {
|
|
4
|
+
const node = { type: 'Literal', value: 123 };
|
|
5
|
+
assert.equal(node.type, 'Literal');
|
|
6
|
+
assert.equal(node.value, 123);
|
|
7
|
+
});
|
|
8
|
+
it("should define ID node correctly", () => {
|
|
9
|
+
const node = { type: 'ID', value: 'myVar' };
|
|
10
|
+
assert.equal(node.type, 'ID');
|
|
11
|
+
assert.equal(node.value, 'myVar');
|
|
12
|
+
});
|
|
13
|
+
it("should define Unary node correctly", () => {
|
|
14
|
+
const node = { type: 'Unary', operator: '-', child: { type: 'ID', value: 'x' } };
|
|
15
|
+
assert.equal(node.type, 'Unary');
|
|
16
|
+
assert.equal(node.operator, '-');
|
|
17
|
+
assert.equal(node.child.value, 'x');
|
|
18
|
+
});
|
|
19
|
+
it("should define Binary node correctly", () => {
|
|
20
|
+
const node = {
|
|
21
|
+
type: 'Binary',
|
|
22
|
+
operator: '+',
|
|
23
|
+
left: { type: 'ID', value: 'x' },
|
|
24
|
+
right: { type: 'ID', value: 'y' },
|
|
25
|
+
};
|
|
26
|
+
assert.equal(node.type, 'Binary');
|
|
27
|
+
assert.equal(node.operator, '+');
|
|
28
|
+
assert.equal(node.left.value, 'x');
|
|
29
|
+
assert.equal(node.right.value, 'y');
|
|
30
|
+
});
|
|
31
|
+
it("should define Getter node correctly", () => {
|
|
32
|
+
const node = { type: 'Getter', receiver: { type: 'ID', value: 'obj' }, name: 'prop', optional: true };
|
|
33
|
+
assert.equal(node.type, 'Getter');
|
|
34
|
+
assert.equal(node.receiver.value, 'obj');
|
|
35
|
+
assert.equal(node.name, 'prop');
|
|
36
|
+
assert.equal(node.optional, true);
|
|
37
|
+
});
|
|
38
|
+
it("should define Invoke node correctly", () => {
|
|
39
|
+
const node = {
|
|
40
|
+
type: 'Invoke',
|
|
41
|
+
receiver: { type: 'ID', value: 'fn' },
|
|
42
|
+
method: 'callMe',
|
|
43
|
+
arguments: [{ type: 'Literal', value: 1 }],
|
|
44
|
+
optional: true,
|
|
45
|
+
};
|
|
46
|
+
assert.equal(node.type, 'Invoke');
|
|
47
|
+
assert.equal(node.receiver.value, 'fn');
|
|
48
|
+
assert.equal(node.method, 'callMe');
|
|
49
|
+
assert.equal(node.arguments[0].value, 1);
|
|
50
|
+
assert.equal(node.optional, true);
|
|
51
|
+
});
|
|
52
|
+
it("should define Index node correctly", () => {
|
|
53
|
+
const node = { type: 'Index', receiver: { type: 'ID', value: 'arr' }, argument: { type: 'Literal', value: 0 }, optional: true };
|
|
54
|
+
assert.equal(node.type, 'Index');
|
|
55
|
+
assert.equal(node.receiver.value, 'arr');
|
|
56
|
+
assert.equal(node.argument.value, 0);
|
|
57
|
+
assert.equal(node.optional, true);
|
|
58
|
+
});
|
|
59
|
+
it("should define Ternary node correctly", () => {
|
|
60
|
+
const node = {
|
|
61
|
+
type: 'Ternary',
|
|
62
|
+
condition: { type: 'ID', value: 'x' },
|
|
63
|
+
trueExpr: { type: 'Literal', value: 1 },
|
|
64
|
+
falseExpr: { type: 'Literal', value: 0 },
|
|
65
|
+
};
|
|
66
|
+
assert.equal(node.type, 'Ternary');
|
|
67
|
+
assert.equal(node.condition.value, 'x');
|
|
68
|
+
});
|
|
69
|
+
it("should define Map node correctly", () => {
|
|
70
|
+
const node = {
|
|
71
|
+
type: 'Map',
|
|
72
|
+
properties: [
|
|
73
|
+
{ type: 'Property', key: 'a', value: { type: 'Literal', value: 1 } },
|
|
74
|
+
{ type: 'SpreadProperty', expression: { type: 'ID', value: 'obj' } },
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
assert.equal(node.type, 'Map');
|
|
78
|
+
assert.equal(node.properties?.length, 2);
|
|
79
|
+
assert.equal(node.properties[0].type, 'Property');
|
|
80
|
+
assert.equal(node.properties[1].type, 'SpreadProperty');
|
|
81
|
+
});
|
|
82
|
+
it("should define List node correctly", () => {
|
|
83
|
+
const node = {
|
|
84
|
+
type: 'List',
|
|
85
|
+
items: [
|
|
86
|
+
{ type: 'Literal', value: 1 },
|
|
87
|
+
{ type: 'SpreadElement', expression: { type: 'ID', value: 'arr' } },
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
assert.equal(node.type, 'List');
|
|
91
|
+
assert.equal(node.items?.length, 2);
|
|
92
|
+
assert.equal(node.items[0]?.type, 'Literal');
|
|
93
|
+
assert.equal(node.items[1]?.type, 'SpreadElement');
|
|
94
|
+
});
|
|
95
|
+
it("should define ArrowFunction node correctly", () => {
|
|
96
|
+
const node = {
|
|
97
|
+
type: 'ArrowFunction',
|
|
98
|
+
params: ['x', 'y'],
|
|
99
|
+
body: { type: 'Binary', operator: '+', left: { type: 'ID', value: 'x' }, right: { type: 'ID', value: 'y' } },
|
|
100
|
+
};
|
|
101
|
+
assert.equal(node.type, 'ArrowFunction');
|
|
102
|
+
assert.deepEqual(node.params, ['x', 'y']);
|
|
103
|
+
assert.equal(node.body.type, 'Binary');
|
|
104
|
+
});
|
|
105
|
+
it("should define SpreadProperty node correctly", () => {
|
|
106
|
+
const node = { type: 'SpreadProperty', expression: { type: 'ID', value: 'obj' } };
|
|
107
|
+
assert.equal(node.type, 'SpreadProperty');
|
|
108
|
+
assert.equal(node.expression.value, 'obj');
|
|
109
|
+
});
|
|
110
|
+
it("should define SpreadElement node correctly", () => {
|
|
111
|
+
const node = { type: 'SpreadElement', expression: { type: 'ID', value: 'arr' } };
|
|
112
|
+
assert.equal(node.type, 'SpreadElement');
|
|
113
|
+
assert.equal(node.expression.value, 'arr');
|
|
114
|
+
});
|
|
115
|
+
it("should define Property node correctly", () => {
|
|
116
|
+
const node = { type: 'Property', key: 'key', value: { type: 'Literal', value: 1 } };
|
|
117
|
+
assert.equal(node.type, 'Property');
|
|
118
|
+
assert.equal(node.key, 'key');
|
|
119
|
+
assert.equal(node.value.value, 1);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
//# sourceMappingURL=ast.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.test.js","sourceRoot":"","sources":["../../src/expressions/ast.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,IAAI,GAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;QAC1D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,IAAI,GAAW,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QACpD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,IAAI,GAAc,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC;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G,EAAE;QAC/C,MAAM,IAAI,GAAiB,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAClG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAE,IAAI,CAAC,KAAqB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as ast from './ast.js';
|
|
2
|
+
export interface AstFactory<E extends ast.Expression> {
|
|
3
|
+
empty(): E;
|
|
4
|
+
literal(value: ast.LiteralValue): E;
|
|
5
|
+
id(name: string): E;
|
|
6
|
+
unary(operator: string, expression: E): E;
|
|
7
|
+
binary(left: E, op: string, right: E | undefined): E;
|
|
8
|
+
getter(receiver: E, name: string, optional?: boolean): E;
|
|
9
|
+
invoke(receiver: E, method: string | undefined, args: Array<E | undefined> | undefined, optional?: boolean): E;
|
|
10
|
+
paren(child: E | undefined): E;
|
|
11
|
+
index(receiver: E, argument: E | undefined, optional?: boolean): E;
|
|
12
|
+
ternary(condition: E, trueExpr: E | undefined, falseExpr: E | undefined): E;
|
|
13
|
+
map(properties: Array<ast.Property | ast.SpreadProperty> | undefined): E;
|
|
14
|
+
list(items: Array<E | undefined> | undefined): E;
|
|
15
|
+
arrowFunction(params: Array<string>, body: E | undefined): E;
|
|
16
|
+
spreadProperty(expression: E): E;
|
|
17
|
+
spreadElement(expression: E): E;
|
|
18
|
+
property(key: string, value: E): E;
|
|
19
|
+
}
|
|
20
|
+
export declare class DefaultAstFactory implements AstFactory<ast.Expression> {
|
|
21
|
+
empty(): ast.Empty;
|
|
22
|
+
literal(value: ast.LiteralValue): ast.Literal;
|
|
23
|
+
id(value: string): ast.ID;
|
|
24
|
+
unary(operator: string, child: ast.Expression): ast.Unary;
|
|
25
|
+
binary(left: ast.Expression, operator: string, right: ast.Expression): ast.Binary;
|
|
26
|
+
getter(receiver: ast.Expression, name: string, optional?: boolean): ast.Getter;
|
|
27
|
+
invoke(receiver: ast.Expression, method: string | undefined, args: Array<ast.Expression> | undefined, optional?: boolean): ast.Invoke;
|
|
28
|
+
paren(child: ast.Expression): ast.Paren;
|
|
29
|
+
index(receiver: ast.Expression, argument: ast.Expression | undefined, optional?: boolean): ast.Index;
|
|
30
|
+
ternary(condition: ast.Expression, trueExpr: ast.Expression, falseExpr: ast.Expression): ast.Ternary;
|
|
31
|
+
map(properties: Array<ast.Property | ast.SpreadProperty>): ast.Map;
|
|
32
|
+
list(items: Array<ast.Expression>): ast.List;
|
|
33
|
+
property(key: string, value: ast.Expression): ast.Property;
|
|
34
|
+
arrowFunction(params: Array<string>, body: ast.Expression): ast.ArrowFunction;
|
|
35
|
+
spreadProperty(expression: ast.Expression): ast.SpreadProperty;
|
|
36
|
+
spreadElement(expression: ast.Expression): ast.SpreadElement;
|
|
37
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license
|
|
3
|
+
* Portions Copyright (c) 2013, the Dart project authors.
|
|
4
|
+
*/
|
|
5
|
+
export class DefaultAstFactory {
|
|
6
|
+
empty() {
|
|
7
|
+
return { type: 'Empty' };
|
|
8
|
+
}
|
|
9
|
+
// TODO(justinfagnani): just use a JS literal?
|
|
10
|
+
literal(value) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'Literal',
|
|
13
|
+
value,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
id(value) {
|
|
17
|
+
return {
|
|
18
|
+
type: 'ID',
|
|
19
|
+
value,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
unary(operator, child) {
|
|
23
|
+
return {
|
|
24
|
+
type: 'Unary',
|
|
25
|
+
operator,
|
|
26
|
+
child,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
binary(left, operator, right) {
|
|
30
|
+
return {
|
|
31
|
+
type: 'Binary',
|
|
32
|
+
operator,
|
|
33
|
+
left,
|
|
34
|
+
right,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
getter(receiver, name, optional) {
|
|
38
|
+
return {
|
|
39
|
+
type: 'Getter',
|
|
40
|
+
receiver,
|
|
41
|
+
name,
|
|
42
|
+
optional,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
invoke(receiver, method, args, optional) {
|
|
46
|
+
// TODO(justinfagnani): do this assertion in the parser
|
|
47
|
+
if (args === undefined) {
|
|
48
|
+
throw new Error('args');
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
type: 'Invoke',
|
|
52
|
+
receiver,
|
|
53
|
+
method,
|
|
54
|
+
arguments: args,
|
|
55
|
+
optional,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
paren(child) {
|
|
59
|
+
return {
|
|
60
|
+
type: 'Paren',
|
|
61
|
+
child,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
index(receiver, argument, optional) {
|
|
65
|
+
return {
|
|
66
|
+
type: 'Index',
|
|
67
|
+
receiver,
|
|
68
|
+
argument,
|
|
69
|
+
optional,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
ternary(condition, trueExpr, falseExpr) {
|
|
73
|
+
return {
|
|
74
|
+
type: 'Ternary',
|
|
75
|
+
condition,
|
|
76
|
+
trueExpr,
|
|
77
|
+
falseExpr,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
map(properties) {
|
|
81
|
+
return {
|
|
82
|
+
type: 'Map',
|
|
83
|
+
properties,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
list(items) {
|
|
87
|
+
return {
|
|
88
|
+
type: 'List',
|
|
89
|
+
items,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
property(key, value) {
|
|
93
|
+
return {
|
|
94
|
+
type: 'Property',
|
|
95
|
+
key,
|
|
96
|
+
value,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
arrowFunction(params, body) {
|
|
100
|
+
return {
|
|
101
|
+
type: 'ArrowFunction',
|
|
102
|
+
params,
|
|
103
|
+
body,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
spreadProperty(expression) {
|
|
107
|
+
return {
|
|
108
|
+
type: 'SpreadProperty',
|
|
109
|
+
expression,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
spreadElement(expression) {
|
|
113
|
+
return {
|
|
114
|
+
type: 'SpreadElement',
|
|
115
|
+
expression,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=ast_factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast_factory.js","sourceRoot":"","sources":["../../src/expressions/ast_factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4BH,MAAM,OAAO,iBAAiB;IAC5B,KAAK;QACH,OAAO,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC;IACzB,CAAC;IAED,8CAA8C;IAC9C,OAAO,CAAC,KAAuB;QAC7B,OAAO;YACL,IAAI,EAAE,SAAS;YACf,KAAK;SACN,CAAC;IACJ,CAAC;IAED,EAAE,CAAC,KAAa;QACd,OAAO;YACL,IAAI,EAAE,IAAI;YACV,KAAK;SACN,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAgB,EAAE,KAAqB;QAC3C,OAAO;YACL,IAAI,EAAE,OAAO;YACb,QAAQ;YACR,KAAK;SACN,CAAC;IACJ,CAAC;IAED,MAAM,CACJ,IAAoB,EACpB,QAAgB,EAChB,KAAqB;QAErB,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,QAAQ;YACR,IAAI;YACJ,KAAK;SACN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ACN,IAAI;SACL,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,UAA0B;QACvC,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,UAAU;SACX,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,UAA0B;QACtC,OAAO;YACL,IAAI,EAAE,eAAe;YACrB,UAAU;SACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { assert } from "../test_utils.js";
|
|
2
|
+
import { DefaultAstFactory } from './ast_factory.js';
|
|
3
|
+
describe("DefaultAstFactory", () => {
|
|
4
|
+
let factory;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
factory = new DefaultAstFactory();
|
|
7
|
+
});
|
|
8
|
+
it("should create Literal nodes", () => {
|
|
9
|
+
const node = factory.literal(123);
|
|
10
|
+
assert.deepEqual(node, { type: 'Literal', value: 123 });
|
|
11
|
+
});
|
|
12
|
+
it("should create ID nodes", () => {
|
|
13
|
+
const node = factory.id('myVar');
|
|
14
|
+
assert.deepEqual(node, { type: 'ID', value: 'myVar' });
|
|
15
|
+
});
|
|
16
|
+
it("should create Unary nodes", () => {
|
|
17
|
+
const child = factory.id('x');
|
|
18
|
+
const node = factory.unary('-', child);
|
|
19
|
+
assert.deepEqual(node, { type: 'Unary', operator: '-', child });
|
|
20
|
+
});
|
|
21
|
+
it("should create Binary nodes", () => {
|
|
22
|
+
const left = factory.id('x');
|
|
23
|
+
const right = factory.id('y');
|
|
24
|
+
const node = factory.binary(left, '+', right);
|
|
25
|
+
assert.deepEqual(node, { type: 'Binary', operator: '+', left, right });
|
|
26
|
+
});
|
|
27
|
+
it("should create Getter nodes", () => {
|
|
28
|
+
const receiver = factory.id('obj');
|
|
29
|
+
const node = factory.getter(receiver, 'prop', true);
|
|
30
|
+
assert.deepEqual(node, { type: 'Getter', receiver, name: 'prop', optional: true });
|
|
31
|
+
});
|
|
32
|
+
it("should create Invoke nodes", () => {
|
|
33
|
+
const receiver = factory.id('fn');
|
|
34
|
+
const arg = factory.literal(1);
|
|
35
|
+
const node = factory.invoke(receiver, 'callMe', [arg], true);
|
|
36
|
+
assert.deepEqual(node, { type: 'Invoke', receiver, method: 'callMe', arguments: [arg], optional: true });
|
|
37
|
+
});
|
|
38
|
+
it("should create Index nodes", () => {
|
|
39
|
+
const receiver = factory.id('arr');
|
|
40
|
+
const argument = factory.literal(0);
|
|
41
|
+
const node = factory.index(receiver, argument, true);
|
|
42
|
+
assert.deepEqual(node, { type: 'Index', receiver, argument, optional: true });
|
|
43
|
+
});
|
|
44
|
+
it("should create Ternary nodes", () => {
|
|
45
|
+
const condition = factory.id('x');
|
|
46
|
+
const trueExpr = factory.literal(1);
|
|
47
|
+
const falseExpr = factory.literal(0);
|
|
48
|
+
const node = factory.ternary(condition, trueExpr, falseExpr);
|
|
49
|
+
assert.deepEqual(node, { type: 'Ternary', condition, trueExpr, falseExpr });
|
|
50
|
+
});
|
|
51
|
+
it("should create Map nodes", () => {
|
|
52
|
+
const prop1 = factory.property('a', factory.literal(1));
|
|
53
|
+
const prop2 = factory.spreadProperty(factory.id('obj'));
|
|
54
|
+
const node = factory.map([prop1, prop2]);
|
|
55
|
+
assert.deepEqual(node, { type: 'Map', properties: [prop1, prop2] });
|
|
56
|
+
});
|
|
57
|
+
it("should create List nodes", () => {
|
|
58
|
+
const item1 = factory.literal(1);
|
|
59
|
+
const item2 = factory.spreadElement(factory.id('arr'));
|
|
60
|
+
const node = factory.list([item1, item2]);
|
|
61
|
+
assert.deepEqual(node, { type: 'List', items: [item1, item2] });
|
|
62
|
+
});
|
|
63
|
+
it("should create ArrowFunction nodes", () => {
|
|
64
|
+
const body = factory.binary(factory.id('x'), '+', factory.id('y'));
|
|
65
|
+
const node = factory.arrowFunction(['x', 'y'], body);
|
|
66
|
+
assert.deepEqual(node, { type: 'ArrowFunction', params: ['x', 'y'], body });
|
|
67
|
+
});
|
|
68
|
+
it("should create SpreadProperty nodes", () => {
|
|
69
|
+
const expr = factory.id('obj');
|
|
70
|
+
const node = factory.spreadProperty(expr);
|
|
71
|
+
assert.deepEqual(node, { type: 'SpreadProperty', expression: expr });
|
|
72
|
+
});
|
|
73
|
+
it("should create SpreadElement nodes", () => {
|
|
74
|
+
const expr = factory.id('arr');
|
|
75
|
+
const node = factory.spreadElement(expr);
|
|
76
|
+
assert.deepEqual(node, { type: 'SpreadElement', expression: expr });
|
|
77
|
+
});
|
|
78
|
+
it("should create Property nodes", () => {
|
|
79
|
+
const value = factory.literal(1);
|
|
80
|
+
const node = factory.property('key', value);
|
|
81
|
+
assert.deepEqual(node, { type: 'Property', key: 'key', value });
|
|
82
|
+
});
|
|
83
|
+
it("should create Empty node", () => {
|
|
84
|
+
const node = factory.empty();
|
|
85
|
+
assert.deepEqual(node, { type: 'Empty' });
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=ast_factory.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast_factory.test.js","sourceRoot":"","sources":["../../src/expressions/ast_factory.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,IAAI,OAA0B,CAAC;IAE/B,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,E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AAO,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5C,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const KEYWORDS: Set<string>;
|
|
2
|
+
export declare const WORD_OPERATORS: Set<string>;
|
|
3
|
+
export declare const UNARY_OPERATORS: Set<string>;
|
|
4
|
+
export declare const BINARY_OPERATORS: Set<string>;
|
|
5
|
+
export declare const PRECEDENCE: Record<string, number>;
|
|
6
|
+
export declare const POSTFIX_PRECEDENCE = 13;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license
|
|
3
|
+
* Portions Copyright (c) 2013, the Dart project authors.
|
|
4
|
+
*/
|
|
5
|
+
export const KEYWORDS = new Set(['this', 'typeof']);
|
|
6
|
+
// Word-based operators (alphabetic tokens that are operators, not keywords)
|
|
7
|
+
export const WORD_OPERATORS = new Set(['in']);
|
|
8
|
+
export const UNARY_OPERATORS = new Set(['+', '-', '!', 'typeof']);
|
|
9
|
+
export const BINARY_OPERATORS = new Set([
|
|
10
|
+
'=',
|
|
11
|
+
'+',
|
|
12
|
+
'-',
|
|
13
|
+
'*',
|
|
14
|
+
'/',
|
|
15
|
+
'%',
|
|
16
|
+
'^',
|
|
17
|
+
'==',
|
|
18
|
+
'!=',
|
|
19
|
+
'>',
|
|
20
|
+
'<',
|
|
21
|
+
'>=',
|
|
22
|
+
'<=',
|
|
23
|
+
'||',
|
|
24
|
+
'&&',
|
|
25
|
+
'??',
|
|
26
|
+
'&',
|
|
27
|
+
'===',
|
|
28
|
+
'!==',
|
|
29
|
+
'|',
|
|
30
|
+
'in',
|
|
31
|
+
]);
|
|
32
|
+
export const PRECEDENCE = {
|
|
33
|
+
'!': 0,
|
|
34
|
+
':': 0,
|
|
35
|
+
',': 0,
|
|
36
|
+
')': 0,
|
|
37
|
+
']': 0,
|
|
38
|
+
'}': 0,
|
|
39
|
+
'?': 2,
|
|
40
|
+
'??': 3,
|
|
41
|
+
'||': 4,
|
|
42
|
+
'&&': 5,
|
|
43
|
+
'|': 6,
|
|
44
|
+
'^': 7,
|
|
45
|
+
'&': 8,
|
|
46
|
+
// equality
|
|
47
|
+
'!=': 9,
|
|
48
|
+
'==': 9,
|
|
49
|
+
'!==': 9,
|
|
50
|
+
'===': 9,
|
|
51
|
+
// relational
|
|
52
|
+
'>=': 10,
|
|
53
|
+
'>': 10,
|
|
54
|
+
'<=': 10,
|
|
55
|
+
'<': 10,
|
|
56
|
+
'in': 10,
|
|
57
|
+
// additive
|
|
58
|
+
'+': 11,
|
|
59
|
+
'-': 11,
|
|
60
|
+
// multiplicative
|
|
61
|
+
'%': 12,
|
|
62
|
+
'/': 12,
|
|
63
|
+
'*': 12,
|
|
64
|
+
// postfix
|
|
65
|
+
'(': 13,
|
|
66
|
+
'[': 13,
|
|
67
|
+
'.': 13,
|
|
68
|
+
'?.': 13,
|
|
69
|
+
'{': 13, // not sure this is correct
|
|
70
|
+
};
|
|
71
|
+
export const POSTFIX_PRECEDENCE = 13;
|
|
72
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/expressions/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,QA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P,iBAAiB;IACjB,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IAEP,UAAU;IACV,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IACP,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,GAAG,EAAE,EAAE,EAAE,2BAA2B;CACrC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { assert } from "../test_utils.js";
|
|
2
|
+
import { KEYWORDS, WORD_OPERATORS, UNARY_OPERATORS, BINARY_OPERATORS, PRECEDENCE, POSTFIX_PRECEDENCE, } from './constants.js';
|
|
3
|
+
describe("Expression Constants", () => {
|
|
4
|
+
it("should define KEYWORDS correctly", () => {
|
|
5
|
+
assert.deepEqual(KEYWORDS, new Set(['this', 'typeof']));
|
|
6
|
+
});
|
|
7
|
+
it("should define WORD_OPERATORS correctly", () => {
|
|
8
|
+
assert.deepEqual(WORD_OPERATORS, new Set(['in']));
|
|
9
|
+
});
|
|
10
|
+
it("should define UNARY_OPERATORS correctly", () => {
|
|
11
|
+
assert.deepEqual(UNARY_OPERATORS, new Set(['+', '-', '!', 'typeof']));
|
|
12
|
+
});
|
|
13
|
+
it("should define BINARY_OPERATORS correctly", () => {
|
|
14
|
+
assert.deepEqual(BINARY_OPERATORS, new Set([
|
|
15
|
+
'=',
|
|
16
|
+
'+',
|
|
17
|
+
'-',
|
|
18
|
+
'*',
|
|
19
|
+
'/',
|
|
20
|
+
'%',
|
|
21
|
+
'^',
|
|
22
|
+
'==',
|
|
23
|
+
'!=',
|
|
24
|
+
'>',
|
|
25
|
+
'<',
|
|
26
|
+
'>=',
|
|
27
|
+
'<=',
|
|
28
|
+
'||',
|
|
29
|
+
'&&',
|
|
30
|
+
'??',
|
|
31
|
+
'&',
|
|
32
|
+
'===',
|
|
33
|
+
'!==',
|
|
34
|
+
'|',
|
|
35
|
+
'in',
|
|
36
|
+
]));
|
|
37
|
+
});
|
|
38
|
+
it("should define PRECEDENCE correctly", () => {
|
|
39
|
+
const expectedPrecedence = {
|
|
40
|
+
'!': 0,
|
|
41
|
+
':': 0,
|
|
42
|
+
',': 0,
|
|
43
|
+
')': 0,
|
|
44
|
+
']': 0,
|
|
45
|
+
'}': 0,
|
|
46
|
+
'?': 2,
|
|
47
|
+
'??': 3,
|
|
48
|
+
'||': 4,
|
|
49
|
+
'&&': 5,
|
|
50
|
+
'|': 6,
|
|
51
|
+
'^': 7,
|
|
52
|
+
'&': 8,
|
|
53
|
+
// equality
|
|
54
|
+
'!=': 9,
|
|
55
|
+
'==': 9,
|
|
56
|
+
'!==': 9,
|
|
57
|
+
'===': 9,
|
|
58
|
+
// relational
|
|
59
|
+
'>=': 10,
|
|
60
|
+
'>': 10,
|
|
61
|
+
'<=': 10,
|
|
62
|
+
'<': 10,
|
|
63
|
+
'in': 10,
|
|
64
|
+
// additive
|
|
65
|
+
'+': 11,
|
|
66
|
+
'-': 11,
|
|
67
|
+
// multiplicative
|
|
68
|
+
'%': 12,
|
|
69
|
+
'/': 12,
|
|
70
|
+
'*': 12,
|
|
71
|
+
// postfix
|
|
72
|
+
'(': 13,
|
|
73
|
+
'[': 13,
|
|
74
|
+
'.': 13,
|
|
75
|
+
'?.': 13,
|
|
76
|
+
'{': 13,
|
|
77
|
+
};
|
|
78
|
+
assert.deepEqual(PRECEDENCE, expectedPrecedence);
|
|
79
|
+
});
|
|
80
|
+
it("should define POSTFIX_PRECEDENCE correctly", () => {
|
|
81
|
+
assert.equal(POSTFIX_PRECEDENCE, 13);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=constants.test.js.map
|