Skip to content

Commit 3119c63

Browse files
authored
Merge pull request #35 from open-wc/fix/events-bug
fix: event name bug
2 parents 03ade50 + 9b72234 commit 3119c63

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

packages/analyzer/browser/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/analyzer/custom-elements.json

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,32 @@
99
{
1010
"kind": "class",
1111
"description": "",
12-
"name": "CustomElementSchemaViewerElement",
12+
"name": "MyElement",
1313
"members": [
1414
{
15-
"kind": "field",
16-
"name": "src",
17-
"description": "Any valid path to load a JSON file that adheres to the custom element manifest schema: https://github.com/webcomponents/custom-elements-manifest/"
15+
"kind": "method",
16+
"name": "myMethod"
17+
}
18+
],
19+
"events": [
20+
{
21+
"type": {
22+
"text": "MyCustomEvent"
23+
}
1824
}
1925
],
2026
"superclass": {
2127
"name": "LitElement"
2228
},
23-
"tagName": "customelement-schema-viewer",
2429
"customElement": true
2530
}
2631
],
2732
"exports": [
2833
{
2934
"kind": "js",
30-
"name": "CustomElementSchemaViewerElement",
31-
"declaration": {
32-
"name": "CustomElementSchemaViewerElement",
33-
"module": "fixtures/-default/package/bar.js"
34-
}
35-
},
36-
{
37-
"kind": "custom-element-definition",
38-
"name": "customelement-schema-viewer",
35+
"name": "MyElement",
3936
"declaration": {
40-
"name": "CustomElementSchemaViewerElement",
37+
"name": "MyElement",
4138
"module": "fixtures/-default/package/bar.js"
4239
}
4340
}
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
@customElement("customelement-schema-viewer")
2-
export class CustomElementSchemaViewerElement extends LitElement {
3-
/**
4-
* Any valid path to load a JSON file that adheres to the custom element manifest schema: {@link https://github.com/webcomponents/custom-elements-manifest/}
5-
*/
6-
src;
7-
}
1+
2+
import { LitElement } from 'lit';
3+
4+
/**
5+
* Some information here.
6+
*/
7+
class MyCustomEvent extends CustomEvent {
8+
constructor(eventInit) {
9+
super('my-custom-event', eventInit);
10+
}
11+
}
12+
13+
export class MyElement extends LitElement {
14+
myMethod() {
15+
// FAILS HERE because no `type` argument is being passed to `MyCustomEvent`.
16+
this.dispatchEvent(new MyCustomEvent());
17+
}
18+
}

packages/analyzer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@custom-elements-manifest/analyzer",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "",
55
"license": "MIT",
66
"type": "module",

packages/analyzer/src/features/analyse-phase/creators/createClass.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ function eventsVisitor(source, classTemplate) {
151151
if (isDispatchEvent(node)) {
152152
node?.arguments?.forEach((arg) => {
153153
if (arg.kind === ts.SyntaxKind.NewExpression) {
154-
const eventName = arg.arguments[0].text;
155-
154+
/** e.g. `selected-changed` */
155+
const eventName = arg?.arguments?.[0]?.text;
156156
/**
157157
* Check if event already exists
158158
*/
159159
const eventExists = classTemplate?.events?.some(event => event.name === eventName);
160160

161161
if(!eventExists) {
162162
let eventDoc = {
163-
name: eventName,
163+
...(eventName ? {name: eventName} : {}),
164164
type: {
165165
text: arg.expression.text,
166166
},

0 commit comments

Comments
 (0)