From 8a8a67b9fe41c8e35581702852a555d4fc5c3ddc Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sat, 6 May 2017 23:17:48 +1000 Subject: [PATCH] fix(typescript): print typeArguments in TSExpressionWithTypeArguments (#1530) --- src/printer.js | 5 ++- .../compiler/__snapshots__/jsfmt.spec.js.snap | 37 +++++++++++++++++++ .../checkInfiniteExpansionTermination.ts | 16 ++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/typescript/compiler/checkInfiniteExpansionTermination.ts diff --git a/src/printer.js b/src/printer.js index d15644cec..70613a88f 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1590,7 +1590,10 @@ function genericPrintNoParens(path, options, print, args) { case "TSHeritageClause": return join(", ", path.map(print, "types")); case "TSExpressionWithTypeArguments": - return path.call(print, "expression"); + return concat([ + path.call(print, "expression"), + printTypeParameters(path, options, print, "typeArguments") + ]); case "TemplateElement": return join(literalline, n.value.raw.split(/\r?\n/g)); case "TemplateLiteral": diff --git a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap index 94753d21f..bd9506446 100644 --- a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,43 @@ interface i2 { `; +exports[`checkInfiniteExpansionTermination.ts 1`] = ` +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable; // Needed, must be T[] +} + +// Needed +interface ISubject extends IObservable { } + +interface Foo { x } +interface Bar { y } + +var values: IObservable; +var values2: ISubject; +values = values2; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable // Needed, must be T[] +} + +// Needed +interface ISubject extends IObservable {} + +interface Foo { x } +interface Bar { y } + +var values: IObservable; +var values2: ISubject; +values = values2; + +`; + exports[`functionOverloadsOnGenericArity1.ts 1`] = ` // overloading on arity not allowed interface C { diff --git a/tests/typescript/compiler/checkInfiniteExpansionTermination.ts b/tests/typescript/compiler/checkInfiniteExpansionTermination.ts new file mode 100644 index 000000000..8514ebce9 --- /dev/null +++ b/tests/typescript/compiler/checkInfiniteExpansionTermination.ts @@ -0,0 +1,16 @@ +// Regression test for #1002 +// Before fix this code would cause infinite loop + +interface IObservable { + n: IObservable; // Needed, must be T[] +} + +// Needed +interface ISubject extends IObservable { } + +interface Foo { x } +interface Bar { y } + +var values: IObservable; +var values2: ISubject; +values = values2;