vsn 0.1.137 → 0.1.139

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.
Files changed (142) hide show
  1. package/demo/resources/xhr-memory-leak-test.html +2 -586
  2. package/demo/vsn.js +2 -2
  3. package/dist/AST/ArithmeticNode.d.ts +1 -1
  4. package/dist/AST/ArithmeticNode.js +1 -1
  5. package/dist/AST/ArithmeticNode.js.map +1 -1
  6. package/dist/AST/ArrayNode.d.ts +1 -1
  7. package/dist/AST/ArrayNode.js +1 -1
  8. package/dist/AST/ArrayNode.js.map +1 -1
  9. package/dist/AST/AsNode.d.ts +1 -1
  10. package/dist/AST/AsNode.js +1 -1
  11. package/dist/AST/AsNode.js.map +1 -1
  12. package/dist/AST/AssignmentNode.d.ts +1 -1
  13. package/dist/AST/AssignmentNode.js +1 -1
  14. package/dist/AST/AssignmentNode.js.map +1 -1
  15. package/dist/AST/BlockNode.d.ts +1 -1
  16. package/dist/AST/BlockNode.js +1 -1
  17. package/dist/AST/BlockNode.js.map +1 -1
  18. package/dist/AST/ClassNode.d.ts +1 -1
  19. package/dist/AST/ClassNode.js +1 -1
  20. package/dist/AST/ClassNode.js.map +1 -1
  21. package/dist/AST/ComparisonNode.d.ts +1 -1
  22. package/dist/AST/ComparisonNode.js +1 -1
  23. package/dist/AST/ComparisonNode.js.map +1 -1
  24. package/dist/AST/ConditionalNode.d.ts +1 -1
  25. package/dist/AST/ConditionalNode.js +1 -1
  26. package/dist/AST/ConditionalNode.js.map +1 -1
  27. package/dist/AST/DispatchEventNode.d.ts +1 -1
  28. package/dist/AST/DispatchEventNode.js +1 -1
  29. package/dist/AST/DispatchEventNode.js.map +1 -1
  30. package/dist/AST/ElementAttributeNode.d.ts +1 -1
  31. package/dist/AST/ElementAttributeNode.js +1 -1
  32. package/dist/AST/ElementAttributeNode.js.map +1 -1
  33. package/dist/AST/ElementQueryNode.d.ts +1 -0
  34. package/dist/AST/ElementQueryNode.js +15 -0
  35. package/dist/AST/ElementQueryNode.js.map +1 -1
  36. package/dist/AST/ElementStyleNode.d.ts +1 -1
  37. package/dist/AST/ElementStyleNode.js +1 -1
  38. package/dist/AST/ElementStyleNode.js.map +1 -1
  39. package/dist/AST/ForStatementNode.d.ts +1 -1
  40. package/dist/AST/ForStatementNode.js +1 -1
  41. package/dist/AST/ForStatementNode.js.map +1 -1
  42. package/dist/AST/FunctionArgumentNode.d.ts +1 -1
  43. package/dist/AST/FunctionArgumentNode.js +1 -1
  44. package/dist/AST/FunctionArgumentNode.js.map +1 -1
  45. package/dist/AST/FunctionCallNode.d.ts +1 -1
  46. package/dist/AST/FunctionCallNode.js +1 -1
  47. package/dist/AST/FunctionCallNode.js.map +1 -1
  48. package/dist/AST/FunctionNode.d.ts +1 -1
  49. package/dist/AST/FunctionNode.js +1 -1
  50. package/dist/AST/FunctionNode.js.map +1 -1
  51. package/dist/AST/IfStatementNode.d.ts +1 -1
  52. package/dist/AST/IfStatementNode.js +1 -1
  53. package/dist/AST/IfStatementNode.js.map +1 -1
  54. package/dist/AST/InNode.d.ts +1 -1
  55. package/dist/AST/InNode.js +1 -1
  56. package/dist/AST/InNode.js.map +1 -1
  57. package/dist/AST/IndexNode.d.ts +1 -1
  58. package/dist/AST/IndexNode.js +1 -1
  59. package/dist/AST/IndexNode.js.map +1 -1
  60. package/dist/AST/LiteralNode.d.ts +1 -1
  61. package/dist/AST/LiteralNode.js +1 -1
  62. package/dist/AST/LiteralNode.js.map +1 -1
  63. package/dist/AST/ModifierNode.d.ts +1 -1
  64. package/dist/AST/ModifierNode.js +1 -1
  65. package/dist/AST/ModifierNode.js.map +1 -1
  66. package/dist/AST/NamedStackNode.d.ts +1 -1
  67. package/dist/AST/NamedStackNode.js +1 -1
  68. package/dist/AST/NamedStackNode.js.map +1 -1
  69. package/dist/AST/Node.d.ts +2 -1
  70. package/dist/AST/Node.js +19 -0
  71. package/dist/AST/Node.js.map +1 -1
  72. package/dist/AST/NotNode.d.ts +1 -1
  73. package/dist/AST/NotNode.js +1 -1
  74. package/dist/AST/NotNode.js.map +1 -1
  75. package/dist/AST/ObjectNode.d.ts +1 -1
  76. package/dist/AST/ObjectNode.js +1 -1
  77. package/dist/AST/ObjectNode.js.map +1 -1
  78. package/dist/AST/RootScopeMemberNode.d.ts +1 -1
  79. package/dist/AST/RootScopeMemberNode.js +1 -1
  80. package/dist/AST/RootScopeMemberNode.js.map +1 -1
  81. package/dist/AST/ScopeMemberNode.d.ts +1 -1
  82. package/dist/AST/ScopeMemberNode.js +1 -1
  83. package/dist/AST/ScopeMemberNode.js.map +1 -1
  84. package/dist/AST/StringFormatNode.d.ts +1 -1
  85. package/dist/AST/StringFormatNode.js +1 -1
  86. package/dist/AST/StringFormatNode.js.map +1 -1
  87. package/dist/AST/WithNode.d.ts +1 -1
  88. package/dist/AST/WithNode.js +1 -1
  89. package/dist/AST/WithNode.js.map +1 -1
  90. package/dist/AST/XHRNode.d.ts +1 -1
  91. package/dist/AST/XHRNode.js +1 -1
  92. package/dist/AST/XHRNode.js.map +1 -1
  93. package/dist/DOM/DOMObject.js +0 -1
  94. package/dist/DOM/DOMObject.js.map +1 -1
  95. package/dist/EventDispatcher.js +2 -1
  96. package/dist/EventDispatcher.js.map +1 -1
  97. package/dist/Scope/ScopeDataAbstract.js +1 -1
  98. package/dist/Scope/ScopeDataAbstract.js.map +1 -1
  99. package/dist/Scope.js +27 -13
  100. package/dist/Scope.js.map +1 -1
  101. package/dist/Tag.d.ts +3 -2
  102. package/dist/Tag.js +8 -0
  103. package/dist/Tag.js.map +1 -1
  104. package/dist/version.d.ts +1 -1
  105. package/dist/version.js +1 -1
  106. package/package.json +1 -1
  107. package/src/AST/ArithmeticNode.ts +1 -1
  108. package/src/AST/ArrayNode.ts +1 -1
  109. package/src/AST/AsNode.ts +1 -1
  110. package/src/AST/AssignmentNode.ts +1 -1
  111. package/src/AST/BlockNode.ts +1 -1
  112. package/src/AST/ClassNode.ts +1 -1
  113. package/src/AST/ComparisonNode.ts +1 -1
  114. package/src/AST/ConditionalNode.ts +1 -1
  115. package/src/AST/DispatchEventNode.ts +1 -1
  116. package/src/AST/ElementAttributeNode.ts +1 -1
  117. package/src/AST/ElementQueryNode.ts +8 -2
  118. package/src/AST/ElementStyleNode.ts +1 -1
  119. package/src/AST/ForStatementNode.ts +1 -1
  120. package/src/AST/FunctionArgumentNode.ts +1 -1
  121. package/src/AST/FunctionCallNode.ts +1 -1
  122. package/src/AST/FunctionNode.ts +1 -1
  123. package/src/AST/IfStatementNode.ts +1 -1
  124. package/src/AST/InNode.ts +1 -1
  125. package/src/AST/IndexNode.ts +1 -1
  126. package/src/AST/LiteralNode.ts +1 -1
  127. package/src/AST/ModifierNode.ts +1 -1
  128. package/src/AST/NamedStackNode.ts +1 -1
  129. package/src/AST/Node.ts +9 -2
  130. package/src/AST/NotNode.ts +1 -1
  131. package/src/AST/ObjectNode.ts +1 -1
  132. package/src/AST/RootScopeMemberNode.ts +1 -1
  133. package/src/AST/ScopeMemberNode.ts +1 -1
  134. package/src/AST/StringFormatNode.ts +1 -1
  135. package/src/AST/WithNode.ts +1 -1
  136. package/src/AST/XHRNode.ts +1 -1
  137. package/src/DOM/DOMObject.ts +0 -1
  138. package/src/EventDispatcher.ts +2 -1
  139. package/src/Scope/ScopeDataAbstract.ts +2 -1
  140. package/src/Scope.ts +6 -1
  141. package/src/Tag.ts +7 -0
  142. package/src/version.ts +1 -1
