Skip to content

Commit

Permalink
add printer branch for TSFirstTypeNode (#1332)
Browse files Browse the repository at this point in the history
* add TSFirstTypeNode

* add test for TSFirstTypeNode
  • Loading branch information
despairblue authored and vjeux committed Apr 19, 2017
1 parent dc499ba commit cb79d82
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/printer.js
Expand Up @@ -1487,7 +1487,11 @@ function genericPrintNoParens(path, options, print, args) {
!shouldTypeScriptTypeAvoidColon(path) &&
// TypeScript should not have a colon before type parameter constraints
!(path.getParentNode().type === "TypeParameter" &&
path.getParentNode().constraint)
path.getParentNode().constraint) &&
// TypeScript should not have a colon in TSFirstTypeNode nodes
// `a is number`
!(path.getParentNode().type === "TypeAnnotation" &&
path.getParentNode().typeAnnotation.type === 'TSFirstTypeNode')
) {
parts.push(": ");
}
Expand Down Expand Up @@ -1922,6 +1926,8 @@ function genericPrintNoParens(path, options, print, args) {
"]: ",
path.call(print, "typeAnnotation")
]);
case "TSFirstTypeNode":
return concat([n.parameterName.name, " is ", path.call(print, "typeAnnotation")])
// TODO
case "ClassHeritage":
// TODO
Expand Down
@@ -0,0 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`firstTypeNode.ts 1`] = `
export function fooWithTypePredicate(a: any): a is number {
return true;
}
export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number {
return true;
}
export function fooWithTypeTypePredicateAndGeneric<T>(a: any): a is T {
return true;
}
export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number {
return true;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export function fooWithTypePredicate(a: any): a is number {
return true;
}
export function fooWithTypePredicateAndMulitpleParams(
a: any,
b: any,
c: any
): a is number {
return true;
}
export function fooWithTypeTypePredicateAndGeneric<T>(a: any): a is T {
return true;
}
export function fooWithTypeTypePredicateAndRestParam(
a: any,
...rest
): a is number {
return true;
}
`;
12 changes: 12 additions & 0 deletions tests/typescript/conformance/types/firstTypeNode/firstTypeNode.ts
@@ -0,0 +1,12 @@
export function fooWithTypePredicate(a: any): a is number {
return true;
}
export function fooWithTypePredicateAndMulitpleParams(a: any, b: any, c: any): a is number {
return true;
}
export function fooWithTypeTypePredicateAndGeneric<T>(a: any): a is T {
return true;
}
export function fooWithTypeTypePredicateAndRestParam(a: any, ...rest): a is number {
return true;
}
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "typescript" });

0 comments on commit cb79d82

Please sign in to comment.