Skip to content

Commit

Permalink
bug: avoid trying to get properties of HTMLElement types
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarluedke committed Mar 9, 2024
1 parent cd14340 commit a20054b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"compile": "tsc",
"prepare": "tsc",
"test": "jest",
"lint:js": "eslint . --ext .js,.ts"
"lint:js": "eslint . --ext .js,.ts",
"lint:js:fix": "eslint . --ext .js,.ts --fix"
},
"dependencies": {
"debug": "^4.3.4",
Expand Down
12 changes: 10 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,18 @@ export default class Parser {
};
}

// check if one element has string ending with Element
let isElement = false;
[symbol?.getName(), typeAsString].forEach((v) => {
if (v && v.endsWith('Element')) {
isElement = true;
}
});

if (
symbol &&
this.isInterfaceOrObjectWithOptionalProperties(symbol, type) &&
!/Element$/.test(symbol.getName())
!isElement &&
this.isInterfaceOrObjectWithOptionalProperties(symbol, type)
) {
const props = type.getApparentProperties();
return {
Expand Down
2 changes: 1 addition & 1 deletion tests/__fixtures__/button-args-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ interface ButtonArgs {
* The button component
* @since 1.0.0
*/
export default class Button extends Component<ButtonArgs> { }
export default class Button extends Component<ButtonArgs> {}
2 changes: 1 addition & 1 deletion tests/__fixtures__/button-with-extended-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ interface Signature {
Args: ButtonArgs;
}

export default class ButtonWithExtendedArgs extends Component<Signature> { }
export default class ButtonWithExtendedArgs extends Component<Signature> {}
3 changes: 3 additions & 0 deletions tests/__fixtures__/dropdown.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Component from '@glimmer/component';
import { type ButtonSignature } from './button';
// eslint-disable-next-line
import type { WithBoundArgs, ModifierLike } from '@glint/template';
interface DropdownArgs {
/**
Expand All @@ -8,6 +9,8 @@ interface DropdownArgs {
* @defaultValue true
*/
closeOnItemSelect?: boolean;

someRandomElement?: HTMLElement;
}

interface Transition {
Expand Down
4 changes: 2 additions & 2 deletions tests/__fixtures__/multiple-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ interface Signature {
// eslint-disable-next-line
class NotExportedButton extends Component<Signature> { }

export class ButtonNotDefault extends Component<Signature> { }
export default class ButtonDefault extends Component<Signature> { }
export class ButtonNotDefault extends Component<Signature> {}
export default class ButtonDefault extends Component<Signature> {}
11 changes: 11 additions & 0 deletions tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,17 @@ option allows to choose where it appears from.",
"type": "boolean",
},
},
{
"defaultValue": undefined,
"description": "",
"identifier": "someRandomElement",
"isInternal": false,
"isRequired": false,
"tags": {},
"type": {
"type": "HTMLElement",
},
},
],
"Blocks": [
{
Expand Down
1 change: 1 addition & 0 deletions tests/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path';
// import fs from 'fs';

function inspect(obj: unknown): void {
// eslint-disable-next-line
console.log(util.inspect(obj, false, 15, true));
}

Expand Down

0 comments on commit a20054b

Please sign in to comment.