@@ -18,7 +18,7 @@ export class ModifierNode extends Node implements TreeNode {
18
18
  return null;
19
19
  }
20
20
 
21
- public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
21
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
22
22
  return null;
23
23
  }
24
24
 
@@ -32,7 +32,7 @@ export class NamedStackNode extends Node implements TreeNode {
32
32
  ]
33
33
  }
34
34
 
35
- public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
35
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
36
36
  if (scope instanceof FunctionScope) { // NamedStackNode doesn't work with FunctionScope
37
37
  scope = scope.parentScope;
38
38
  }
package/src/AST/Node.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {Scope} from "../Scope";
2
2
  import {DOM} from "../DOM";
3
- import {Tag} from "../Tag";
3
+ import {Tag, TagState} from "../Tag";
4
4
  import {Token, TokenType, TreeNode} from "../AST";
5
5
  import {Modifiers} from "../Modifiers";
6
6
 
@@ -14,7 +14,14 @@ export abstract class Node implements TreeNode {
14
14
  protected childNodes: Node[];
15
15
  protected nodeCache: {[key: string]: Node[]} = {};
16
16
  public readonly modifiers: Modifiers = new Modifiers();
17
- abstract evaluate(scope: Scope, dom: DOM, tag?: Tag);
17
+
18
+ async evaluate(scope: Scope, dom: DOM, tag?: Tag): Promise<any> {
19
+ if (scope.isGarbage || (tag && tag.state === TagState.Deconstructed))
20
+ return;
21
+ return await this._evaluate(scope, dom, tag);
22
+ }
23
+
24
+ protected async _evaluate(scope: Scope, dom: DOM, tag?: Tag): Promise<any> {}
18
25
 
19
26
  isPreparationRequired(): boolean {
20
27
  if (this.requiresPrep)
@@ -11,7 +11,7 @@ export class NotNode extends Node implements TreeNode {
11
11
  super();
12
12
  }
13
13
 
14
- public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
14
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
15
15
  const flipping = await this.toFlip.evaluate(scope, dom, tag);
16
16
  return !flipping;
17
17
  }
@@ -16,7 +16,7 @@ export class ObjectNode extends Node implements TreeNode {
16
16
  return new Array(...this.values);
17
17
  }
18
18
 
19
- async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
19
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
20
20
  const obj: Scope = new Scope();
21
21
  for (let i = 0; i < this.values.length; i++) {
22
22
  const key = this.keys[i];
@@ -18,7 +18,7 @@ export class RootScopeMemberNode<T = any> extends ScopeNodeAbstract implements T
18
18
  ]
19
19
  }
