wc-compiler 0.21.0 → 0.22.0

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": "wc-compiler",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "WCC supports server-rendering of standard Web Components, generating HTML directly from your custom element definitions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,8 +54,7 @@
54
54
  "test:tdd:jsx": "npm run test:jsx -- --watch",
55
55
  "test:docs": "vitest run --coverage",
56
56
  "test:docs:tdd": "vitest",
57
- "prepare": "husky",
58
- "postinstall": "patch-package"
57
+ "prepare": "husky"
59
58
  },
60
59
  "dependencies": {
61
60
  "@projectevergreen/acorn-jsx-esm": "~0.1.0",
@@ -81,7 +80,7 @@
81
80
  "@vitest/browser-playwright": "^4.0.18",
82
81
  "@vitest/coverage-v8": "^4.0.18",
83
82
  "c8": "^7.11.2",
84
- "chai": "^4.3.6",
83
+ "chai": "^6.2.2",
85
84
  "eslint": "^9.39.1",
86
85
  "eslint-config-prettier": "^10.1.8",
87
86
  "eslint-plugin-no-only-tests": "^3.3.0",
@@ -102,9 +101,9 @@
102
101
  "rehype-slug": "^3.0.0",
103
102
  "remark-gfm": "^4.0.0",
104
103
  "remark-github": "^10.0.1",
105
- "stylelint": "^16.10.0",
106
- "stylelint-config-recommended": "^14.0.1",
107
- "typescript": "^5.9.3",
104
+ "stylelint": "^17.4.0",
105
+ "stylelint-config-recommended": "^18.0.0",
106
+ "typescript": "^6.0.3",
108
107
  "typescript-eslint": "^8.46.2",
109
108
  "vite": "^7.3.1",
110
109
  "vitest": "^4.0.18"
package/src/jsx-loader.js CHANGED
@@ -128,7 +128,13 @@ function findThisReferences(context, statement) {
128
128
  return references;
129
129
  }
130
130
 
131
- function parseJsxElement(element, moduleContents = '', inferredObservability) {
131
+ function parseJsxElement(
132
+ element,
133
+ moduleContents = '',
134
+ inferredObservability,
135
+ hasShadowRoot = false,
136
+ currentDepth = 1,
137
+ ) {
132
138
  try {
133
139
  const { type } = element;
134
140
 
@@ -154,20 +160,21 @@ function parseJsxElement(element, moduleContents = '', inferredObservability) {
154
160
  if (expression.property.type === 'Identifier') {
155
161
  // we leave markers for `this` so we can replace it later while also NOT accidentally replacing
156
162
  // legitimate uses of this that might be actual content / markup of the custom element
157
- string += ` ${name}="__this__.${expression.property.name}()"`;
163
+ string += ` ${name}="__this__.${expression.property.name}(event)"`;
158
164
  }
159
165
  }
160
166
  }
161
167
 
162
- // onclick={() => this.deleteUser(user.id)}
163
- // TODO onclick={(e) => { this.deleteUser(user.id) }}
164
- // TODO onclick={(e) => { this.deleteUser(user.id) && this.logAction(user.id) }}
165
- // https://github.com/ProjectEvergreen/wcc/issues/88
166
- if (expression.type === 'ArrowFunctionExpression') {
167
- if (expression.body && expression.body.type === 'CallExpression') {
168
- const { start, end } = expression;
169
- string += ` ${name}="${moduleContents.slice(start, end).replace(/this./g, '__this__.').replace('() => ', '')}"`;
170
- }
168
+ // <button onclick={(e: Event) => this.count.set(this.count.get() * 2)}>Double (++)</button>
169
+ if (expression.type === 'ArrowFunctionExpression' && expression.body) {
170
+ // quick hack to get expression contents until we can properly build this all up from an AST
171
+ const contents = generate(expression.body);
172
+ const eventIdentifier = expression?.params[0]?.name || 'event';
173
+ const root = hasShadowRoot
174
+ ? '.getRootNode().host'
175
+ : `${'.parentElement'.repeat(currentDepth)}`;
176
+
177
+ string += ` ${name}="(function (${eventIdentifier}, self) { ${contents.replace(/this./g, 'self.').replace('() => ', '')} })(event, this${root})"`;
171
178
  }
172
179
 
173
180
  if (expression.type === 'AssignmentExpression') {
@@ -241,7 +248,13 @@ function parseJsxElement(element, moduleContents = '', inferredObservability) {
241
248
 
242
249
  if (element.children.length > 0) {
243
250
  element.children.forEach((child) =>
244
- parseJsxElement(child, moduleContents, inferredObservability),
251
+ parseJsxElement(
252
+ child,
253
+ moduleContents,
254
+ inferredObservability,
255
+ hasShadowRoot,
256
+ currentDepth + 1,
257
+ ),
245
258
  );
246
259
  }
247
260
 
@@ -692,7 +705,13 @@ export function parseJsx(moduleURL) {
692
705
  const n = n1.value.body.body[n2];
693
706
 
694
707
  if (n.type === 'ReturnStatement' && n.argument.type === 'JSXElement') {
695
- const html = parseJsxElement(n.argument, moduleContents, inferredObservability);
708
+ const html = parseJsxElement(
709
+ n.argument,
710
+ moduleContents,
711
+ inferredObservability,
712
+ hasShadowRoot,
713
+ 1,
714
+ );
696
715
  const elementTree = getParse(html)(html);
697
716
  const elementRoot = hasShadowRoot ? 'this.shadowRoot' : 'this';
698
717
 
package/src/jsx.d.ts CHANGED
@@ -9,13 +9,15 @@ type ElementAttributes<E extends HTMLElement> = {
9
9
  class?: string;
10
10
  };
11
11
 
12
+ type PopoverState = 'auto' | 'manual' | 'hint';
12
13
  type PopoverTargetAction = 'show' | 'hide' | 'toggle';
13
- type PopoverTargetAttributes = {
14
+ type PopoverAttributes = {
14
15
  // have to manage this manually, can't seem to get this from TypeScript itself (not sure if just skill issue? :D)
15
16
  // https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1790
16
17
  // it should be there per https://github.com/mdn/browser-compat-data/pull/21875
17
18
  // https://github.com/ProjectEvergreen/wcc/issues/236
18
19
  // per the spec, this should only apply to <button> and <input> elements.
20
+ popover?: PopoverState;
19
21
  popovertarget?: string;
20
22
  popovertargetaction?: PopoverTargetAction;
21
23
  };
@@ -23,7 +25,7 @@ type PopoverTargetAttributes = {
23
25
  // map each HTML tag to its attributes
24
26
  type IntrinsicElementsFromDom = {
25
27
  [E in keyof HTMLElementTagNameMap]: ElementAttributes<HTMLElementTagNameMap[E]> &
26
- (E extends 'button' | 'input' ? PopoverTargetAttributes : {});
28
+ (E extends 'button' | 'input' ? PopoverAttributes : {});
27
29
  };
28
30
 
29
31
  declare namespace JSX {