@auscope/angular2parse 2.0.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 +49 -0
- package/ng-package.json +7 -0
- package/package.json +18 -0
- package/src/lib/angular/compiler/assertions.ts +49 -0
- package/src/lib/angular/compiler/ast.ts +393 -0
- package/src/lib/angular/compiler/chars.ts +89 -0
- package/src/lib/angular/compiler/interpolation-config.ts +25 -0
- package/src/lib/angular/compiler/lexer.ts +383 -0
- package/src/lib/angular/compiler/parser.ts +811 -0
- package/src/lib/angular/compiler.ts +6 -0
- package/src/lib/angular/facade/lang.ts +124 -0
- package/src/lib/angular/facade.ts +1 -0
- package/src/lib/angular.ts +2 -0
- package/src/lib/module.ts +12 -0
- package/src/lib/parse.ts +78 -0
- package/src/lib/util/binary-operations.ts +17 -0
- package/src/lib/util/lang.ts +15 -0
- package/src/lib/util.ts +2 -0
- package/src/lib/visitors/parse-visitor-compiler.ts +149 -0
- package/src/lib/visitors/parse-visitor-resolver.ts +208 -0
- package/src/lib/visitors.ts +2 -0
- package/src/public-api.ts +5 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.lib.prod.json +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# angular2parse
|
|
2
|
+
Parse util for angular expressions: html string -> angular temaplte
|
|
3
|
+
|
|
4
|
+
# install
|
|
5
|
+
`npm install angular2parse`
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
// app.module.ts
|
|
9
|
+
@NgModule({
|
|
10
|
+
imports: [Angular2ParseModule, ...],
|
|
11
|
+
// ...
|
|
12
|
+
})
|
|
13
|
+
class AppModule {}
|
|
14
|
+
```
|
|
15
|
+
# usage
|
|
16
|
+
```typescript
|
|
17
|
+
import { Parse } from 'angular2parse';
|
|
18
|
+
|
|
19
|
+
@Injectable()
|
|
20
|
+
class MyService {
|
|
21
|
+
constructor(private parser: Parse) {}
|
|
22
|
+
|
|
23
|
+
parseAngularString() {
|
|
24
|
+
const expression = `{
|
|
25
|
+
positions: track.positions,
|
|
26
|
+
cornerType: getCornerType(),
|
|
27
|
+
material: track.color,
|
|
28
|
+
width : 200000.0 }`;
|
|
29
|
+
|
|
30
|
+
const expressionEvalFn = this.parser.eval(expression)
|
|
31
|
+
|
|
32
|
+
const context = {
|
|
33
|
+
getCornerType: () => 'value',
|
|
34
|
+
track: {
|
|
35
|
+
positions: [1,2,3],
|
|
36
|
+
color: 'red',
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const result = expressionEvalFn(context);
|
|
42
|
+
console.log(result);
|
|
43
|
+
// {positions: [1,2,3], cornerType: 'value', material: 'red', width: 2000}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```
|
package/ng-package.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@auscope/angular2parse",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Fork of articode repo for Angular v13",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/AuScope/angular2parse/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/AuScope/angular2parse.git",
|
|
11
|
+
"directory": "projects/angular2parse"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/AuScope/angular2parse#readme",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@angular/common": "^13.0.0",
|
|
16
|
+
"@angular/core": "^13.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import {isBlank, isPresent} from '../facade/lang';
|
|
11
|
+
|
|
12
|
+
const isDevMode = () => false;
|
|
13
|
+
|
|
14
|
+
export function assertArrayOfStrings(identifier: string, value: any) {
|
|
15
|
+
if (!isDevMode() || isBlank(value)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(value)) {
|
|
19
|
+
throw new Error(`Expected '${identifier}' to be an array of strings.`);
|
|
20
|
+
}
|
|
21
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
22
|
+
if (typeof value[i] !== 'string') {
|
|
23
|
+
throw new Error(`Expected '${identifier}' to be an array of strings.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const INTERPOLATION_BLACKLIST_REGEXPS = [
|
|
29
|
+
/^\s*$/, // empty
|
|
30
|
+
/[<>]/, // html tag
|
|
31
|
+
/^[{}]$/, // i18n expansion
|
|
32
|
+
/&(#|[a-z])/i, // character reference,
|
|
33
|
+
/^\/\//, // comment
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export function assertInterpolationSymbols(identifier: string, value: any): void {
|
|
37
|
+
if (isPresent(value) && !(Array.isArray(value) && value.length == 2)) {
|
|
38
|
+
throw new Error(`Expected '${identifier}' to be an array, [start, end].`);
|
|
39
|
+
} else if (isDevMode() && !isBlank(value)) {
|
|
40
|
+
const start = value[0] as string;
|
|
41
|
+
const end = value[1] as string;
|
|
42
|
+
// black list checking
|
|
43
|
+
INTERPOLATION_BLACKLIST_REGEXPS.forEach(regexp => {
|
|
44
|
+
if (regexp.test(start) || regexp.test(end)) {
|
|
45
|
+
throw new Error(`['${start}', '${end}'] contains unusable interpolation symbol.`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import {isBlank} from '../facade/lang';
|
|
11
|
+
|
|
12
|
+
export class ParserError {
|
|
13
|
+
public message: string;
|
|
14
|
+
constructor(
|
|
15
|
+
message: string, public input: string, public errLocation: string, public ctxLocation?: any) {
|
|
16
|
+
this.message = `Parser Error: ${message} ${errLocation} [${input}] in ${ctxLocation}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ParseSpan {
|
|
21
|
+
constructor(public start: number, public end: number) {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class AST {
|
|
25
|
+
constructor(public span: ParseSpan) {}
|
|
26
|
+
visit(visitor: AstVisitor, context: any = null): any { return null; }
|
|
27
|
+
toString(): string { return 'AST'; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Represents a quoted expression of the form:
|
|
32
|
+
*
|
|
33
|
+
* quote = prefix `:` uninterpretedExpression
|
|
34
|
+
* prefix = identifier
|
|
35
|
+
* uninterpretedExpression = arbitrary string
|
|
36
|
+
*
|
|
37
|
+
* A quoted expression is meant to be pre-processed by an AST transformer that
|
|
38
|
+
* converts it into another AST that no longer contains quoted expressions.
|
|
39
|
+
* It is meant to allow third-party developers to extend Angular template
|
|
40
|
+
* expression language. The `uninterpretedExpression` part of the quote is
|
|
41
|
+
* therefore not interpreted by the Angular's own expression parser.
|
|
42
|
+
*/
|
|
43
|
+
export class Quote extends AST {
|
|
44
|
+
constructor(
|
|
45
|
+
span: ParseSpan, public prefix: string, public uninterpretedExpression: string,
|
|
46
|
+
public location: any) {
|
|
47
|
+
super(span);
|
|
48
|
+
}
|
|
49
|
+
visit(visitor: AstVisitor, context: any = null): any { return visitor.visitQuote(this, context); }
|
|
50
|
+
toString(): string { return 'Quote'; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class EmptyExpr extends AST {
|
|
54
|
+
visit(visitor: AstVisitor, context: any = null) {
|
|
55
|
+
// do nothing
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class ImplicitReceiver extends AST {
|
|
60
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
61
|
+
return visitor.visitImplicitReceiver(this, context);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Multiple expressions separated by a semicolon.
|
|
67
|
+
*/
|
|
68
|
+
export class Chain extends AST {
|
|
69
|
+
constructor(span: ParseSpan, public expressions: any[]) { super(span); }
|
|
70
|
+
visit(visitor: AstVisitor, context: any = null): any { return visitor.visitChain(this, context); }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class Conditional extends AST {
|
|
74
|
+
constructor(span: ParseSpan, public condition: AST, public trueExp: AST, public falseExp: AST) {
|
|
75
|
+
super(span);
|
|
76
|
+
}
|
|
77
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
78
|
+
return visitor.visitConditional(this, context);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class PropertyRead extends AST {
|
|
83
|
+
constructor(span: ParseSpan, public receiver: AST, public name: string) { super(span); }
|
|
84
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
85
|
+
return visitor.visitPropertyRead(this, context);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export class PropertyWrite extends AST {
|
|
90
|
+
constructor(span: ParseSpan, public receiver: AST, public name: string, public value: AST) {
|
|
91
|
+
super(span);
|
|
92
|
+
}
|
|
93
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
94
|
+
return visitor.visitPropertyWrite(this, context);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export class SafePropertyRead extends AST {
|
|
99
|
+
constructor(span: ParseSpan, public receiver: AST, public name: string) { super(span); }
|
|
100
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
101
|
+
return visitor.visitSafePropertyRead(this, context);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class KeyedRead extends AST {
|
|
106
|
+
constructor(span: ParseSpan, public obj: AST, public key: AST) { super(span); }
|
|
107
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
108
|
+
return visitor.visitKeyedRead(this, context);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export class KeyedWrite extends AST {
|
|
113
|
+
constructor(span: ParseSpan, public obj: AST, public key: AST, public value: AST) { super(span); }
|
|
114
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
115
|
+
return visitor.visitKeyedWrite(this, context);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export class BindingPipe extends AST {
|
|
120
|
+
constructor(span: ParseSpan, public exp: AST, public name: string, public args: any[]) {
|
|
121
|
+
super(span);
|
|
122
|
+
}
|
|
123
|
+
visit(visitor: AstVisitor, context: any = null): any { return visitor.visitPipe(this, context); }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class LiteralPrimitive extends AST {
|
|
127
|
+
constructor(span: ParseSpan, public value: any) { super(span); }
|
|
128
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
129
|
+
return visitor.visitLiteralPrimitive(this, context);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export class LiteralArray extends AST {
|
|
134
|
+
constructor(span: ParseSpan, public expressions: any[]) { super(span); }
|
|
135
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
136
|
+
return visitor.visitLiteralArray(this, context);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export class LiteralMap extends AST {
|
|
141
|
+
constructor(span: ParseSpan, public keys: any[], public values: any[]) { super(span); }
|
|
142
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
143
|
+
return visitor.visitLiteralMap(this, context);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export class Interpolation extends AST {
|
|
148
|
+
constructor(span: ParseSpan, public strings: any[], public expressions: any[]) { super(span); }
|
|
149
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
150
|
+
return visitor.visitInterpolation(this, context);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class Binary extends AST {
|
|
155
|
+
constructor(span: ParseSpan, public operation: string, public left: AST, public right: AST) {
|
|
156
|
+
super(span);
|
|
157
|
+
}
|
|
158
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
159
|
+
return visitor.visitBinary(this, context);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export class PrefixNot extends AST {
|
|
164
|
+
constructor(span: ParseSpan, public expression: AST) { super(span); }
|
|
165
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
166
|
+
return visitor.visitPrefixNot(this, context);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class MethodCall extends AST {
|
|
171
|
+
constructor(span: ParseSpan, public receiver: AST, public name: string, public args: any[]) {
|
|
172
|
+
super(span);
|
|
173
|
+
}
|
|
174
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
175
|
+
return visitor.visitMethodCall(this, context);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export class SafeMethodCall extends AST {
|
|
180
|
+
constructor(span: ParseSpan, public receiver: AST, public name: string, public args: any[]) {
|
|
181
|
+
super(span);
|
|
182
|
+
}
|
|
183
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
184
|
+
return visitor.visitSafeMethodCall(this, context);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export class FunctionCall extends AST {
|
|
189
|
+
constructor(span: ParseSpan, public target: AST, public args: any[]) { super(span); }
|
|
190
|
+
visit(visitor: AstVisitor, context: any = null): any {
|
|
191
|
+
return visitor.visitFunctionCall(this, context);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export class ASTWithSource extends AST {
|
|
196
|
+
constructor(
|
|
197
|
+
public ast: AST, public source: string, public location: string,
|
|
198
|
+
public errors: ParserError[]) {
|
|
199
|
+
super(new ParseSpan(0, isBlank(source) ? 0 : source.length));
|
|
200
|
+
}
|
|
201
|
+
visit(visitor: AstVisitor, context: any = null): any { return this.ast.visit(visitor, context); }
|
|
202
|
+
toString(): string { return `${this.source} in ${this.location}`; }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export class TemplateBinding {
|
|
206
|
+
constructor(
|
|
207
|
+
public span: ParseSpan, public key: string, public keyIsVar: boolean, public name: string,
|
|
208
|
+
public expression: ASTWithSource) {}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface AstVisitor {
|
|
212
|
+
visitBinary(ast: Binary, context: any): any;
|
|
213
|
+
visitChain(ast: Chain, context: any): any;
|
|
214
|
+
visitConditional(ast: Conditional, context: any): any;
|
|
215
|
+
visitFunctionCall(ast: FunctionCall, context: any): any;
|
|
216
|
+
visitImplicitReceiver(ast: ImplicitReceiver, context: any): any;
|
|
217
|
+
visitInterpolation(ast: Interpolation, context: any): any;
|
|
218
|
+
visitKeyedRead(ast: KeyedRead, context: any): any;
|
|
219
|
+
visitKeyedWrite(ast: KeyedWrite, context: any): any;
|
|
220
|
+
visitLiteralArray(ast: LiteralArray, context: any): any;
|
|
221
|
+
visitLiteralMap(ast: LiteralMap, context: any): any;
|
|
222
|
+
visitLiteralPrimitive(ast: LiteralPrimitive, context: any): any;
|
|
223
|
+
visitMethodCall(ast: MethodCall, context: any): any;
|
|
224
|
+
visitPipe(ast: BindingPipe, context: any): any;
|
|
225
|
+
visitPrefixNot(ast: PrefixNot, context: any): any;
|
|
226
|
+
visitPropertyRead(ast: PropertyRead, context: any): any;
|
|
227
|
+
visitPropertyWrite(ast: PropertyWrite, context: any): any;
|
|
228
|
+
visitQuote(ast: Quote, context: any): any;
|
|
229
|
+
visitSafeMethodCall(ast: SafeMethodCall, context: any): any;
|
|
230
|
+
visitSafePropertyRead(ast: SafePropertyRead, context: any): any;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export class RecursiveAstVisitor implements AstVisitor {
|
|
234
|
+
visitBinary(ast: Binary, context: any): any {
|
|
235
|
+
ast.left.visit(this);
|
|
236
|
+
ast.right.visit(this);
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
visitChain(ast: Chain, context: any): any { return this.visitAll(ast.expressions, context); }
|
|
240
|
+
visitConditional(ast: Conditional, context: any): any {
|
|
241
|
+
ast.condition.visit(this);
|
|
242
|
+
ast.trueExp.visit(this);
|
|
243
|
+
ast.falseExp.visit(this);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
visitPipe(ast: BindingPipe, context: any): any {
|
|
247
|
+
ast.exp.visit(this);
|
|
248
|
+
this.visitAll(ast.args, context);
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
visitFunctionCall(ast: FunctionCall, context: any): any {
|
|
252
|
+
ast.target.visit(this);
|
|
253
|
+
this.visitAll(ast.args, context);
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
visitImplicitReceiver(ast: ImplicitReceiver, context: any): any { return null; }
|
|
257
|
+
visitInterpolation(ast: Interpolation, context: any): any {
|
|
258
|
+
return this.visitAll(ast.expressions, context);
|
|
259
|
+
}
|
|
260
|
+
visitKeyedRead(ast: KeyedRead, context: any): any {
|
|
261
|
+
ast.obj.visit(this);
|
|
262
|
+
ast.key.visit(this);
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
visitKeyedWrite(ast: KeyedWrite, context: any): any {
|
|
266
|
+
ast.obj.visit(this);
|
|
267
|
+
ast.key.visit(this);
|
|
268
|
+
ast.value.visit(this);
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
visitLiteralArray(ast: LiteralArray, context: any): any {
|
|
272
|
+
return this.visitAll(ast.expressions, context);
|
|
273
|
+
}
|
|
274
|
+
visitLiteralMap(ast: LiteralMap, context: any): any { return this.visitAll(ast.values, context); }
|
|
275
|
+
visitLiteralPrimitive(ast: LiteralPrimitive, context: any): any { return null; }
|
|
276
|
+
visitMethodCall(ast: MethodCall, context: any): any {
|
|
277
|
+
ast.receiver.visit(this);
|
|
278
|
+
return this.visitAll(ast.args, context);
|
|
279
|
+
}
|
|
280
|
+
visitPrefixNot(ast: PrefixNot, context: any): any {
|
|
281
|
+
ast.expression.visit(this);
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
visitPropertyRead(ast: PropertyRead, context: any): any {
|
|
285
|
+
ast.receiver.visit(this);
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
visitPropertyWrite(ast: PropertyWrite, context: any): any {
|
|
289
|
+
ast.receiver.visit(this);
|
|
290
|
+
ast.value.visit(this);
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
visitSafePropertyRead(ast: SafePropertyRead, context: any): any {
|
|
294
|
+
ast.receiver.visit(this);
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
visitSafeMethodCall(ast: SafeMethodCall, context: any): any {
|
|
298
|
+
ast.receiver.visit(this);
|
|
299
|
+
return this.visitAll(ast.args, context);
|
|
300
|
+
}
|
|
301
|
+
visitAll(asts: AST[], context: any): any {
|
|
302
|
+
asts.forEach(ast => ast.visit(this, context));
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
visitQuote(ast: Quote, context: any): any { return null; }
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export class AstTransformer implements AstVisitor {
|
|
309
|
+
visitImplicitReceiver(ast: ImplicitReceiver, context: any): AST { return ast; }
|
|
310
|
+
|
|
311
|
+
visitInterpolation(ast: Interpolation, context: any): AST {
|
|
312
|
+
return new Interpolation(ast.span, ast.strings, this.visitAll(ast.expressions));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
visitLiteralPrimitive(ast: LiteralPrimitive, context: any): AST {
|
|
316
|
+
return new LiteralPrimitive(ast.span, ast.value);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
visitPropertyRead(ast: PropertyRead, context: any): AST {
|
|
320
|
+
return new PropertyRead(ast.span, ast.receiver.visit(this), ast.name);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
visitPropertyWrite(ast: PropertyWrite, context: any): AST {
|
|
324
|
+
return new PropertyWrite(ast.span, ast.receiver.visit(this), ast.name, ast.value);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
visitSafePropertyRead(ast: SafePropertyRead, context: any): AST {
|
|
328
|
+
return new SafePropertyRead(ast.span, ast.receiver.visit(this), ast.name);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
visitMethodCall(ast: MethodCall, context: any): AST {
|
|
332
|
+
return new MethodCall(ast.span, ast.receiver.visit(this), ast.name, this.visitAll(ast.args));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
visitSafeMethodCall(ast: SafeMethodCall, context: any): AST {
|
|
336
|
+
return new SafeMethodCall(
|
|
337
|
+
ast.span, ast.receiver.visit(this), ast.name, this.visitAll(ast.args));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
visitFunctionCall(ast: FunctionCall, context: any): AST {
|
|
341
|
+
return new FunctionCall(ast.span, ast.target.visit(this), this.visitAll(ast.args));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
visitLiteralArray(ast: LiteralArray, context: any): AST {
|
|
345
|
+
return new LiteralArray(ast.span, this.visitAll(ast.expressions));
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
visitLiteralMap(ast: LiteralMap, context: any): AST {
|
|
349
|
+
return new LiteralMap(ast.span, ast.keys, this.visitAll(ast.values));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
visitBinary(ast: Binary, context: any): AST {
|
|
353
|
+
return new Binary(ast.span, ast.operation, ast.left.visit(this), ast.right.visit(this));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
visitPrefixNot(ast: PrefixNot, context: any): AST {
|
|
357
|
+
return new PrefixNot(ast.span, ast.expression.visit(this));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
visitConditional(ast: Conditional, context: any): AST {
|
|
361
|
+
return new Conditional(
|
|
362
|
+
ast.span, ast.condition.visit(this), ast.trueExp.visit(this), ast.falseExp.visit(this));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
visitPipe(ast: BindingPipe, context: any): AST {
|
|
366
|
+
return new BindingPipe(ast.span, ast.exp.visit(this), ast.name, this.visitAll(ast.args));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
visitKeyedRead(ast: KeyedRead, context: any): AST {
|
|
370
|
+
return new KeyedRead(ast.span, ast.obj.visit(this), ast.key.visit(this));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
visitKeyedWrite(ast: KeyedWrite, context: any): AST {
|
|
374
|
+
return new KeyedWrite(
|
|
375
|
+
ast.span, ast.obj.visit(this), ast.key.visit(this), ast.value.visit(this));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
visitAll(asts: any[]): any[] {
|
|
379
|
+
const res = new Array(asts.length);
|
|
380
|
+
for (let i = 0; i < asts.length; ++i) {
|
|
381
|
+
res[i] = asts[i].visit(this);
|
|
382
|
+
}
|
|
383
|
+
return res;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
visitChain(ast: Chain, context: any): AST {
|
|
387
|
+
return new Chain(ast.span, this.visitAll(ast.expressions));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
visitQuote(ast: Quote, context: any): AST {
|
|
391
|
+
return new Quote(ast.span, ast.prefix, ast.uninterpretedExpression, ast.location);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const $EOF = 0;
|
|
10
|
+
export const $TAB = 9;
|
|
11
|
+
export const $LF = 10;
|
|
12
|
+
export const $VTAB = 11;
|
|
13
|
+
export const $FF = 12;
|
|
14
|
+
export const $CR = 13;
|
|
15
|
+
export const $SPACE = 32;
|
|
16
|
+
export const $BANG = 33;
|
|
17
|
+
export const $DQ = 34;
|
|
18
|
+
export const $HASH = 35;
|
|
19
|
+
export const $$ = 36;
|
|
20
|
+
export const $PERCENT = 37;
|
|
21
|
+
export const $AMPERSAND = 38;
|
|
22
|
+
export const $SQ = 39;
|
|
23
|
+
export const $LPAREN = 40;
|
|
24
|
+
export const $RPAREN = 41;
|
|
25
|
+
export const $STAR = 42;
|
|
26
|
+
export const $PLUS = 43;
|
|
27
|
+
export const $COMMA = 44;
|
|
28
|
+
export const $MINUS = 45;
|
|
29
|
+
export const $PERIOD = 46;
|
|
30
|
+
export const $SLASH = 47;
|
|
31
|
+
export const $COLON = 58;
|
|
32
|
+
export const $SEMICOLON = 59;
|
|
33
|
+
export const $LT = 60;
|
|
34
|
+
export const $EQ = 61;
|
|
35
|
+
export const $GT = 62;
|
|
36
|
+
export const $QUESTION = 63;
|
|
37
|
+
|
|
38
|
+
export const $0 = 48;
|
|
39
|
+
export const $9 = 57;
|
|
40
|
+
|
|
41
|
+
export const $A = 65;
|
|
42
|
+
export const $E = 69;
|
|
43
|
+
export const $F = 70;
|
|
44
|
+
export const $X = 88;
|
|
45
|
+
export const $Z = 90;
|
|
46
|
+
|
|
47
|
+
export const $LBRACKET = 91;
|
|
48
|
+
export const $BACKSLASH = 92;
|
|
49
|
+
export const $RBRACKET = 93;
|
|
50
|
+
export const $CARET = 94;
|
|
51
|
+
export const $_ = 95;
|
|
52
|
+
|
|
53
|
+
export const $a = 97;
|
|
54
|
+
export const $e = 101;
|
|
55
|
+
export const $f = 102;
|
|
56
|
+
export const $n = 110;
|
|
57
|
+
export const $r = 114;
|
|
58
|
+
export const $t = 116;
|
|
59
|
+
export const $u = 117;
|
|
60
|
+
export const $v = 118;
|
|
61
|
+
export const $x = 120;
|
|
62
|
+
export const $z = 122;
|
|
63
|
+
|
|
64
|
+
export const $LBRACE = 123;
|
|
65
|
+
export const $BAR = 124;
|
|
66
|
+
export const $RBRACE = 125;
|
|
67
|
+
export const $NBSP = 160;
|
|
68
|
+
|
|
69
|
+
export const $PIPE = 124;
|
|
70
|
+
export const $TILDA = 126;
|
|
71
|
+
export const $AT = 64;
|
|
72
|
+
|
|
73
|
+
export const $BT = 96;
|
|
74
|
+
|
|
75
|
+
export function isWhitespace(code: number): boolean {
|
|
76
|
+
return (code >= $TAB && code <= $SPACE) || (code == $NBSP);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isDigit(code: number): boolean {
|
|
80
|
+
return $0 <= code && code <= $9;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isAsciiLetter(code: number): boolean {
|
|
84
|
+
return code >= $a && code <= $z || code >= $A && code <= $Z;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function isAsciiHexDigit(code: number): boolean {
|
|
88
|
+
return code >= $a && code <= $f || code >= $A && code <= $F || isDigit(code);
|
|
89
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {assertInterpolationSymbols} from './assertions';
|
|
10
|
+
|
|
11
|
+
export class InterpolationConfig {
|
|
12
|
+
static fromArray(markers: [string, string]): InterpolationConfig {
|
|
13
|
+
if (!markers) {
|
|
14
|
+
return DEFAULT_INTERPOLATION_CONFIG;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
assertInterpolationSymbols('interpolation', markers);
|
|
18
|
+
return new InterpolationConfig(markers[0], markers[1]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(public start: string, public end: string){};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_INTERPOLATION_CONFIG: InterpolationConfig =
|
|
25
|
+
new InterpolationConfig('{{', '}}');
|