20
20
 
21
- async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
21
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
22
22
  const name = await this.name.evaluate(scope, dom, tag);
23
23
  await this.applyModifiers(name, scope, dom, tag);
24
24
  const value = scope.get(name);
@@ -25,7 +25,7 @@ export class ScopeMemberNode extends ScopeNodeAbstract implements TreeNode {
25
25
  ]
26
26
  }
27
27
 
28
- async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
28
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
29
29
  let scopes = [];
30
30
  const values = [];
31
31
  if (this.scope instanceof ElementQueryNode) {
@@ -16,7 +16,7 @@ export class StringFormatNode extends Node implements TreeNode {
16
16
  return this.segments && Object.values(this.segments) || [];
17
17
  }
18
18
 
19
- async evaluate(scope: Scope, dom: DOM, tag?: Tag) {
19
+ protected async _evaluate(scope: Scope, dom: DOM, tag?: Tag) {
20
20
  let value = this.value;
21
21
  for (const key in this.segments) {
22
22
  const segment = this.segments[key];
@@ -23,7 +23,7 @@ export class WithNode extends Node implements TreeNode {
23
23
  ]
24
24
  }
25
25
 
26
- public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
26
+ protected async _evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
27
27
  const context = await this.context.evaluate(scope, dom, tag);
28
28
  let tags = [];
29
29
  if (context instanceof TagList) {
@@ -22,7 +22,7 @@ export class XHRNode extends Node implements TreeNode {
22
22
  return nodes;
23
23
  }
24
24
 
25
- async evaluate(scope: Scope, dom: DOM, tag?: Tag) {
25
+ protected async _evaluate(scope: Scope, dom: DOM, tag?: Tag) {
26
26
  let url = await this.url.evaluate(scope, dom, tag);
27
27
  let method: string;
28
28
  let data = this.left ? await this.left.evaluate(scope, dom, tag) : {};
@@ -71,7 +71,6 @@ export abstract class DOMObject extends EventDispatcher {
71
71
  if (this.element) {
72
72
  this.element[Tag.TaggedVariable] = null;
73
73
  this.element[ClassNode.ClassesVariable] = null;
74
- (this as any).element = null;
75
74
  }
76
75
  super.deconstruct();
77
76
  }
@@ -51,8 +51,9 @@ export class EventDispatcher {
51
51
  deconstruct() {
52
52
  this.dispatch('deconstruct', this);
53
53
  const sourceIndex = EventDispatcher.sources.indexOf(this);
54
- if (sourceIndex > -1)
54
+ if (sourceIndex > -1) {
55
55
  EventDispatcher.sources.splice(sourceIndex, 1);
56
+ }
56
57
 
57
58
  for (const k in this._listeners) {
58
59
  for (const cb of this._listeners[k]) {
@@ -25,7 +25,7 @@ export class ScopeDataAbstract extends EventDispatcher {
25
25
  deconstruct() {
26
26
  super.deconstruct();
27
27
  this._lastData = null;
28
- for (const prop of this.__properties__) {
28
+ for (const prop of Array.from(this.__properties__)) {
29
29
  this.removeProperty(prop);
30
30
  }
31
31
  this.__properties__.length = 0;
@@ -39,6 +39,7 @@ export class ScopeDataAbstract extends EventDispatcher {
39
39
  if (this.hasProperty(name)) {
40
40
  return this.getProperty(name);
41
41
  }
42
+
42
43
  config = config || {};
43
44
  const instance = new propertyType(config.default, config);
44
45
  const propDesc = Object.getOwnPropertyDescriptor(this, name);
package/src/Scope.ts CHANGED
@@ -29,12 +29,17 @@ export class Scope extends ScopeAbstract {
29
29
  deconstruct() {
30
30
  super.deconstruct();
31
31
  this.collectGarbage(true);
32
+
32
33
  this.wrapped = null;
33
34
  if (this._data)
34
35
  this._data.deconstruct();
35
36
  this._data = null;
37
+
38
+ for (const child of this.children) {
39
+ child.deconstruct();
40
+ }
36
41
  this.children.length = 0;
37
- this._parentScope = null;
42
+ this.parentScope = null;
38
43
  }
39
44
 
40
45
  public get data(): ScopeData {
package/src/Tag.ts CHANGED
@@ -19,6 +19,7 @@ export enum TagState {
19
19
  AttributesExtracted,
20
20
  AttributesConnected,
21
21
  Built,
22
+ Deconstructed,
22
23
  }
23
24
 
24
25
  export class Tag extends DOMObject {
@@ -412,6 +413,7 @@ export class Tag extends DOMObject {
412
413
  }
413
414
 
414
415
  public setElementAttribute(key: string, value: any) {
416
+ if (!this.element) return null;
415
417
  if (this.isMagicAttribute(key)) {
416
418
  if (key === '@text')
417
419
  this.element.innerText = value;
@@ -441,6 +443,7 @@ export class Tag extends DOMObject {
441
443
  }
442
444
 
443
445
  public getElementAttribute(key: string): any {
446
+ if (!this.element) return null;
444
447
  if (this.isMagicAttribute(key)) {
445
448
  if (key === '@text')
446
449
  return this.element.innerText;
@@ -620,6 +623,9 @@ export class Tag extends DOMObject {
620
623
  }
621
624
 
622
625
  protected handleEvent(eventType: string, e) {
626
+ if (this.state === TagState.Deconstructed)
627
+ return
628
+
623
629
  if (e)
624
630
  e.stopPropagation();
625
631
 
@@ -809,6 +815,7 @@ export class Tag extends DOMObject {
809
815
  }
810
816
 
811
817
  deconstruct() {
818
+ this._state = TagState.Deconstructed
812
819
  const dom = this.dom || DOM.instance;
813
820
  if (dom) {
814
821
  dom.removedQueued(this.element);
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.137';
1
+ export const VERSION = '0.1.139';
2
2