vsn 0.1.119 → 0.1.121

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.118';
4
+ exports.VERSION = '0.1.121';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.119",
3
+ "version": "0.1.121",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -24,7 +24,9 @@ export class ModifierNode extends Node implements TreeNode {
24
24
 
25
25
  public static parse(lastNode, token, tokens: Token[]): Node {
26
26
  const modifier = tokens.shift().value.substr(1);
27
- lastNode.modifiers.push(modifier);
27
+ if (lastNode) {
28
+ lastNode.modifiers.push(modifier);
29
+ }
28
30
  return lastNode;
29
31
  }
30
32
  }
package/src/AST/Node.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {Scope} from "../Scope";
2
2
  import {DOM} from "../DOM";
3
3
  import {Tag} from "../Tag";
4
- import {TreeNode} from "../AST";
4
+ import {Token, TokenType, TreeNode} from "../AST";
5
5
 
6
6
  export interface INodeMeta {
7
7
  [key: string]: string | number | boolean | null;
@@ -78,5 +78,15 @@ export abstract class Node implements TreeNode {
78
78
 
79
79
  return nodes;
80
80
  }
81
+
82
+ hasModifier(modifier: string): boolean {
83
+ return this.modifiers.indexOf(modifier) !== -1;
84
+ }
85
+
86
+ public static moveModifiers(from: Token[], to: Token[]) {
87
+ while (from[0].type == TokenType.MODIFIER) {
88
+ to.unshift(from.shift());
89
+ }
90
+ }
81
91
  }
82
92
 
@@ -1,12 +1,14 @@
1
1
  import {Scope} from "../Scope";
2
2
  import {DOM} from "../DOM";
3
3
  import {Tag} from "../Tag";
4
- import {BlockType, Token, TokenType, Tree, TreeNode} from "../AST";
4
+ import {Token, TokenType, Tree, TreeNode} from "../AST";
5
5
  import {Node} from "./Node";
6
6
  import {BlockNode} from "./BlockNode";
7
7
  import {TagList} from "../Tag/TagList";
8
8
 
