vsn 0.1.73 → 0.1.74

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.73",
3
+ "version": "0.1.74",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -13,7 +13,8 @@
13
13
  ],
14
14
  "main": "./dist/vsn.js",
15
15
  "scripts": {
16
- "build": "rm -rf ./dist/ && tsc",
16
+ "build": "rm -rf ./dist/ && npm run-script version && tsc",
17
+ "version": "echo -n \"export const VERSION = '${npm_package_version}';\n\" > src/version.ts",
17
18
  "build_dev": "rm -rf ./dist/ && webpack --env BUILD=development BENCHMARK=1",
18
19
  "demo": "webpack --env BUILD=production BENCHMARK=1 && cp ./dist/vsn.min.js ./demo/vsn.js",
19
20
  "test": "karma start --single-run",
@@ -39,6 +39,7 @@ export class ClassNode extends Node implements TreeNode {
39
39
  public async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta?: INodeMeta): Promise<void> {
40
40
  meta = Object.assign({}, meta) || {};
41
41
  const initial = !!meta['initial'];
42
+ let root: boolean = false;
42
43
  meta['ClassNodePrepare'] = initial;
43
44
 
44
45
  // Only prepare once during the initial prep, all subsequent prepares are on tag class blocks
@@ -47,6 +48,7 @@ export class ClassNode extends Node implements TreeNode {
47
48
  ClassNode.classChildren[meta['ClassNodeSelector'] as string].push(this.selector);
48
49
  meta['ClassNodeSelector'] = `${meta['ClassNodeSelector']} ${this.selector}`;
49
50
  } else {
51
+ root = true;
50
52
  meta['ClassNodeSelector'] = this.selector;
51
53
  }
52
54
 
@@ -63,14 +65,25 @@ export class ClassNode extends Node implements TreeNode {
63
65
  await this.block.prepare(this.classScope, dom, tag, meta);
64
66
  Registry.class(this);
65
67
 
66
- for (const element of Array.from(dom.querySelectorAll(this._fullSelector))) {
67
- await ClassNode.addElementClass(this._fullSelector, element as HTMLElement, dom, element[Tag.TaggedVariable] || null);
68
+ if (root) {
69
+ await this.findClassElements(dom);
68
70
  }
69
71
  } else {
70
72
  await this.block.prepare(this.classScope, dom, tag, meta);
71
73
  }
72
74
  }
73
75
 
76
+ public async findClassElements(dom) {
77
+ for (const element of Array.from(dom.querySelectorAll(this._fullSelector))) {
78
+ await ClassNode.addElementClass(this._fullSelector, element as HTMLElement, dom, element[Tag.TaggedVariable] || null);
79
+ }
80
+ for (const childSelector of ClassNode.classChildren[this._fullSelector]) {
81
+ const node = ClassNode.classes[`${this._fullSelector} ${childSelector}`];
82
+ if (!node) continue;
83
+ await node.findClassElements(dom);
84
+ }
85
+ }
86
+
74
87
  public async constructTag(tag: Tag, dom: DOM, hasConstructor: boolean | null = null) {
75
88
  if (hasConstructor === null)
76
89
  hasConstructor = this.classScope.has('construct');
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = '0.1.74';
package/src/vsn.ts CHANGED
@@ -8,6 +8,7 @@ import {Query} from "./Query";
8
8
  import {EventDispatcher} from "./EventDispatcher";
9
9
  import {DynamicScopeData} from "./Scope/DynamicScopeData";
10
10
  import {Controller} from "./Controller";
11
+ import {VERSION} from "./version";
11
12
 
12
13
  export class Vision extends EventDispatcher {
13
14
  protected static _instance: Vision;
@@ -59,7 +60,7 @@ export class Vision extends EventDispatcher {
59
60
  await this._dom.buildFrom(document, true);
60
61
  const now = (new Date()).getTime();
61
62
  const setupTime = now - startTime;
62
- console.info(`Took ${setupTime}ms to start up VisionJS. https://www.vsnjs.com/`, window ? `v${window['VSN_VERSION']}` : null);
63
+ console.info(`Took ${setupTime}ms to start up VisionJS. https://www.vsnjs.com/`, `v${VERSION}`);
63
64
  }
64
65
 
65
66
  public static get instance() {
@@ -2,6 +2,7 @@ import {DOM} from "../../src/DOM";
2
2
  import {ClassNode} from "../../src/AST/ClassNode";
3
3
  import {Registry} from "../../src/Registry";
4
4
  import {TagList} from "../../src/Tag/List";
5
+ import {Tag} from "../../src/Tag";
5
6
 
6
7
 
7
8
  describe('ClassNode', () => {
@@ -55,4 +56,29 @@ describe('ClassNode', () => {
55
56
  await dom.exec('?(.simple-construct).test()');
56
57
  expect(await dom.exec('?(.simple-construct).a')).toEqual([16, 16]);
57
58
  });
59
+
60
+ it("properly define a simple class with a parent", async () => {
61
+ document.body.innerHTML = `
62
+ <script type="text/vsn" vsn-script>
63
+ class .testing {
64
+ func construct() {
65
+ a|integer = 0;
66
+ }
67
+
68
+ class .test {
69
+ func construct() {
70
+ ?<(.testing).a += 1;
71
+ }
72
+ }
73
+ }
74
+ </script>
75
+ <div class="testing"><span class="test"></span></div>
76
+ `;
77
+ const dom = new DOM(document);
78
+ await dom.ready;
79
+ await Registry.instance.classes.get('.testing .test');
80
+ const t = await dom.exec('?(.testing .test)[0]');
81
+ await t.promise('.testing .test.construct');
82
+ expect(await dom.exec('?(.testing)[0].a')).toEqual(1);
83
+ });
58
84
  });