vsn 0.1.44 → 0.1.47

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 (98) hide show
  1. package/demo/demo.html +11 -9
  2. package/demo/markup.html +2 -0
  3. package/demo/vsn.js +1 -1
  4. package/demo/xhr.vsn +4 -0
  5. package/dist/AST/ArithmeticAssignmentNode.js +8 -1
  6. package/dist/AST/ArithmeticAssignmentNode.js.map +1 -1
  7. package/dist/AST/FunctionNode.d.ts +0 -0
  8. package/dist/AST/FunctionNode.js +1 -0
  9. package/dist/AST/FunctionNode.js.map +1 -0
  10. package/dist/AST/StringFormatNode.d.ts +18 -0
  11. package/dist/{attributes/ClickToggleClass.js → AST/StringFormatNode.js} +49 -49
  12. package/dist/AST/StringFormatNode.js.map +1 -0
  13. package/dist/AST/WASM/Context.d.ts +4 -0
  14. package/dist/AST/WASM/Context.js +18 -0
  15. package/dist/AST/WASM/Context.js.map +1 -0
  16. package/dist/AST/WASM/Function.d.ts +22 -0
  17. package/dist/AST/WASM/Function.js +110 -0
  18. package/dist/AST/WASM/Function.js.map +1 -0
  19. package/dist/AST/WASM/Memory.d.ts +12 -0
  20. package/dist/AST/WASM/Memory.js +22 -0
  21. package/dist/AST/WASM/Memory.js.map +1 -0
  22. package/dist/AST/WASM/Section.d.ts +5 -0
  23. package/dist/AST/WASM/Section.js +11 -0
  24. package/dist/AST/WASM/Section.js.map +1 -0
  25. package/dist/AST/WASM.d.ts +58 -0
  26. package/dist/AST/WASM.js +277 -0
  27. package/dist/AST/WASM.js.map +1 -0
  28. package/dist/AST/XHRNode.d.ts +15 -0
  29. package/dist/AST/XHRNode.js +146 -0
  30. package/dist/AST/XHRNode.js.map +1 -0
  31. package/dist/AST.d.ts +62 -55
  32. package/dist/AST.js +123 -83
  33. package/dist/AST.js.map +1 -1
  34. package/dist/DOM/DOMObject.d.ts +1 -0
  35. package/dist/DOM/DOMObject.js +6 -0
  36. package/dist/DOM/DOMObject.js.map +1 -1
  37. package/dist/DOM.js +61 -90
  38. package/dist/DOM.js.map +1 -1
  39. package/dist/Registry.d.ts +2 -0
  40. package/dist/Registry.js +13 -9
  41. package/dist/Registry.js.map +1 -1
  42. package/dist/Scope/ScopeDataAbstract.js +2 -2
  43. package/dist/Scope/ScopeDataAbstract.js.map +1 -1
  44. package/dist/Scope/properties/Property.d.ts +5 -6
  45. package/dist/Scope/properties/Property.js +17 -25
  46. package/dist/Scope/properties/Property.js.map +1 -1
  47. package/dist/Scope/properties/_imports.d.ts +1 -1
  48. package/dist/Scope/properties/_imports.js.map +1 -1
  49. package/dist/Tag.d.ts +5 -0
  50. package/dist/Tag.js +55 -11
  51. package/dist/Tag.js.map +1 -1
  52. package/dist/attributes/Bind.js +2 -2
  53. package/dist/attributes/Bind.js.map +1 -1
  54. package/dist/attributes/StandardAttribute.d.ts +0 -1
  55. package/dist/attributes/StandardAttribute.js +4 -34
  56. package/dist/attributes/StandardAttribute.js.map +1 -1
  57. package/dist/attributes/_imports.d.ts +0 -2
  58. package/dist/attributes/_imports.js +1 -5
  59. package/dist/attributes/_imports.js.map +1 -1
  60. package/dist/helpers/VisionHelper.d.ts +1 -0
  61. package/dist/helpers/VisionHelper.js +17 -0
  62. package/dist/helpers/VisionHelper.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/AST/ArithmeticAssignmentNode.ts +9 -2
  65. package/src/AST/FunctionNode.ts +0 -0
  66. package/src/AST/StringFormatNode.ts +43 -0
  67. package/src/AST/WASM/Context.ts +12 -0
  68. package/src/AST/WASM/Function.ts +67 -0
  69. package/src/AST/WASM/Memory.ts +21 -0
  70. package/src/AST/WASM/Section.ts +6 -0
  71. package/src/AST/WASM.ts +244 -0
  72. package/src/AST/XHRNode.ts +81 -0
  73. package/src/AST.ts +66 -31
  74. package/src/DOM/DOMObject.ts +6 -0
  75. package/src/DOM.ts +11 -25
  76. package/src/Registry.ts +12 -9
  77. package/src/Scope/ScopeDataAbstract.ts +2 -2
  78. package/src/Scope/properties/Property.ts +17 -28
  79. package/src/Scope/properties/_imports.ts +1 -1
  80. package/src/Tag.ts +56 -9
  81. package/src/attributes/AddClassIf.ts +1 -1
  82. package/src/attributes/Bind.ts +2 -2
  83. package/src/attributes/StandardAttribute.ts +4 -32
  84. package/src/attributes/_imports.ts +0 -2
  85. package/src/helpers/VisionHelper.ts +13 -0
  86. package/test/AST/ArithmeticAssignmentNode.spec.ts +0 -2
  87. package/test/AST/StringFormatNode.spec.ts +12 -0
  88. package/test/AST/WASM.spec.ts +63 -0
  89. package/test/AST/XHRNode.spec.ts +10 -0
  90. package/test/Scope/ScopeData.spec.ts +5 -5
  91. package/types/vsn-component.d.ts +5 -0
  92. package/dist/attributes/ClickRemoveClass.d.ts +0 -8
  93. package/dist/attributes/ClickRemoveClass.js +0 -114
  94. package/dist/attributes/ClickRemoveClass.js.map +0 -1
  95. package/dist/attributes/ClickToggleClass.d.ts +0 -8
  96. package/dist/attributes/ClickToggleClass.js.map +0 -1
  97. package/src/attributes/ClickRemoveClass.ts +0 -30
  98. package/src/attributes/ClickToggleClass.ts +0 -30
