Skip to content

Commit

Permalink
#89, rewrite Class*Question interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvincent committed Mar 31, 2024
1 parent b2ec88e commit c5a0c0a
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 116 deletions.
41 changes: 13 additions & 28 deletions dist/exports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2243,43 +2243,28 @@ interface MemberedStatementsKey {
readonly groupType: TypeMemberImpl | undefined;
}

type ClassMemberQuestion<
StructureProperty extends string,
ClassMemberType extends ClassMemberImpl,
Returns,
> = Record<
StructureProperty,
(
isStatic: boolean,
kind: ClassMemberType["kind"],
memberName: string,
) => Returns
>;

interface ClassAbstractMemberQuestion {
isAbstract(
kind: Exclude<ClassMemberImpl, ConstructorDeclarationImpl>["kind"],
memberName: string,
): boolean;
}

type ClassAsyncMethodQuestion = ClassMemberQuestion<
"isAsync",
MethodDeclarationImpl,
boolean
>;
interface ClassAsyncMethodQuestion {
isAsync(isStatic: boolean, methodName: string): boolean;
}

type ClassGeneratorMethodQuestion = ClassMemberQuestion<
"isGenerator",
MethodDeclarationImpl,
boolean
>;
interface ClassGeneratorMethodQuestion {
isGenerator(isStatic: boolean, methodName: string): boolean;
}

type ClassScopeMemberQuestion = ClassMemberQuestion<
"getScope",
ClassMemberImpl,
Scope | undefined
>;
interface ClassScopeMemberQuestion {
getScope(
isStatic: boolean,
kind: ClassMemberImpl["kind"],
memberName: string,
): Scope | undefined;
}