9
9
  export class WithNode extends Node implements TreeNode {
10
+ protected requiresPrep: boolean = true;
11
+
10
12
  constructor(
11
13
  public readonly context: Node,
12
14
  public readonly statements: BlockNode
@@ -23,15 +25,35 @@ export class WithNode extends Node implements TreeNode {
23
25
 
24
26
  public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
25
27
  const context = await this.context.evaluate(scope, dom, tag);
26
- let tags;
28
+ let tags = [];
27
29
  if (context instanceof TagList) {
28
30
  tags = context;
29
31
  } else if (context instanceof Tag) {
30
32
  tags = [context];
31
33
  }
32
34
  let ret = [];
33
- for (const _tag of tags) {
34
- ret.push(await this.statements.evaluate(_tag.scope, dom, _tag))
35
+ if (tags.length) {
36
+ if (this.hasModifier('sequential')) { // More like a for loop, needed?
37
+ for (const _tag of tags) {
38
+ await this.statements.prepare(_tag.scope, dom, _tag);
39
+ ret.push(await this.statements.evaluate(_tag.scope, dom, _tag));
40
+ }
41
+ } else {
42
+ const promises = [];
43
+ for (const _tag of tags) {
44
+ await this.statements.prepare(_tag.scope, dom, _tag);
45
+ promises.push(this.statements.evaluate(_tag.scope, dom, _tag));
46
+ }
47
+ ret = await Promise.all(promises);
48
+ }
49
+ } else {
50
+ let _scope;
51
+ if (context instanceof Scope) {
52
+ _scope = context;
53
+ }
54
+
55
+ if (_scope)
56
+ ret.push(await this.statements.evaluate(_scope, dom, tag))
35
57
  }
36
58
  return ret.length === 1 ? ret[0] : ret;
37
59
  }
@@ -40,6 +62,7 @@ export class WithNode extends Node implements TreeNode {
40
62
  tokens.shift(); // Consume with
41
63
  const contextTokens = Tree.getTokensUntil(tokens, TokenType.L_BRACE, false, false, true);
42
64
  const statementTokens = Tree.getNextStatementTokens(tokens);
65
+ this.moveModifiers(contextTokens, tokens);
43
66
  return new WithNode(Tree.processTokens(contextTokens), Tree.processTokens(statementTokens));
44
67
  }
45
68
  }
package/src/AST.ts CHANGED
@@ -202,7 +202,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
202
202
  },
203
203
  {
204
204
  type: TokenType.WITH,
205
- pattern: /^with\s/
205
+ pattern: /^with(?=\||\s)?/ // Allows with|sequential
206
206
  },
207
207
  {
208
208
  type: TokenType.FOR,
@@ -495,9 +495,10 @@ export class Tree {
495
495
  return tokens;
496
496
  }
497
497
 
498
- public static processTokens(tokens: Token[]): BlockNode {
498
+ public static processTokens(tokens: Token[], _node: Node=null, _lastBlock: Node=null): BlockNode {
499
499
  let blockNodes: Node[] = [];
500
- let node: Node = null;
500
+ let lastBlock: Node = _lastBlock;
501
+ let node: Node = _node;
501
502
  let count: number = 0;
502
503
 
503
504
  Tree.stripWhiteSpace(tokens);
@@ -521,26 +522,34 @@ export class Tree {
521
522
  node = DispatchEventNode.parse(node, tokens[0], tokens);
522
523
  } else if (token.type === TokenType.WITH) {
523
524
  node = WithNode.parse(node, tokens[0], tokens);
525
+ lastBlock = node;
526
+ blockNodes.push(node);
527
+ node = null;
524
528
  } else if (token.type === TokenType.AS) {
525
529
  node = AsNode.parse(node, tokens[0], tokens);
526
530
  } else if (token.type === TokenType.IF) {
527
531
  node = IfStatementNode.parse(node, token, tokens);
532
+ lastBlock = node;
528
533
  blockNodes.push(node);
529
534
  node = null;
530
535
  } else if (token.type === TokenType.FOR) {
531
536
  node = ForStatementNode.parse(node, token, tokens);
537
+ lastBlock = node;
532
538
  blockNodes.push(node);
533
539
  node = null;
534
540
  } else if (token.type === TokenType.FUNC) {
535
541
  node = FunctionNode.parse(node, token, tokens);
542
+ lastBlock = node;
536
543
  blockNodes.push(node);
537
544
  node = null;
538
545
  } else if (token.type === TokenType.ON) {
539
546
  node = OnNode.parse(node, token, tokens);
547
+ lastBlock = node;
540
548
  blockNodes.push(node);
541
549
  node = null;
542
550
  } else if (token.type === TokenType.CLASS) {
543
551
  node = ClassNode.parse(node, token, tokens);
552
+ lastBlock = node;
544
553
  blockNodes.push(node);
545
554
  node = null;
546
555
  } else if (StringFormatNode.match(tokens)) {
@@ -618,7 +627,7 @@ export class Tree {
618
627
  } else if (tokens[0].type === TokenType.EXCLAMATION_POINT) {
619
628
  node = NotNode.parse(node, tokens[0], tokens);
620
629
  } else if (tokens[0].type === TokenType.MODIFIER) {
621
- node = ModifierNode.parse(node, tokens[0], tokens);
630
+ ModifierNode.parse(node ? node : lastBlock, tokens[0], tokens);
622
631
  } else {
623
632
  let code: string = Tree.toCode(tokens, 10);
624
633
  throw Error(`Syntax Error. Near ${code}`);
package/src/Scope.ts CHANGED
@@ -4,6 +4,7 @@ import {QueryReference} from "./Scope/QueryReference";
4
4
  import {WrappedArray} from "./Scope/WrappedArray";
5
5
  import {ScopeData} from "./Scope/ScopeData";
6
6
  import {DynamicScopeData} from "./Scope/DynamicScopeData";
7
+ import {DOM} from "./DOM";
7
8
 
8
9
 
9
10
  export class Scope extends EventDispatcher {
@@ -28,7 +29,11 @@ export class Scope extends EventDispatcher {
28
29
  }
29
30
 
30
31
  public get parentScope(): Scope {
31
- return this._parentScope;
32
+ if (this._parentScope)
33
+ return this._parentScope;
34
+
35
+ const rootScope = DOM.instance.root.scope;
36
+ return this == rootScope ? null : rootScope;
32
37
  }
33
38
 
34
39
  public set parentScope(scope: Scope) {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.119';
1
+ export const VERSION = '0.1.121';
2
2