vsn 0.1.13 → 0.1.17
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/demo/demo.html +15 -7
- package/demo/vision.js +1 -1
- package/dist/AST.d.ts +2 -2
- package/dist/Scope.d.ts +2 -0
- package/dist/Vision.d.ts +4 -1
- package/dist/attributes/_imports.d.ts +27 -27
- package/dist/vision.min.js +1 -0
- package/main.py +16 -0
- package/package.json +1 -1
- package/src/AST.ts +40 -26
- package/src/Scope.ts +11 -0
- package/src/Vision.ts +6 -3
- package/src/attributes/_imports.ts +27 -27
- package/test/AST.spec.ts +41 -12
- package/test/DOM.spec.ts +2 -2
- package/test/Scope.spec.ts +14 -0
- package/test/attributes/Bind.spec.ts +13 -0
- package/dist/AST.js +0 -1978
- package/dist/AST.js.map +0 -1
- package/dist/Attribute.js +0 -187
- package/dist/Attribute.js.map +0 -1
- package/dist/Bencmark.js +0 -179
- package/dist/Bencmark.js.map +0 -1
- package/dist/Configuration.js +0 -64
- package/dist/Configuration.js.map +0 -1
- package/dist/Controller.js +0 -39
- package/dist/Controller.js.map +0 -1
- package/dist/DOM/DOMObject.js +0 -45
- package/dist/DOM/DOMObject.js.map +0 -1
- package/dist/DOM/WrappedDocument.js +0 -34
- package/dist/DOM/WrappedDocument.js.map +0 -1
- package/dist/DOM/WrappedWindow.js +0 -45
- package/dist/DOM/WrappedWindow.js.map +0 -1
- package/dist/DOM.js +0 -547
- package/dist/DOM.js.map +0 -1
- package/dist/Formats.js +0 -44
- package/dist/Formats.js.map +0 -1
- package/dist/Query.js +0 -66
- package/dist/Query.js.map +0 -1
- package/dist/Registry.js +0 -138
- package/dist/Registry.js.map +0 -1
- package/dist/Scope.js +0 -496
- package/dist/Scope.js.map +0 -1
- package/dist/Tag/List.js +0 -85
- package/dist/Tag/List.js.map +0 -1
- package/dist/Tag.js +0 -715
- package/dist/Tag.js.map +0 -1
- package/dist/Types.js +0 -48
- package/dist/Types.js.map +0 -1
- package/dist/Vision.js +0 -155
- package/dist/Vision.js.map +0 -1
- package/dist/attributes/AddClassIf.js +0 -93
- package/dist/attributes/AddClassIf.js.map +0 -1
- package/dist/attributes/Bind.js +0 -272
- package/dist/attributes/Bind.js.map +0 -1
- package/dist/attributes/ClassConstructor.js +0 -104
- package/dist/attributes/ClassConstructor.js.map +0 -1
- package/dist/attributes/ClickRemoveClass.js +0 -102
- package/dist/attributes/ClickRemoveClass.js.map +0 -1
- package/dist/attributes/ClickToggleClass.js +0 -102
- package/dist/attributes/ClickToggleClass.js.map +0 -1
- package/dist/attributes/ControllerAttribute.js +0 -28
- package/dist/attributes/ControllerAttribute.js.map +0 -1
- package/dist/attributes/DisableIf.js +0 -94
- package/dist/attributes/DisableIf.js.map +0 -1
- package/dist/attributes/Exec.js +0 -102
- package/dist/attributes/Exec.js.map +0 -1
- package/dist/attributes/Format.js +0 -96
- package/dist/attributes/Format.js.map +0 -1
- package/dist/attributes/If.js +0 -147
- package/dist/attributes/If.js.map +0 -1
- package/dist/attributes/JSONAttribute.js +0 -115
- package/dist/attributes/JSONAttribute.js.map +0 -1
- package/dist/attributes/KeyAbstract.js +0 -110
- package/dist/attributes/KeyAbstract.js.map +0 -1
- package/dist/attributes/KeyDown.js +0 -82
- package/dist/attributes/KeyDown.js.map +0 -1
- package/dist/attributes/KeyUp.js +0 -82
- package/dist/attributes/KeyUp.js.map +0 -1
- package/dist/attributes/List.js +0 -273
- package/dist/attributes/List.js.map +0 -1
- package/dist/attributes/ListItem.js +0 -135
- package/dist/attributes/ListItem.js.map +0 -1
- package/dist/attributes/ListItemModel.js +0 -39
- package/dist/attributes/ListItemModel.js.map +0 -1
- package/dist/attributes/ModelAttribute.js +0 -29
- package/dist/attributes/ModelAttribute.js.map +0 -1
- package/dist/attributes/Name.js +0 -88
- package/dist/attributes/Name.js.map +0 -1
- package/dist/attributes/On.js +0 -123
- package/dist/attributes/On.js.map +0 -1
- package/dist/attributes/Radio.js +0 -127
- package/dist/attributes/Radio.js.map +0 -1
- package/dist/attributes/Referenced.js +0 -38
- package/dist/attributes/Referenced.js.map +0 -1
- package/dist/attributes/RootAttribute.js +0 -85
- package/dist/attributes/RootAttribute.js.map +0 -1
- package/dist/attributes/ScopeAttribute.js +0 -40
- package/dist/attributes/ScopeAttribute.js.map +0 -1
- package/dist/attributes/ScopeChange.js +0 -124
- package/dist/attributes/ScopeChange.js.map +0 -1
- package/dist/attributes/SetAttribute.js +0 -130
- package/dist/attributes/SetAttribute.js.map +0 -1
- package/dist/attributes/StandardAttribute.js +0 -168
- package/dist/attributes/StandardAttribute.js.map +0 -1
- package/dist/attributes/Template.js +0 -39
- package/dist/attributes/Template.js.map +0 -1
- package/dist/attributes/TypeAttribute.js +0 -101
- package/dist/attributes/TypeAttribute.js.map +0 -1
- package/dist/attributes/_imports.js +0 -30
- package/dist/attributes/_imports.js.map +0 -1
- package/dist/helpers/DOMHelper.js +0 -81
- package/dist/helpers/DOMHelper.js.map +0 -1
- package/dist/helpers/ElementHelper.js +0 -25
- package/dist/helpers/ElementHelper.js.map +0 -1
- package/dist/helpers/VisionHelper.js +0 -71
- package/dist/helpers/VisionHelper.js.map +0 -1
- package/dist/helpers/decorators.js +0 -38
- package/dist/helpers/decorators.js.map +0 -1
package/main.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# This is a sample Python script.
|
|
2
|
+
|
|
3
|
+
# Press Shift+F10 to execute it or replace it with your code.
|
|
4
|
+
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def print_hi(name):
|
|
8
|
+
# Use a breakpoint in the code line below to debug your script.
|
|
9
|
+
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Press the green button in the gutter to run the script.
|
|
13
|
+
if __name__ == '__main__':
|
|
14
|
+
print_hi('PyCharm')
|
|
15
|
+
|
|
16
|
+
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
|
package/package.json
CHANGED
package/src/AST.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Scope} from "./Scope";
|
|
1
|
+
import {Scope, WrappedArray} from "./Scope";
|
|
2
2
|
import {DOM} from "./DOM";
|
|
3
3
|
import {DOMObject} from "./DOM/DOMObject";
|
|
4
4
|
import {TagList} from "./Tag/List";
|
|
@@ -143,7 +143,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
145
|
type: TokenType.ELEMENT_ATTRIBUTE,
|
|
146
|
-
pattern:
|
|
146
|
+
pattern: /^\.?@[_a-zA-Z0-9]*/
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
type: TokenType.ELEMENT_REFERENCE,
|
|
@@ -151,7 +151,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
153
|
type: TokenType.ELEMENT_QUERY,
|
|
154
|
-
pattern:
|
|
154
|
+
pattern: /^\?\(([#.\[\]:,=\-_a-zA-Z0-9*\s]*[\]_a-zA-Z0-9*])\)/
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
157
|
type: TokenType.NAME,
|
|
@@ -287,13 +287,11 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
287
287
|
}
|
|
288
288
|
];
|
|
289
289
|
|
|
290
|
-
|
|
291
290
|
export interface TreeNode<T = any> {
|
|
292
291
|
evaluate(scope: Scope, dom: DOM, tag?: Tag);
|
|
293
292
|
prepare(scope: Scope, dom: DOM, tag?: Tag);
|
|
294
293
|
}
|
|
295
294
|
|
|
296
|
-
|
|
297
295
|
export abstract class Node implements TreeNode {
|
|
298
296
|
protected requiresPrep: boolean = false;
|
|
299
297
|
protected _isPreparationRequired: boolean;
|
|
@@ -450,10 +448,15 @@ class ConditionalNode extends Node implements TreeNode {
|
|
|
450
448
|
|
|
451
449
|
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
452
450
|
const condition = await this.condition.evaluate(scope, dom, tag);
|
|
453
|
-
|
|
454
|
-
|
|
451
|
+
let evaluation = false;
|
|
452
|
+
|
|
453
|
+
if (condition instanceof WrappedArray) {
|
|
454
|
+
evaluation = condition.length > 0;
|
|
455
|
+
} else {
|
|
456
|
+
evaluation = !!condition;
|
|
455
457
|
}
|
|
456
|
-
|
|
458
|
+
|
|
459
|
+
return evaluation;
|
|
457
460
|
}
|
|
458
461
|
}
|
|
459
462
|
|
|
@@ -472,7 +475,7 @@ class IfStatementNode extends Node implements TreeNode {
|
|
|
472
475
|
|
|
473
476
|
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
474
477
|
for (const condition of this.nodes) {
|
|
475
|
-
const uno: boolean = await condition.
|
|
478
|
+
const uno: boolean = await condition.evaluate(scope, dom, tag);
|
|
476
479
|
if (uno) {
|
|
477
480
|
return await condition.block.evaluate(scope, dom, tag);
|
|
478
481
|
}
|
|
@@ -789,7 +792,8 @@ class RootScopeMemberNode<T = any> extends Node implements TreeNode {
|
|
|
789
792
|
}
|
|
790
793
|
|
|
791
794
|
async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
792
|
-
const
|
|
795
|
+
const name = await this.name.evaluate(scope, dom, tag);
|
|
796
|
+
const value = scope.get(name);
|
|
793
797
|
return value instanceof Scope && value.wrapped || value;
|
|
794
798
|
}
|
|
795
799
|
}
|
|
@@ -868,7 +872,7 @@ class ArithmeticAssignmentNode extends Node implements TreeNode {
|
|
|
868
872
|
} else {
|
|
869
873
|
scopes.push(inner);
|
|
870
874
|
}
|
|
871
|
-
} else if (this.left instanceof ElementAttributeNode) {
|
|
875
|
+
} else if (this.left instanceof ElementAttributeNode && this.left.elementRef) {
|
|
872
876
|
scopes = await this.left.elementRef.evaluate(scope, dom, tag);
|
|
873
877
|
} else
|
|
874
878
|
scopes.push(scope);
|
|
@@ -1092,7 +1096,7 @@ class ArrayNode extends Node implements TreeNode {
|
|
|
1092
1096
|
}
|
|
1093
1097
|
|
|
1094
1098
|
async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
1095
|
-
const arr: any
|
|
1099
|
+
const arr: WrappedArray<any> = new WrappedArray();
|
|
1096
1100
|
for (const val of this.values) {
|
|
1097
1101
|
arr.push(await val.evaluate(scope, dom, tag));
|
|
1098
1102
|
}
|
|
@@ -1187,7 +1191,7 @@ class ElementAttributeNode extends Node implements TreeNode {
|
|
|
1187
1191
|
protected requiresPrep: boolean = true;
|
|
1188
1192
|
|
|
1189
1193
|
constructor(
|
|
1190
|
-
public readonly elementRef: ElementQueryNode,
|
|
1194
|
+
public readonly elementRef: ElementQueryNode | null,
|
|
1191
1195
|
public readonly attr: string
|
|
1192
1196
|
) {
|
|
1193
1197
|
super();
|
|
@@ -1198,9 +1202,10 @@ class ElementAttributeNode extends Node implements TreeNode {
|
|
|
1198
1202
|
}
|
|
1199
1203
|
|
|
1200
1204
|
protected _getChildNodes(): Node[] {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1205
|
+
let nodes = [];
|
|
1206
|
+
if (this.elementRef)
|
|
1207
|
+
nodes.push(this.elementRef)
|
|
1208
|
+
return nodes;
|
|
1204
1209
|
}
|
|
1205
1210
|
|
|
1206
1211
|
get attributeName(): string {
|
|
@@ -1210,17 +1215,30 @@ class ElementAttributeNode extends Node implements TreeNode {
|
|
|
1210
1215
|
}
|
|
1211
1216
|
|
|
1212
1217
|
async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
1213
|
-
|
|
1218
|
+
let tags: TagList;
|
|
1219
|
+
if (this.elementRef) {
|
|
1220
|
+
tags = await this.elementRef.evaluate(scope, dom, tag);
|
|
1221
|
+
} else if (tag) {
|
|
1222
|
+
tags = new TagList(tag)
|
|
1223
|
+
} else {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1214
1227
|
if (tags.length === 1)
|
|
1215
1228
|
return tags[0].scope.get(`@${this.attributeName}`);
|
|
1229
|
+
|
|
1216
1230
|
return tags.map((tag) => tag.scope.get(`@${this.attributeName}`));
|
|
1217
1231
|
}
|
|
1218
1232
|
|
|
1219
1233
|
async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1234
|
+
if (this.elementRef) {
|
|
1235
|
+
await this.elementRef.prepare(scope, dom, tag);
|
|
1236
|
+
const tags: TagList = await this.elementRef.evaluate(scope, dom, tag);
|
|
1237
|
+
for (const t of tags)
|
|
1238
|
+
await t.watchAttribute(this.attributeName);
|
|
1239
|
+
} else if(tag) {
|
|
1223
1240
|
await tag.watchAttribute(this.attributeName);
|
|
1241
|
+
}
|
|
1224
1242
|
}
|
|
1225
1243
|
}
|
|
1226
1244
|
|
|
@@ -1273,7 +1291,7 @@ export class Tree {
|
|
|
1273
1291
|
let _scope: Scope = scope;
|
|
1274
1292
|
if (node instanceof ScopeMemberNode)
|
|
1275
1293
|
_scope = await node.scope.evaluate(scope, dom);
|
|
1276
|
-
else if (node instanceof ElementAttributeNode) {
|
|
1294
|
+
else if (node instanceof ElementAttributeNode && node.elementRef) {
|
|
1277
1295
|
_scope = (await node.elementRef.evaluate(scope, dom, tag))[0].scope;
|
|
1278
1296
|
}
|
|
1279
1297
|
|
|
@@ -1367,11 +1385,7 @@ export class Tree {
|
|
|
1367
1385
|
} else if (tokens[0].type === TokenType.L_BRACE) {
|
|
1368
1386
|
node = ObjectNode.parse(node, token, tokens);
|
|
1369
1387
|
} else if (tokens[0].type === TokenType.ELEMENT_ATTRIBUTE) {
|
|
1370
|
-
|
|
1371
|
-
node = new ElementAttributeNode(node, tokens[0].value);
|
|
1372
|
-
} else {
|
|
1373
|
-
node = new ScopeMemberNode(node, new LiteralNode<string>(tokens[0].value.substr(1)));
|
|
1374
|
-
}
|
|
1388
|
+
node = new ElementAttributeNode(node as any, tokens[0].value);
|
|
1375
1389
|
tokens.splice(0, 1);
|
|
1376
1390
|
} else if (node !== null && token.type === TokenType.PERIOD && tokens[1].type === TokenType.NAME) {
|
|
1377
1391
|
node = new ScopeMemberNode(
|
package/src/Scope.ts
CHANGED
|
@@ -101,6 +101,13 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
101
101
|
return removed;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
get(key: string) {
|
|
105
|
+
const keys: string[] = [
|
|
106
|
+
'length'
|
|
107
|
+
];
|
|
108
|
+
return keys.indexOf(key) > -1 ? this[key] : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
104
111
|
get length(): number {
|
|
105
112
|
let c: number = 0;
|
|
106
113
|
for (const item of this) {
|
|
@@ -110,6 +117,10 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
set length(num: number) {
|
|
120
|
+
this.setLength(num);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setLength(num: number) {
|
|
113
124
|
let c: number = 0;
|
|
114
125
|
const toRemove: T[] = [];
|
|
115
126
|
for (const item of this) {
|
package/src/Vision.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {DOM} from "./DOM";
|
|
2
2
|
import {EventDispatcher} from "simple-ts-event-dispatcher";
|
|
3
|
-
import {
|
|
3
|
+
import {WrappedArray} from "./Scope";
|
|
4
4
|
import {DataModel} from "simple-ts-models";
|
|
5
5
|
import {Registry} from "./Registry";
|
|
6
6
|
import "./Types";
|
|
7
7
|
import "./Formats";
|
|
8
|
-
import "./attributes/_imports";
|
|
9
8
|
import {Configuration} from "./Configuration";
|
|
10
9
|
import {VisionHelper} from "./helpers/VisionHelper";
|
|
11
10
|
import {Tree} from "./AST";
|
|
@@ -57,7 +56,7 @@ export class Vision extends EventDispatcher {
|
|
|
57
56
|
await this._dom.buildFrom(document, true);
|
|
58
57
|
const now = (new Date()).getTime();
|
|
59
58
|
const setupTime = now - startTime;
|
|
60
|
-
console.warn(`Took ${setupTime}ms to start up VisionJS
|
|
59
|
+
console.warn(`Took ${setupTime}ms to start up VisionJS. https://www.vsnjs.com/`);
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
public static get instance() {
|
|
@@ -68,6 +67,10 @@ export class Vision extends EventDispatcher {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
70
|
+
export * from "./attributes/_imports";
|
|
71
71
|
export * from './Registry';
|
|
72
72
|
export * from './Attribute';
|
|
73
|
+
export * from './AST';
|
|
74
|
+
export {DOM} from './DOM';
|
|
75
|
+
export {WrappedArray, Scope} from './Scope';
|
|
73
76
|
export const vision: Vision = Vision.instance;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
export {AddClassIf} from "./AddClassIf";
|
|
2
|
+
export {Bind} from "./Bind";
|
|
3
|
+
export {ClickRemoveClass} from "./ClickRemoveClass";
|
|
4
|
+
export {ClickToggleClass} from "./ClickToggleClass";
|
|
5
|
+
export {ControllerAttribute} from "./ControllerAttribute";
|
|
6
|
+
export {DisableIf} from "./DisableIf";
|
|
7
|
+
export {Exec} from "./Exec";
|
|
8
|
+
export {Format} from "./Format";
|
|
9
|
+
export {If} from "./If";
|
|
10
|
+
export {JSONAttribute} from "./JSONAttribute";
|
|
11
|
+
export {KeyDown} from "./KeyDown";
|
|
12
|
+
export {KeyUp} from "./KeyUp";
|
|
13
|
+
export {List} from "./List";
|
|
14
|
+
export {ListItem} from "./ListItem";
|
|
15
|
+
export {ListItemModel} from "./ListItemModel";
|
|
16
|
+
export {ModelAttribute} from "./ModelAttribute";
|
|
17
|
+
export {Name} from "./Name";
|
|
18
|
+
export {On} from "./On";
|
|
19
|
+
export {Radio} from "./Radio";
|
|
20
|
+
export {Referenced} from "./Referenced";
|
|
21
|
+
export {RootAttribute} from "./RootAttribute";
|
|
22
|
+
export {ScopeAttribute} from "./ScopeAttribute";
|
|
23
|
+
export {ScopeChange} from "./ScopeChange";
|
|
24
|
+
export {SetAttribute} from "./SetAttribute";
|
|
25
|
+
export {StandardAttribute} from "./StandardAttribute";
|
|
26
|
+
export {Template} from "./Template";
|
|
27
|
+
export {TypeAttribute} from "./TypeAttribute";
|
package/test/AST.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Promise as SimplePromise, IDeferred} from 'simple-ts-promise';
|
|
2
|
-
import {Scope} from "../src/Scope";
|
|
2
|
+
import {Scope, WrappedArray} from "../src/Scope";
|
|
3
3
|
import {Tree} from "../src/AST";
|
|
4
4
|
import {DOM} from "../src/DOM";
|
|
5
5
|
|
|
@@ -144,20 +144,44 @@ describe('Tree', () => {
|
|
|
144
144
|
expect(await tree.evaluate(scope, dom)).toBe(true);
|
|
145
145
|
// Multiple if statements
|
|
146
146
|
tree = new Tree(`
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
147
|
+
foo = 15;
|
|
148
|
+
if (foo > 5) {
|
|
149
|
+
foo = 3;
|
|
150
150
|
} else if (true) {
|
|
151
|
-
|
|
151
|
+
foo = 5;
|
|
152
152
|
} else {
|
|
153
|
-
|
|
153
|
+
foo = false;
|
|
154
154
|
}
|
|
155
|
-
if (
|
|
156
|
-
|
|
155
|
+
if (foo == 3) {
|
|
156
|
+
foo = 5;
|
|
157
157
|
}`);
|
|
158
158
|
await tree.evaluate(scope, dom);
|
|
159
|
-
expect(scope.get('
|
|
160
|
-
|
|
159
|
+
expect(scope.get('foo')).toBe(5);
|
|
160
|
+
|
|
161
|
+
// Array literals should be instantiaed as WrappedArray
|
|
162
|
+
tree = new Tree(`[123,456];`);
|
|
163
|
+
expect((await tree.evaluate(scope, dom)) instanceof WrappedArray).toBe(true);
|
|
164
|
+
|
|
165
|
+
// Array if statement and length test
|
|
166
|
+
tree = new Tree(`
|
|
167
|
+
foo1 = [1234,5678,9101112];
|
|
168
|
+
bar1 = [];
|
|
169
|
+
fooLength = foo1.length;
|
|
170
|
+
fooTest = false;
|
|
171
|
+
barTest = false;
|
|
172
|
+
|
|
173
|
+
if (foo1) {
|
|
174
|
+
fooTest = true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (bar1) {
|
|
178
|
+
barTest = true;
|
|
179
|
+
}
|
|
180
|
+
`);
|
|
181
|
+
await tree.evaluate(scope, dom);
|
|
182
|
+
expect(scope.get('fooTest')).toBe(true);
|
|
183
|
+
expect(scope.get('barTest')).toBe(false);
|
|
184
|
+
expect(scope.get('fooLength')).toBe(3);
|
|
161
185
|
});
|
|
162
186
|
|
|
163
187
|
it("should be able to assign variables properly", async () => {
|
|
@@ -203,11 +227,16 @@ describe('Tree', () => {
|
|
|
203
227
|
const dom: DOM = new DOM(document, false);
|
|
204
228
|
await tree.evaluate(scope, dom);
|
|
205
229
|
const something = scope.get('something');
|
|
206
|
-
expect(something).toEqual(
|
|
230
|
+
expect(something.length).toEqual(3);
|
|
231
|
+
expect(something[0]).toEqual(5);
|
|
232
|
+
expect(something[1]).toEqual(6);
|
|
233
|
+
expect(something[2]).toEqual(10);
|
|
207
234
|
|
|
208
235
|
tree = new Tree(`something -= 5;`);
|
|
209
236
|
await tree.evaluate(scope, dom);
|
|
210
|
-
expect(something).toEqual(
|
|
237
|
+
expect(something.length).toEqual(2);
|
|
238
|
+
expect(something[0]).toEqual(6);
|
|
239
|
+
expect(something[1]).toEqual(10);
|
|
211
240
|
});
|
|
212
241
|
|
|
213
242
|
it("should be able to block properly with promises", async () => {
|
package/test/DOM.spec.ts
CHANGED
|
@@ -28,8 +28,8 @@ describe('DOM', () => {
|
|
|
28
28
|
`;
|
|
29
29
|
const dom = new DOM(document);
|
|
30
30
|
dom.once('built', async () => {
|
|
31
|
-
expect(await dom.eval('(
|
|
32
|
-
expect(await dom.eval('(
|
|
31
|
+
expect(await dom.eval('?(#parent).asd')).toBe(123);
|
|
32
|
+
expect(await dom.eval('?(#testing).asd')).toBe(345);
|
|
33
33
|
done();
|
|
34
34
|
});
|
|
35
35
|
});
|
package/test/Scope.spec.ts
CHANGED
|
@@ -40,4 +40,18 @@ describe('WrappedArray', () => {
|
|
|
40
40
|
expect(removes).toBe(2);
|
|
41
41
|
expect(a.length).toBe(1);
|
|
42
42
|
});
|
|
43
|
+
|
|
44
|
+
it("should trigger change events", async () => {
|
|
45
|
+
const a = new WrappedArray();
|
|
46
|
+
let changes: number = 0;
|
|
47
|
+
a.bind('change', (e) => {
|
|
48
|
+
changes += 1;
|
|
49
|
+
});
|
|
50
|
+
a.push(1);
|
|
51
|
+
a.push(2);
|
|
52
|
+
a.push(3);
|
|
53
|
+
a.setLength(0);
|
|
54
|
+
expect(changes).toBe(6);
|
|
55
|
+
expect(a.length).toBe(0);
|
|
56
|
+
});
|
|
43
57
|
});
|
|
@@ -18,6 +18,19 @@ describe('Bind', () => {
|
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
it("vsn-bind to work with inner text with @text", (done) => {
|
|
22
|
+
document.body.innerHTML = `
|
|
23
|
+
<span id="test" test="testing" vsn-bind="@test"></span>
|
|
24
|
+
`;
|
|
25
|
+
const dom = new DOM(document);
|
|
26
|
+
dom.once('built', async () => {
|
|
27
|
+
const tag = await dom.getTagForElement(document.getElementById('test'));
|
|
28
|
+
expect(tag).toBeTruthy();
|
|
29
|
+
expect(tag.scope.get('@test')).toBe('testing');
|
|
30
|
+
done();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
21
34
|
it("vsn-bind order of execution to be left to right and top to bottom", (done) => {
|
|
22
35
|
document.body.innerHTML = `
|
|
23
36
|
<span id="test" vsn-name="test" vsn-bind:id="test.id" vsn-bind="test.id">testing</span>
|