Skip to content

Commit 1204fde

Browse files
authored
Merge pull request #29 from open-wc/fix/default-export-handling
fix: improve handling of classes that are default exported
2 parents a2da865 + bffc802 commit 1204fde

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
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: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,64 @@
77
"path": "fixtures/-default/package/bar.js",
88
"declarations": [
99
{
10-
"kind": "function",
11-
"name": "bar"
10+
"kind": "class",
11+
"description": "",
12+
"name": "default",
13+
"cssParts": [
14+
{
15+
"name": "foo"
16+
}
17+
],
18+
"members": [
19+
{
20+
"kind": "field",
21+
"name": "propertyDecorator",
22+
"type": {
23+
"text": "string"
24+
},
25+
"default": "hi"
26+
},
27+
{
28+
"kind": "field",
29+
"name": "mobileopen",
30+
"privacy": "public",
31+
"default": "false"
32+
}
33+
],
34+
"attributes": [
35+
{
36+
"name": "propertyDecorator",
37+
"type": {
38+
"text": "string"
39+
},
40+
"default": "hi",
41+
"fieldName": "propertyDecorator"
42+
},
43+
{
44+
"name": "mobileopen",
45+
"fieldName": "mobileopen"
46+
}
47+
],
48+
"superclass": {
49+
"name": "LitElement"
50+
},
51+
"customElement": true
1252
}
1353
],
1454
"exports": [
1555
{
1656
"kind": "js",
17-
"name": "bar",
57+
"name": "default",
58+
"declaration": {
59+
"name": "default",
60+
"module": "fixtures/-default/package/bar.js"
61+
}
62+
},
63+
{
64+
"kind": "custom-element-definition",
65+
"name": "top-bar",
1866
"declaration": {
19-
"name": "bar",
67+
"name": "TopBar",
2068
"module": "fixtures/-default/package/bar.js"
2169
}
2270
}

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.2.2",
3+
"version": "0.2.3",
44
"description": "",
55
"license": "MIT",
66
"type": "module",

packages/analyzer/src/features/analyse-phase/class-jsdoc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export function classJsDocPlugin() {
1313
analyzePhase({ts, node, moduleDoc}){
1414
switch (node.kind) {
1515
case ts.SyntaxKind.ClassDeclaration:
16-
const className = node?.name?.text;
16+
const hasDefaultModifier = node?.modifiers?.some(mod => ts.SyntaxKind.DefaultKeyword === mod.kind);
17+
const className = hasDefaultModifier ? 'default' : node?.name?.getText();
1718
const classDoc = moduleDoc?.declarations?.find(declaration => declaration.name === className);
1819

1920
/**

packages/analyzer/src/features/framework-plugins/decorators/attr.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export function attrDecoratorPlugin() {
88
analyzePhase({ts, node, moduleDoc}){
99
switch(node.kind) {
1010
case ts.SyntaxKind.ClassDeclaration:
11-
const className = node?.name?.text;
11+
const hasDefaultModifier = node?.modifiers?.some(mod => ts.SyntaxKind.DefaultKeyword === mod.kind);
12+
const className = hasDefaultModifier ? 'default' : node?.name?.getText();
1213
const classDoc = moduleDoc?.declarations?.find(declaration => declaration.name === className);
1314

1415
/**

packages/analyzer/src/features/framework-plugins/lit/property-decorator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export function propertyDecoratorPlugin() {
1414
analyzePhase({ts, node, moduleDoc}){
1515
switch (node.kind) {
1616
case ts.SyntaxKind.ClassDeclaration:
17-
const className = node?.name?.getText();
17+
const hasDefaultModifier = node?.modifiers?.some(mod => ts.SyntaxKind.DefaultKeyword === mod.kind);
18+
const className = hasDefaultModifier ? 'default' : node?.name?.getText();
1819
const currClass = moduleDoc?.declarations?.find(declaration => declaration.name === className);
1920

2021
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export function staticPropertiesPlugin() {
1313
analyzePhase({ts, node, moduleDoc}){
1414
switch (node.kind) {
1515
case ts.SyntaxKind.ClassDeclaration:
16-
const className = node?.name?.getText();
16+
const hasDefaultModifier = node?.modifiers?.some(mod => ts.SyntaxKind.DefaultKeyword === mod.kind);
17+
const className = hasDefaultModifier ? 'default' : node?.name?.getText();
1718
const currClass = moduleDoc?.declarations?.find(declaration => declaration.name === className);
1819

1920
node?.members?.forEach(member => {
@@ -39,7 +40,8 @@ export function staticPropertiesPlugin() {
3940
if(attributeName) {
4041
attribute.name = attributeName;
4142
}
42-
currClass?.attributes.push(attribute);
43+
44+
currClass.attributes = [...(currClass?.attributes || []), attribute]
4345
}
4446

4547
currClass?.members.push(classMember);

packages/analyzer/src/features/framework-plugins/stencil/stencil.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export function stencilPlugin() {
1616
* Add tagName to classDoc, extracted from `@Component({tag: 'foo-bar'})` decorator
1717
* Add custom-element-definition to exports
1818
*/
19-
const className = node?.name?.getText();
20-
2119
const componentDecorator = node?.decorators?.find(decorator('Component'))?.expression;
2220

2321
const tagName = componentDecorator?.arguments?.[0]?.properties?.find(prop => {
2422
return prop?.name?.getText() === 'tag'
2523
})?.initializer?.text;
2624

25+
const hasDefaultModifier = node?.modifiers?.some(mod => ts.SyntaxKind.DefaultKeyword === mod.kind);
26+
const className = hasDefaultModifier ? 'default' : node?.name?.getText();
2727
const currClass = moduleDoc?.declarations?.find(declaration => declaration.name === className);
2828
if(tagName) {
2929
currClass.tagName = tagName;

0 commit comments

Comments
 (0)