leanweb 1.2.5 → 1.2.6

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/README.md CHANGED
@@ -324,14 +324,13 @@ imageWidth = 400;
324
324
  `demo-parent.html`
325
325
 
326
326
  ```html
327
- <demo-child lw-input:parent="self" lw-input:userData="user"></demo-child>
327
+ <demo-child lw-input:parent="this" lw-input:userData="user"></demo-child>
328
328
  ```
329
329
 
330
330
  `demo-parent.js`
331
331
 
332
332
  ```javascript
333
333
  // ...
334
- // self is defined in LWElement as `self = this`;
335
334
  user = { firstname: "Qian", lastname: "Chen" };
336
335
  // ...
337
336
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leanweb",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Builds framework agnostic web components.",
5
5
  "bin": {
6
6
  "leanweb": "leanweb.js",
@@ -97,7 +97,6 @@ const nextAllSiblings = (el, selector) => {
97
97
  };
98
98
 
99
99
  export default class LWElement extends HTMLElement {
100
- self = this;
101
100
  constructor(ast) {
102
101
  super();
103
102
  this.ast = ast;
@@ -133,7 +132,7 @@ export default class LWElement extends HTMLElement {
133
132
 
134
133
  _getNodeContext(node) {
135
134
  const contextNode = node.closest('[lw-context]');
136
- return contextNode?.['lw-context'] ?? [this, globalThis];
135
+ return contextNode?.['lw-context'] ?? [{ 'this': this }, this, globalThis];
137
136
  }
138
137
 
139
138
  update(rootNode = this.shadowRoot) {
@@ -127,6 +127,14 @@ const nodeHandlers = {
127
127
  return context[node.name];
128
128
  }
129
129
  },
130
+ 'ThisExpression': (node, context) => {
131
+ if (Array.isArray(context)) {
132
+ const hitContext = context.find(contextObj => 'this' in contextObj);
133
+ return hitContext ? hitContext['this'] : undefined;
134
+ } else if (typeof context === 'object') {
135
+ return context['this'];
136
+ }
137
+ },
130
138
 
131
139
  'CallExpression': (node, context) => callFunction(node, context),
132
140
  'OptionalCallExpression': (node, context) => callFunction(node, context),