package/src/DOM.ts CHANGED
@@ -3,8 +3,6 @@ import {ElementHelper} from "./helpers/ElementHelper";
3
3
  import {Configuration} from "./Configuration";
4
4
  import {Tree} from "./AST";
5
5
  import {TagList} from "./Tag/List";
6
- import {benchmarkEnd, benchmarkStart} from "./Bencmark";
7
- import {VisionHelper} from "./helpers/VisionHelper";
8
6
  import {WrappedWindow} from "./DOM/WrappedWindow";
9
7
  import {WrappedDocument} from "./DOM/WrappedDocument";
10
8
  import {Scope} from "./Scope";
@@ -50,6 +48,8 @@ export class DOM extends EventDispatcher {
50
48
  return new TagList(this.window);
51
49
  case 'document':
52
50
  return new TagList(this.document);
51
+ case 'body':
52
+ return new TagList(this.root);
53
53
  default:
54
54
  const nodes = this.querySelectorAll(selector, tag);
55
55
  return await this.getTagsForElements(Array.from(nodes) as Element[], create);
@@ -119,6 +119,13 @@ export class DOM extends EventDispatcher {
119
119
  if (tag) {
120
120
  tag.mutate(mutation);
121
121
  }
122
+
123
+ for (const ele of Array.from(mutation.removedNodes)) {
124
+ const toRemove: Tag = await this.getTagForElement(ele as HTMLElement);
125
+ if (toRemove) {
126
+ toRemove.deconstruct();
127
+ }
128
+ }
122
129
  }
123
130
  }
