vsn 0.1.59 → 0.1.60
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 +4 -3
- package/demo/vsn.js +2 -2
- package/demo/{xhr.vsn → xhr.html} +8 -1
- package/dist/AST/ArithmeticAssignmentNode.d.ts +2 -1
- package/dist/AST/ArithmeticAssignmentNode.js +20 -18
- package/dist/AST/ArithmeticAssignmentNode.js.map +1 -1
- package/dist/AST/FunctionCallNode.js +13 -8
- package/dist/AST/FunctionCallNode.js.map +1 -1
- package/dist/AST/FunctionNode.d.ts +1 -1
- package/dist/AST/FunctionNode.js +30 -27
- package/dist/AST/FunctionNode.js.map +1 -1
- package/dist/Scope.d.ts +1 -0
- package/dist/Scope.js +5 -0
- package/dist/Scope.js.map +1 -1
- package/dist/attributes/RootAttribute.js +3 -0
- package/dist/attributes/RootAttribute.js.map +1 -1
- package/dist/vsn.js +1 -1
- package/dist/vsn.min.js +2 -2
- package/package.json +1 -1
- package/src/AST/ArithmeticAssignmentNode.ts +19 -17
- package/src/AST/FunctionCallNode.ts +7 -1
- package/src/AST/FunctionNode.ts +9 -8
- package/src/Scope.ts +6 -0
- package/src/attributes/RootAttribute.ts +3 -0
- package/src/vsn.ts +1 -1
package/package.json
CHANGED
|
@@ -59,7 +59,7 @@ export class ArithmeticAssignmentNode extends Node implements TreeNode {
|
|
|
59
59
|
const values = [];
|
|
60
60
|
for (let localScope of scopes) {
|
|
61
61
|
if (localScope instanceof DOMObject) {
|
|
62
|
-
await this.handleDOMObject(name, dom, localScope, tag);
|
|
62
|
+
await this.handleDOMObject(name, dom, scope, localScope, tag);
|
|
63
63
|
} else {
|
|
64
64
|
if (localScope['$wrapped'] && localScope['$scope']) {
|
|
65
65
|
localScope = localScope['$scope'];
|
|
@@ -68,16 +68,7 @@ export class ArithmeticAssignmentNode extends Node implements TreeNode {
|
|
|
68
68
|
// We get the values from the passed scope, but set the value on the local scope
|
|
69
69
|
let left: number | Array<any> | string = await this.left.evaluate(scope, dom, tag);
|
|
70
70
|
let right: number | Array<any> | string = await this.right.evaluate(scope, dom, tag);
|
|
71
|
-
|
|
72
|
-
if (left instanceof Array) {
|
|
73
|
-
left = this.handleArray(name, left, right, localScope);
|
|
74
|
-
} else if ((left as any) instanceof UnitLiteral || right instanceof UnitLiteral) {
|
|
75
|
-
left = this.handleUnit(name, left, right, localScope);
|
|
76
|
-
} else if (Number.isFinite(left)) {
|
|
77
|
-
left = this.handleNumber(name, left, right, localScope);
|
|
78
|
-
} else {
|
|
79
|
-
left = this.handleString(name, left, right, localScope);
|
|
80
|
-
}
|
|
71
|
+
left = this.handle(name, left, right, localScope);
|
|
81
72
|
|
|
82
73
|
values.push(left);
|
|
83
74
|
}
|
|
@@ -85,6 +76,20 @@ export class ArithmeticAssignmentNode extends Node implements TreeNode {
|
|
|
85
76
|
return values.length > 1 ? values : values[0];
|
|
86
77
|
}
|
|
87
78
|
|
|
79
|
+
public handle(name, left, right, localScope) {
|
|
80
|
+
if (left instanceof Array) {
|
|
81
|
+
left = this.handleArray(name, left, right, localScope);
|
|
82
|
+
} else if ((left as any) instanceof UnitLiteral || right instanceof UnitLiteral) {
|
|
83
|
+
left = this.handleUnit(name, left, right, localScope);
|
|
84
|
+
} else if (Number.isFinite(left)) {
|
|
85
|
+
left = this.handleNumber(name, left, right, localScope);
|
|
86
|
+
} else {
|
|
87
|
+
left = this.handleString(name, left, right, localScope);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return left;
|
|
91
|
+
}
|
|
92
|
+
|
|
88
93
|
public handleNumber(key, left, right, scope) {
|
|
89
94
|
if (right !== null && !Number.isFinite(right))
|
|
90
95
|
right = parseFloat(`${right}`);
|
|
@@ -167,13 +172,10 @@ export class ArithmeticAssignmentNode extends Node implements TreeNode {
|
|
|
167
172
|
return left;
|
|
168
173
|
}
|
|
169
174
|
|
|
170
|
-
public async handleDOMObject(key: string, dom: DOM, domObject: DOMObject, tag: Tag) {
|
|
175
|
+
public async handleDOMObject(key: string, dom: DOM, scope: Scope, domObject: DOMObject, tag: Tag) {
|
|
171
176
|
let left = domObject.scope.get(key);
|
|
172
|
-
let right: number | Array<any> | string = await this.right.evaluate(
|
|
173
|
-
|
|
174
|
-
return this.handleArray(key, left, right, domObject.scope);
|
|
175
|
-
|
|
176
|
-
return this.handleString(key, left, right, domObject.scope);
|
|
177
|
+
let right: number | Array<any> | string = await this.right.evaluate(scope, dom, tag);
|
|
178
|
+
return this.handle(key, left, right, domObject.scope);
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
public handleArray(key, left, right, scope) {
|
|
@@ -5,6 +5,7 @@ import {TreeNode} from "../AST";
|
|
|
5
5
|
import {Node} from "./Node";
|
|
6
6
|
import {FunctionArgumentNode} from "./FunctionArgumentNode";
|
|
7
7
|
import {ScopeMemberNode} from "./ScopeMemberNode";
|
|
8
|
+
import {FunctionNode} from "./FunctionNode";
|
|
8
9
|
|
|
9
10
|
export class FunctionCallNode<T = any> extends Node implements TreeNode {
|
|
10
11
|
constructor(
|
|
@@ -27,6 +28,11 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
|
|
|
27
28
|
functionScope = await this.fnc.scope.evaluate(scope, dom, tag);
|
|
28
29
|
}
|
|
29
30
|
const values = await this.args.evaluate(scope, dom, tag);
|
|
30
|
-
|
|
31
|
+
const func = await this.fnc.evaluate(scope, dom, tag);
|
|
32
|
+
if (func instanceof FunctionNode) {
|
|
33
|
+
return (await func.evaluate(functionScope, dom, tag) as any)(...values);
|
|
34
|
+
} else {
|
|
35
|
+
return func.call(functionScope.wrapped || functionScope, ...values);
|
|
36
|
+
}
|
|
31
37
|
}
|
|
32
38
|
}
|
package/src/AST/FunctionNode.ts
CHANGED
|
@@ -22,18 +22,19 @@ export class FunctionNode extends Node implements TreeNode {
|
|
|
22
22
|
];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
26
|
-
scope.set(this.name,
|
|
25
|
+
public async prepare(scope: Scope, dom: DOM, tag: Tag = null): Promise<void> {
|
|
26
|
+
scope.set(this.name, this);
|
|
27
|
+
await super.prepare(scope, dom, tag);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
31
|
+
return async (...args) => {
|
|
27
32
|
const functionScope = new Scope(scope);
|
|
28
33
|
for (const arg of this.args) {
|
|
29
34
|
functionScope.set(arg, args.shift());
|
|
30
35
|
}
|
|
31
|
-
return await this.evaluate(functionScope, dom, tag);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
36
|
-
return await this.block.evaluate(scope, dom, tag);
|
|
36
|
+
return await this.block.evaluate(functionScope, dom, tag);
|
|
37
|
+
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
public static parse(lastNode, token, tokens: Token[]): FunctionNode {
|
package/src/Scope.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {Attribute} from "../Attribute";
|
|
2
2
|
import {VisionHelper} from "../helpers/VisionHelper";
|
|
3
3
|
import {Registry} from "../Registry";
|
|
4
|
+
import {Scope} from "../Scope";
|
|
4
5
|
|
|
5
6
|
@Registry.attribute('vsn-root')
|
|
6
7
|
export class RootAttribute extends Attribute {
|
|
@@ -9,6 +10,8 @@ export class RootAttribute extends Attribute {
|
|
|
9
10
|
|
|
10
11
|
public async setup() {
|
|
11
12
|
this.tag.scope.set('$mobile', VisionHelper.isMobile());
|
|
13
|
+
if (console && !this.tag.scope.get('console'))
|
|
14
|
+
this.tag.scope.set('console', Scope.fromObject(console));
|
|
12
15
|
await super.setup();
|
|
13
16
|
}
|
|
14
17
|
}
|
package/src/vsn.ts
CHANGED
|
@@ -55,7 +55,7 @@ export class Vision extends EventDispatcher {
|
|
|
55
55
|
await this._dom.buildFrom(document, true);
|
|
56
56
|
const now = (new Date()).getTime();
|
|
57
57
|
const setupTime = now - startTime;
|
|
58
|
-
console.
|
|
58
|
+
console.info(`Took ${setupTime}ms to start up VisionJS. https://www.vsnjs.com/`, window ? `v${window['VSN_VERSION']}` : null);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
public static get instance() {
|