diff --git a/src/printer.js b/src/printer.js index cf504dfa..9c005ebb 100644 --- a/src/printer.js +++ b/src/printer.js @@ -770,7 +770,7 @@ function genericPrintNoParens(path, options, print, args) { n.typeParameters ? path.call(print, "typeParameters") : "", " " ); - + if (n.heritage.length) { parts.push( "extends ", @@ -778,9 +778,9 @@ function genericPrintNoParens(path, options, print, args) { " " ); } - + parts.push(path.call(print, "body")); - + return concat(parts); case "ObjectExpression": case "ObjectPattern": @@ -805,7 +805,7 @@ function genericPrintNoParens(path, options, print, args) { const parent = path.getParentNode(0); const parentIsUnionTypeAnnotation = parent.type === "UnionTypeAnnotation"; let propertiesField; - + if (n.type === 'TSTypeLiteral') { propertiesField = "members"; } else if (n.type === "TSInterfaceBody") { @@ -1129,8 +1129,7 @@ function genericPrintNoParens(path, options, print, args) { parts = [ isNodeStartingWithDeclare(n, options) ? "declare " : "", n.kind, - " ", - printed[0], + printed.length ? concat([" ", printed[0]]) : "", indent(concat(printed.slice(1).map(p => concat([",", line, p])))) ]; @@ -1629,11 +1628,11 @@ function genericPrintNoParens(path, options, print, args) { return concat(parts); case "TSInterfaceHeritage": parts.push(path.call(print, "id")); - + if (n.typeParameters) { parts.push(path.call(print, "typeParameters")); } - + return concat(parts); case "TSHeritageClause": return join(", ", path.map(print, "types")); @@ -2207,7 +2206,11 @@ function genericPrintNoParens(path, options, print, args) { path.call(print, "typeAnnotation") ]); case "TSFirstTypeNode": - return concat([n.parameterName.name, " is ", path.call(print, "typeAnnotation")]) + return concat([ + path.call(print, "parameterName"), + " is ", + path.call(print, "typeAnnotation") + ]); case "TSNonNullExpression": return concat([path.call(print, "expression"), "!"]); case "TSThisType": @@ -2748,7 +2751,7 @@ function printArgumentsList(path, options, print) { function printFunctionTypeParameters(path, options, print) { const fun = path.getValue(); const paramsFieldIsArray = Array.isArray(fun["typeParameters"]) - + if (fun.typeParameters) { // for TSFunctionType typeParameters is an array // for FunctionTypeAnnotation it's a single node diff --git a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap index 2fd97e68..1b16b7d9 100644 --- a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap @@ -194,6 +194,12 @@ interface i2 { `; +exports[`downlevelLetConst1.ts 1`] = ` +const~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const; + +`; + exports[`errorOnInitializerInInterfaceProperty.ts 1`] = ` interface Foo { bar: number = 5; diff --git a/tests/typescript/compiler/downlevelLetConst1.ts b/tests/typescript/compiler/downlevelLetConst1.ts new file mode 100644 index 00000000..8baacf4e --- /dev/null +++ b/tests/typescript/compiler/downlevelLetConst1.ts @@ -0,0 +1 @@ +const \ No newline at end of file diff --git a/tests/typescript/conformance/declarationEmit/typePredicates/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/declarationEmit/typePredicates/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..475e25a3 --- /dev/null +++ b/tests/typescript/conformance/declarationEmit/typePredicates/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`declarationEmitThisPredicatesWithPrivateName01.ts 1`] = ` +// @declaration: true +// @module: commonjs + +export class C { + m(): this is D { + return this instanceof D; + } +} + +class D extends C { +}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// @declaration: true +// @module: commonjs + +export class C { + m(): this is D { + return this instanceof D; + } +} + +class D extends C {} + +`; diff --git a/tests/typescript/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts b/tests/typescript/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts new file mode 100644 index 00000000..461c7d17 --- /dev/null +++ b/tests/typescript/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts @@ -0,0 +1,11 @@ +// @declaration: true +// @module: commonjs + +export class C { + m(): this is D { + return this instanceof D; + } +} + +class D extends C { +} \ No newline at end of file diff --git a/tests/typescript/conformance/declarationEmit/typePredicates/jsfmt.spec.js b/tests/typescript/conformance/declarationEmit/typePredicates/jsfmt.spec.js new file mode 100644 index 00000000..bc085c48 --- /dev/null +++ b/tests/typescript/conformance/declarationEmit/typePredicates/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "typescript" }); diff --git a/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..d0586696 --- /dev/null +++ b/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,31 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`parserES5ForOfStatement2.ts 1`] = ` +//@target: ES5 +for (var of X) { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//@target: ES5 +for (var of X) { +} + +`; + +exports[`parserES5ForOfStatement21.ts 1`] = ` +//@target: ES5 +for (var of of) { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//@target: ES5 +for (var of of) { +} + +`; + +exports[`parserForInStatement2.ts 1`] = ` +for (var in X) { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +for (var in X) { +} + +`; diff --git a/tests/typescript/conformance/parser/ecmascript5/Statements/jsfmt.spec.js b/tests/typescript/conformance/parser/ecmascript5/Statements/jsfmt.spec.js new file mode 100644 index 00000000..bc085c48 --- /dev/null +++ b/tests/typescript/conformance/parser/ecmascript5/Statements/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "typescript" }); diff --git a/tests/typescript/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement2.ts b/tests/typescript/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement2.ts new file mode 100644 index 00000000..d67611bd --- /dev/null +++ b/tests/typescript/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement2.ts @@ -0,0 +1,3 @@ +//@target: ES5 +for (var of X) { +} diff --git a/tests/typescript/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement21.ts b/tests/typescript/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement21.ts new file mode 100644 index 00000000..6d28e4c0 --- /dev/null +++ b/tests/typescript/conformance/parser/ecmascript5/Statements/parserES5ForOfStatement21.ts @@ -0,0 +1,2 @@ +//@target: ES5 +for (var of of) { } diff --git a/tests/typescript/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts b/tests/typescript/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts new file mode 100644 index 00000000..3bf9bc29 --- /dev/null +++ b/tests/typescript/conformance/parser/ecmascript5/Statements/parserForInStatement2.ts @@ -0,0 +1,2 @@ +for (var in X) { +}