wc-compiler 0.3.0 → 0.3.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/dom-shim.js +15 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wc-compiler",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Experimental native Web Components compiler.",
5
5
  "main": "src/wcc.js",
6
6
  "type": "module",
package/src/dom-shim.js CHANGED
@@ -3,6 +3,7 @@ class EventTarget { }
3
3
 
4
4
  // https://developer.mozilla.org/en-US/docs/Web/API/Node
5
5
  // EventTarget <- Node
6
+ // TODO should be an interface?
6
7
  class Node extends EventTarget {
7
8
  constructor() {
8
9
  super();
@@ -15,7 +16,7 @@ class Node extends EventTarget {
15
16
  }
16
17
 
17
18
  appendChild(node) {
18
- this.innerHTML = this.innerHTML ? this.innerHTML += node.textContent : node.textContent;
19
+ this.innerHTML = this.innerHTML ? this.innerHTML += node.innerHTML : node.innerHTML;
19
20
  }
20
21
  }
21
22
 
@@ -63,14 +64,9 @@ class HTMLElement extends Element {
63
64
  }
64
65
 
65
66
  // https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md#serialization
67
+ // eslint-disable-next-line
66
68
  getInnerHTML(options = {}) {
67
- return options.includeShadowRoots
68
- ? `
69
- <template shadowroot="${this.shadowRoot.mode}">
70
- ${this.shadowRoot.innerHTML}
71
- </template>
72
- `
73
- : this.shadowRoot.innerHTML;
69
+ return this.shadowRoot.innerHTML;
74
70
  }
75
71
  }
76
72
 
@@ -101,11 +97,20 @@ class HTMLTemplateElement extends HTMLElement {
101
97
  super();
102
98
  // console.debug('HTMLTemplateElement constructor');
103
99
 
104
- this.content = new DocumentFragment(this.innerHTML);
100
+ this.content = new DocumentFragment();
105
101
  }
106
102
 
103
+ // TODO open vs closed shadow root
107
104
  set innerHTML(html) {
108
- this.content.textContent = html;
105
+ this.content.innerHTML = `
106
+ <template shadowroot="open">
107
+ ${html}
108
+ </template>
109
+ `;
110
+ }
111
+
112
+ get innerHTML() {
113
+ return this.content && this.content.innerHTML ? this.content.innerHTML : undefined;
109
114
  }
110
115
  }
111
116