124
131
 
@@ -139,7 +146,6 @@ export class DOM extends EventDispatcher {
139
146
  const toBuild: HTMLElement[] = [];
140
147
  const toSkip: HTMLElement[] = [];
141
148
 
142
- if (VisionHelper.doBenchmark) benchmarkStart('DOM','findElements');
143
149
  if (ele && ele.querySelectorAll) {
144
150
  for (const element of (Array.from(ele.querySelectorAll(`*`)) as HTMLElement[])) { // Don't build items more than once
145
151
  if (!ElementHelper.hasVisionAttribute(element)) continue;
@@ -152,9 +158,7 @@ export class DOM extends EventDispatcher {
152
158
  toBuild.push(element);
153
159
  }
154
160
  }
155
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'findElements');
156
161
 
157
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'buildTags');
158
162
  for (const element of toBuild) {
159
163
  if (allElements.indexOf(element) > -1) continue;
160
164
  const tag: Tag = new Tag(element, this);
@@ -162,23 +166,17 @@ export class DOM extends EventDispatcher {
162
166
  newTags.push(tag);
163
167
  allElements.push(element as HTMLElement);
164
168
  }
165
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'buildTags');
166
169
 
167
170
  if (isRoot)
168
171
  this._root = await this.getTagForElement(document.body);
169
172
 
170
173
  // Configure, setup & execute attributes
171
- if (VisionHelper.doBenchmark) benchmarkStart('DOM','buildTagAttributes');
172
174
  for (const tag of newTags)
173
175
  await tag.buildAttributes();
174
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM','buildTagAttributes');
175
176
 
176
- if (VisionHelper.inDevelopment) benchmarkStart('DOM', 'compileAttributes');
177
177
  for (const tag of newTags)
178
178
  await tag.compileAttributes();
179
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM','compileAttributes');
180
179
 
181
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'buildTree');
182
180
  for (const tag of newTags) {
183
181
  if (tag === this.root)
184
182
  continue;
@@ -198,39 +196,27 @@ export class DOM extends EventDispatcher {
198
196
  if (!foundParent)
199
197
  console.error('Could not find parent for ', tag);
200
198
  }
201
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'buildTree');
202
199
 
203
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'setupAttributes');
204
200
  for (const tag of newTags)
205
201
  await tag.setupAttributes();
206
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'setupAttributes');
207
202
 
208
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'extractAttributes');
209
203
  for (const tag of newTags)
210
204
  await tag.extractAttributes();
211
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'extractAttributes');
212
205
 
213
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'connectAttributes');
214
206
  for (const tag of newTags)
215
207
  await tag.connectAttributes();
216
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'connectAttributes');
217
208
 
218
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'finalizeTags');
219
209
  for (const tag of newTags) {
220
210
  await tag.finalize();
221
211
  this.queued.splice(this.queued.indexOf(tag.element), 1);
222
212
  }
223
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'finalizeTags');
224
213
 
225
- if (VisionHelper.doBenchmark) benchmarkStart('DOM', 'observeTags');
226
- for (const tag of newTags)
227
- this.observer.observe(tag.element, {
214
+ newTags.forEach(tag => this.observer.observe(tag.element, {
228
215
  attributes: true,
229
216
  characterData: true,
230
217
  childList: true,
231
218
  subtree: true
232
- });
233
- if (VisionHelper.doBenchmark) benchmarkEnd('DOM', 'observeTags');
219
+ }));
234
220
 
235
221
  this.dispatch('built');
236
222
  }
package/src/Registry.ts CHANGED
@@ -1,4 +1,3 @@
1
- import {VisionHelper} from "./helpers/VisionHelper";
2
1
  import {EventDispatcher} from "./EventDispatcher";
3
2
  import {IDeferred, IPromise, SimplePromise} from "./SimplePromise";
4
3
 
