vsn 0.1.69 → 0.1.70
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/vsn.js +2 -2
- package/demo/xhr.html +6 -68
- package/dist/vsn.min.js +2 -0
- package/package.json +1 -1
- package/src/AST/FunctionCallNode.ts +22 -10
- package/src/AST/FunctionNode.ts +1 -0
- package/test/AST/ClassNode.spec.ts +29 -0
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import {FunctionArgumentNode} from "./FunctionArgumentNode";
|
|
|
7
7
|
import {ScopeMemberNode} from "./ScopeMemberNode";
|
|
8
8
|
import {FunctionNode} from "./FunctionNode";
|
|
9
9
|
import {Registry} from "../Registry";
|
|
10
|
+
import {ElementQueryNode} from "./ElementQueryNode";
|
|
10
11
|
|
|
11
12
|
export class FunctionCallNode<T = any> extends Node implements TreeNode {
|
|
12
13
|
constructor(
|
|
@@ -24,26 +25,37 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
28
|
+
// @todo: Need to rewrite/refactor this. It's a bit of a mess with element queries.
|
|
29
|
+
let tags: Tag[];
|
|
27
30
|
let functionScope: Scope = scope;
|
|
28
31
|
if (this.fnc instanceof ScopeMemberNode) {
|
|
29
32
|
functionScope = await this.fnc.scope.evaluate(scope, dom, tag);
|
|
33
|
+
if (this.fnc.scope instanceof ElementQueryNode) {
|
|
34
|
+
tags = await this.fnc.scope.evaluate(scope, dom, tag) as Tag[];
|
|
35
|
+
} else {
|
|
36
|
+
tags = [tag];
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
const values = await this.args.evaluate(scope, dom, tag);
|
|
33
|
-
|
|
34
|
-
if (!func) {
|
|
41
|
+
let func = await this.fnc.evaluate(scope, dom, tag);
|
|
42
|
+
if (!func || func instanceof Array) {
|
|
35
43
|
const functionName = await (this.fnc as any).name.evaluate(scope, dom, tag);
|
|
36
44
|
const returnValues = [];
|
|
37
45
|
const toCleanup = [];
|
|
38
46
|
let calls = 0;
|
|
39
|
-
for (const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
for (const _tag of tags) {
|
|
48
|
+
let tagNum = 0;
|
|
49
|
+
for (const className of _tag.preppedClasses) {
|
|
50
|
+
tagNum++;
|
|
51
|
+
const cls = Registry.instance.classes.getSynchronous(className);
|
|
52
|
+
if (cls) {
|
|
53
|
+
if (cls.classScope.has(functionName)) {
|
|
54
|
+
const fnc = cls.classScope.get(functionName);
|
|
55
|
+
toCleanup.push(fnc);
|
|
56
|
+
returnValues.push(await (await fnc.evaluate(_tag.scope, dom, _tag))(...values));
|
|
57
|
+
calls++;
|
|
58
|
+
}
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
}
|
package/src/AST/FunctionNode.ts
CHANGED
|
@@ -41,6 +41,7 @@ export class FunctionNode extends Node implements TreeNode {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
public async getFunction(scope: Scope, dom: DOM, tag: Tag = null, createFunctionScope: boolean = true) {
|
|
44
|
+
console.log(`FunctionNode.getFunction(${this.name})`);
|
|
44
45
|
const self = this;
|
|
45
46
|
return async (...args) => {
|
|
46
47
|
let functionScope;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {DOM} from "../../src/DOM";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
describe('ClassNode', () => {
|
|
5
|
+
it("properly define a simple class", (done) => {
|
|
6
|
+
document.body.innerHTML = `
|
|
7
|
+
<script type="text/vsn" vsn-script>
|
|
8
|
+
class simple {
|
|
9
|
+
func construct() {
|
|
10
|
+
a|integer = "15";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func test() {
|
|
14
|
+
a += 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
18
|
+
<div class="simple"></div>
|
|
19
|
+
<div class="simple"></div>
|
|
20
|
+
`;
|
|
21
|
+
const dom = new DOM(document);
|
|
22
|
+
dom.once('built', async () => {
|
|
23
|
+
expect(await dom.exec('?(.simple).a')).toEqual([15, 15]);
|
|
24
|
+
await dom.exec('?(.simple).test()');
|
|
25
|
+
expect(await dom.exec('?(.simple).a')).toEqual([16, 16]);
|
|
26
|
+
done();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|