vsn 0.1.68 → 0.1.69

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 (45) hide show
  1. package/demo/vsn.js +2 -2
  2. package/demo/xhr.html +9 -2
  3. package/dist/AST/ClassNode.js +18 -12
  4. package/dist/AST/ClassNode.js.map +1 -1
  5. package/dist/AST/FunctionCallNode.js +46 -24
  6. package/dist/AST/FunctionCallNode.js.map +1 -1
  7. package/dist/AST/FunctionNode.d.ts +4 -2
  8. package/dist/AST/FunctionNode.js +25 -2
  9. package/dist/AST/FunctionNode.js.map +1 -1
  10. package/dist/AST/ModifierNode.d.ts +14 -0
  11. package/dist/AST/ModifierNode.js +88 -0
  12. package/dist/AST/ModifierNode.js.map +1 -0
  13. package/dist/AST/Node.d.ts +2 -0
  14. package/dist/AST/Node.js +24 -0
  15. package/dist/AST/Node.js.map +1 -1
  16. package/dist/AST/OnNode.js +26 -8
  17. package/dist/AST/OnNode.js.map +1 -1
  18. package/dist/AST/RootScopeMemberNode.d.ts +2 -1
  19. package/dist/AST/RootScopeMemberNode.js +5 -2
  20. package/dist/AST/RootScopeMemberNode.js.map +1 -1
  21. package/dist/AST/ScopeMemberNode.d.ts +2 -1
  22. package/dist/AST/ScopeMemberNode.js +9 -6
  23. package/dist/AST/ScopeMemberNode.js.map +1 -1
  24. package/dist/AST/ScopeNodeAbstract.d.ts +8 -0
  25. package/dist/AST/ScopeNodeAbstract.js +82 -0
  26. package/dist/AST/ScopeNodeAbstract.js.map +1 -0
  27. package/dist/AST.d.ts +2 -1
  28. package/dist/AST.js +9 -0
  29. package/dist/AST.js.map +1 -1
  30. package/dist/Scope.d.ts +4 -0
  31. package/dist/Scope.js +32 -3
  32. package/dist/Scope.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/AST/ClassNode.ts +7 -4
  35. package/src/AST/FunctionCallNode.ts +9 -2
  36. package/src/AST/FunctionNode.ts +17 -2
  37. package/src/AST/ModifierNode.ts +30 -0
  38. package/src/AST/Node.ts +7 -0
  39. package/src/AST/OnNode.ts +7 -2
  40. package/src/AST/RootScopeMemberNode.ts +3 -1
  41. package/src/AST/ScopeMemberNode.ts +3 -1
  42. package/src/AST/ScopeNodeAbstract.ts +20 -0
  43. package/src/AST.ts +8 -0
  44. package/src/Scope.ts +32 -3
  45. package/dist/vsn.min.js +0 -2
@@ -6,8 +6,9 @@ import {DOMObject} from "../DOM/DOMObject";
6
6
  import {TreeNode} from "../AST";
7
7
  import {Node} from "./Node";
8
8
  import {ElementQueryNode} from "./ElementQueryNode";
9
+ import {ScopeNodeAbstract} from "./ScopeNodeAbstract";
9
10
 
