vsn 0.1.144 → 0.1.145

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/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.1.144';
4
+ exports.VERSION = '0.1.145';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.144",
3
+ "version": "0.1.145",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -29,23 +29,20 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
29
29
  // @todo: Need to rewrite/refactor this. It's a bit of a mess with element queries.
30
30
  let tags: Tag[] = [];
31
31
  let functionScope: Scope = scope;
32
- let functionName: string = '';
33
- let instanceOfScopeMemberNode = false;
34
32
  if (this.fnc instanceof ScopeMemberNode) {
35
- instanceOfScopeMemberNode = true
36
- functionScope = await this.fnc.scope.evaluate(scope, dom, tag);
37
- functionName = await this.fnc.name.evaluate(scope, dom, tag);
38
33
  if (this.fnc.scope instanceof ElementQueryNode) {
39
34
  const _tags = await this.fnc.scope.evaluate(scope, dom, tag);
40
35
  if (_tags instanceof Array) {
41
36
  tags = _tags;
42
37
  } else if (_tags instanceof Tag) {
43
38
  tags = [_tags];
39
+ functionScope = _tags.scope;
44
40
  } else {
45
41
  throw new Error('Invalid element query result');
46
42
  }
47
43
  } else {
48
44
  tags = [tag];
45
+ functionScope = await this.fnc.scope.evaluate(scope, dom, tag);
49
46
  }
50
47
  }
51
48
 
@@ -54,28 +51,22 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
54
51
  if (!func || func instanceof Array) {
55
52
  const functionName = await (this.fnc as any).name.evaluate(scope, dom, tag);
56
53
  const returnValues = [];
57
- const toCleanup = [];
58
- let calls = 0;
59
54
 
60
55
  for (const _tag of tags) {
61
- let tagNum = 0;
62
- for (const className of _tag.element[ClassNode.ClassesVariable] || []) {
63
- tagNum++;
64
- const cls = Registry.instance.classes.getSynchronous(className);
65
- if (cls) {
66
- if (cls.classScope.has(functionName)) {
67
- const fnc = cls.classScope.get(functionName);
68
- toCleanup.push(fnc);
69
- returnValues.push(await (await fnc.evaluate(_tag.scope, dom, _tag))(...values));
70
- calls++;
71
- }
72
- }
56
+ functionScope = _tag.scope;
57
+ func = functionScope.get(functionName);
58
+ if (func instanceof FunctionNode) {
59
+ returnValues.push(await (await func.evaluate(functionScope, dom, _tag) as any)(...values));
60
+ await func.collectGarbage();
61
+ } else if (typeof func === 'function') {
62
+ returnValues.push(func.call(functionScope, ...values));
63
+ await func.collectGarbage();
64
+ } else {
65
+ console.warn(`Function ${functionName} was not found in current scope.`);
73
66
  }
74
67
  }
75
68
 
76
- for (const fnc of toCleanup) {
77
- await fnc.collectGarbage();
78
- }
69
+ const calls = returnValues.length;
79
70
  if (calls === 1) {
80
71
  return returnValues[0];
81
72
  } else if (calls === 0) {
package/src/AST.ts CHANGED
@@ -558,21 +558,29 @@ export class Tree {
558
558
  async bindToScopeChanges(scope, fnc, dom: DOM, tag: Tag = null) {
559
559
  for (const node of this._root.findChildrenByTypes<ScopeMemberNode | ElementAttributeNode>([RootScopeMemberNode, ScopeMemberNode, ElementAttributeNode], 'ScopeMemberNodes')) {
560
560
  let _scope: Scope = scope;
561
- if (node instanceof ScopeMemberNode)
561
+ const name = await node.name.evaluate(scope, dom, tag);
562
+ if (node instanceof ScopeMemberNode) {
562
563
  _scope = await node.scope.evaluate(scope, dom);
563
- else if (node instanceof ElementAttributeNode && node.elementRef) {
564
- _scope = (await node.elementRef.evaluate(scope, dom, tag))[0].scope;
564
+ _scope.on(`change:${name}`, fnc);
565
+ } else if (node instanceof ElementAttributeNode && node.elementRef) {
566
+ const ref = await node.elementRef.evaluate(scope, dom, tag);
567
+ if (ref instanceof Tag) {
568
+ ref.scope.on(`change:${name}`, fnc);
569
+ } else if (ref instanceof Array) {
570
+ for (const tag of ref) {
571
+ tag.scope.on(`change:${name}`, fnc);
572
+ }
573
+ } else {
574
+ console.warn(`Cannot bind to changes for ${name}.`);
575
+ }
565
576
  }
566
-
567
- const name = await node.name.evaluate(scope, dom, tag);
568
- _scope.on(`change:${name}`, fnc);
569
577
  }
570
578
  }
571
579
 
572
- public static reprepareExecutingTrees() {
573
- Tree.executing.forEach(async context => {
580
+ public static async reprepareExecutingTrees() {
581
+ for (const context of this.executing) {
574
582
  await context.tree.prepare(context.scope, context.dom, context.tag);
575
- });
583
+ }
576
584
  }
577
585
 
578
586
  public static tokenize(code: string): Token[] {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.144';
1
+ export const VERSION = '0.1.145';
2
2