wc-compiler 0.21.1 → 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 +5 -5
- package/src/jsx-loader.js +32 -13
- package/src/jsx.d.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wc-compiler",
|
|
3
|
-
"version": "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",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"@vitest/browser-playwright": "^4.0.18",
|
|
81
81
|
"@vitest/coverage-v8": "^4.0.18",
|
|
82
82
|
"c8": "^7.11.2",
|
|
83
|
-
"chai": "^
|
|
83
|
+
"chai": "^6.2.2",
|
|
84
84
|
"eslint": "^9.39.1",
|
|
85
85
|
"eslint-config-prettier": "^10.1.8",
|
|
86
86
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
@@ -101,9 +101,9 @@
|
|
|
101
101
|
"rehype-slug": "^3.0.0",
|
|
102
102
|
"remark-gfm": "^4.0.0",
|
|
103
103
|
"remark-github": "^10.0.1",
|
|
104
|
-
"stylelint": "^
|
|
105
|
-
"stylelint-config-recommended": "^
|
|
106
|
-
"typescript": "^
|
|
104
|
+
"stylelint": "^17.4.0",
|
|
105
|
+
"stylelint-config-recommended": "^18.0.0",
|
|
106
|
+
"typescript": "^6.0.3",
|
|
107
107
|
"typescript-eslint": "^8.46.2",
|
|
108
108
|
"vite": "^7.3.1",
|
|
109
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(
|
|
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.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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(
|
|
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(
|
|
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
|
|
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' ?
|
|
28
|
+
(E extends 'button' | 'input' ? PopoverAttributes : {});
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
declare namespace JSX {
|