Skip to content

Commit

Permalink
fix: mark fields and methods starting with # as private
Browse files Browse the repository at this point in the history
  • Loading branch information
thepassle committed May 7, 2024
1 parent ac5227b commit a61e373
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 13 deletions.
3 changes: 3 additions & 0 deletions packages/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Release 0.10.2
- Mark fields and methods starting with `#` as `private`

## Release 0.10.1
- Escape newlines and whitespaces from object output

Expand Down
3 changes: 3 additions & 0 deletions packages/analyzer/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203730,6 +203730,9 @@ function handleModifiers(doc, node) {
break;
}
});
if (node.name?.text.startsWith("#")) {
doc.privacy = "private";
}
return doc;
}
function handleJsDoc(doc, node) {
Expand Down
9 changes: 3 additions & 6 deletions packages/analyzer/custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
"name": "Foo",
"members": [
{
"kind": "field",
"name": "foo",
"type": {
"text": "object"
},
"default": "{ foo: 'bar' }"
"kind": "method",
"name": "#foo",
"privacy": "private"
}
],
"superclass": {
Expand Down
7 changes: 1 addition & 6 deletions packages/analyzer/fixtures/01-class/-default/package/bar.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

export class Foo extends HTMLElement{
constructor() {
super();
this.foo = {
foo: 'bar'
};
}
#foo() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@
"kind": "field",
"name": "arrowfn"
},
{
"kind": "field",
"name": "#truePrivateField",
"privacy": "private",
"type": {
"text": "number"
},
"default": "1"
},
{
"kind": "method",
"name": "#truePrivateMethod",
"privacy": "private"
},
{
"kind": "field",
"name": "commaprop1",
Expand Down
14 changes: 14 additions & 0 deletions packages/analyzer/fixtures/01-class/01-fields/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,20 @@
"kind": "field",
"name": "arrowfn"
},
{
"kind": "field",
"name": "#truePrivateField",
"privacy": "private",
"type": {
"text": "number"
},
"default": "1"
},
{
"kind": "method",
"name": "#truePrivateMethod",
"privacy": "private"
},
{
"kind": "field",
"name": "commaprop1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ class MyEl extends HTMLElement {
console.log('dont output me')
}

#truePrivateField = 1;
#truePrivateMethod() {}

constructor() {
super();
this.prop2 = 'default';
Expand Down
2 changes: 1 addition & 1 deletion packages/analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@custom-elements-manifest/analyzer",
"version": "0.10.1",
"version": "0.10.2",
"description": "",
"license": "MIT",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function handleModifiers(doc, node) {
}
});

if (node.name?.text.startsWith('#')) {
doc.privacy = 'private';
}

return doc;
}

Expand Down

0 comments on commit a61e373

Please sign in to comment.