More factory functions#15531
Conversation
|
|
||
| export function createKeywordTypeNode(kind: KeywordTypeNode["kind"]) { | ||
| return <KeywordTypeNode>createSynthesizedNode(kind); | ||
| export function createMethod(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, asteriskToken: AsteriskToken | undefined, name: string | PropertyName, questionToken: QuestionToken | undefined, typeParameters: TypeParameterDeclaration[] | undefined, parameters: ParameterDeclaration[], type: TypeNode | undefined, body: Block | undefined) { |
There was a problem hiding this comment.
why make the Declaration part of the name implicit?
There was a problem hiding this comment.
Consistency with most other factory functions. Most of the time we're transforming to JavaScript, and JavaScript doesn't have method signatures.
| export function createParenthesizedType(type: TypeNode) { | ||
| const node = <ParenthesizedTypeNode>createSynthesizedNode(SyntaxKind.ParenthesizedType); | ||
| /* @internal */ | ||
| export function createSignatureDeclaration(kind: SyntaxKind, typeParameters: TypeParameterDeclaration[] | undefined, parameters: ParameterDeclaration[], type: TypeNode | undefined) { |
There was a problem hiding this comment.
In analogue to the above, should this be createSignature?
There was a problem hiding this comment.
Per above, signatures are purely TypeScript. We can probably change the name if only to make it more concise.
| // Type Elements | ||
| // Signature elements | ||
|
|
||
| export function createSignatureDeclaration(kind: SyntaxKind, typeParameters: TypeParameterDeclaration[] | undefined, parameters: ParameterDeclaration[], type: TypeNode | undefined) { |
There was a problem hiding this comment.
I can't really tell from the diff if the code was merely re-ordered or if there are more substantive changes. Looks similar on the LHS and RHS though.
There was a problem hiding this comment.
Mostly reordered to align with the order in SyntaxKind. It makes finding things easier.
This adds a number of missing factory functions for anyone writing custom transformers, as well as performs some cleanup in factory.ts.
Note, there are a few breaking API name changes in this PR as part of the public factory functions. I feel this is acceptable as custom transforms are still a fairly experimental feature, though if necessary we could export aliases for the renamed functions for backwards compatibility.
There's also a small change to the transform unit tests so that they aren't dependent on the new-line format of the host platform running the tests.
This builds on #15500 and #15511.