Skip to content

Commit e97c1b9

Browse files
committed
fix: avoid duplicate fields in litplugin if class jsdoc is used
1 parent 128d1c6 commit e97c1b9

File tree

7 files changed

+63
-31
lines changed

7 files changed

+63
-31
lines changed

packages/analyzer/custom-elements.json

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,48 @@
77
"path": "fixtures/-default/package/bar.js",
88
"declarations": [
99
{
10-
"kind": "function",
11-
"name": "bar"
10+
"kind": "class",
11+
"description": "",
12+
"name": "CustomElementSchemaViewerElement",
13+
"members": [
14+
{
15+
"type": {
16+
"text": "boolean"
17+
},
18+
"description": "this is desc",
19+
"name": "src",
20+
"kind": "field",
21+
"privacy": "public"
22+
}
23+
],
24+
"attributes": [
25+
{
26+
"name": "src",
27+
"fieldName": "src"
28+
}
29+
],
30+
"superclass": {
31+
"name": "LitElement"
32+
},
33+
"tagName": "customelement-schema-viewer",
34+
"customElement": true
1235
}
1336
],
1437
"exports": [
1538
{
1639
"kind": "js",
17-
"name": "bar",
40+
"name": "CustomElementSchemaViewerElement",
1841
"declaration": {
19-
"name": "bar",
42+
"name": "CustomElementSchemaViewerElement",
2043
"module": "fixtures/-default/package/bar.js"
2144
}
22-
}
23-
]
24-
},
25-
{
26-
"kind": "javascript-module",
27-
"path": "fixtures/-default/package/foo.js",
28-
"declarations": [
45+
},
2946
{
30-
"kind": "function",
31-
"name": "foo"
32-
}
33-
],
34-
"exports": [
35-
{
36-
"kind": "js",
37-
"name": "foo",
47+
"kind": "custom-element-definition",
48+
"name": "customelement-schema-viewer",
3849
"declaration": {
39-
"name": "foo",
40-
"module": "fixtures/-default/package/foo.js"
50+
"name": "CustomElementSchemaViewerElement",
51+
"module": "fixtures/-default/package/bar.js"
4152
}
4253
}
4354
]
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import type foo from 'ts';
2-
import { named } from 'thirdparty';
3-
export function bar() {
1+
/**
2+
* @property {boolean} src this is desc
3+
*/
4+
@customElement("customelement-schema-viewer")
5+
export class CustomElementSchemaViewerElement extends LitElement {
46

7+
8+
static get properties() {
9+
return {
10+
src: { type: Boolean }
11+
}
12+
}
513
}

packages/analyzer/fixtures/-default/package/foo.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/analyzer/fixtures/plugin-lit/fixture/custom-elements.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
{
2727
"kind": "field",
2828
"name": "prop1",
29+
"type": {
30+
"text": "string"
31+
},
32+
"description": "this is the description",
2933
"privacy": "public",
3034
"default": "'foo'"
3135
},

packages/analyzer/fixtures/plugin-lit/output.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
"name": "decoratedPropertyNoAttr"
2525
},
2626
{
27-
"kind": "field",
27+
"type": {
28+
"text": "string"
29+
},
30+
"description": "this is the description",
2831
"name": "prop1",
32+
"kind": "field",
2933
"privacy": "public",
3034
"default": "'foo'"
3135
},

packages/analyzer/fixtures/plugin-lit/package/my-element.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { LitElement, property, customElement } from 'lit-element';
22

3+
/**
4+
* @prop {string} prop1 this is the description
5+
*/
36
@customElement('my-element')
47
class MyElement extends LitElement {
58
static get properties() {

packages/analyzer/src/features/framework-plugins/lit/static-properties.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ export function staticPropertiesPlugin() {
4444
currClass.attributes = [...(currClass?.attributes || []), attribute]
4545
}
4646

47-
currClass?.members.push(classMember);
47+
48+
const existingField = currClass?.members?.find(field => field.name === classMember.name);
49+
50+
if(!existingField) {
51+
currClass.members.push(classMember);
52+
} else {
53+
currClass.members = currClass?.members?.map(field => field.name === classMember.name ? ({...field, ...classMember}) : field);
54+
}
4855
});
4956
return;
5057
}

0 commit comments

Comments
 (0)