interface ClassStatementsGetter {
getStatements(
Expand Down
4 changes: 2 additions & 2 deletions dist/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5738,10 +5738,10 @@ class MemberedTypeToClass {
const methods = members.filter((member) => member.kind === StructureKind.Method);
methods.forEach((method) => {
if (this.#isAsyncCallback) {
method.isAsync = this.#isAsyncCallback.isAsync(method.isStatic, method.kind, method.name);
method.isAsync = this.#isAsyncCallback.isAsync(method.isStatic, method.name);
}
if (this.#isGeneratorCallback) {
method.isGenerator = this.#isGeneratorCallback.isGenerator(method.isStatic, method.kind, method.name);
method.isGenerator = this.#isGeneratorCallback.isGenerator(method.isStatic, method.name);
}
});
}
Expand Down
23 changes: 23 additions & 0 deletions docs/api/ts-morph-structures.classasyncmethodquestion.isasync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [ts-morph-structures](./ts-morph-structures.md) &gt; [ClassAsyncMethodQuestion](./ts-morph-structures.classasyncmethodquestion.md) &gt; [isAsync](./ts-morph-structures.classasyncmethodquestion.isasync.md)

## ClassAsyncMethodQuestion.isAsync() method

**Signature:**

```typescript
isAsync(isStatic: boolean, methodName: string): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| isStatic | boolean | |
| methodName | string | |

**Returns:**

boolean

15 changes: 8 additions & 7 deletions docs/api/ts-morph-structures.classasyncmethodquestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

[Home](./index.md) &gt; [ts-morph-structures](./ts-morph-structures.md) &gt; [ClassAsyncMethodQuestion](./ts-morph-structures.classasyncmethodquestion.md)

## ClassAsyncMethodQuestion type
## ClassAsyncMethodQuestion interface

**Signature:**

```typescript
export type ClassAsyncMethodQuestion = ClassMemberQuestion<
"isAsync",
MethodDeclarationImpl,
boolean
>;
export interface ClassAsyncMethodQuestion
```
**References:** [MethodDeclarationImpl](./ts-morph-structures.methoddeclarationimpl.md)

## Methods

| Method | Description |
| --- | --- |
| [isAsync(isStatic, methodName)](./ts-morph-structures.classasyncmethodquestion.isasync.md) | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [ts-morph-structures](./ts-morph-structures.md) &gt; [ClassGeneratorMethodQuestion](./ts-morph-structures.classgeneratormethodquestion.md) &gt; [isGenerator](./ts-morph-structures.classgeneratormethodquestion.isgenerator.md)

## ClassGeneratorMethodQuestion.isGenerator() method

**Signature:**

```typescript
isGenerator(isStatic: boolean, methodName: string): boolean;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| isStatic | boolean | |
| methodName | string | |

**Returns:**

boolean

15 changes: 8 additions & 7 deletions docs/api/ts-morph-structures.classgeneratormethodquestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

[Home](./index.md) &gt; [ts-morph-structures](./ts-morph-structures.md) &gt; [ClassGeneratorMethodQuestion](./ts-morph-structures.classgeneratormethodquestion.md)

## ClassGeneratorMethodQuestion type
## ClassGeneratorMethodQuestion interface

**Signature:**

```typescript
export type ClassGeneratorMethodQuestion = ClassMemberQuestion<
"isGenerator",
MethodDeclarationImpl,
boolean
>;
export interface ClassGeneratorMethodQuestion
```
**References:** [MethodDeclarationImpl](./ts-morph-structures.methoddeclarationimpl.md)

## Methods

| Method | Description |
| --- | --- |
| [isGenerator(isStatic, methodName)](./ts-morph-structures.classgeneratormethodquestion.isgenerator.md) | |

28 changes: 28 additions & 0 deletions docs/api/ts-morph-structures.classscopememberquestion.getscope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [ts-morph-structures](./ts-morph-structures.md) &gt; [ClassScopeMemberQuestion](./ts-morph-structures.classscopememberquestion.md) &gt; [getScope](./ts-morph-structures.classscopememberquestion.getscope.md)

## ClassScopeMemberQuestion.getScope() method

**Signature:**

```typescript
getScope(
isStatic: boolean,
kind: ClassMemberImpl["kind"],
memberName: string,
): Scope | undefined;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| isStatic | boolean | |
| kind | [ClassMemberImpl](./ts-morph-structures.classmemberimpl.md)<!-- -->\["kind"\] | |
| memberName | string | |

**Returns:**

Scope \| undefined

15 changes: 8 additions & 7 deletions docs/api/ts-morph-structures.classscopememberquestion.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

[Home](./index.md) &gt; [ts-morph-structures](./ts-morph-structures.md) &gt; [ClassScopeMemberQuestion](./ts-morph-structures.classscopememberquestion.md)

## ClassScopeMemberQuestion type
## ClassScopeMemberQuestion interface

**Signature:**

```typescript
export type ClassScopeMemberQuestion = ClassMemberQuestion<
"getScope",
ClassMemberImpl,
Scope | undefined
>;
export interface ClassScopeMemberQuestion
```
**References:** [ClassMemberImpl](./ts-morph-structures.classmemberimpl.md)

## Methods

| Method | Description |
| --- | --- |
| [getScope(isStatic, kind, memberName)](./ts-morph-structures.classscopememberquestion.getscope.md) | |

6 changes: 3 additions & 3 deletions docs/api/ts-morph-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@
| [AsyncableNodeStructureClassIfc](./ts-morph-structures.asyncablenodestructureclassifc.md) | |
| [CallSignatureDeclarationStructureClassIfc](./ts-morph-structures.callsignaturedeclarationstructureclassifc.md) | |
| [ClassAbstractMemberQuestion](./ts-morph-structures.classabstractmemberquestion.md) | |
| [ClassAsyncMethodQuestion](./ts-morph-structures.classasyncmethodquestion.md) | |
| [ClassDeclarationStructureClassIfc](./ts-morph-structures.classdeclarationstructureclassifc.md) | |
| [ClassDeclarationWithImplementsTypeStructures](./ts-morph-structures.classdeclarationwithimplementstypestructures.md) | |
| [ClassGeneratorMethodQuestion](./ts-morph-structures.classgeneratormethodquestion.md) | |
| [ClassScopeMemberQuestion](./ts-morph-structures.classscopememberquestion.md) | |
| [ClassStatementsGetter](./ts-morph-structures.classstatementsgetter.md) | |
| [ClassStaticBlockDeclarationStructureClassIfc](./ts-morph-structures.classstaticblockdeclarationstructureclassifc.md) | |
| [ConditionalTypeStructureParts](./ts-morph-structures.conditionaltypestructureparts.md) | |
Expand Down Expand Up @@ -182,12 +185,9 @@

| Type Alias | Description |
| --- | --- |
| [ClassAsyncMethodQuestion](./ts-morph-structures.classasyncmethodquestion.md) | |
| [ClassFieldStatement](./ts-morph-structures.classfieldstatement.md) | |
| [ClassGeneratorMethodQuestion](./ts-morph-structures.classgeneratormethodquestion.md) | |
| [ClassMemberImpl](./ts-morph-structures.classmemberimpl.md) | |
| [ClassMemberStructureImpls](./ts-morph-structures.classmemberstructureimpls.md) | |
| [ClassScopeMemberQuestion](./ts-morph-structures.classscopememberquestion.md) | |
| [InterfaceMemberStructureImpls](./ts-morph-structures.interfacememberstructureimpls.md) | |
| [JsxStructureImpls](./ts-morph-structures.jsxstructureimpls.md) | |
| [NamedClassMemberImpl](./ts-morph-structures.namedclassmemberimpl.md) | |
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/MemberedTypeToClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,11 @@ export interface ClassAbstractMemberQuestion {
}

export interface ClassAsyncMethodQuestion {
isAsync(isStatic: boolean, kind: StructureKind.Method, memberName: string): boolean;
isAsync(isStatic: boolean, memberName: string): boolean;
}

export interface ClassGeneratorMethodQuestion {
isGenerator(isStatic: boolean, kind: StructureKind.Method, memberName: string): boolean;
isGenerator(isStatic: boolean, memberName: string): boolean;
}

export interface ClassScopeMemberQuestion {
Expand Down Expand Up @@ -547,6 +547,6 @@ Some time ago, [a TypeScript bug on "static implements"](https://github.com/micr

You can do dumb things with ts-morph-structures, like provide a getter and a property with the same name. You can do the same dumb things with ts-morph. The utilities here don't try very hard to protect you from this.

## Enjoy!
## Enjoy

Please, let me know of any pain points you encounter - and suggestions for improving them. Unlike the structure classes, these are more complex. I can add new features as necessary.
4 changes: 2 additions & 2 deletions stage_2_integration/source/toolbox/MemberedTypeToClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,12 @@ export default class MemberedTypeToClass {
methods.forEach(method => {
if (this.#isAsyncCallback) {
method.isAsync = this.#isAsyncCallback.isAsync(
method.isStatic, method.kind, method.name
method.isStatic, method.name
);
}
if (this.#isGeneratorCallback) {
method.isGenerator = this.#isGeneratorCallback.isGenerator(
method.isStatic, method.kind, method.name
method.isStatic, method.name
);
}
});
Expand Down
41 changes: 19 additions & 22 deletions stage_2_integration/source/toolbox/types/toolbox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,34 @@ export interface MemberedStatementsKey {
readonly groupType: TypeMemberImpl | undefined;
}

type ClassMemberQuestion<
StructureProperty extends string,
ClassMemberType extends ClassMemberImpl,
Returns,
> = Record<
StructureProperty,
(
isStatic: boolean,
kind: ClassMemberType["kind"],
memberName: string,
) => Returns
>;

export interface ClassAbstractMemberQuestion {
isAbstract(
kind: Exclude<ClassMemberImpl, ConstructorDeclarationImpl>["kind"],
memberName: string
): boolean
}

export type ClassAsyncMethodQuestion = ClassMemberQuestion<
"isAsync", MethodDeclarationImpl, boolean
>;
export interface ClassAsyncMethodQuestion {
isAsync(
isStatic: boolean,
methodName: string,
): boolean;
}

export type ClassGeneratorMethodQuestion = ClassMemberQuestion<
"isGenerator", MethodDeclarationImpl, boolean
>;
export interface ClassGeneratorMethodQuestion {
isGenerator(
isStatic: boolean,
methodName: string,
): boolean
}

export type ClassScopeMemberQuestion = ClassMemberQuestion<
"getScope", ClassMemberImpl, Scope | undefined
>;
export interface ClassScopeMemberQuestion {
getScope(
isStatic: boolean,
kind: ClassMemberImpl["kind"],
memberName: string,
): Scope | undefined;
}

export interface ClassStatementsGetter {
getStatements(key: MemberedStatementsKey): readonly stringWriterOrStatementImpl[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,12 @@ export default class MemberedTypeToClass {
if (this.#isAsyncCallback) {
method.isAsync = this.#isAsyncCallback.isAsync(
method.isStatic,
method.kind,
method.name,
);
}
if (this.#isGeneratorCallback) {
method.isGenerator = this.#isGeneratorCallback.isGenerator(
method.isStatic,
method.kind,
method.name,
);
}
Expand Down
Loading

0 comments on commit c5a0c0a

Please sign in to comment.