@@ -53,6 +52,7 @@ export class RegistryStore extends EventDispatcher {
53
52
 
54
53
  export class Registry extends EventDispatcher {
55
54
  protected static _instance: Registry;
55
+ public readonly components: RegistryStore;
56
56
  public readonly classes: RegistryStore;
57
57
  public readonly models: RegistryStore;
58
58
  public readonly templates: RegistryStore;
@@ -63,15 +63,18 @@ export class Registry extends EventDispatcher {
63
63
 
64
64
  constructor() {
65
65
  super();
66
+ this.components = new RegistryStore();
67
+ this.classes = new RegistryStore();
68
+ this.models = new RegistryStore();
69
+ this.templates = new RegistryStore();
70
+ this.types = new RegistryStore();
71
+ this.validators = new RegistryStore();
72
+ this.formats = new RegistryStore();
73
+ this.attributes = new RegistryStore();
74
+ }
66
75
 
67
- const w = VisionHelper.window || {};
68
- this.classes = new RegistryStore(w['$classes'] || {});
69
- this.models = new RegistryStore(w['$models'] || {});
70
- this.templates = new RegistryStore(w['$templates'] || {});
71
- this.types = new RegistryStore(w['$types'] || {});
72
- this.validators = new RegistryStore(w['$validators'] || {});
73
- this.formats = new RegistryStore(w['$formats'] || {});
74
- this.attributes = new RegistryStore(w['$attributes'] || {});
76
+ public static component(key: string = null, setup = null) {
77
+ return register('components', key, setup);
75
78
  }
76
79
 
77
80
  public static class(key: string = null, setup = null) {
@@ -65,7 +65,7 @@ export class ScopeDataAbstract extends EventDispatcher {
65
65
  const keys = [];
66
66
  for (const key of this.keys) {
67
67
  const property = this.getProperty(key);
68
- if (property.hasTags(tags)) {
68
+ if (property.hasLabels(tags)) {
69
69
  keys.push(key);
70
70
  }
71
71
  }
@@ -86,7 +86,7 @@ export class ScopeDataAbstract extends EventDispatcher {
86
86
  propLoop: for (const key of this.getProperties()) {
87
87
  const property = this['__'+key];
88
88
  for (const tag of tags) {
89
- if (!property.hasTag(tag))
89
+ if (!property.hasLabel(tag))
90
90
  continue propLoop;
91
91
  }
92
92
 
@@ -30,7 +30,7 @@ export interface IPropertyConfig {
30
30
  type?: string;
31
31
  default?: any;
32
32
  validators?: TValidator[];
33
- tags?: string[];
33
+ labels?: string[];
34
34
  }
35
35
 
36
36
  export class Property<T = any> extends EventDispatcher {
@@ -41,8 +41,8 @@ export class Property<T = any> extends EventDispatcher {
41
41
  constructor(value?: T, config?: IPropertyConfig) {
42
42
  super();
43
43
  this.config = config;
44
- if (!this.config.tags)
45
- this.config.tags = [];
44
+ if (!this.config.labels)
45
+ this.config.labels = [];
46
46
  if (!this.config.validators)
47
47
  this.config.validators = [];
48
48
  this.type = config.type || 'any';
@@ -109,43 +109,32 @@ export class Property<T = any> extends EventDispatcher {
109
109
  this.config.validators.push(validator);
110
110
  }
111
111
 
112
- removeValidator(validator: TValidator | string) {
113
- if (typeof validator == 'string') {
114
- validator = this.getValidator(validator);
115
- }
116
-
117
- const index = this.config.validators.indexOf(validator);
118
- if (index != -1)
119
- this.config.validators.splice(index, 1);
120
- }
121
-
122
-
123
- addTag(tag: string) {
124
- if(this.config.tags == undefined) {
125
- this.config.tags = [];
112
+ addLabel(label: string) {
113
+ if(this.config.labels == undefined) {
114
+ this.config.labels = [];
126
115
  }
127
- if(this.config.tags.indexOf(tag) == -1) {
128
- this.config.tags.push(tag);
116
+ if(this.config.labels.indexOf(label) == -1) {
117
+ this.config.labels.push(label);
129
118
  }
130
119
  }
131
120
 
132
- removeTag(tag: string) {
133
- if(this.config.tags == undefined) {
121
+ removeLabel(label: string) {
122
+ if(this.config.labels == undefined) {
134
123
  return;
135
124
  }
136
- const index = this.config.tags.indexOf(tag);
125
+ const index = this.config.labels.indexOf(label);
137
126
  if(index != -1) {
138
- this.config.tags.splice(index, 1);
127
+ this.config.labels.splice(index, 1);
139
128
  }
140
129
  }
141
130
 
142
- hasTag(tag: string) {
143
- return this.config.tags.indexOf(tag) !== -1;
131
+ hasLabel(label: string) {
132
+ return this.config.labels.indexOf(label) !== -1;
144
133
  }
145
134
 
146
- hasTags(tags: string[]) {
147
- for(const tag of tags) {
148
- if(!this.hasTag(tag)) {
135
+ hasLabels(labels: string[]) {
136
+ for(const label of labels) {
137
+ if(!this.hasLabel(label)) {
149
138
  return false;
150
139
  }
151
140
  }
@@ -1,2 +1,2 @@
1
- export {Property, property} from './Property';
1
+ export {Property, property, IPropertyConfig} from './Property';
2
2
  export {ArrayProperty} from './ArrayProperty';
package/src/Tag.ts CHANGED
@@ -32,6 +32,13 @@ export class Tag extends DOMObject {
32
32
  protected _children: Tag[] = [];
33
33
  protected _controller: Controller;
34
34
 
35
+ public static readonly magicAttributes: string[] = [
36
+ '@text',
37
+ '@html',
38
+ '@class',
39
+ '@value'
40
+ ];
41
+
35
42
  protected inputTags: string[] = [
36
43
  'input',
37
44
  'select',
@@ -72,12 +79,7 @@ export class Tag extends DOMObject {
72
79
  if (this._nonDeferredAttributes.length > 0)
73
80
  return this._nonDeferredAttributes;
74
81
 
75
- const attrs: Attribute[] = [];
76
- for (const attribute of this.attributes) {
77
- if (attribute.state === AttributeState.Deferred)
78
- continue;
79
- attrs.push(attribute);
80
- }
82
+ const attrs: Attribute[] = this.attributes.filter(attr => attr.state !== AttributeState.Deferred);
81
83
  this._nonDeferredAttributes = attrs;
82
84
  return attrs;
83
85
  }
@@ -119,9 +121,7 @@ export class Tag extends DOMObject {
119
121
  }
120
122
 
121
123
  mutate(mutation: MutationRecord): void {
122
- for (const attr of this.attributes) {
123
- attr.mutate(mutation);
124
- }
124
+ this.attributes.map(attr => attr.mutate(mutation));
125
125
  this.dispatch('mutate', mutation);
126
126
  }
127
127
 
@@ -336,6 +336,45 @@ export class Tag extends DOMObject {
336
336
  return attr as any as T;
337
337
  }
338
338
 
339
+ public isMagicAttribute(key: string): boolean {
340
+ return Tag.magicAttributes.indexOf(key) > -1;
341
+ }
342
+
343
+ public setElementAttribute(key: string, value: any) {
344
+ if (this.isMagicAttribute(key)) {
345
+ if (key === '@text')
346
+ this.element.innerText = value;
347
+ else if (key === '@html') {
348
+ this.element.innerHTML = value;
349
+ DOM.instance.buildFrom(this.element);
350
+ } else if (key === '@value')
351
+ this.value = value;
352
+ else if (key === '@class' && value) {
353
+ this.element.classList.remove(...Array.from(this.element.classList));
354
+ const classes: string[] = value instanceof Array ? value : [value];
355
+ if (classes.length)
356
+ this.element.classList.add(...classes);
357
+ }
358
+ } else {
359
+ this.element.setAttribute(key, value);
360
+ }
361
+ }
362
+
363
+ public getElementAttribute(key: string): any {
364
+ if (this.isMagicAttribute(key)) {
365
+ if (key === '@text')
366
+ return this.element.innerText;
367
+ else if (key === '@html')
368
+ return this.element.innerHTML;
369
+ else if (key === '@value')
370
+ return this.value;
371
+ else if (key === '@class') {
372
+ return Array.from(this.element.classList);
373
+ }
374
+ }
375
+ return this.element.getAttribute(key);
376
+ }
377
+
339
378
  public getRawAttributeValue(key: string, fallback: any = null) {
340
379
  return this.rawAttributes[key] ? this.rawAttributes[key] : fallback;
341
380
  }
@@ -579,4 +618,12 @@ export class Tag extends DOMObject {
579
618
  await this.setupAttribute(attr);
580
619
  this.deferredAttributes.length = 0;
581
620
  }
621
+
622
+ deconstruct() {
623
+ this.attributes.forEach(attr => attr.deconstruct());
624
+ this.attributes.length = 0;
625
+ this._children.forEach(child => child.deconstruct());
626
+ this._children.length = 0;
627
+ super.deconstruct();
628
+ }
582
629
  }
@@ -11,4 +11,4 @@ export class AddClassIf extends If {
11
11
  this.tag.element.classList.remove(this.getAttributeBinding());
12
12
  }
13
13
  }
14
- }
14
+ }
@@ -81,7 +81,7 @@ export class Bind extends Attribute {
81
81
  get valueFromElement(): string {
82
82
  let value;
83
83
  if (this.property) {
84
- value = this.tag.element.getAttribute(this.property);
84
+ value = this.tag.getElementAttribute(this.property);
85
85
  } else {
86
86
  value = this.tag.value;
87
87
  }
@@ -131,7 +131,7 @@ export class Bind extends Attribute {
131
131
  if (!this.doUpdateTo) return;
132
132
  const value = this.formatter(this.value);
133
133
  if (this.property) {
134
- this.tag.element.setAttribute(this.property, value);
134
+ this.tag.setElementAttribute(this.property, value);
135
135
  } else {
136
136
  this.tag.value = value;
137
137
  }
@@ -2,15 +2,9 @@ import {Attribute} from "../Attribute";
2
2
 
3
3
  export class StandardAttribute extends Attribute {
4
4
  public static readonly canDefer: boolean = false;
5
- protected static readonly magicAttributes: string[] = [
6
- '@text',
7
- '@html',
8
- '@class',
9
- '@value'
10
- ];
11
5
 
12
6
  public async setup() {
13
- if (StandardAttribute.magicAttributes.indexOf(this.key) === -1 && !this.tag.element.hasAttribute(this.attributeName)) {
7
+ if (!this.tag.isMagicAttribute(this.key) && !this.tag.element.hasAttribute(this.attributeName)) {
14
8
  this.tag.element.setAttribute(this.attributeName, '');
15
9
  }
16
10
  await super.setup();
@@ -51,7 +45,7 @@ export class StandardAttribute extends Attribute {
51
45
 
52
46
  public updateTo() {
53
47
  if (this.needsToBeSynced)
54
- this.value = this.tag.scope.get(`@${this.attributeName}`);
48
+ this.value = this.tag.scope.get(this.key);
55
49
  }
56
50
 
57
51
  public updateFrom() {
@@ -64,32 +58,10 @@ export class StandardAttribute extends Attribute {
64
58
  }
65
59
 
66
60
  public set value(value: any) {
67
- if (this.key === '@text')
68
- this.tag.element.innerText = value;
69
- else if (this.key === '@html')
70
- this.tag.element.innerHTML = value;
71
- else if (this.key === '@value')
72
- this.tag.value = value;
73
- else if (this.key === '@class' && value) {
74
- this.tag.element.classList.remove(...Array.from(this.tag.element.classList));
75
- const classes: string[] = value instanceof Array ? value : [value];
76
- if (classes.length)
77
- this.tag.element.classList.add(...classes);
78
- }
79
- else
80
- this.tag.element.setAttribute(this.attributeName, value);
61
+ this.tag.setElementAttribute(this.tag.isMagicAttribute(this.key) ? this.key : this.attributeName, value);
81
62
  }
82
63
 
83
64
  public get value(): any {
84
- if (this.key === '@text')
85
- return this.tag.element.innerText;
86
- else if (this.key === '@html')
87
- return this.tag.element.innerHTML;
88
- else if (this.key === '@value')
89
- return this.tag.value;
90
- else if (this.key === '@class') {
91
- return Array.from(this.tag.element.classList);
92
- } else
93
- return this.tag.element.getAttribute(this.attributeName);
65
+ return this.tag.getElementAttribute(this.tag.isMagicAttribute(this.key) ? this.key : this.attributeName);
94
66
  }
95
67
  }
@@ -1,7 +1,5 @@
1
1
  export {AddClassIf} from "./AddClassIf";
2
2
  export {Bind} from "./Bind";
3
- export {ClickRemoveClass} from "./ClickRemoveClass";
4
- export {ClickToggleClass} from "./ClickToggleClass";
5
3
  export {ControllerAttribute} from "./ControllerAttribute";
6
4
  export {DisableIf} from "./DisableIf";
7
5
  export {Exec} from "./Exec";
@@ -47,4 +47,17 @@ export class VisionHelper {
47
47
  setTimeout(callback, timeout);
48
48
  }
49
49
  }
50
+
51
+ public static get wasmSupport(): boolean {
52
+ try {
53
+ if (typeof WebAssembly === "object"
54
+ && typeof WebAssembly.instantiate === "function") {
55
+ const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
56
+ if (module instanceof WebAssembly.Module)
57
+ return new WebAssembly.Instance(module) instanceof WebAssembly.Instance;
58
+ }
59
+ } catch (e) {
60
+ }
61
+ return false;
62
+ }
50
63
  }
@@ -1,5 +1,3 @@
1
- import {SimplePromise} from "../../src/SimplePromise";
2
- import {DOM} from "../../src/DOM";
3
1
  import {Tree} from "../../src/AST";
4
2
  import {Scope} from "../../src/Scope";
5
3
 
@@ -0,0 +1,12 @@
1
+ import {Tree} from "../../src/AST";
2
+ import {Scope} from "../../src/Scope";
3
+
4
+
5
+ describe('StringFormatNode', () => {
6
+ it("should format simple format strings", async () => {
7
+ const tree = new Tree("`Hello ${name}`");
8
+ const scope = new Scope();
9
+ scope.set("name", "World");
10
+ expect(await tree.evaluate(scope, null, null)).toBe("Hello World");
11
+ });
12
+ });
@@ -0,0 +1,63 @@
1
+ import {compile, EOpCode, EValueType, run} from "../../src/AST/WASM";
2
+ import {VisionHelper} from "../../src/helpers/VisionHelper";
3
+ import {FunctionSection} from "../../src/AST/WASM/Function";
4
+
5
+ describe('WASM', () => {
6
+ it("should support wasm", async () => {
7
+ expect(VisionHelper.wasmSupport).toBe(true);
8
+ });
9
+
10
+ it("should allow a simple addition function to be made", async () => {
11
+ const main = new FunctionSection("main");
12
+ main.addParam(EValueType.i32);
13
+ main.addParam(EValueType.i32);
14
+ main.addResult(EValueType.i32);
15
+ main.addCode([
16
+ 0x00, // local declare count
17
+ EOpCode.get_local,
18
+ 0x00, // local var 0
19
+ EOpCode.get_local,
20
+ 0x01, // local var 1
21
+ EOpCode.i32_add,
22
+ EOpCode.end
23
+ ]);
24
+ expect(await run(main, 10, 15)).toBe(25);
25
+ });
26
+
27
+ it("should allow a simple subtraction function to be made", async () => {
28
+ const main = new FunctionSection("main");
29
+ main.addParam(EValueType.i32);
30
+ main.addParam(EValueType.i32);
31
+ main.addResult(EValueType.i32);
32
+ main.addCode([
33
+ 0x00, // local declare count
34
+ EOpCode.get_local,
35
+ 0x00, // local var 0
36
+ EOpCode.get_local,
37
+ 0x01, // local var 1
38
+ EOpCode.i32_sub,
39
+ EOpCode.end
40
+ ]);
41
+ expect(await run(main, 10, 15)).toBe(-5);
42
+ });
43
+
44
+ it("should allow a simple function to be made", async () => {
45
+ const main = new FunctionSection("main");
46
+ main.addParam(EValueType.i32);
47
+ main.addParam(EValueType.i32);
48
+ main.addResult(EValueType.i32);
49
+ main.addCode([
50
+ 0x00, // local declare count
51
+ EOpCode.get_local,
52
+ 0x00, // local var 0
53
+ EOpCode.get_local,
54
+ 0x01, // local var 1
55
+ EOpCode.i32_sub,
56
+ EOpCode.get_local,
57
+ 0x00, // local var 0
58
+ EOpCode.i32_mul,
59
+ EOpCode.end
60
+ ]);
61
+ expect(await run(main, 100, 15)).toBe(8500);
62
+ });
63
+ });
@@ -0,0 +1,10 @@
1
+ import {Tree} from "../../src/AST";
2
+ import {Scope} from "../../src/Scope";
3
+
4
+
5
+ describe('XHRNode', () => {
6
+ it("should parse and stuff", async () => {
7
+ const tree = new Tree(`{asd:123} >> '/test'`);
8
+ const scope = new Scope();
9
+ });
10
+ });
@@ -6,15 +6,15 @@ describe('ScopeData', () => {
6
6
  it("should set tags correctly", async () => {
7
7
  const data = new ScopeData();
8
8
  data.createProperty('test', Property, {
9
- tags: ['test']
9
+ labels: ['test']
10
10
  });
11
11
 
12
12
  data.createProperty('test_int', Property, {
13
- tags: ['test']
13
+ labels: ['test']
14
14
  });
15
15
 
16
16
  data.createProperty('not_test', Property, {
17
- tags: ['not_test']
17
+ labels: ['not_test']
18
18
  });
19
19
 
20
20
  data['test'] = 'test';
@@ -40,7 +40,7 @@ describe('ScopeData', () => {
40
40
  });
41
41
 
42
42
  const notTestProp = data.getProperty('not_test');
43
- notTestProp.addTag('test');
43
+ notTestProp.addLabel('test');
44
44
  const taggedNotTestData2 = data.getData('test');
45
45
  expect(taggedNotTestData2).toEqual({
46
46
  test: 'test',
@@ -48,7 +48,7 @@ describe('ScopeData', () => {
48
48
  not_test: 'not_test'
49
49
  });
50
50
 
51
- notTestProp.removeTag('test');
51
+ notTestProp.removeLabel('test');
52
52
  const taggedNotTestData3 = data.getData('test');
53
53
  expect(taggedNotTestData3).toEqual({
54
54
  test: 'test',
@@ -0,0 +1,5 @@
1
+
2
+ declare module "*.vsn" {
3
+ const content: string;
4
+ export default content;
5
+ }
@@ -1,8 +0,0 @@
1
- import { Attribute } from "../Attribute";
2
- export declare class ClickRemoveClass extends Attribute {
3
- protected cssClass: string;
4
- protected target: string;
5
- setup(): Promise<void>;
6
- connect(): Promise<void>;
7
- onClick(e: any): void;
8
- }