JamesHenry / typescript-estree

:sparkles: A parser that converts TypeScript source code into an ESTree-compatible form
https://jameshenry.blog
Other
84 stars 13 forks source link

BREAKING: correct nodes TSConstructorType and TSConstructorType (variant 1) #60

Closed armano2 closed 5 years ago

armano2 commented 5 years ago

This is breaking change https://github.com/babel/babel/issues/9231 and i'm unsure if we should apply it.

There is alternative way of fixing it #74

Right now we are missing support for TSCallSignature

This PR changes typeAnnotation property to correct returnType, and make it consistent with FunctionExpression, ArrowFunctionExpression, FunctionDeclaration, and so on

fixes: #30

armano2 commented 5 years ago

if you don't think that is a good idea, feel free to close this :>

armano2 commented 5 years ago

74

babel parses CallSignature and ConstructSignature as TSCallSignatureDeclaration and TSConstructSignatureDeclaration and has fields:

  interface foo {
    <P>(x: X): A
  }

right now we are parsing it as typeParameters, (params or parameters) and typeAnnotation


we could align it to what babel expect, by changing types and replacing params with parameters for CallSignature

    case SyntaxKind.CallSignature:
    case SyntaxKind.ConstructSignature: {
      Object.assign(result, {
        type: AST_NODE_TYPES[`TS${SyntaxKind[node.kind]}Declaration`],
        parameters: convertParameters(node.parameters)
      });

      if (node.type) {
        result.typeAnnotation = convertTypeAnnotation(
          node.type
        );
      }

      if (node.typeParameters) {
        result.typeParameters = convertTSTypeParametersToTypeParametersDeclaration(
          node.typeParameters
        );
      }

      break;
    }