@angular-wave/angular.ts 0.0.46 → 0.0.48
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/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/angular.spec.js +1 -2
- package/src/animations/animate-css-driver.js +1 -1
- package/src/animations/animate-queue.js +3 -4
- package/src/animations/animation.js +1 -1
- package/src/animations/raf-scheduler.js +0 -1
- package/src/animations/shared.js +1 -1
- package/src/core/animate/animate.js +0 -1
- package/src/core/compile/compile.spec.js +1 -1
- package/src/core/filter/filter.js +2 -2
- package/src/core/location/location.js +1 -1
- package/src/core/location/location.spec.js +1 -1
- package/src/core/parser/ast-type.js +22 -0
- package/src/core/parser/ast.js +422 -0
- package/src/core/parser/compiler.js +561 -0
- package/src/core/parser/interpreter.js +422 -0
- package/src/core/parser/lexer.js +257 -0
- package/src/core/parser/parse.js +9 -1930
- package/src/core/parser/parse.spec.js +2 -2
- package/src/core/parser/parser.js +39 -0
- package/src/core/parser/shared.js +228 -0
- package/src/core/q/q.spec.js +0 -1
- package/src/core/sce/sce.js +3 -6
- package/src/core/scope/scope.js +19 -11
- package/src/core/task-tracker-factory.js +0 -1
- package/src/directive/attrs/attrs.js +4 -185
- package/src/directive/attrs/attrs.md +224 -0
- package/src/directive/class/class.js +0 -2
- package/src/directive/form/form.js +0 -3
- package/src/directive/include/include.js +1 -1
- package/src/directive/include/include.spec.js +0 -1
- package/src/directive/input/input.js +1 -2
- package/src/directive/model/model.js +1 -3
- package/src/directive/model/model.spec.js +0 -1
- package/src/directive/repeat/repeat.spec.js +0 -2
- package/src/exts/aria/aria.js +0 -1
- package/src/filters/filter.spec.js +0 -1
- package/src/injector.js +1 -1
- package/src/injector.spec.js +0 -5
- package/src/loader.js +0 -5
- package/src/services/cookie-reader.js +0 -1
- package/src/services/http/http.spec.js +0 -2
- package/src/shared/jqlite/jqlite.js +219 -140
- package/src/shared/utils.js +18 -7
- package/src/types.js +10 -0
- package/types/core/parser/ast-type.d.ts +20 -0
- package/types/core/parser/ast.d.ts +78 -0
- package/types/core/parser/compiler.d.ts +49 -0
- package/types/core/parser/interpreter.d.ts +57 -0
- package/types/core/parser/parse.d.ts +79 -0
- package/types/core/parser/parser.d.ts +22 -0
- package/types/core/parser/shared.d.ts +29 -0
- package/types/core/scope/scope.d.ts +9 -2
- package/types/directive/attrs/attrs.d.ts +0 -174
- package/types/shared/jqlite/jqlite.d.ts +33 -4
- package/types/shared/utils.d.ts +18 -5
- package/types/types.d.ts +1 -0
- package/types-back/index.d.ts +0 -12
package/package.json
CHANGED
package/src/angular.spec.js
CHANGED
|
@@ -884,9 +884,8 @@ describe("angular", () => {
|
|
|
884
884
|
merge(dst, src);
|
|
885
885
|
|
|
886
886
|
if (typeof dst.__proto__ !== "undefined") {
|
|
887
|
-
// eslint-disable-line
|
|
888
887
|
// Should not overwrite the __proto__ property or pollute the Object prototype
|
|
889
|
-
expect(dst.__proto__).toBe(Object.prototype);
|
|
888
|
+
expect(dst.__proto__).toBe(Object.prototype);
|
|
890
889
|
}
|
|
891
890
|
expect({}.xxx).toBeUndefined();
|
|
892
891
|
});
|
|
@@ -137,7 +137,7 @@ export const $$AnimateCssDriverProvider = [
|
|
|
137
137
|
|
|
138
138
|
// we iterate directly since safari messes up and doesn't return
|
|
139
139
|
// all the keys for the coords object when iterated
|
|
140
|
-
|
|
140
|
+
["width", "height", "top", "left"].forEach((key) => {
|
|
141
141
|
let value = coords[key];
|
|
142
142
|
switch (key) {
|
|
143
143
|
case "top":
|
|
@@ -54,7 +54,7 @@ export const $$AnimateQueueProvider = [
|
|
|
54
54
|
const keys = classString.split(ONE_SPACE);
|
|
55
55
|
const map = Object.create(null);
|
|
56
56
|
|
|
57
|
-
forEach(
|
|
57
|
+
keys.forEach((key) => {
|
|
58
58
|
map[key] = true;
|
|
59
59
|
});
|
|
60
60
|
return map;
|
|
@@ -248,7 +248,6 @@ export const $$AnimateQueueProvider = [
|
|
|
248
248
|
const contains =
|
|
249
249
|
window.Node.prototype.contains ||
|
|
250
250
|
function (arg) {
|
|
251
|
-
// eslint-disable-next-line no-bitwise
|
|
252
251
|
return this === arg || !!(this.compareDocumentPosition(arg) & 16);
|
|
253
252
|
};
|
|
254
253
|
|
|
@@ -256,7 +255,7 @@ export const $$AnimateQueueProvider = [
|
|
|
256
255
|
const matches = [];
|
|
257
256
|
const entries = callbackRegistry[event];
|
|
258
257
|
if (entries) {
|
|
259
|
-
forEach(
|
|
258
|
+
entries.forEach((entry) => {
|
|
260
259
|
if (contains.call(entry.node, targetNode)) {
|
|
261
260
|
matches.push(entry.callback);
|
|
262
261
|
} else if (
|
|
@@ -694,7 +693,7 @@ export const $$AnimateQueueProvider = [
|
|
|
694
693
|
runInNextPostDigestOrNow(() => {
|
|
695
694
|
const callbacks = findCallbacks(parentNode, node, event);
|
|
696
695
|
if (callbacks.length) {
|
|
697
|
-
forEach(
|
|
696
|
+
callbacks.forEach((callback) => {
|
|
698
697
|
callback(element, phase, data);
|
|
699
698
|
});
|
|
700
699
|
cleanupEventListeners(phase, node);
|
|
@@ -52,7 +52,7 @@ export function $$AnimationProvider() {
|
|
|
52
52
|
|
|
53
53
|
// this is done first beforehand so that the map
|
|
54
54
|
// is filled with a list of the elements that will be animated
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
for (i = 0; i < animations.length; i++) {
|
|
57
57
|
const animation = animations[i];
|
|
58
58
|
lookup.set(
|
package/src/animations/shared.js
CHANGED
|
@@ -96,7 +96,7 @@ export function packageStyles(options) {
|
|
|
96
96
|
|
|
97
97
|
export function pendClasses(classes, fix, isPrefix) {
|
|
98
98
|
let className = "";
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
classes = Array.isArray(classes)
|
|
101
101
|
? classes
|
|
102
102
|
: classes && isString(classes) && classes.length
|
|
@@ -11138,7 +11138,7 @@ describe("$compile", () => {
|
|
|
11138
11138
|
|
|
11139
11139
|
it("should eventually expose isolate scope variables on ES6 class controller with controllerAs when bindToController is true", () => {
|
|
11140
11140
|
var controllerCalled = false;
|
|
11141
|
-
|
|
11141
|
+
|
|
11142
11142
|
var Controller = eval(
|
|
11143
11143
|
"(\n" +
|
|
11144
11144
|
"class Foo {\n" +
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isObject } from "../../shared/utils";
|
|
2
2
|
import { filterFilter } from "../../filters/filter";
|
|
3
3
|
import { jsonFilter } from "../../filters/filters";
|
|
4
4
|
import { limitToFilter } from "../../filters/limit-to";
|
|
@@ -11,7 +11,7 @@ export function $FilterProvider($provide) {
|
|
|
11
11
|
function register(name, factory) {
|
|
12
12
|
if (isObject(name)) {
|
|
13
13
|
const filters = {};
|
|
14
|
-
forEach(
|
|
14
|
+
Object.entries(name).forEach(([key, filter]) => {
|
|
15
15
|
filters[key] = register(key, filter);
|
|
16
16
|
});
|
|
17
17
|
return filters;
|
|
@@ -583,7 +583,7 @@ const locationPrototype = {
|
|
|
583
583
|
} else if (isObject(search)) {
|
|
584
584
|
search = structuredClone(search, {});
|
|
585
585
|
// remove object undefined or null properties
|
|
586
|
-
forEach(
|
|
586
|
+
Object.entries(search).forEach(([key, value]) => {
|
|
587
587
|
if (value == null) delete search[key];
|
|
588
588
|
});
|
|
589
589
|
|
|
@@ -3233,7 +3233,7 @@ describe("$location", () => {
|
|
|
3233
3233
|
expect(
|
|
3234
3234
|
parseLinkAndReturn(locationUrl, "http://server/pre/#otherPath"),
|
|
3235
3235
|
).toEqual("http://server/pre/#/otherPath");
|
|
3236
|
-
|
|
3236
|
+
|
|
3237
3237
|
expect(parseLinkAndReturn(locationUrl, "javascript:void(0)")).toEqual(
|
|
3238
3238
|
undefined,
|
|
3239
3239
|
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {("Program"|"ExpressionStatement"|"AssignmentExpression"|"ConditionalExpression"|"LogicalExpression"|"BinaryExpression"|"UnaryExpression"|"CallExpression"|"MemberExpression"|"Identifier"|"Literal"|"ArrayExpression"|"Property"|"ObjectExpression"|"ThisExpression"|"LocalsExpression"|"NGValueParameter")} ASTType
|
|
3
|
+
*/
|
|
4
|
+
export const ASTType = {
|
|
5
|
+
Program: "Program",
|
|
6
|
+
ExpressionStatement: "ExpressionStatement",
|
|
7
|
+
AssignmentExpression: "AssignmentExpression",
|
|
8
|
+
ConditionalExpression: "ConditionalExpression",
|
|
9
|
+
LogicalExpression: "LogicalExpression",
|
|
10
|
+
BinaryExpression: "BinaryExpression",
|
|
11
|
+
UnaryExpression: "UnaryExpression",
|
|
12
|
+
CallExpression: "CallExpression",
|
|
13
|
+
MemberExpression: "MemberExpression",
|
|
14
|
+
Identifier: "Identifier",
|
|
15
|
+
Literal: "Literal",
|
|
16
|
+
ArrayExpression: "ArrayExpression",
|
|
17
|
+
Property: "Property",
|
|
18
|
+
ObjectExpression: "ObjectExpression",
|
|
19
|
+
ThisExpression: "ThisExpression",
|
|
20
|
+
LocalsExpression: "LocalsExpression",
|
|
21
|
+
NGValueParameter: "NGValueParameter",
|
|
22
|
+
};
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
import { $parseMinErr } from "./parse";
|
|
2
|
+
import { isAssignable } from "./shared";
|
|
3
|
+
import { ASTType } from "./ast-type";
|
|
4
|
+
|
|
5
|
+
export function AST(lexer, options) {
|
|
6
|
+
this.lexer = lexer;
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
AST.prototype = {
|
|
11
|
+
ast(text) {
|
|
12
|
+
this.text = text;
|
|
13
|
+
this.tokens = this.lexer.lex(text);
|
|
14
|
+
|
|
15
|
+
const value = this.program();
|
|
16
|
+
|
|
17
|
+
if (this.tokens.length !== 0) {
|
|
18
|
+
this.throwError("is an unexpected token", this.tokens[0]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return value;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
program() {
|
|
25
|
+
const body = [];
|
|
26
|
+
let hasMore = true;
|
|
27
|
+
while (hasMore) {
|
|
28
|
+
if (this.tokens.length > 0 && !this.peek("}", ")", ";", "]"))
|
|
29
|
+
body.push(this.expressionStatement());
|
|
30
|
+
if (!this.expect(";")) {
|
|
31
|
+
hasMore = false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return { type: ASTType.Program, body };
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
expressionStatement() {
|
|
38
|
+
return {
|
|
39
|
+
type: ASTType.ExpressionStatement,
|
|
40
|
+
expression: this.filterChain(),
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
filterChain() {
|
|
45
|
+
let left = this.expression();
|
|
46
|
+
while (this.expect("|")) {
|
|
47
|
+
left = this.filter(left);
|
|
48
|
+
}
|
|
49
|
+
return left;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
expression() {
|
|
53
|
+
return this.assignment();
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
assignment() {
|
|
57
|
+
let result = this.ternary();
|
|
58
|
+
if (this.expect("=")) {
|
|
59
|
+
if (!isAssignable(result)) {
|
|
60
|
+
throw $parseMinErr("lval", "Trying to assign a value to a non l-value");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
result = {
|
|
64
|
+
type: ASTType.AssignmentExpression,
|
|
65
|
+
left: result,
|
|
66
|
+
right: this.assignment(),
|
|
67
|
+
operator: "=",
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
ternary() {
|
|
74
|
+
const test = this.logicalOR();
|
|
75
|
+
let alternate;
|
|
76
|
+
let consequent;
|
|
77
|
+
if (this.expect("?")) {
|
|
78
|
+
alternate = this.expression();
|
|
79
|
+
if (this.consume(":")) {
|
|
80
|
+
consequent = this.expression();
|
|
81
|
+
return {
|
|
82
|
+
type: ASTType.ConditionalExpression,
|
|
83
|
+
test,
|
|
84
|
+
alternate,
|
|
85
|
+
consequent,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return test;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
logicalOR() {
|
|
93
|
+
let left = this.logicalAND();
|
|
94
|
+
while (this.expect("||")) {
|
|
95
|
+
left = {
|
|
96
|
+
type: ASTType.LogicalExpression,
|
|
97
|
+
operator: "||",
|
|
98
|
+
left,
|
|
99
|
+
right: this.logicalAND(),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return left;
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
logicalAND() {
|
|
106
|
+
let left = this.equality();
|
|
107
|
+
while (this.expect("&&")) {
|
|
108
|
+
left = {
|
|
109
|
+
type: ASTType.LogicalExpression,
|
|
110
|
+
operator: "&&",
|
|
111
|
+
left,
|
|
112
|
+
right: this.equality(),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return left;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
equality() {
|
|
119
|
+
let left = this.relational();
|
|
120
|
+
let token;
|
|
121
|
+
while ((token = this.expect("==", "!=", "===", "!=="))) {
|
|
122
|
+
left = {
|
|
123
|
+
type: ASTType.BinaryExpression,
|
|
124
|
+
operator: token.text,
|
|
125
|
+
left,
|
|
126
|
+
right: this.relational(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return left;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
relational() {
|
|
133
|
+
let left = this.additive();
|
|
134
|
+
let token;
|
|
135
|
+
while ((token = this.expect("<", ">", "<=", ">="))) {
|
|
136
|
+
left = {
|
|
137
|
+
type: ASTType.BinaryExpression,
|
|
138
|
+
operator: token.text,
|
|
139
|
+
left,
|
|
140
|
+
right: this.additive(),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return left;
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
additive() {
|
|
147
|
+
let left = this.multiplicative();
|
|
148
|
+
let token;
|
|
149
|
+
while ((token = this.expect("+", "-"))) {
|
|
150
|
+
left = {
|
|
151
|
+
type: ASTType.BinaryExpression,
|
|
152
|
+
operator: token.text,
|
|
153
|
+
left,
|
|
154
|
+
right: this.multiplicative(),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return left;
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
multiplicative() {
|
|
161
|
+
let left = this.unary();
|
|
162
|
+
let token;
|
|
163
|
+
while ((token = this.expect("*", "/", "%"))) {
|
|
164
|
+
left = {
|
|
165
|
+
type: ASTType.BinaryExpression,
|
|
166
|
+
operator: token.text,
|
|
167
|
+
left,
|
|
168
|
+
right: this.unary(),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return left;
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
unary() {
|
|
175
|
+
let token;
|
|
176
|
+
if ((token = this.expect("+", "-", "!"))) {
|
|
177
|
+
return {
|
|
178
|
+
type: ASTType.UnaryExpression,
|
|
179
|
+
operator: token.text,
|
|
180
|
+
prefix: true,
|
|
181
|
+
argument: this.unary(),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return this.primary();
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
primary() {
|
|
188
|
+
let primary;
|
|
189
|
+
if (this.expect("(")) {
|
|
190
|
+
primary = this.filterChain();
|
|
191
|
+
this.consume(")");
|
|
192
|
+
} else if (this.expect("[")) {
|
|
193
|
+
primary = this.arrayDeclaration();
|
|
194
|
+
} else if (this.expect("{")) {
|
|
195
|
+
primary = this.object();
|
|
196
|
+
} else if (
|
|
197
|
+
Object.prototype.hasOwnProperty.call(
|
|
198
|
+
this.selfReferential,
|
|
199
|
+
this.peek().text,
|
|
200
|
+
)
|
|
201
|
+
) {
|
|
202
|
+
primary = structuredClone(this.selfReferential[this.consume().text]);
|
|
203
|
+
} else if (
|
|
204
|
+
Object.prototype.hasOwnProperty.call(
|
|
205
|
+
this.options.literals,
|
|
206
|
+
this.peek().text,
|
|
207
|
+
)
|
|
208
|
+
) {
|
|
209
|
+
primary = {
|
|
210
|
+
type: ASTType.Literal,
|
|
211
|
+
value: this.options.literals[this.consume().text],
|
|
212
|
+
};
|
|
213
|
+
} else if (this.peek().identifier) {
|
|
214
|
+
primary = this.identifier();
|
|
215
|
+
} else if (this.peek().constant) {
|
|
216
|
+
primary = this.constant();
|
|
217
|
+
} else {
|
|
218
|
+
this.throwError("not a primary expression", this.peek());
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let next;
|
|
222
|
+
while ((next = this.expect("(", "[", "."))) {
|
|
223
|
+
if (next.text === "(") {
|
|
224
|
+
primary = {
|
|
225
|
+
type: ASTType.CallExpression,
|
|
226
|
+
callee: primary,
|
|
227
|
+
arguments: this.parseArguments(),
|
|
228
|
+
};
|
|
229
|
+
this.consume(")");
|
|
230
|
+
} else if (next.text === "[") {
|
|
231
|
+
primary = {
|
|
232
|
+
type: ASTType.MemberExpression,
|
|
233
|
+
object: primary,
|
|
234
|
+
property: this.expression(),
|
|
235
|
+
computed: true,
|
|
236
|
+
};
|
|
237
|
+
this.consume("]");
|
|
238
|
+
} else if (next.text === ".") {
|
|
239
|
+
primary = {
|
|
240
|
+
type: ASTType.MemberExpression,
|
|
241
|
+
object: primary,
|
|
242
|
+
property: this.identifier(),
|
|
243
|
+
computed: false,
|
|
244
|
+
};
|
|
245
|
+
} else {
|
|
246
|
+
this.throwError("IMPOSSIBLE");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return primary;
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
filter(baseExpression) {
|
|
253
|
+
const args = [baseExpression];
|
|
254
|
+
const result = {
|
|
255
|
+
type: ASTType.CallExpression,
|
|
256
|
+
callee: this.identifier(),
|
|
257
|
+
arguments: args,
|
|
258
|
+
filter: true,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
while (this.expect(":")) {
|
|
262
|
+
args.push(this.expression());
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return result;
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
parseArguments() {
|
|
269
|
+
const args = [];
|
|
270
|
+
if (this.peekToken().text !== ")") {
|
|
271
|
+
do {
|
|
272
|
+
args.push(this.filterChain());
|
|
273
|
+
} while (this.expect(","));
|
|
274
|
+
}
|
|
275
|
+
return args;
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
identifier() {
|
|
279
|
+
const token = this.consume();
|
|
280
|
+
if (!token.identifier) {
|
|
281
|
+
this.throwError("is not a valid identifier", token);
|
|
282
|
+
}
|
|
283
|
+
return { type: ASTType.Identifier, name: token.text };
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
constant() {
|
|
287
|
+
// TODO check that it is a constant
|
|
288
|
+
return { type: ASTType.Literal, value: this.consume().value };
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
arrayDeclaration() {
|
|
292
|
+
const elements = [];
|
|
293
|
+
if (this.peekToken().text !== "]") {
|
|
294
|
+
do {
|
|
295
|
+
if (this.peek("]")) {
|
|
296
|
+
// Support trailing commas per ES5.1.
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
elements.push(this.expression());
|
|
300
|
+
} while (this.expect(","));
|
|
301
|
+
}
|
|
302
|
+
this.consume("]");
|
|
303
|
+
|
|
304
|
+
return { type: ASTType.ArrayExpression, elements };
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
object() {
|
|
308
|
+
const properties = [];
|
|
309
|
+
let property;
|
|
310
|
+
if (this.peekToken().text !== "}") {
|
|
311
|
+
do {
|
|
312
|
+
if (this.peek("}")) {
|
|
313
|
+
// Support trailing commas per ES5.1.
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
property = { type: ASTType.Property, kind: "init" };
|
|
317
|
+
if (this.peek().constant) {
|
|
318
|
+
property.key = this.constant();
|
|
319
|
+
property.computed = false;
|
|
320
|
+
this.consume(":");
|
|
321
|
+
property.value = this.expression();
|
|
322
|
+
} else if (this.peek().identifier) {
|
|
323
|
+
property.key = this.identifier();
|
|
324
|
+
property.computed = false;
|
|
325
|
+
if (this.peek(":")) {
|
|
326
|
+
this.consume(":");
|
|
327
|
+
property.value = this.expression();
|
|
328
|
+
} else {
|
|
329
|
+
property.value = property.key;
|
|
330
|
+
}
|
|
331
|
+
} else if (this.peek("[")) {
|
|
332
|
+
this.consume("[");
|
|
333
|
+
property.key = this.expression();
|
|
334
|
+
this.consume("]");
|
|
335
|
+
property.computed = true;
|
|
336
|
+
this.consume(":");
|
|
337
|
+
property.value = this.expression();
|
|
338
|
+
} else {
|
|
339
|
+
this.throwError("invalid key", this.peek());
|
|
340
|
+
}
|
|
341
|
+
properties.push(property);
|
|
342
|
+
} while (this.expect(","));
|
|
343
|
+
}
|
|
344
|
+
this.consume("}");
|
|
345
|
+
|
|
346
|
+
return { type: ASTType.ObjectExpression, properties };
|
|
347
|
+
},
|
|
348
|
+
|
|
349
|
+
throwError(msg, token) {
|
|
350
|
+
throw $parseMinErr(
|
|
351
|
+
"syntax",
|
|
352
|
+
"Syntax Error: Token '{0}' {1} at column {2} of the expression [{3}] starting at [{4}].",
|
|
353
|
+
token.text,
|
|
354
|
+
msg,
|
|
355
|
+
token.index + 1,
|
|
356
|
+
this.text,
|
|
357
|
+
this.text.substring(token.index),
|
|
358
|
+
);
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
consume(e1) {
|
|
362
|
+
if (this.tokens.length === 0) {
|
|
363
|
+
throw $parseMinErr(
|
|
364
|
+
"ueoe",
|
|
365
|
+
"Unexpected end of expression: {0}",
|
|
366
|
+
this.text,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const token = this.expect(e1);
|
|
371
|
+
if (!token) {
|
|
372
|
+
this.throwError(`is unexpected, expecting [${e1}]`, this.peek());
|
|
373
|
+
}
|
|
374
|
+
return token;
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
peekToken() {
|
|
378
|
+
if (this.tokens.length === 0) {
|
|
379
|
+
throw $parseMinErr(
|
|
380
|
+
"ueoe",
|
|
381
|
+
"Unexpected end of expression: {0}",
|
|
382
|
+
this.text,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
return this.tokens[0];
|
|
386
|
+
},
|
|
387
|
+
|
|
388
|
+
peek(e1, e2, e3, e4) {
|
|
389
|
+
return this.peekAhead(0, e1, e2, e3, e4);
|
|
390
|
+
},
|
|
391
|
+
|
|
392
|
+
peekAhead(i, e1, e2, e3, e4) {
|
|
393
|
+
if (this.tokens.length > i) {
|
|
394
|
+
const token = this.tokens[i];
|
|
395
|
+
const t = token.text;
|
|
396
|
+
if (
|
|
397
|
+
t === e1 ||
|
|
398
|
+
t === e2 ||
|
|
399
|
+
t === e3 ||
|
|
400
|
+
t === e4 ||
|
|
401
|
+
(!e1 && !e2 && !e3 && !e4)
|
|
402
|
+
) {
|
|
403
|
+
return token;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return false;
|
|
407
|
+
},
|
|
408
|
+
|
|
409
|
+
expect(e1, e2, e3, e4) {
|
|
410
|
+
const token = this.peek(e1, e2, e3, e4);
|
|
411
|
+
if (token) {
|
|
412
|
+
this.tokens.shift();
|
|
413
|
+
return token;
|
|
414
|
+
}
|
|
415
|
+
return false;
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
selfReferential: {
|
|
419
|
+
this: { type: ASTType.ThisExpression },
|
|
420
|
+
$locals: { type: ASTType.LocalsExpression },
|
|
421
|
+
},
|
|
422
|
+
};
|