vsn 0.1.14 → 0.1.18
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/vision.js +1 -1
- package/dist/AST.d.ts +2 -2
- package/dist/Scope.d.ts +1 -0
- package/dist/Vision.d.ts +4 -1
- package/dist/attributes/_imports.d.ts +27 -27
- package/dist/vision.min.js +1 -1
- package/package.json +2 -2
- package/src/AST.ts +13 -9
- package/src/Scope.ts +7 -0
- package/src/Vision.ts +6 -3
- package/src/attributes/_imports.ts +27 -27
- package/test/AST.spec.ts +41 -12
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vsn",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "SEO Friendly Javascript/Typescript Framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
7
7
|
"typescript"
|
|
8
8
|
],
|
|
9
|
-
"main": "./dist/
|
|
9
|
+
"main": "./dist/vision.min.js",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "rm -rf ./dist/ && tsc",
|
|
12
12
|
"build_dev": "rm -rf ./dist/ && webpack --env BUILD=development BENCHMARK=1",
|
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";
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
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) {
|
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 () => {
|