@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
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { AST } from "./ast";
|
|
2
|
-
import {
|
|
2
|
+
import { ASTType } from "./ast-type";
|
|
3
3
|
import { ASTInterpreter } from "./interpreter";
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} ParsedAST
|
|
7
|
+
* @property {import("./ast").ASTNode} ast - AST representation of expression
|
|
8
|
+
* @property {boolean} oneTime - True if expression should be evaluated only once
|
|
9
|
+
*/
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* @constructor
|
|
@@ -10,18 +15,23 @@ export class Parser {
|
|
|
10
15
|
/**
|
|
11
16
|
*
|
|
12
17
|
* @param {import('./lexer').Lexer} lexer
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {*} options
|
|
18
|
+
* @param {function(any):any} $filter
|
|
15
19
|
*/
|
|
16
|
-
constructor(lexer, $filter
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
constructor(lexer, $filter) {
|
|
21
|
+
/** @type {AST} */
|
|
22
|
+
this.ast = new AST(lexer);
|
|
23
|
+
|
|
24
|
+
/** @type {ASTInterpreter} */
|
|
25
|
+
this.astCompiler = new ASTInterpreter($filter);
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param {string} exp - Expression to be parsed
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
parse(exp) {
|
|
34
|
+
const { ast, oneTime } = this.getAst(exp);
|
|
25
35
|
const fn = this.astCompiler.compile(ast);
|
|
26
36
|
fn.literal = isLiteral(ast);
|
|
27
37
|
fn.constant = isConstant(ast);
|
|
@@ -29,6 +39,10 @@ export class Parser {
|
|
|
29
39
|
return fn;
|
|
30
40
|
}
|
|
31
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} exp - Expression to be parsed
|
|
44
|
+
* @returns {ParsedAST}
|
|
45
|
+
*/
|
|
32
46
|
getAst(exp) {
|
|
33
47
|
let oneTime = false;
|
|
34
48
|
exp = exp.trim();
|
|
@@ -43,3 +57,17 @@ export class Parser {
|
|
|
43
57
|
};
|
|
44
58
|
}
|
|
45
59
|
}
|
|
60
|
+
|
|
61
|
+
function isLiteral(ast) {
|
|
62
|
+
return (
|
|
63
|
+
ast.body.length === 0 ||
|
|
64
|
+
(ast.body.length === 1 &&
|
|
65
|
+
(ast.body[0].expression.type === ASTType.Literal ||
|
|
66
|
+
ast.body[0].expression.type === ASTType.ArrayExpression ||
|
|
67
|
+
ast.body[0].expression.type === ASTType.ObjectExpression))
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isConstant(ast) {
|
|
72
|
+
return ast.constant;
|
|
73
|
+
}
|
package/src/directive/csp.md
CHANGED
|
@@ -18,12 +18,6 @@
|
|
|
18
18
|
-
|
|
19
19
|
- The following default rules in CSP affect AngularJS:
|
|
20
20
|
-
|
|
21
|
-
- - The use of `eval()`, `Function(string)` and similar functions to dynamically create and execute
|
|
22
|
-
- code from strings is forbidden. AngularJS makes use of this in the {@link $parse} service to
|
|
23
|
-
- provide a 30% increase in the speed of evaluating AngularJS expressions. (This CSP rule can be
|
|
24
|
-
- disabled with the CSP keyword `unsafe-eval`, but it is generally not recommended as it would
|
|
25
|
-
- weaken the protections offered by CSP.)
|
|
26
|
-
-
|
|
27
21
|
- - The use of inline resources, such as inline `<script>` and `<style>` elements, are forbidden.
|
|
28
22
|
- This prevents apps from injecting custom styles directly into the document. AngularJS makes use of
|
|
29
23
|
- this to include some CSS rules (e.g. {@link ngCloak} and {@link ngHide}). To make these
|
|
@@ -31,22 +25,6 @@
|
|
|
31
25
|
- in your HTML manually. (This CSP rule can be disabled with the CSP keyword `unsafe-inline`, but
|
|
32
26
|
- it is generally not recommended as it would weaken the protections offered by CSP.)
|
|
33
27
|
-
|
|
34
|
-
- If you do not provide `ngCsp` then AngularJS tries to autodetect if CSP is blocking dynamic code
|
|
35
|
-
- creation from strings (e.g., `unsafe-eval` not specified in CSP header) and automatically
|
|
36
|
-
- deactivates this feature in the {@link $parse} service. This autodetection, however, triggers a
|
|
37
|
-
- CSP error to be logged in the console:
|
|
38
|
-
-
|
|
39
|
-
- ```
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
- Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of
|
|
44
|
-
- script in the following Content Security Policy directive: "default-src 'self'". Note that
|
|
45
|
-
- 'script-src' was not explicitly set, so 'default-src' is used as a fallback.
|
|
46
|
-
- ```
|
|
47
|
-
|
|
48
|
-
```
|
|
49
|
-
|
|
50
28
|
-
|
|
51
29
|
- This error is harmless but annoying. To prevent the error from showing up, put the `ngCsp`
|
|
52
30
|
- directive on an element of the HTML document that appears before the `<script>` tag that loads
|
|
@@ -59,7 +37,6 @@
|
|
|
59
37
|
-
|
|
60
38
|
- - no-inline-style: this stops AngularJS from injecting CSS styles into the DOM
|
|
61
39
|
-
|
|
62
|
-
- - no-unsafe-eval: this stops AngularJS from optimizing $parse with unsafe eval of strings
|
|
63
40
|
-
|
|
64
41
|
- You can use these values in the following combinations:
|
|
65
42
|
-
|
|
@@ -72,9 +49,6 @@
|
|
|
72
49
|
- styles and unsafe eval. E.g. `<body ng-csp>`. This is backwardly compatible with previous
|
|
73
50
|
- versions of AngularJS.
|
|
74
51
|
-
|
|
75
|
-
- - Specifying only `no-unsafe-eval` tells AngularJS that we must not use eval, but that we can
|
|
76
|
-
- inject inline styles. E.g. `<body ng-csp="no-unsafe-eval">`.
|
|
77
|
-
-
|
|
78
52
|
- - Specifying only `no-inline-style` tells AngularJS that we must not inject styles, but that we can
|
|
79
53
|
- run eval - no automatic check for unsafe eval will occur. E.g. `<body ng-csp="no-inline-style">`
|
|
80
54
|
-
|
package/src/loader.js
CHANGED
|
@@ -112,6 +112,9 @@ export class Angular {
|
|
|
112
112
|
|
|
113
113
|
/** @type {errorHandlingConfig} */
|
|
114
114
|
this.errorHandlingConfig = errorHandlingConfig;
|
|
115
|
+
|
|
116
|
+
/** @type {Function} */
|
|
117
|
+
this.doBootstrap;
|
|
115
118
|
}
|
|
116
119
|
|
|
117
120
|
/**
|
|
@@ -171,13 +174,14 @@ export class Angular {
|
|
|
171
174
|
* * `strictDi` - disable automatic function annotation for the application. This is meant to
|
|
172
175
|
* assist in finding bugs which break minified code. Defaults to `false`.
|
|
173
176
|
*
|
|
174
|
-
* @returns {
|
|
177
|
+
* @returns {any} InjectorService - Returns the newly created injector for this app.
|
|
175
178
|
*/
|
|
176
179
|
bootstrap(element, modules, config) {
|
|
177
180
|
config = config || {
|
|
178
181
|
debugInfoEnabled: false,
|
|
179
182
|
strictDi: false,
|
|
180
183
|
};
|
|
184
|
+
|
|
181
185
|
this.doBootstrap = function () {
|
|
182
186
|
// @ts-ignore
|
|
183
187
|
element = JQLite(element);
|
|
@@ -366,7 +366,7 @@ JQLite.prototype.removeData = function (name) {
|
|
|
366
366
|
/**
|
|
367
367
|
* Gets or sets data on a parent element
|
|
368
368
|
* @param {string} name
|
|
369
|
-
* @param {any} value
|
|
369
|
+
* @param {any} [value]
|
|
370
370
|
* @returns {JQLite|any}
|
|
371
371
|
*/
|
|
372
372
|
JQLite.prototype.inheritedData = function (name, value) {
|
|
@@ -383,7 +383,7 @@ JQLite.prototype.inheritedData = function (name, value) {
|
|
|
383
383
|
|
|
384
384
|
/**
|
|
385
385
|
* Gets or sets innerHTML on the first element in JQLite collection
|
|
386
|
-
* @param {string} value
|
|
386
|
+
* @param {string} [value]
|
|
387
387
|
* @returns {JQLite|any|undefined}
|
|
388
388
|
*/
|
|
389
389
|
JQLite.prototype.html = function (value) {
|
package/src/types.js
CHANGED
|
@@ -11,16 +11,6 @@
|
|
|
11
11
|
* @template T
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {Object|function(any, any=): any} CompiledExpression
|
|
16
|
-
* @property {boolean} literal - Indicates if the expression is a literal.
|
|
17
|
-
* @property {boolean} constant - Indicates if the expression is constant.
|
|
18
|
-
* @property {function(any, any): any} assign - Assigns a value to a context. If value is not provided,
|
|
19
|
-
* undefined is gonna be used since the implementation
|
|
20
|
-
* does not check the parameter. Let's force a value for consistency. If consumer
|
|
21
|
-
* wants to undefine it, pass the undefined value explicitly.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
14
|
/**
|
|
25
15
|
* @typedef {Object} ComponentOptions
|
|
26
16
|
* @description Component definition object (a simplified directive definition object)
|
|
@@ -41,7 +41,7 @@ export let TRANSITIONEND_EVENT: any;
|
|
|
41
41
|
export let ANIMATION_PROP: any;
|
|
42
42
|
export let ANIMATIONEND_EVENT: any;
|
|
43
43
|
export const DURATION_KEY: "Duration";
|
|
44
|
-
export const PROPERTY_KEY:
|
|
44
|
+
export const PROPERTY_KEY: 13;
|
|
45
45
|
export const DELAY_KEY: "Delay";
|
|
46
46
|
export const TIMING_KEY: "TimingFunction";
|
|
47
47
|
export const ANIMATION_ITERATION_COUNT_KEY: "IterationCount";
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
export type ASTType =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
export type ASTType = number;
|
|
2
|
+
/**
|
|
3
|
+
* @readonly
|
|
4
|
+
* @enum {number}
|
|
5
|
+
*/
|
|
6
|
+
export const ASTType: Readonly<{
|
|
7
|
+
Program: 1;
|
|
8
|
+
ExpressionStatement: 2;
|
|
9
|
+
AssignmentExpression: 3;
|
|
10
|
+
ConditionalExpression: 4;
|
|
11
|
+
LogicalExpression: 5;
|
|
12
|
+
BinaryExpression: 6;
|
|
13
|
+
UnaryExpression: 7;
|
|
14
|
+
CallExpression: 8;
|
|
15
|
+
MemberExpression: 9;
|
|
16
|
+
Identifier: 10;
|
|
17
|
+
Literal: 11;
|
|
18
|
+
ArrayExpression: 12;
|
|
19
|
+
Property: 13;
|
|
20
|
+
ObjectExpression: 14;
|
|
21
|
+
ThisExpression: 15;
|
|
22
|
+
LocalsExpression: 16;
|
|
23
|
+
NGValueParameter: 17;
|
|
24
|
+
}>;
|
|
@@ -1,86 +1,279 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @
|
|
2
|
+
* @typedef {Object} ASTNode
|
|
3
|
+
* @property {number} type - The type of the AST node.
|
|
4
|
+
* @property {string} [name] - The name of the identifier.
|
|
5
|
+
* @property {string} [kind] - The kind of the property (e.g., 'init').
|
|
6
|
+
* @property {*} [value] - The value of the node if it is a literal.
|
|
7
|
+
* @property {ASTNode[]} [elements] - The elements of an array node.
|
|
8
|
+
* @property {ASTNode[]} [properties] - The properties of an object node.
|
|
9
|
+
* @property {ASTNode} [key] - The key of an object property.
|
|
10
|
+
* @property {ASTNode} [value] - The value of an object property.
|
|
11
|
+
* @property {ASTNode} [left] - The left-hand side of a binary expression.
|
|
12
|
+
* @property {ASTNode} [right] - The right-hand side of a binary expression.
|
|
13
|
+
* @property {ASTNode} [argument] - The argument of a unary expression.
|
|
14
|
+
* @property {ASTNode} [test] - The test expression of a conditional expression.
|
|
15
|
+
* @property {ASTNode} [alternate] - The alternate expression of a conditional expression.
|
|
16
|
+
* @property {ASTNode} [consequent] - The consequent expression of a conditional expression.
|
|
17
|
+
* @property {ASTNode[]} [body] - The body of a program or block statement.
|
|
18
|
+
* @property {ASTNode} [expression] - The expression of an expression statement.
|
|
19
|
+
* @property {ASTNode} [callee] - The callee of a call expression.
|
|
20
|
+
* @property {ASTNode[]} [arguments] - The arguments of a call expression.
|
|
21
|
+
* @property {boolean} [prefix] - Indicates if a unary operator is a prefix.
|
|
22
|
+
* @property {ASTNode} [object] - The object of a member expression.
|
|
23
|
+
* @property {ASTNode} [property] - The property of a member expression.
|
|
24
|
+
* @property {boolean} [computed] - Indicates if a member expression is computed.
|
|
25
|
+
* @property {string} [operator] - The operator of a binary or logical expression.
|
|
26
|
+
* @property {boolean} [filter]
|
|
27
|
+
*/
|
|
28
|
+
/** @type {Map<string,any>} */
|
|
29
|
+
export const literals: Map<string, any>;
|
|
30
|
+
/**
|
|
31
|
+
* @class
|
|
4
32
|
*/
|
|
5
|
-
export function AST(lexer: import("./lexer").Lexer, options: any): void;
|
|
6
33
|
export class AST {
|
|
7
34
|
/**
|
|
8
|
-
* @param {import('./lexer').Lexer} lexer
|
|
9
|
-
* @param {*} options
|
|
35
|
+
* @param {import('./lexer').Lexer} lexer - The lexer instance for tokenizing input
|
|
10
36
|
*/
|
|
11
|
-
constructor(lexer: import("./lexer").Lexer
|
|
37
|
+
constructor(lexer: import("./lexer").Lexer);
|
|
38
|
+
/** @type {import('./lexer').Lexer} */
|
|
12
39
|
lexer: import("./lexer").Lexer;
|
|
13
|
-
options: any;
|
|
14
|
-
ast(text: any): {
|
|
15
|
-
type: string;
|
|
16
|
-
body: {
|
|
17
|
-
type: string;
|
|
18
|
-
expression: any;
|
|
19
|
-
}[];
|
|
20
|
-
};
|
|
21
|
-
text: any;
|
|
22
|
-
tokens: import("./lexer").Token[];
|
|
23
|
-
program(): {
|
|
24
|
-
type: string;
|
|
25
|
-
body: {
|
|
26
|
-
type: string;
|
|
27
|
-
expression: any;
|
|
28
|
-
}[];
|
|
29
|
-
};
|
|
30
|
-
expressionStatement(): {
|
|
31
|
-
type: string;
|
|
32
|
-
expression: any;
|
|
33
|
-
};
|
|
34
|
-
filterChain(): any;
|
|
35
|
-
expression(): any;
|
|
36
|
-
assignment(): any;
|
|
37
|
-
ternary(): any;
|
|
38
|
-
logicalOR(): any;
|
|
39
|
-
logicalAND(): any;
|
|
40
|
-
equality(): any;
|
|
41
|
-
relational(): any;
|
|
42
|
-
additive(): any;
|
|
43
|
-
multiplicative(): any;
|
|
44
|
-
unary(): any;
|
|
45
|
-
primary(): any;
|
|
46
|
-
filter(baseExpression: any): {
|
|
47
|
-
type: string;
|
|
48
|
-
callee: {
|
|
49
|
-
type: string;
|
|
50
|
-
name: any;
|
|
51
|
-
};
|
|
52
|
-
arguments: any[];
|
|
53
|
-
filter: boolean;
|
|
54
|
-
};
|
|
55
|
-
parseArguments(): any;
|
|
56
|
-
identifier(): {
|
|
57
|
-
type: string;
|
|
58
|
-
name: any;
|
|
59
|
-
};
|
|
60
|
-
constant(): {
|
|
61
|
-
type: string;
|
|
62
|
-
value: any;
|
|
63
|
-
};
|
|
64
|
-
arrayDeclaration(): any;
|
|
65
|
-
object(): {
|
|
66
|
-
type: string;
|
|
67
|
-
properties: {
|
|
68
|
-
type: string;
|
|
69
|
-
kind: string;
|
|
70
|
-
}[];
|
|
71
|
-
};
|
|
72
|
-
throwError(msg: any, token: any): never;
|
|
73
|
-
consume(e1: any): false | import("./lexer").Token;
|
|
74
|
-
peekToken(): import("./lexer").Token;
|
|
75
|
-
peek(e1: any, e2: any, e3: any, e4: any): false | import("./lexer").Token;
|
|
76
|
-
peekAhead(i: any, e1: any, e2: any, e3: any, e4: any): false | import("./lexer").Token;
|
|
77
|
-
expect(e1: any, e2: any, e3: any, e4: any): false | import("./lexer").Token;
|
|
78
40
|
selfReferential: {
|
|
79
41
|
this: {
|
|
80
|
-
type:
|
|
42
|
+
type: 15;
|
|
81
43
|
};
|
|
82
44
|
$locals: {
|
|
83
|
-
type:
|
|
45
|
+
type: 16;
|
|
84
46
|
};
|
|
85
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Parses the input text and generates an AST.
|
|
50
|
+
* @param {string} text - The input text to parse.
|
|
51
|
+
* @returns {ASTNode} The root node of the AST.
|
|
52
|
+
*/
|
|
53
|
+
ast(text: string): ASTNode;
|
|
54
|
+
text: string;
|
|
55
|
+
tokens: import("./lexer").Token[];
|
|
56
|
+
/**
|
|
57
|
+
* Parses a program.
|
|
58
|
+
* @returns {ASTNode} The program node.
|
|
59
|
+
*/
|
|
60
|
+
program(): ASTNode;
|
|
61
|
+
/**
|
|
62
|
+
* Parses an expression statement.
|
|
63
|
+
* @returns {ASTNode} The expression statement node.
|
|
64
|
+
*/
|
|
65
|
+
expressionStatement(): ASTNode;
|
|
66
|
+
/**
|
|
67
|
+
* Parses a filter chain.
|
|
68
|
+
* @returns {ASTNode} The filter chain node.
|
|
69
|
+
*/
|
|
70
|
+
filterChain(): ASTNode;
|
|
71
|
+
/**
|
|
72
|
+
* Parses an assignment expression.
|
|
73
|
+
* @returns {ASTNode} The assignment expression node.
|
|
74
|
+
*/
|
|
75
|
+
assignment(): ASTNode;
|
|
76
|
+
/**
|
|
77
|
+
* Parses a ternary expression.
|
|
78
|
+
* @returns {ASTNode} The ternary expression node.
|
|
79
|
+
*/
|
|
80
|
+
ternary(): ASTNode;
|
|
81
|
+
/**
|
|
82
|
+
* Parses a logical OR expression.
|
|
83
|
+
* @returns {ASTNode} The logical OR expression node.
|
|
84
|
+
*/
|
|
85
|
+
logicalOR(): ASTNode;
|
|
86
|
+
/**
|
|
87
|
+
* Parses a logical AND expression.
|
|
88
|
+
* @returns {ASTNode} The logical AND expression node.
|
|
89
|
+
*/
|
|
90
|
+
logicalAND(): ASTNode;
|
|
91
|
+
/**
|
|
92
|
+
* Parses an equality expression.
|
|
93
|
+
* @returns {ASTNode} The equality expression node.
|
|
94
|
+
*/
|
|
95
|
+
equality(): ASTNode;
|
|
96
|
+
/**
|
|
97
|
+
* Parses a relational expression.
|
|
98
|
+
* @returns {ASTNode} The relational expression node.
|
|
99
|
+
*/
|
|
100
|
+
relational(): ASTNode;
|
|
101
|
+
/**
|
|
102
|
+
* Parses an additive expression.
|
|
103
|
+
* @returns {ASTNode} The additive expression node.
|
|
104
|
+
*/
|
|
105
|
+
additive(): ASTNode;
|
|
106
|
+
/**
|
|
107
|
+
* Parses a multiplicative expression.
|
|
108
|
+
* @returns {ASTNode} The multiplicative expression node.
|
|
109
|
+
*/
|
|
110
|
+
multiplicative(): ASTNode;
|
|
111
|
+
/**
|
|
112
|
+
* Parses a unary expression.
|
|
113
|
+
* @returns {ASTNode} The unary expression node.
|
|
114
|
+
*/
|
|
115
|
+
unary(): ASTNode;
|
|
116
|
+
/**
|
|
117
|
+
* Parses a primary expression.
|
|
118
|
+
* @returns {ASTNode} The primary expression node.
|
|
119
|
+
*/
|
|
120
|
+
primary(): ASTNode;
|
|
121
|
+
/**
|
|
122
|
+
* Parses a filter.
|
|
123
|
+
* @param {ASTNode} baseExpression - The base expression to apply the filter to.
|
|
124
|
+
* @returns {ASTNode} The filter node.
|
|
125
|
+
*/
|
|
126
|
+
filter(baseExpression: ASTNode): ASTNode;
|
|
127
|
+
/**
|
|
128
|
+
* Parses function arguments.
|
|
129
|
+
* @returns {ASTNode[]} The arguments array.
|
|
130
|
+
*/
|
|
131
|
+
parseArguments(): ASTNode[];
|
|
132
|
+
/**
|
|
133
|
+
* Parses an identifier.
|
|
134
|
+
* @returns {ASTNode} The identifier node.
|
|
135
|
+
*/
|
|
136
|
+
identifier(): ASTNode;
|
|
137
|
+
/**
|
|
138
|
+
* Parses a constant.
|
|
139
|
+
* @returns {ASTNode} The constant node.
|
|
140
|
+
*/
|
|
141
|
+
constant(): ASTNode;
|
|
142
|
+
/**
|
|
143
|
+
* Parses an array declaration.
|
|
144
|
+
* @returns {ASTNode} The array declaration node.
|
|
145
|
+
*/
|
|
146
|
+
arrayDeclaration(): ASTNode;
|
|
147
|
+
/**
|
|
148
|
+
* Parses an object.
|
|
149
|
+
* @returns {ASTNode} The object node.
|
|
150
|
+
*/
|
|
151
|
+
object(): ASTNode;
|
|
152
|
+
/**
|
|
153
|
+
* Throws a syntax error.
|
|
154
|
+
* @param {string} msg - The error message.
|
|
155
|
+
* @param {import("./lexer").Token} [token] - The token that caused the error.
|
|
156
|
+
*/
|
|
157
|
+
throwError(msg: string, token?: import("./lexer").Token): void;
|
|
158
|
+
/**
|
|
159
|
+
* Consumes a token if it matches the expected type.
|
|
160
|
+
* @param {string} [e1] - The expected token type.
|
|
161
|
+
* @returns {import("./lexer").Token} The consumed token.
|
|
162
|
+
*/
|
|
163
|
+
consume(e1?: string): import("./lexer").Token;
|
|
164
|
+
/**
|
|
165
|
+
* Returns the next token without consuming it.
|
|
166
|
+
* @returns {import("./lexer").Token} The next token.
|
|
167
|
+
*/
|
|
168
|
+
peekToken(): import("./lexer").Token;
|
|
169
|
+
/**
|
|
170
|
+
* Checks if the next token matches any of the expected types.
|
|
171
|
+
* @param {...string} [expected] - The expected token types.
|
|
172
|
+
* @returns {import('./lexer').Token|boolean} The next token if it matches, otherwise false.
|
|
173
|
+
*/
|
|
174
|
+
peek(...expected?: string[]): import("./lexer").Token | boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Checks if the token at the specified index matches any of the expected types.
|
|
177
|
+
* @param {number} i - The index to check.
|
|
178
|
+
* @param {...string} [expected] - The expected token types.
|
|
179
|
+
* @returns {import("./lexer").Token|boolean} The token at the specified index if it matches, otherwise false.
|
|
180
|
+
*/
|
|
181
|
+
peekAhead(i: number, ...expected?: string[]): import("./lexer").Token | boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Consumes the next token if it matches any of the expected types.
|
|
184
|
+
* @param {...string} [expected] - The expected token types.
|
|
185
|
+
* @returns {import("./lexer").Token|boolean} The consumed token if it matches, otherwise false.
|
|
186
|
+
*/
|
|
187
|
+
expect(...expected?: string[]): import("./lexer").Token | boolean;
|
|
86
188
|
}
|
|
189
|
+
export type ASTNode = {
|
|
190
|
+
/**
|
|
191
|
+
* - The type of the AST node.
|
|
192
|
+
*/
|
|
193
|
+
type: number;
|
|
194
|
+
/**
|
|
195
|
+
* - The name of the identifier.
|
|
196
|
+
*/
|
|
197
|
+
name?: string;
|
|
198
|
+
/**
|
|
199
|
+
* - The kind of the property (e.g., 'init').
|
|
200
|
+
*/
|
|
201
|
+
kind?: string;
|
|
202
|
+
/**
|
|
203
|
+
* - The value of the node if it is a literal.
|
|
204
|
+
*/
|
|
205
|
+
value?: any;
|
|
206
|
+
/**
|
|
207
|
+
* - The elements of an array node.
|
|
208
|
+
*/
|
|
209
|
+
elements?: ASTNode[];
|
|
210
|
+
/**
|
|
211
|
+
* - The properties of an object node.
|
|
212
|
+
*/
|
|
213
|
+
properties?: ASTNode[];
|
|
214
|
+
/**
|
|
215
|
+
* - The key of an object property.
|
|
216
|
+
*/
|
|
217
|
+
key?: ASTNode;
|
|
218
|
+
/**
|
|
219
|
+
* - The left-hand side of a binary expression.
|
|
220
|
+
*/
|
|
221
|
+
left?: ASTNode;
|
|
222
|
+
/**
|
|
223
|
+
* - The right-hand side of a binary expression.
|
|
224
|
+
*/
|
|
225
|
+
right?: ASTNode;
|
|
226
|
+
/**
|
|
227
|
+
* - The argument of a unary expression.
|
|
228
|
+
*/
|
|
229
|
+
argument?: ASTNode;
|
|
230
|
+
/**
|
|
231
|
+
* - The test expression of a conditional expression.
|
|
232
|
+
*/
|
|
233
|
+
test?: ASTNode;
|
|
234
|
+
/**
|
|
235
|
+
* - The alternate expression of a conditional expression.
|
|
236
|
+
*/
|
|
237
|
+
alternate?: ASTNode;
|
|
238
|
+
/**
|
|
239
|
+
* - The consequent expression of a conditional expression.
|
|
240
|
+
*/
|
|
241
|
+
consequent?: ASTNode;
|
|
242
|
+
/**
|
|
243
|
+
* - The body of a program or block statement.
|
|
244
|
+
*/
|
|
245
|
+
body?: ASTNode[];
|
|
246
|
+
/**
|
|
247
|
+
* - The expression of an expression statement.
|
|
248
|
+
*/
|
|
249
|
+
expression?: ASTNode;
|
|
250
|
+
/**
|
|
251
|
+
* - The callee of a call expression.
|
|
252
|
+
*/
|
|
253
|
+
callee?: ASTNode;
|
|
254
|
+
/**
|
|
255
|
+
* - The arguments of a call expression.
|
|
256
|
+
*/
|
|
257
|
+
arguments?: ASTNode[];
|
|
258
|
+
/**
|
|
259
|
+
* - Indicates if a unary operator is a prefix.
|
|
260
|
+
*/
|
|
261
|
+
prefix?: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* - The object of a member expression.
|
|
264
|
+
*/
|
|
265
|
+
object?: ASTNode;
|
|
266
|
+
/**
|
|
267
|
+
* - The property of a member expression.
|
|
268
|
+
*/
|
|
269
|
+
property?: ASTNode;
|
|
270
|
+
/**
|
|
271
|
+
* - Indicates if a member expression is computed.
|
|
272
|
+
*/
|
|
273
|
+
computed?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* - The operator of a binary or logical expression.
|
|
276
|
+
*/
|
|
277
|
+
operator?: string;
|
|
278
|
+
filter?: boolean;
|
|
279
|
+
};
|