Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

BREAKING: correct nodes TSConstructorType and TSConstructorType #74

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ast-node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export const AST_NODE_TYPES: { [key: string]: string } = {
TSBigIntKeyword: 'TSBigIntKeyword',
TSConditionalType: 'TSConditionalType',
TSConstructorType: 'TSConstructorType',
TSConstructSignature: 'TSConstructSignature',
TSCallSignatureDeclaration: 'TSCallSignatureDeclaration',
TSConstructSignatureDeclaration: 'TSConstructSignatureDeclaration',
TSDeclareKeyword: 'TSDeclareKeyword',
TSDeclareFunction: 'TSDeclareFunction',
TSEnumDeclaration: 'TSEnumDeclaration',
Expand Down
15 changes: 11 additions & 4 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2450,13 +2450,20 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
break;
}

case SyntaxKind.ConstructSignature: {
case SyntaxKind.ConstructSignature:
case SyntaxKind.CallSignature: {
Object.assign(result, {
type: AST_NODE_TYPES.TSConstructSignature,
params: convertParameters(node.parameters),
typeAnnotation: node.type ? convertTypeAnnotation(node.type) : null
type:
node.kind === SyntaxKind.ConstructSignature
? AST_NODE_TYPES.TSConstructSignatureDeclaration
: AST_NODE_TYPES.TSCallSignatureDeclaration,
params: convertParameters(node.parameters)
});

if (node.type) {
(result as any).returnType = convertTypeAnnotation(node.type);
}

if (node.typeParameters) {
result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
Expand Down
26 changes: 26 additions & 0 deletions tests/ast-alignment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,32 @@ export function preprocessBabylonAST(ast: any): any {
BooleanLiteral(node: any) {
node.type = 'Literal';
node.raw = String(node.value);
},
/**
* Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231
*/
TSCallSignatureDeclaration(node: any) {
if (node.typeAnnotation) {
node.returnType = node.typeAnnotation;
delete node.typeAnnotation;
}
if (node.parameters) {
node.params = node.parameters;
delete node.parameters;
}
},
/**
* Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9231
*/
TSConstructSignatureDeclaration(node: any) {
if (node.typeAnnotation) {
node.returnType = node.typeAnnotation;
delete node.typeAnnotation;
}
if (node.parameters) {
node.params = node.parameters;
delete node.parameters;
}
}
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type foo = {
<T>(a: string): string
new<T>(a: string): string
}
4 changes: 4 additions & 0 deletions tests/fixtures/typescript/basics/call-signatures.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type foo = {
(a: string): string
new(a: string): string
}
4 changes: 4 additions & 0 deletions tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,10 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntaticAndSemanticIssues" en

exports[`Parse all fixtures with "errorOnTypeScriptSyntaticAndSemanticIssues" enabled fixtures/typescript/basics/async-function-with-var-declaration.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntaticAndSemanticIssues" enabled fixtures/typescript/basics/call-signatures.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntaticAndSemanticIssues" enabled fixtures/typescript/basics/call-signatures-with-generics.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntaticAndSemanticIssues" enabled fixtures/typescript/basics/cast-as-expression.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntaticAndSemanticIssues" enabled fixtures/typescript/basics/cast-as-multi.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Loading