vsn 0.1.106 → 0.1.107
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/examples/events.html +21 -0
- package/demo/vsn.js +2 -2
- package/dist/AST/AsNode.d.ts +13 -0
- package/dist/AST/AsNode.js +92 -0
- package/dist/AST/AsNode.js.map +1 -0
- package/dist/AST/DispatchEventNode.d.ts +15 -0
- package/dist/AST/DispatchEventNode.js +118 -0
- package/dist/AST/DispatchEventNode.js.map +1 -0
- package/dist/AST/WithNode.d.ts +14 -0
- package/dist/AST/WithNode.js +116 -0
- package/dist/AST/WithNode.js.map +1 -0
- package/dist/AST.d.ts +58 -55
- package/dist/AST.js +85 -58
- package/dist/AST.js.map +1 -1
- package/dist/Component.js +4 -1
- package/dist/Component.js.map +1 -1
- package/dist/DOM.js +4 -4
- package/dist/DOM.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vsn.min.js +2 -2
- package/package.json +1 -1
- package/src/AST/AsNode.ts +32 -0
- package/src/AST/DispatchEventNode.ts +50 -0
- package/src/AST/WithNode.ts +45 -0
- package/src/AST.ts +27 -3
- package/src/Component.ts +1 -0
- package/src/DOM.ts +4 -4
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {Scope} from "../Scope";
|
|
2
|
+
import {DOM} from "../DOM";
|
|
3
|
+
import {Tag} from "../Tag";
|
|
4
|
+
import {Token, TreeNode} from "../AST";
|
|
5
|
+
import {Node} from "./Node";
|
|
6
|
+
|
|
7
|
+
export class AsNode extends Node implements TreeNode {
|
|
8
|
+
constructor(
|
|
9
|
+
public readonly context: Node,
|
|
10
|
+
public readonly name: string
|
|
11
|
+
) {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected _getChildNodes(): Node[] {
|
|
16
|
+
return [
|
|
17
|
+
this.context
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
22
|
+
const context = await this.context.evaluate(scope, dom, tag);
|
|
23
|
+
scope.set(this.name, context);
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public static parse(lastNode, token, tokens: Token[]) {
|
|
28
|
+
tokens.shift(); // Consume as
|
|
29
|
+
const name = tokens.shift();
|
|
30
|
+
return new AsNode(lastNode, name.value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {Scope} from "../Scope";
|
|
2
|
+
import {DOM} from "../DOM";
|
|
3
|
+
import {Tag} from "../Tag";
|
|
4
|
+
import {Token, TokenType, Tree, TreeNode} from "../AST";
|
|
5
|
+
import {Node} from "./Node";
|
|
6
|
+
import {ObjectNode} from "./ObjectNode";
|
|
7
|
+
import {ScopeData} from "../Scope/ScopeData";
|
|
8
|
+
|
|
9
|
+
export class DispatchEventNode extends Node implements TreeNode {
|
|
10
|
+
constructor(
|
|
11
|
+
public readonly name: string,
|
|
12
|
+
public readonly data: ObjectNode | null,
|
|
13
|
+
public readonly bubbles: boolean = false
|
|
14
|
+
) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected _getChildNodes(): Node[] {
|
|
19
|
+
const nodes: Node[] = [];
|
|
20
|
+
if (this.data)
|
|
21
|
+
nodes.push(this.data);
|
|
22
|
+
return nodes;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
26
|
+
let detail = this.data ? await this.data.evaluate(scope, dom, tag) : {};
|
|
27
|
+
if (detail instanceof Scope)
|
|
28
|
+
detail = detail.data.getData();
|
|
29
|
+
else if (detail instanceof ScopeData)
|
|
30
|
+
detail = detail.getData();
|
|
31
|
+
|
|
32
|
+
detail['source'] = tag.element;
|
|
33
|
+
|
|
34
|
+
tag.element.dispatchEvent(new CustomEvent(this.name, {
|
|
35
|
+
bubbles: this.bubbles,
|
|
36
|
+
detail: detail
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static parse(lastNode, token, tokens: Token[]) {
|
|
41
|
+
const name = tokens.shift();
|
|
42
|
+
let data: ObjectNode = null;
|
|
43
|
+
if (tokens.length && tokens[0].type === TokenType.L_PAREN) {
|
|
44
|
+
const containedTokens = Tree.getNextStatementTokens(tokens, true, true, false);
|
|
45
|
+
data = Tree.processTokens(containedTokens).statements[0] as ObjectNode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return new DispatchEventNode(name.value, data, name.full.startsWith('!!!'));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {Scope} from "../Scope";
|
|
2
|
+
import {DOM} from "../DOM";
|
|
3
|
+
import {Tag} from "../Tag";
|
|
4
|
+
import {BlockType, Token, TokenType, Tree, TreeNode} from "../AST";
|
|
5
|
+
import {Node} from "./Node";
|
|
6
|
+
import {BlockNode} from "./BlockNode";
|
|
7
|
+
import {TagList} from "../Tag/TagList";
|
|
8
|
+
|
|
9
|
+
export class WithNode extends Node implements TreeNode {
|
|
10
|
+
constructor(
|
|
11
|
+
public readonly context: Node,
|
|
12
|
+
public readonly statements: BlockNode
|
|
13
|
+
) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected _getChildNodes(): Node[] {
|
|
18
|
+
return [
|
|
19
|
+
this.context,
|
|
20
|
+
this.statements
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
25
|
+
const context = await this.context.evaluate(scope, dom, tag);
|
|
26
|
+
let tags;
|
|
27
|
+
if (context instanceof TagList) {
|
|
28
|
+
tags = context;
|
|
29
|
+
} else if (context instanceof Tag) {
|
|
30
|
+
tags = [context];
|
|
31
|
+
}
|
|
32
|
+
let ret = [];
|
|
33
|
+
for (const _tag of tags) {
|
|
34
|
+
ret.push(await this.statements.evaluate(_tag.scope, dom, _tag))
|
|
35
|
+
}
|
|
36
|
+
return ret.length === 1 ? ret[0] : ret;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static parse(lastNode, token, tokens: Token[]) {
|
|
40
|
+
tokens.shift(); // Consume with
|
|
41
|
+
const contextTokens = Tree.getTokensUntil(tokens, TokenType.L_BRACE, false, false, true);
|
|
42
|
+
const statementTokens = Tree.getNextStatementTokens(tokens);
|
|
43
|
+
return new WithNode(Tree.processTokens(contextTokens), Tree.processTokens(statementTokens));
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/AST.ts
CHANGED
|
@@ -30,6 +30,9 @@ import {FunctionNode} from "./AST/FunctionNode";
|
|
|
30
30
|
import {ClassNode} from "./AST/ClassNode";
|
|
31
31
|
import {OnNode} from "./AST/OnNode";
|
|
32
32
|
import {ModifierNode} from "./AST/ModifierNode";
|
|
33
|
+
import {DispatchEventNode} from "./AST/DispatchEventNode";
|
|
34
|
+
import {WithNode} from "./AST/WithNode";
|
|
35
|
+
import {AsNode} from "./AST/AsNode";
|
|
33
36
|
|
|
34
37
|
function lower(str: string): string {
|
|
35
38
|
return str ? str.toLowerCase() : null;
|
|
@@ -64,7 +67,9 @@ export enum TokenType {
|
|
|
64
67
|
RETURN,
|
|
65
68
|
NOT,
|
|
66
69
|
OF,
|
|
70
|
+
AS,
|
|
67
71
|
IN,
|
|
72
|
+
WITH,
|
|
68
73
|
FOR,
|
|
69
74
|
IF,
|
|
70
75
|
ELSE_IF,
|
|
@@ -119,6 +124,7 @@ export enum TokenType {
|
|
|
119
124
|
XHR_PUT,
|
|
120
125
|
XHR_DELETE,
|
|
121
126
|
MODIFIER,
|
|
127
|
+
DISPATCH_EVENT,
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
const TOKEN_PATTERNS: TokenPattern[] = [
|
|
@@ -142,6 +148,10 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
142
148
|
type: TokenType.XHR_DELETE,
|
|
143
149
|
pattern: /^></
|
|
144
150
|
},
|
|
151
|
+
{
|
|
152
|
+
type: TokenType.DISPATCH_EVENT,
|
|
153
|
+
pattern: /^!!!?([_a-zA-Z][-_a-zA-Z0-9]+)/
|
|
154
|
+
},
|
|
145
155
|
{
|
|
146
156
|
type: TokenType.TYPE_INT,
|
|
147
157
|
pattern: /^int+/
|
|
@@ -186,6 +196,14 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
186
196
|
type: TokenType.IN,
|
|
187
197
|
pattern: /^in\s/
|
|
188
198
|
},
|
|
199
|
+
{
|
|
200
|
+
type: TokenType.AS,
|
|
201
|
+
pattern: /^as\s/
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: TokenType.WITH,
|
|
205
|
+
pattern: /^with\s/
|
|
206
|
+
},
|
|
189
207
|
{
|
|
190
208
|
type: TokenType.FOR,
|
|
191
209
|
pattern: /^for\s?(?=\()/
|
|
@@ -499,6 +517,12 @@ export class Tree {
|
|
|
499
517
|
tokens.shift()
|
|
500
518
|
} else if (XHRNode.match(tokens)) {
|
|
501
519
|
node = XHRNode.parse(node, tokens[0], tokens);
|
|
520
|
+
} else if (token.type === TokenType.DISPATCH_EVENT) {
|
|
521
|
+
node = DispatchEventNode.parse(node, tokens[0], tokens);
|
|
522
|
+
} else if (token.type === TokenType.WITH) {
|
|
523
|
+
node = WithNode.parse(node, tokens[0], tokens);
|
|
524
|
+
} else if (token.type === TokenType.AS) {
|
|
525
|
+
node = AsNode.parse(node, tokens[0], tokens);
|
|
502
526
|
} else if (token.type === TokenType.IF) {
|
|
503
527
|
node = IfStatementNode.parse(node, token, tokens);
|
|
504
528
|
blockNodes.push(node);
|
|
@@ -730,13 +754,13 @@ export class Tree {
|
|
|
730
754
|
for (let i: number = 0; i < tokens.length; i++) {
|
|
731
755
|
const token: Token = tokens[i];
|
|
732
756
|
if (!(token.type === blockInfo.open && i === 0)) { // Skip opener
|
|
733
|
-
if (token.type === TokenType.L_PAREN)
|
|
757
|
+
if (token.type === TokenType.L_PAREN && terminator !== TokenType.L_PAREN)
|
|
734
758
|
openParens += 1;
|
|
735
759
|
|
|
736
|
-
if (token.type === TokenType.L_BRACE)
|
|
760
|
+
if (token.type === TokenType.L_BRACE && terminator !== TokenType.L_BRACE)
|
|
737
761
|
openBraces += 1;
|
|
738
762
|
|
|
739
|
-
if (token.type === TokenType.L_BRACKET)
|
|
763
|
+
if (token.type === TokenType.L_BRACKET && terminator !== TokenType.L_BRACKET)
|
|
740
764
|
openBrackets += 1;
|
|
741
765
|
}
|
|
742
766
|
|
package/src/Component.ts
CHANGED
package/src/DOM.ts
CHANGED
|
@@ -132,16 +132,16 @@ export class DOM extends EventDispatcher {
|
|
|
132
132
|
const nodeList = [];
|
|
133
133
|
for (const _element of Array.from(this.querySelectorElement(element, _q))) {
|
|
134
134
|
if (rest.length > 0) {
|
|
135
|
-
nodeList.push(...Array.from(this.querySelectorElement(_element
|
|
135
|
+
nodeList.push(...Array.from(this.querySelectorElement(DOM.getParentElement(_element as HTMLElement), rest)));
|
|
136
136
|
} else {
|
|
137
|
-
nodeList.push(_element
|
|
137
|
+
nodeList.push(DOM.getParentElement(_element as HTMLElement));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
return nodeList;
|
|
141
141
|
} else if (rest.length === 0) {
|
|
142
|
-
return [element
|
|
142
|
+
return [DOM.getParentElement(element as HTMLElement)];
|
|
143
143
|
} else {
|
|
144
|
-
return this.querySelectorElement(element
|
|
144
|
+
return this.querySelectorElement(DOM.getParentElement(element as HTMLElement), rest);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
let matches = element.querySelectorAll(q);
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.107';
|
|
2
2
|
|