@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.
@@ -1,228 +0,0 @@
1
- import { ASTType } from "./ast-type";
2
- import { forEach, isFunction } from "../../shared/utils";
3
-
4
- const objectValueOf = {}.constructor.prototype.valueOf;
5
-
6
- /**
7
- * Converts parameter to strings property name for use as keys in an object.
8
- * Any non-string object, including a number, is typecasted into a string via the toString method.
9
- * {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors#Property_names}
10
- *
11
- * @param {!any} name
12
- * @returns {string}
13
- */
14
- export function getStringValue(name) {
15
- return `${name}`;
16
- }
17
-
18
- /// //////////////////////////////////////
19
-
20
- export function ifDefined(v, d) {
21
- return typeof v !== "undefined" ? v : d;
22
- }
23
-
24
- export function plusFn(l, r) {
25
- if (typeof l === "undefined") return r;
26
- if (typeof r === "undefined") return l;
27
- return l + r;
28
- }
29
-
30
- export function isStateless($filter, filterName) {
31
- const fn = $filter(filterName);
32
- return !fn.$stateful;
33
- }
34
-
35
- export const PURITY_ABSOLUTE = 1;
36
- export const PURITY_RELATIVE = 2;
37
-
38
- // Detect nodes which could depend on non-shallow state of objects
39
- export function isPure(node, parentIsPure) {
40
- switch (node.type) {
41
- // Computed members might invoke a stateful toString()
42
- case ASTType.MemberExpression:
43
- if (node.computed) {
44
- return false;
45
- }
46
- break;
47
-
48
- // Unary always convert to primative
49
- case ASTType.UnaryExpression:
50
- return PURITY_ABSOLUTE;
51
-
52
- // The binary + operator can invoke a stateful toString().
53
- case ASTType.BinaryExpression:
54
- return node.operator !== "+" ? PURITY_ABSOLUTE : false;
55
-
56
- // Functions / filters probably read state from within objects
57
- case ASTType.CallExpression:
58
- return false;
59
- }
60
-
61
- return undefined === parentIsPure ? PURITY_RELATIVE : parentIsPure;
62
- }
63
-
64
- export function findConstantAndWatchExpressions(ast, $filter, parentIsPure) {
65
- let allConstants;
66
- let argsToWatch;
67
- let isStatelessFilter;
68
-
69
- const astIsPure = (ast.isPure = isPure(ast, parentIsPure));
70
-
71
- switch (ast.type) {
72
- case ASTType.Program:
73
- allConstants = true;
74
- /** @type {[any]} */ (ast.body).forEach((expr) => {
75
- findConstantAndWatchExpressions(expr.expression, $filter, astIsPure);
76
- allConstants = allConstants && expr.expression.constant;
77
- });
78
- ast.constant = allConstants;
79
- break;
80
- case ASTType.Literal:
81
- ast.constant = true;
82
- ast.toWatch = [];
83
- break;
84
- case ASTType.UnaryExpression:
85
- findConstantAndWatchExpressions(ast.argument, $filter, astIsPure);
86
- ast.constant = ast.argument.constant;
87
- ast.toWatch = ast.argument.toWatch;
88
- break;
89
- case ASTType.BinaryExpression:
90
- findConstantAndWatchExpressions(ast.left, $filter, astIsPure);
91
- findConstantAndWatchExpressions(ast.right, $filter, astIsPure);
92
- ast.constant = ast.left.constant && ast.right.constant;
93
- ast.toWatch = ast.left.toWatch.concat(ast.right.toWatch);
94
- break;
95
- case ASTType.LogicalExpression:
96
- findConstantAndWatchExpressions(ast.left, $filter, astIsPure);
97
- findConstantAndWatchExpressions(ast.right, $filter, astIsPure);
98
- ast.constant = ast.left.constant && ast.right.constant;
99
- ast.toWatch = ast.constant ? [] : [ast];
100
- break;
101
- case ASTType.ConditionalExpression:
102
- findConstantAndWatchExpressions(ast.test, $filter, astIsPure);
103
- findConstantAndWatchExpressions(ast.alternate, $filter, astIsPure);
104
- findConstantAndWatchExpressions(ast.consequent, $filter, astIsPure);
105
- ast.constant =
106
- ast.test.constant && ast.alternate.constant && ast.consequent.constant;
107
- ast.toWatch = ast.constant ? [] : [ast];
108
- break;
109
- case ASTType.Identifier:
110
- ast.constant = false;
111
- ast.toWatch = [ast];
112
- break;
113
- case ASTType.MemberExpression:
114
- findConstantAndWatchExpressions(ast.object, $filter, astIsPure);
115
- if (ast.computed) {
116
- findConstantAndWatchExpressions(ast.property, $filter, astIsPure);
117
- }
118
- ast.constant =
119
- ast.object.constant && (!ast.computed || ast.property.constant);
120
- ast.toWatch = ast.constant ? [] : [ast];
121
- break;
122
- case ASTType.CallExpression:
123
- isStatelessFilter = ast.filter
124
- ? isStateless($filter, ast.callee.name)
125
- : false;
126
- allConstants = isStatelessFilter;
127
- argsToWatch = [];
128
- forEach(ast.arguments, (expr) => {
129
- findConstantAndWatchExpressions(expr, $filter, astIsPure);
130
- allConstants = allConstants && expr.constant;
131
- argsToWatch.push.apply(argsToWatch, expr.toWatch);
132
- });
133
- ast.constant = allConstants;
134
- ast.toWatch = isStatelessFilter ? argsToWatch : [ast];
135
- break;
136
- case ASTType.AssignmentExpression:
137
- findConstantAndWatchExpressions(ast.left, $filter, astIsPure);
138
- findConstantAndWatchExpressions(ast.right, $filter, astIsPure);
139
- ast.constant = ast.left.constant && ast.right.constant;
140
- ast.toWatch = [ast];
141
- break;
142
- case ASTType.ArrayExpression:
143
- allConstants = true;
144
- argsToWatch = [];
145
- forEach(ast.elements, (expr) => {
146
- findConstantAndWatchExpressions(expr, $filter, astIsPure);
147
- allConstants = allConstants && expr.constant;
148
- argsToWatch.push.apply(argsToWatch, expr.toWatch);
149
- });
150
- ast.constant = allConstants;
151
- ast.toWatch = argsToWatch;
152
- break;
153
- case ASTType.ObjectExpression:
154
- allConstants = true;
155
- argsToWatch = [];
156
- forEach(ast.properties, (property) => {
157
- findConstantAndWatchExpressions(property.value, $filter, astIsPure);
158
- allConstants = allConstants && property.value.constant;
159
- argsToWatch.push.apply(argsToWatch, property.value.toWatch);
160
- if (property.computed) {
161
- // `{[key]: value}` implicitly does `key.toString()` which may be non-pure
162
- findConstantAndWatchExpressions(
163
- property.key,
164
- $filter,
165
- /* parentIsPure= */ false,
166
- );
167
- allConstants = allConstants && property.key.constant;
168
- argsToWatch.push.apply(argsToWatch, property.key.toWatch);
169
- }
170
- });
171
- ast.constant = allConstants;
172
- ast.toWatch = argsToWatch;
173
- break;
174
- case ASTType.ThisExpression:
175
- ast.constant = false;
176
- ast.toWatch = [];
177
- break;
178
- case ASTType.LocalsExpression:
179
- ast.constant = false;
180
- ast.toWatch = [];
181
- break;
182
- }
183
- }
184
-
185
- export function getInputs(body) {
186
- if (body.length !== 1) return;
187
- const lastExpression = body[0].expression;
188
- const candidate = lastExpression.toWatch;
189
- if (candidate.length !== 1) return candidate;
190
- return candidate[0] !== lastExpression ? candidate : undefined;
191
- }
192
-
193
- export function isAssignable(ast) {
194
- return (
195
- ast.type === ASTType.Identifier || ast.type === ASTType.MemberExpression
196
- );
197
- }
198
-
199
- export function assignableAST(ast) {
200
- if (ast.body.length === 1 && isAssignable(ast.body[0].expression)) {
201
- return {
202
- type: ASTType.AssignmentExpression,
203
- left: ast.body[0].expression,
204
- right: { type: ASTType.NGValueParameter },
205
- operator: "=",
206
- };
207
- }
208
- }
209
-
210
- export function isLiteral(ast) {
211
- return (
212
- ast.body.length === 0 ||
213
- (ast.body.length === 1 &&
214
- (ast.body[0].expression.type === ASTType.Literal ||
215
- ast.body[0].expression.type === ASTType.ArrayExpression ||
216
- ast.body[0].expression.type === ASTType.ObjectExpression))
217
- );
218
- }
219
-
220
- export function isConstant(ast) {
221
- return ast.constant;
222
- }
223
-
224
- export function getValueOf(value) {
225
- return isFunction(value.valueOf)
226
- ? value.valueOf()
227
- : objectValueOf.call(value);
228
- }
@@ -1,49 +0,0 @@
1
- export function ASTCompiler($filter: any): void;
2
- export class ASTCompiler {
3
- constructor($filter: any);
4
- $filter: any;
5
- compile(ast: any): any;
6
- state: {
7
- nextId: number;
8
- filters: {};
9
- fn: {
10
- vars: any[];
11
- body: any[];
12
- own: {};
13
- };
14
- assign: {
15
- vars: any[];
16
- body: any[];
17
- own: {};
18
- };
19
- inputs: any[];
20
- };
21
- stage: string;
22
- watchFns(): string;
23
- generateFunction(name: any, params: any): string;
24
- filterPrefix(): string;
25
- varsPrefix(section: any): string;
26
- body(section: any): any;
27
- recurse(ast: any, intoId: any, nameId: any, recursionFn: any, create: any, skipWatchIdCheck: any): void;
28
- getHasOwnProperty(element: any, property: any): any;
29
- assign(id: any, value: any): any;
30
- filter(filterName: any): any;
31
- ifDefined(id: any, defaultValue: any): string;
32
- plus(left: any, right: any): string;
33
- return_(id: any): void;
34
- if_(test: any, alternate: any, consequent: any): void;
35
- not(expression: any): string;
36
- isNull(expression: any): string;
37
- notNull(expression: any): string;
38
- nonComputedMember(left: any, right: any): string;
39
- computedMember(left: any, right: any): string;
40
- member(left: any, right: any, computed: any): string;
41
- getStringValue(item: any): void;
42
- lazyRecurse(ast: any, intoId: any, nameId: any, recursionFn: any, create: any, skipWatchIdCheck: any): () => void;
43
- lazyAssign(id: any, value: any): () => void;
44
- stringEscapeRegex: RegExp;
45
- stringEscapeFn(c: any): string;
46
- escape(value: any): any;
47
- nextId(skip: any, init: any): string;
48
- current(): any;
49
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Converts parameter to strings property name for use as keys in an object.
3
- * Any non-string object, including a number, is typecasted into a string via the toString method.
4
- * {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors#Property_names}
5
- *
6
- * @param {!any} name
7
- * @returns {string}
8
- */
9
- export function getStringValue(name: any): string;
10
- export function ifDefined(v: any, d: any): any;
11
- export function plusFn(l: any, r: any): any;
12
- export function isStateless($filter: any, filterName: any): boolean;
13
- export function isPure(node: any, parentIsPure: any): any;
14
- export function findConstantAndWatchExpressions(ast: any, $filter: any, parentIsPure: any): void;
15
- export function getInputs(body: any): any;
16
- export function isAssignable(ast: any): boolean;
17
- export function assignableAST(ast: any): {
18
- type: string;
19
- left: any;
20
- right: {
21
- type: string;
22
- };
23
- operator: string;
24
- };
25
- export function isLiteral(ast: any): boolean;
26
- export function isConstant(ast: any): any;
27
- export function getValueOf(value: any): any;
28
- export const PURITY_ABSOLUTE: 1;
29
- export const PURITY_RELATIVE: 2;