Skip to content

Commit

Permalink
add printer branches for some TypeScript nodes (#1331)
Browse files Browse the repository at this point in the history
* add TSNeverKeyword

* add TSUndefinedKeyword

* add TSSymbolKeyword

* add TSNonNullExpression

* add TSThisType

* add tests for simple typescript nodes
  • Loading branch information
despairblue authored and vjeux committed Apr 19, 2017
1 parent 88e0041 commit d823fe6
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,16 @@ function genericPrintNoParens(path, options, print, args) {
]);
case "TSFirstTypeNode":
return concat([n.parameterName.name, " is ", path.call(print, "typeAnnotation")])
case "TSNeverKeyword":
return "never";
case "TSUndefinedKeyword":
return "undefined";
case "TSSymbolKeyword":
return "symbol";
case "TSNonNullExpression":
return concat([path.call(print, "expression"), "!"]);
case "TSThisType":
return "this";
// TODO
case "ClassHeritage":
// TODO
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`never.ts 1`] = `
var x: never
var x: never | string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x: never;
var x: never | string;
`;
1 change: 1 addition & 0 deletions tests/typescript/conformance/types/never/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });
2 changes: 2 additions & 0 deletions tests/typescript/conformance/types/never/never.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var x: never
var x: never | string
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`nonNullExpression.ts 1`] = `
var xx = (xx!, xx);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var xx = (xx!, xx);
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var xx = (xx!, xx);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`symbol.ts 1`] = `
var x: symbol
var x: symbol | string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x: symbol;
var x: symbol | string;
`;
1 change: 1 addition & 0 deletions tests/typescript/conformance/types/symbol/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });
2 changes: 2 additions & 0 deletions tests/typescript/conformance/types/symbol/symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var x: symbol
var x: symbol | string
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`thisType.ts 1`] = `
declare class MyArray<T> extends Array<T> {
sort(compareFn?: (a: T, b: T) => number): this;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class MyArray<T> extends Array {
sort(compareFn?: (a: T, b: T) => number): this
}
`;
1 change: 1 addition & 0 deletions tests/typescript/conformance/types/thisType/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });
3 changes: 3 additions & 0 deletions tests/typescript/conformance/types/thisType/thisType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare class MyArray<T> extends Array<T> {
sort(compareFn?: (a: T, b: T) => number): this;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`undefined.ts 1`] = `
var x: undefined
var x: undefined | string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var x: undefined;
var x: undefined | string;
`;
1 change: 1 addition & 0 deletions tests/typescript/conformance/types/undefined/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });
2 changes: 2 additions & 0 deletions tests/typescript/conformance/types/undefined/undefined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var x: undefined
var x: undefined | string

0 comments on commit d823fe6

Please sign in to comment.