10
- export class ScopeMemberNode extends Node implements TreeNode {
11
+ export class ScopeMemberNode extends ScopeNodeAbstract implements TreeNode {
11
12
  constructor(
12
13
  public readonly scope: TreeNode<Scope>,
13
14
  public readonly name: TreeNode<string>
@@ -50,6 +51,7 @@ export class ScopeMemberNode extends Node implements TreeNode {
50
51
  throw Error(`Cannot access "${await this.name.evaluate(scope, dom, tag)}" of undefined.`);
51
52
  }
52
53
  const name = await this.name.evaluate(scope, dom, tag);
54
+ await this.applyModifiers(name, parent, dom, tag);
53
55
  const value: any = parent.get(name, false);
54
56
  values.push(value instanceof Scope && value.wrapped || value);
55
57
  }
@@ -0,0 +1,20 @@
1
+ import {Node} from "./Node";
2
+ import {TreeNode} from "../AST";
3
+ import {Scope} from "../Scope";
4
+ import {DOM} from "../DOM";
5
+ import {Tag} from "../Tag";
6
+ import {Registry} from "../Registry";
7
+
8
+ export abstract class ScopeNodeAbstract extends Node implements TreeNode {
9
+ async applyModifiers(name: string, scope: Scope, dom: DOM, tag: Tag) {
10
+ let type: string;
11
+ for (const modifier of this.modifiers) {
12
+ if (Registry.instance.types.has(modifier)) {
13
+ type = modifier;
14
+ break;
15
+ }
16
+ }
17
+ if (type)
18
+ scope.setType(name, type);
19
+ }
20
+ }
package/src/AST.ts CHANGED
@@ -29,6 +29,7 @@ import {StringFormatNode} from "./AST/StringFormatNode";
29
29
  import {FunctionNode} from "./AST/FunctionNode";
30
30
  import {ClassNode} from "./AST/ClassNode";
31
31
  import {OnNode} from "./AST/OnNode";
32
+ import {ModifierNode} from "./AST/ModifierNode";
32
33
 
33
34
  function lower(str: string): string {
34
35
  return str ? str.toLowerCase() : null;
@@ -117,6 +118,7 @@ export enum TokenType {
117
118
  XHR_POST,
118
119
  XHR_PUT,
119
120
  XHR_DELETE,
121
+ MODIFIER,
120
122
  }
121
123
 
122
124
  const TOKEN_PATTERNS: TokenPattern[] = [
@@ -363,6 +365,10 @@ const TOKEN_PATTERNS: TokenPattern[] = [
363
365
  {
364
366
  type: TokenType.EXCLAMATION_POINT,
365
367
  pattern: /^!/
368
+ },
369
+ {
370
+ type: TokenType.MODIFIER,
371
+ pattern: /^\|\S+/
366
372
  }
367
373
  ];
368
374
 
@@ -585,6 +591,8 @@ export class Tree {
585
591
  tokens.shift()
586
592
  } else if (tokens[0].type === TokenType.EXCLAMATION_POINT) {
587
593
  node = NotNode.parse(node, tokens[0], tokens);
594
+ } else if (tokens[0].type === TokenType.MODIFIER) {
595
+ node = ModifierNode.parse(node, tokens[0], tokens);
588
596
  } else {
589
597
  let code: string = Tree.toCode(tokens, 10);
590
598
  throw Error(`Syntax Error. Near ${code}`);
package/src/Scope.ts CHANGED
@@ -32,14 +32,25 @@ export class Scope extends EventDispatcher {
32
32
  }
33
33
 
34
34
  public set parentScope(scope: Scope) {
35
- this._parentScope = scope;
36
- scope.addChild(this);
35
+ if (scope) {
36
+ this._parentScope = scope;
37
+ scope.addChild(this);
38
+ } else if (this._parentScope){
39
+ this._parentScope.removeChild(this);
40
+ this._parentScope = null;
41
+ }
37
42
  }
38
43
 
39
44
  public addChild(scope: Scope) {
40
45
  this.children.push(scope);
41
46
  }
42
47
 
48
+ public removeChild(scope: Scope) {
49
+ const index = this.children.indexOf(scope);
50
+ if (index > -1)
51
+ this.children.splice(index, 1);
52
+ }
53
+
43
54
  getReference(path: string, createIfNotFound: boolean = true): ScopeReference {
44
55
  const scopePath: string[] = path.split('.');
45
56
  let key: string = scopePath[0];
@@ -127,6 +138,19 @@ export class Scope extends EventDispatcher {
127
138
  this.parentScope = null;
128
139
  }
129
140
 
141
+ collectGarbage(force: boolean = false) {
142
+ for (const child of this.children) {
143
+ child.collectGarbage(force);
144
+ }
145
+ if (force)
146
+ this.cleanup();
147
+ }
148
+
149
+ deconstruct() {
150
+ super.deconstruct();
151
+ this.collectGarbage(true);
152
+ }
153
+
130
154
  public wrap(toWrap: any, triggerUpdates: boolean = false, updateFromWrapped: boolean = true) {
131
155
  if (toWrap instanceof ScopeData) {
132
156
  if (this._data instanceof EventDispatcher) {
@@ -235,10 +259,15 @@ export class FunctionScope extends Scope {
235
259
  }
236
260
 
237
261
  set(key: string, value: any) {
238
- if (this.parentScope.has(key) || ['$', '@'].indexOf(key[0]) > -1) {
262
+ if (this.parentScope && (this.parentScope.has(key) || ['$', '@'].indexOf(key[0]) > -1)) {
239
263
  this.parentScope.set(key, value);
240
264
  } else {
241
265
  super.set(key, value);
242
266
  }
243
267
  }
268
+
269
+ collectGarbage(force: boolean = true) {
270
+ super.collectGarbage(true);
271
+ this.cleanup();
272
+ }
244
273
  }