Skip to content

Commit

Permalink
fix(ts-estree): align typeArguments and typeParameters across nodes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and JamesHenry committed Feb 7, 2019
1 parent 690bff3 commit 3306198
Show file tree
Hide file tree
Showing 13 changed files with 4,605 additions and 12 deletions.
2,284 changes: 2,284 additions & 0 deletions packages/parser/tests/lib/__snapshots__/typescript.ts.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo<>();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
new Foo<>()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function f1<>() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class foo {
constructor<>() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const foo = function<>() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface foo {
test<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class foo {
test<>() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function f1<>() {}
22 changes: 11 additions & 11 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export class Converter {
}

// Process typeParameters
if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -897,7 +897,7 @@ export class Converter {
}

// Process typeParameters
if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
method.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -1003,7 +1003,7 @@ export class Converter {
});

// Process typeParameters
if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
constructor.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -1060,7 +1060,7 @@ export class Converter {
}

// Process typeParameters
if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -1159,7 +1159,7 @@ export class Converter {
}

// Process typeParameters
if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -1368,7 +1368,7 @@ export class Converter {
}
}

if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -1640,7 +1640,7 @@ export class Converter {
callee: this.convertChild(node.expression),
arguments: node.arguments.map(el => this.convertChild(el))
});
if (node.typeArguments && node.typeArguments.length) {
if (node.typeArguments) {
result.typeParameters = this.convertTypeArgumentsToTypeParameters(
node.typeArguments
);
Expand All @@ -1656,7 +1656,7 @@ export class Converter {
? node.arguments.map(el => this.convertChild(el))
: []
});
if (node.typeArguments && node.typeArguments.length) {
if (node.typeArguments) {
result.typeParameters = this.convertTypeArgumentsToTypeParameters(
node.typeArguments
);
Expand Down Expand Up @@ -2060,7 +2060,7 @@ export class Converter {
}

// Process typeParameters
if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down Expand Up @@ -2216,7 +2216,7 @@ export class Converter {
expression: this.convertChild(node.expression)
});

if (node.typeArguments && node.typeArguments.length) {
if (node.typeArguments) {
result.typeParameters = this.convertTypeArgumentsToTypeParameters(
node.typeArguments
);
Expand All @@ -2236,7 +2236,7 @@ export class Converter {
id: this.convertChild(node.name)
});

if (node.typeParameters && node.typeParameters.length) {
if (node.typeParameters) {
result.typeParameters = this.convertTSTypeParametersToTypeParametersDeclaration(
node.typeParameters
);
Expand Down
5 changes: 4 additions & 1 deletion packages/typescript-estree/tests/ast-alignment/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ export function preprocessBabylonAST(ast: any): any {
/**
* babel issue: ranges of typeParameters are not included in FunctionExpression range
*/
if (node.typeParameters) {
if (
node.typeParameters &&
node.typeParameters.range[0] < node.range[0]
) {
node.range[0] = node.typeParameters.range[0];
node.loc.start = Object.assign({}, node.typeParameters.loc.start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,22 @@ Object {

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-call-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-arguments-in-new-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-arrow-function.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-constructor.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-function-expression.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/empty-type-parameters-in-method-signature.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/errorRecovery/enum-with-keywords.src 1`] = `
Object {
"column": 7,
Expand Down
Loading

0 comments on commit 3306198

Please sign in to comment.